Esempio n. 1
0
        public static void NextGame(Update update, string[] args)
        {
            var groupId = update.Message.Chat.Id;

            using (var db = new WWContext())
            {
                var grp = db.Groups.FirstOrDefault(x => x.GroupId == groupId);
                if (grp == null)
                {
                    grp = MakeDefaultGroup(groupId, update.Message.Chat.Title, "nextgame");
                    db.Groups.Add(grp);
                    db.SaveChanges();
                }

                //check nodes to see if player is in a game
                //node = GetPlayerNode(update.Message.From.Id);
                var game = GetGroupNodeAndGame(update.Message.Chat.Id);
                if (game != null && (game?.Users.Contains(update.Message.From.Id) ?? false) &&
                    game?.GroupId != update.Message.Chat.Id)
                {
                    //player is already in a game, and alive
                    Send(
                        GetLocaleString("AlreadyInGame", grp.Language ?? "English",
                                        game.ChatGroup.ToBold()), update.Message.Chat.Id);
                    return;
                }

                var button = new InlineKeyboardMarkup(new InlineKeyboardButton[]
                {
                    new InlineKeyboardCallbackButton(GetLocaleString("Cancel", grp.Language), $"stopwaiting|{groupId}")
                });

                if (db.NotifyGame.Any(x => x.GroupId == groupId && x.UserId == update.Message.From.Id))
                {
                    Send(GetLocaleString("AlreadyOnWaitList", grp.Language, grp.Name.ToBold()),
                         update.Message.From.Id, customMenu: button);
                }
                else
                {
                    db.NotifyGame.Add(new NotifyGame
                    {
                        UserId  = update.Message.From.Id,
                        GroupId = groupId
                    });

                    db.SaveChanges();

                    Send(GetLocaleString("AddedToWaitList", grp.Language, grp.Name.ToBold()),
                         update.Message.From.Id, customMenu: button);
                }
            }
        }
Esempio n. 2
0
        private static void ApiOnStatusChanged(object sender, StatusChangeEventArgs statusChangeEventArgs)
        {
            try
            {
                using (var db = new WWContext())
                {
                    var id =
#if RELEASE
                        1;
#elif RELEASE2
                        2;
#elif BETA
                        3;
#else
                        4;
#endif
                    if (id == 4)
                    {
                        return;
                    }
                    var b = db.BotStatus.Find(id);
                    b.BotStatus   = statusChangeEventArgs.Status.ToString();
                    CurrentStatus = b.BotStatus;
                    db.SaveChanges();
                }
            }
            finally
            {
            }
        }
Esempio n. 3
0
        public static void Update(Update update, string[] args)
        {
            if (update.Message.Date > DateTime.UtcNow.AddSeconds(-3))
            {
                Process.Start(Path.Combine(Bot.RootDirectory, "Resources\\update.exe"), update.Message.Chat.Id.ToString());
                Bot.Running     = false;
                Program.Running = false;
                Bot.Api.StopReceiving();
                //Thread.Sleep(500);
                using (var db = new WWContext())
                {
                    var bot =
#if DEBUG
                        4;
#elif BETA
                        3;
#elif RELEASE
                        1;
#elif RELEASE2
                        2;
#endif
                    db.BotStatus.Find(bot).BotStatus = "Updating";
                    db.SaveChanges();
                }
                Environment.Exit(1);
            }
        }
Esempio n. 4
0
        public static void ForceStart(Update update, string[] args)
        {
            var id = update.Message.Chat.Id;

            using (var db = new WWContext())
            {
                var grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
                if (grp == null)
                {
                    grp = MakeDefaultGroup(id, update.Message.Chat.Title, "forcestart");
                    db.Groups.Add(grp);
                    db.SaveChanges();
                }

                var game = GetGroupNodeAndGame(update.Message.Chat.Id);
                if (game != null)
                {
                    //send forcestart
                    game.ForceStart();
                }
                else
                {
                    Send(GetLocaleString("NoGame", grp.Language), id);
                }
            }
        }
Esempio n. 5
0
 public static void ShowRank(Update update, string[] args)
 {
     using (var db = new WWContext())
     {
         var dbp = db.Players.FirstOrDefault(x => x.TelegramId == update.Message.From.Id);
         if (dbp != null)
         {
             if (dbp.Score < 1000)
             {
                 Send(GetLocaleString("CantShowRank", "Spanish.xml"), update.Message.From.Id);
             }
             else
             {
                 var show = dbp.ShowRank ?? true;
                 if (show)
                 {
                     dbp.ShowRank = false;
                     Send(GetLocaleString("ShowRankDisabled", "Spanish.xml"), update.Message.From.Id);
                 }
                 else
                 {
                     dbp.ShowRank = true;
                     Send(GetLocaleString("ShowRankEnabled", "Spanish.xml"), update.Message.From.Id);
                 }
                 db.SaveChanges();
             }
         }
     }
 }
Esempio n. 6
0
        public static void RemGrp(Update u, string[] args)
        {
            var link = args[1];

            if (String.IsNullOrEmpty(link))
            {
                Send("Use /remgrp <link>", u.Message.Chat.Id);
                return;
            }
            //grouplink should be the argument
            using (var db = new WWContext())
            {
                var grp = db.Groups.FirstOrDefault(x => x.GroupLink == link);
                if (grp != null)
                {
                    try
                    {
                        var result = Bot.Api.LeaveChat(grp.GroupId).Result;
                        Send($"Bot removed from group: " + result, u.Message.Chat.Id);
                    }
                    catch
                    {
                    }
                    grp.GroupLink = null;
                    db.SaveChanges();
                    Send($"Group {grp.Name} removed from /grouplist", u.Message.Chat.Id);
                }
            }
        }
Esempio n. 7
0
        public static void Join(Update update, string[] args)
        {
            var id = update.Message.Chat.Id;

            using (var db = new WWContext())
            {
                if (update.Message.Chat.Title == null)
                {
                    //PM....  can't do that here
                    Send("You must join a game from within a group chat!", id);
                    return;
                }
                var grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
                if (grp == null)
                {
                    grp = MakeDefaultGroup(id, update.Message.Chat.Title, "join");
                    db.Groups.Add(grp);
                    db.SaveChanges();
                }

                //check nodes to see if player is in a game
                var node = GetPlayerNode(update.Message.From.Id);
                var game = GetGroupNodeAndGame(update.Message.Chat.Id);
                if (game != null || node != null)
                {
                    //try grabbing the game again...
                    if (node != null && game == null)
                    {
                        game =
                            node.Games.FirstOrDefault(
                                x => x.Users.Contains(update.Message.From.Id));
                    }
                    if (game?.Users.Contains(update.Message.From.Id) ?? false)
                    {
                        if (game?.GroupId != update.Message.Chat.Id)
                        {
                            //player is already in a game, and alive
                            Send(
                                GetLocaleString("AlreadyInGame", grp.Language ?? "English",
                                                game.ChatGroup), update.Message.Chat.Id);
                            return;
                        }
                    }
                    //try again.....
                    if (game == null)
                    {
                        game = GetGroupNodeAndGame(update.Message.Chat.Id);
                    }
                    //player is not in game, they need to join, if they can
                    game?.AddPlayer(update);
                    if (game == null)
                    {
                        Program.Log($"{update.Message.From.FirstName} tried to join a game on node {node?.ClientId}, but game object was null", true);
                    }
                    return;
                }

                Send(GetLocaleString("NoGame", grp?.Language ?? "English"), id);
            }
        }
Esempio n. 8
0
        public static void Join(Update update, string[] args)
        {
            var id = update.Message.Chat.Id;

            using (var db = new WWContext())
            {
                if (update.Message.Chat.Type == ChatType.Private)
                {
                    //PM....  can't do that here
                    Send(GetLocaleString("JoinFromGroup", GetLanguage(update.Message.From.Id)), id);
                    return;
                }
                //check if there is a game in that group
                var game = GetGroupNodeAndGame(update.Message.Chat.Id);
                if (game != null)
                {
                    game.ShowJoinButton();
                }
                else
                {
                    var grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
                    if (grp == null)
                    {
                        grp = MakeDefaultGroup(id, update.Message.Chat.Title, "join");
                        db.Groups.Add(grp);
                        db.SaveChanges();
                    }
                    Send(GetLocaleString("NoGame", grp?.Language ?? "English"), id);
                }
            }
        }
Esempio n. 9
0
        public static void Config(Update update, string[] args)
        {
            var id = update.Message.Chat.Id;

            //make sure the group is in the database
            using (var db = new WWContext())
            {
                var grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
                if (grp == null)
                {
                    grp = MakeDefaultGroup(id, update.Message.Chat.Title, "config");
                    db.Groups.Add(grp);
                }

                grp.BotInGroup = true;
                grp.UserName   = update.Message.Chat.Username;
                grp.Name       = update.Message.Chat.Title;
                grp.UpdateFlags();
                db.SaveChanges();
            }

            var language = GetLanguage(update.Message.From.Id);

            var menu = UpdateHandler.GetConfigMenu(update.Message.Chat.Id, language);

            Bot.Api.SendTextMessageAsync(update.Message.From.Id, GetLocaleString("WhatToDo", language),
                                         replyMarkup: menu);
        }
Esempio n. 10
0
        public static void NextGame(Update update, string[] args)
        {
            var id = update.Message.Chat.Id;

            using (var db = new WWContext())
            {
                var grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
                if (grp == null)
                {
                    grp = MakeDefaultGroup(id, update.Message.Chat.Title, "nextgame");
                    db.Groups.Add(grp);
                    db.SaveChanges();
                }

                //check nodes to see if player is in a game
                //node = GetPlayerNode(update.Message.From.Id);
                var game = GetGroupNodeAndGame(update.Message.Chat.Id);
                if (game != null)
                {
                    if (game?.Users.Contains(update.Message.From.Id) ?? false)
                    {
                        if (game?.GroupId != update.Message.Chat.Id)
                        {
                            //player is already in a game, and alive
                            Send(
                                GetLocaleString("AlreadyInGame", grp.Language ?? "English",
                                                game.ChatGroup.ToBold()), update.Message.Chat.Id);
                            return;
                        }
                    }
                }

                if (db.NotifyGames.Any(x => x.GroupId == id && x.UserId == update.Message.From.Id))
                {
                    Send(GetLocaleString("AlreadyOnWaitList", grp.Language, grp.Name.ToBold()),
                         update.Message.From.Id);
                }
                else
                {
                    db.Database.ExecuteSqlCommand(
                        $"INSERT INTO NotifyGame VALUES ({update.Message.From.Id}, {id})");
                    db.SaveChanges();
                    Send(GetLocaleString("AddedToWaitList", grp.Language, grp.Name.ToBold()),
                         update.Message.From.Id);
                }
            }
        }
Esempio n. 11
0
 public void SaveProduct(Product product)
 {
     using (var context = new WWContext())
     {
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
Esempio n. 12
0
 public void UpdateProduct(Product product)
 {
     using (var context = new WWContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void UpdateCategory(Category category)
 {
     using (var context = new WWContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void SaveCategory(Category category)
 {
     using (var context = new WWContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
Esempio n. 15
0
        public static void RemoveBan(Update u, string[] args)
        {
            var tosmite = new List <int>();

            foreach (var e in u.Message.Entities)
            {
                switch (e.Type)
                {
                case MessageEntityType.Mention:
                    //get user
                    var username = u.Message.Text.Substring(e.Offset + 1, e.Length - 1);
                    using (var db = new WWContext())
                    {
                        var player = db.Players.FirstOrDefault(x => x.UserName == username);
                        if (player != null)
                        {
                            var ban = db.GlobalBans.FirstOrDefault(x => x.TelegramId == player.TelegramId);
                            if (ban != null)
                            {
                                var localban = UpdateHandler.BanList.FirstOrDefault(x => x.Id == ban.Id);
                                if (localban != null)
                                {
                                    UpdateHandler.BanList.Remove(localban);
                                }
                                db.GlobalBans.Remove(ban);
                                db.SaveChanges();
                                Send("User has been unbanned.", u.Message.Chat.Id);
                            }
                        }
                    }
                    break;

                case MessageEntityType.TextMention:
                    using (var db = new WWContext())
                    {
                        var player = db.Players.FirstOrDefault(x => x.TelegramId == e.User.Id);
                        if (player != null)
                        {
                            var ban = db.GlobalBans.FirstOrDefault(x => x.TelegramId == player.TelegramId);
                            if (ban != null)
                            {
                                var localban = UpdateHandler.BanList.FirstOrDefault(x => x.Id == ban.Id);
                                if (localban != null)
                                {
                                    UpdateHandler.BanList.Remove(localban);
                                }
                                db.GlobalBans.Remove(ban);
                                db.SaveChanges();
                                Send("User has been unbanned.", u.Message.Chat.Id);
                            }
                        }
                    }
                    break;
                }
            }
        }
 public void DeleteCategory(int ID)
 {
     using (var context = new WWContext())
     {
         //  context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         var category = context.Categories.Find(ID);
         context.Categories.Remove(category);
         context.SaveChanges();
     }
 }
Esempio n. 17
0
 public void DeleteProduct(int ID)
 {
     using (var context = new WWContext())
     {
         //  context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         var product = context.Products.Find(ID);
         context.Products.Remove(product);
         context.SaveChanges();
     }
 }
Esempio n. 18
0
        public static void RequestGif(CallbackQuery q)
        {
            Bot.Api.DeleteMessageAsync(q.From.Id, q.Message.MessageId);
            var choice = q.Data.Split('|')[1].Split(' ')[0];

            if (choice == "submit")
            {
                using (var db = new WWContext())
                {
                    var p = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    if (p != null)
                    {
                        var json = p?.CustomGifSet;
                        var data = JsonConvert.DeserializeObject <CustomGifData>(json);
                        data.Submitted = true;
                        p.CustomGifSet = JsonConvert.SerializeObject(data);
                        db.SaveChanges();
                    }
                }

                var menu = new Menu(2);
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Review", "reviewgifs|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Dismiss", "cancel|cancel|cancel"));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: SFW", "approvesfw|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: NSFW", "approvensfw|" + q.From.Id));
                Bot.Send($"User {q.From.Id} - @{q.From.Username} - has submitted a gif pack for approval",
                         Settings.AdminChatId, customMenu: menu.CreateMarkupFromMenu());
                Bot.Send("Your pack has been submitted for approval to the admin.  Please wait while we review.",
                         q.From.Id);
                return;
            }

            if (choice == "togglebadge")
            {
                using (var db = new WWContext())
                {
                    var p    = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    var json = p?.CustomGifSet;
                    var data = JsonConvert.DeserializeObject <CustomGifData>(json);
                    data.ShowBadge = !data.ShowBadge;
                    p.CustomGifSet = JsonConvert.SerializeObject(data);
                    db.SaveChanges();
                    Bot.Send($"You badge will {(data.ShowBadge ? "" : "not ")}be shown.", q.From.Id,
                             customMenu: GetGifMenu(data));
                    return;
                }
            }

            Bot.Api.SendTextMessageAsync(q.From.Id,
                                         q.Data.Split('|')[1] + "\nOk, send me the GIF you want to use for this situation, as a reply\n" +
                                         "#" + choice,
                                         replyMarkup: new ForceReply {
                Force = true
            });
        }
Esempio n. 19
0
        public static void RemLink(Update u, string[] args)
        {
            using (var db = new WWContext())
            {
                var grp = db.Groups.FirstOrDefault(x => x.GroupId == u.Message.Chat.Id) ??
                          MakeDefaultGroup(u.Message.Chat.Id, u.Message.Chat.Title, "setlink");
                grp.GroupLink = null;
                db.SaveChanges();
            }

            Send($"Your group link has been removed.", u.Message.Chat.Id);
        }
Esempio n. 20
0
        private static void ApiOnStatusChanged(object sender, StatusChangeEventArgs statusChangeEventArgs)
        {
            using (var db = new WWContext())
            {
                var id = 1;

                var b = db.BotStatus.Find(id);
                b.Status      = statusChangeEventArgs.Status.ToString();
                CurrentStatus = b.Status;
                db.SaveChanges();
            }
        }
Esempio n. 21
0
        public static void SetList(Update update, string[] args)
        {
            if (args[1] != null)
            {
                using (var db = new WWContext())
                {
                    var dbp = db.Players.FirstOrDefault(x => x.TelegramId == update.Message.From.Id);
                    if (dbp == null)
                    {
                        return;
                    }
                    if (dbp.Score < 1600 && dbp.TelegramId != 294728091)
                    {
                        Send(GetLocaleString("CantSetRolelist", "Spanish.xml"), update.Message.Chat.Id);
                        return;
                    }
                    else
                    {
                        List <string> finalList = new List <string>();
                        var           cards     = args[1].Split(',');
                        foreach (var card in cards)
                        {
                            var role = TranslateEmoji(card, finalList, cards);
                            if (role != null)
                            {
                                finalList.Add(role);
                            }
                            else
                            {
                                Send(GetLocaleString("InvalidRolelist", "Spanish.xml"), update.Message.Chat.Id);
                                return;
                            }
                        }
                        if (!finalList.Take(4).Any(x => x == "Wolf" || x == "WolfCub" || x == "AlphaWolf" || x == "Lycan" || x == "HungryWolf" || x == "RabidWolf" || x == "SpeedWolf" || x == "SnowWolf" || x == "Snooper" || x == "SerialKiller" || x == "Pyro" || x == "Cultist" || x == "RandomKiller" || x == "RandomBaddie" || x == "RandomWolf" || x == "RandomSkyro"))
                        {
                            Send(GetLocaleString("NotEnoughBaddies", "Spanish.xml"), update.Message.Chat.Id);
                            return;
                        }

                        // turn the rolelist into a string to save it
                        var roleList = finalList[0];
                        for (int i = 1; i < finalList.Count; i++)
                        {
                            roleList += "," + finalList[i];
                        }

                        dbp.Rolelist = roleList;
                        Send(GetLocaleString("RolelistSaved", "Spanish.xml"), update.Message.Chat.Id);
                        db.SaveChanges();
                    }
                }
            }
        }
Esempio n. 22
0
        public static void ApproveGifs(Update u, string[] args)
        {
#if !BETA
            using (var db = new WWContext())
            {
                if (args[1] == null)
                {
                    Send("Please use /approvegifs <player id> <1|0 (nsfw)>", u.Message.Chat.Id);
                }
                else
                {
                    var parms = args[1].Split(' ');
                    if (parms.Length == 1)
                    {
                        Send("Please use /approvegifs <player id> <1|0 (nsfw)>", u.Message.Chat.Id);
                        return;
                    }
                    var pid  = int.Parse(parms[0]);
                    var nsfw = parms[1] == "1";
                    var p    = db.Players.FirstOrDefault(x => x.TelegramId == pid);
                    if (p == null)
                    {
                        Send("Id not found.", u.Message.Chat.Id);
                        return;
                    }
                    var json = p.CustomGifSet;
                    if (String.IsNullOrEmpty(json))
                    {
                        Send("User does not have a custom gif pack", u.Message.Chat.Id);
                        return;
                    }

                    var pack = JsonConvert.DeserializeObject <CustomGifData>(json);
                    // save gifs for external access
                    new Thread(() => Task.WhenAll(DownloadGifFromJson(pack, u))).Start();
                    // end
                    var id = u.Message.From.Id;
                    pack.Approved   = true;
                    pack.ApprovedBy = id;
                    pack.NSFW       = nsfw;
                    pack.Submitted  = false;
                    var msg = $"Approval Status: ";
                    var by  = db.Players.FirstOrDefault(x => x.TelegramId == pack.ApprovedBy);
                    msg           += "Approved By " + by.Name + "\nNSFW: " + pack.NSFW;
                    p.CustomGifSet = JsonConvert.SerializeObject(pack);
                    db.SaveChanges();
                    Bot.Send(msg, pid);
                    Bot.Send(msg, u.Message.Chat.Id);
                }
            }
#endif
        }
Esempio n. 23
0
 /// <summary>
 /// Get language for a player
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static string GetLanguage(int id)
 {
     using (var db = new WWContext())
     {
         var p = db.Players.FirstOrDefault(x => x.TelegramId == id);
         if (String.IsNullOrEmpty(p?.Language) && p != null)
         {
             p.Language = "English";
             db.SaveChanges();
         }
         return(p?.Language ?? "English");
     }
 }
Esempio n. 24
0
        public static void Start(Update update, string[] args)
        {
            if (update.Message.Chat.Type == ChatType.Private)
            {
                if (update.Message.From != null)
                {
                    using (var db = new WWContext())
                    {
                        var p = GetDBPlayer(update.Message.From.Id, db);
                        if (p == null)
                        {
                            var u = update.Message.From;
                            p = new Player
                            {
                                UserName   = u.Username,
                                Name       = (u.FirstName + " " + u.LastName).Trim(),
                                TelegramId = u.Id,
                                Language   = "English"
                            };
                            db.Players.Add(p);
                            db.SaveChanges();
                            p = GetDBPlayer(update.Message.From.Id, db);
                        }
#if RELEASE
                        p.HasPM = true;
#elif RELEASE2
                        p.HasPM2 = true;
#elif BETA
                        p.HasDebugPM = true;
#endif
                        db.SaveChanges();
                        Bot.Send(
                            $"Hi there! I'm @{Bot.Me.Username}, and I moderate games of Werewolf.\nJoin the main group @werewolfgame, or to find a group to play in, you can use /grouplist.\nFor role information, use /rolelist.\nIf you want to set your default language, use /setlang.\nBe sure to stop by <a href=\"https://telegram.me/werewolfsupport\">Werewolf Support</a> for any questions, and subscribe to @werewolfdev for updates from the developer.\nMore infomation can be found <a href=\"www.tgwerewolf.com?referrer=start\">here</a>!",
                            update.Message.Chat.Id);
                        //Bot.Send(GetLocaleString("PMTrue", GetLanguage(update.Message.Chat.Id)), update.Message.Chat.Id);
                    }
                }
            }
        }
Esempio n. 25
0
        public static void DisapproveGifs(Update u, string[] args)
        {
            #if !BETA
            using (var db = new WWContext())
            {
                if (args[1] == null)
                {
                    Send("Please use /disapprovegifs <player id> <reason>", u.Message.Chat.Id);
                }
                else
                {
                    var parms = args[1].Split(' ');
                    if (parms.Length == 1)
                    {
                        Send("Please use /disapprovegifs <player id> <reason>", u.Message.Chat.Id);
                        return;
                    }

                    var pid    = int.Parse(parms[0]);
                    var reason = args[1].Replace(parms[0] + " ", "");
                    var p      = db.Players.FirstOrDefault(x => x.TelegramId == pid);
                    if (p == null)
                    {
                        Send("Id not found.", u.Message.Chat.Id);
                        return;
                    }

                    var json = p.CustomGifSet;
                    if (string.IsNullOrEmpty(json))
                    {
                        Send("User does not have a custom gif pack", u.Message.Chat.Id);
                        return;
                    }

                    var pack = JsonConvert.DeserializeObject <CustomGifData>(json);
                    var id   = u.Message.From.Id;
                    pack.Approved   = false;
                    pack.ApprovedBy = id;
                    pack.Submitted  = false;
                    pack.DenyReason = reason;
                    var msg = $"Approval Status: ";
                    var by  = db.Players.FirstOrDefault(x => x.TelegramId == pack.ApprovedBy);
                    msg           += "Dispproved By " + by.Name + " for: " + pack.DenyReason;
                    p.CustomGifSet = JsonConvert.SerializeObject(pack);
                    db.SaveChanges();
                    Bot.Send(msg, pid);
                    Bot.Send(msg, u.Message.Chat.Id);
                }
            }
            #endif
        }
Esempio n. 26
0
        public static void RequestGif(CallbackQuery q)
        {
            Bot.Api.DeleteMessageAsync(q.From.Id, q.Message.MessageId);
            var choice = q.Data.Split('|')[1].Split(' ')[0];

            if (choice == "submit")
            {
                using (var db = new WWContext())
                {
                    var p = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    if (p != null)
                    {
                        var json = p?.CustomGifSet;
                        if ((p.DonationLevel ?? 0) < 10)
                        {
                            Bot.Send("You have not unlocked a custom GIF pack.  Please use /donate", q.From.Id);
                            return;
                        }
                        var data = JsonConvert.DeserializeObject <CustomGifData>(json);
                        if (data.Approved != null)
                        {
                            Bot.Send($"Your current GIF pack has already been {(data.Approved == true ? "" : "dis")}approved! You can't submit it again without any changes!", q.From.Id, customMenu: GetGifMenu(data));
                            return;
                        }
                        if (new[] { data.CultWins, data.LoversWin, data.NoWinner, data.SerialKillerWins, data.SKKilled, data.StartChaosGame, data.StartGame, data.TannerWin, data.VillagerDieImage, data.VillagersWin, data.WolfWin, data.WolvesWin, data.ArsonistWins, data.BurnToDeath }.All(x => string.IsNullOrEmpty(x)))
                        {
                            Bot.Send($"Please set at least one GIF before you submit your pack!", q.From.Id, customMenu: GetGifMenu(data));
                            return;
                        }
                        if (data.LastSubmit.AddMinutes(60) >= DateTime.UtcNow)
                        {
                            Bot.Send($"You have already submitted your GIF pack in the last hour! If you submit your GIFs and then change something before it gets approved, you don't have to submit it again! Please wait patiently while your GIFs are being reviewed.", q.From.Id, customMenu: GetGifMenu(data));
                            return;
                        }
                        data.Submitted  = true;
                        data.LastSubmit = DateTime.UtcNow;
                        p.CustomGifSet  = JsonConvert.SerializeObject(data);
                        db.SaveChanges();
                    }
                }
                var menu = new Menu(2);
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Review", "reviewgifs|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Dismiss", $"dismiss|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: SFW", "approvesfw|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: NSFW", "approvensfw|" + q.From.Id));
                Bot.Send($"User {q.From.Id} - {(q.From.Username == null ? q.From.FirstName : $"@{q.From.Username}")} - has submitted a gif pack for approval", Settings.AdminChatId, customMenu: menu.CreateMarkupFromMenu());
                Bot.Send("Your GIF pack has been submitted to the admins for approval!\n\nPlease keep in mind that admins have a huge number of GIF packs to review, hence this process may take up to 2-5 working days.\n\nOur admins will keep track of the submitted GIF packs, you don’t have to PM them directly. Thank you for your patience!", q.From.Id);
                return;
            }
Esempio n. 27
0
 public static void Start(Update update, string[] args)
 {
     if (update.Message.Chat.Type == ChatType.Private)
     {
         if (update.Message.From != null)
         {
             using (var db = new WWContext())
             {
                 var p = GetDBPlayer(update.Message.From.Id, db);
                 p.HasPM = true;
                 db.SaveChanges();
                 Bot.Send("PM Status set to true", update.Message.Chat.Id);
             }
         }
     }
 }
Esempio n. 28
0
 /// <summary>
 /// Gets the language for the group, defaulting to English
 /// </summary>
 /// <param name="id">The ID of the group</param>
 /// <returns></returns>
 public static string GetLanguage(long id)
 {
     using (var db = new WWContext())
     {
         Player p   = null;
         var    grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
         if (grp == null)
         {
             p = db.Players.FirstOrDefault(x => x.TelegramId == id);
         }
         if (p != null && String.IsNullOrEmpty(p.Language))
         {
             p.Language = "English";
             db.SaveChanges();
         }
         return(grp?.Language ?? p?.Language ?? "English");
     }
 }
Esempio n. 29
0
        public static void RequestGif(CallbackQuery q)
        {
            Bot.Api.DeleteMessageAsync(q.From.Id, q.Message.MessageId);
            var choice = q.Data.Split('|')[1].Split(' ')[0];

            if (choice == "submit")
            {
                using (var db = new WWContext())
                {
                    var p = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    if (p != null)
                    {
                        var json = p?.CustomGifSet;
                        if ((p.DonationLevel ?? 0) < 10)
                        {
                            Bot.Send("You have not unlocked a custom GIF pack.  Please use /donate", q.From.Id);
                            return;
                        }
                        var data = JsonConvert.DeserializeObject <CustomGifData>(json);
                        if (data.Approved != null)
                        {
                            Bot.Send($"Your current GIF pack has already been {(data.Approved == true ? "" : "dis")}approved! You can't submit it again without any changes!", q.From.Id, customMenu: GetGifMenu(data));
                            return;
                        }
                        if (new[] { data.CultWins, data.LoversWin, data.NoWinner, data.SerialKillerWins, data.SKKilled, data.StartChaosGame, data.StartGame, data.TannerWin, data.VillagerDieImage, data.VillagersWin, data.WolfWin, data.WolvesWin, data.ArsonistWins, data.BurnToDeath }.All(x => string.IsNullOrEmpty(x)))
                        {
                            Bot.Send($"Please set at least one GIF before you submit your pack!", q.From.Id, customMenu: GetGifMenu(data));
                            return;
                        }
                        data.Submitted = true;
                        p.CustomGifSet = JsonConvert.SerializeObject(data);
                        db.SaveChanges();
                    }
                }
                var menu = new Menu(2);
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Review", "reviewgifs|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Dismiss", $"dismiss|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: SFW", "approvesfw|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: NSFW", "approvensfw|" + q.From.Id));
                Bot.Send($"User {q.From.Id} - {(q.From.Username == null ? q.From.FirstName : $"@{q.From.Username}")} - has submitted a gif pack for approval", Settings.AdminChatId, customMenu: menu.CreateMarkupFromMenu());
                Bot.Send("Your pack has been submitted for approval to the admins.  Please wait while we review.",
                         q.From.Id);
                return;
            }
Esempio n. 30
0
        public static void ForceStart(Update update, string[] args)
        {
            var id = update.Message.Chat.Id;

            using (var db = new WWContext())
            {
                var grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
                if (grp == null)
                {
                    grp = MakeDefaultGroup(id, update.Message.Chat.Title, "forcestart");
                    db.Groups.Add(grp);
                    db.SaveChanges();
                }
                if (UpdateHelper.IsGroupAdmin(update))
                {
                    var game = GetGroupNodeAndGame(update.Message.Chat.Id);
                    if (game != null)
                    {
                        if (game.Users.Contains(update.Message.From.Id))
                        {
                            //send forcestart
                            game.ForceStart();
                        }
                        else
                        {
                            Send(GetLocaleString("NotInGame", grp.Language), id);
                        }
                    }
                    else
                    {
                        Send(GetLocaleString("NoGame", grp.Language), id);
                    }
                }
                else
                {
                    Send(GetLocaleString("GroupAdminOnly", grp?.Language ?? "English"), id);
                }
            }
        }