Ejemplo n.º 1
0
 /// <summary>
 /// Gets the language for the group, defaulting to English
 /// </summary>
 /// <param name="id">The ID of the group</param>
 /// <returns></returns>
 private static string GetLanguage(long id)
 {
     using (var db = new WWContext())
     {
         var grp = db.Groups.FirstOrDefault(x => x.GroupId == id);
         return grp?.Language ?? "English";
     }
 }
Ejemplo n.º 2
0
 public static void GetRoles(Update update, string[] args)
 {
     if (args.Length > 1)
     {
         var groupName = args.Skip(1).Aggregate((a, b) => a + " " + b).Trim();
         using (var db = new WWContext())
         {
             var roles = db.getRoles(groupName);
             var msg = roles.Aggregate("", (current, r) => current + $"{r.name}: {r.role}\n");
             Bot.Send(msg, update.Message.Chat.Id);
         }
     }
 }
Ejemplo n.º 3
0
        public static async void GetUserImage(int userid)
        {
            using (var db = new WWContext())
            {
                var p = db.Players.FirstOrDefault(x => x.TelegramId == userid);
                if (p != null)
                {
                    var photos = await Program.Bot.GetUserProfilePhotos(userid, limit: 1);
                    if (photos.Photos.Length == 0) return;//nada
                    var sizes = photos.Photos[0];
                    var id = "";
                    var largest = 0;
                    foreach (var s in sizes)
                    {
                        if (s.FileSize > largest)
                            id = s.FileId;

                    }

                    if (String.IsNullOrEmpty(id))
                    {
                        return;
                    }



                    var file = await Program.Bot.GetFile(id);
                    var photoPath = file.FilePath;
                    var fileName = photoPath.Substring(photoPath.LastIndexOf("/") + 1);
                    //check that the file name is different
                    if (p.ImageFile == fileName) 
                        return; //same, no reason to download again

                    var uri = $"https://api.telegram.org/file/bot{Program.APIToken}/{photoPath}";

                    //write the new info to the database

                    


                    //now download the photo to the path
                    using (var client = new WebClient())
                    {
                        client.DownloadFile(new Uri(uri), ImagePath + fileName);
                    }
                    p.ImageFile = fileName;
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 4
0
 public static void PlayTime(Update update, string[] args)
 {
     if (args.Length > 1)
     {
         var playerCount = int.Parse(args[1]);
         using (var db = new WWContext())
         {
             var counts = db.getPlayTime(playerCount).First();
             var msg =
                 $"(In minutes)\nMin: {counts.Minimum}\nMax: {counts.Maximum}\nAverage: {counts.Average}";
             Bot.Send(msg, update.Message.Chat.Id);
         }
     }
 }
Ejemplo n.º 5
0
        public Werewolf(long chatid, User u, string chatGroup, bool chaos = false)
        {
            try
            {
                new Thread(GroupQueue).Start();
                //DB = new WWContext();
                using (var db = new WWContext())
                {
                    ChatGroup = chatGroup;
                    ChatId = chatid;
                    DbGroup = db.Groups.FirstOrDefault(x => x.GroupId == ChatId);

                    if (DbGroup == null)
                    {
                        MessageQueueing = false;
                        Program.RemoveGame(this);
                        return;
                    }

                    //decide if chaos or not
                    if (DbGroup.Mode == "Player")
                        Chaos = chaos;
                    else
                    {
                        Chaos = DbGroup.Mode == "Chaos";
                    }
                    //Log = new Log(Program.RootDirectory + "\\logs\\log-" + ChatId + "\\");
                    //Log.WriteLine($"{u.FirstName} {u.LastName} is starting a game");
                    LoadLanguage(DbGroup.Language);
                    AddPlayer(u, false);
                }
                SendGif(GetLocaleString(Chaos ? "PlayerStartedChaosGame" : "PlayerStartedGame", u.FirstName),
                    Chaos ? Settings.StartChaosGame : Settings.StartGame);
                new Thread(GameTimer).Start();
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                    ex = ex.InnerException;
                Program.Send("Hmm.. something went wrong, please try starting the game again...\n" + ex.Message, chatid);
            #if DEBUG
                Send(ex.StackTrace);
            #else
                Send(Program.Version.FileVersion + $"\nGroup: {ChatId} ({ChatGroup})\nLanguage: {DbGroup?.Language ?? "null"}\n{ex.Message}\n{ex.StackTrace}", Program.Para);
            #endif
                Program.RemoveGame(this);
            }
        }
Ejemplo n.º 6
0
        public static void GetIdles(Update update, string[] args)
        {
            //check user ids and such
            List<int> ids = new List<int>();
            foreach (var arg in args.Skip(1).FirstOrDefault()?.Split(' ')??new [] {""})
            {
                var id = 0;
                if (int.TryParse(arg, out id))
                {
                    ids.Add(id);
                }
            }

            //now check for mentions
            foreach (var ent in update.Message.Entities.Where(x => x.Type == MessageEntityType.TextMention))
            {
                ids.Add(ent.User.Id);
            }

            //check for reply
            if (update.Message.ReplyToMessage != null)
                ids.Add(update.Message.ReplyToMessage.From.Id);

            var reply = "";
            //now get the idle kills
            using (var db = new WWContext())
            {
                foreach (var id in ids)
                {
                    var idles = db.GetIdleKills24Hours(id).FirstOrDefault() ?? 0;
                    //get the user
                    ChatMember user = null;
                    try
                    {
                        user = Bot.Api.GetChatMember(update.Message.Chat.Id, id).Result;
                    }
                    catch
                    {
                        // ignored
                    }

                    reply += $"{id} ({user?.User.FirstName}) has been idle killed {idles} time(s) in the past 24 hours\n";
                }
            }

            Send(reply, update.Message.Chat.Id);
        }
Ejemplo n.º 7
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), 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),
                        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),
                        update.Message.From.Id);
                }
            }
        }
Ejemplo n.º 8
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;
                db.SaveChanges();
            }

            var menu = UpdateHandler.GetConfigMenu(update.Message.Chat.Id);
            Bot.Api.SendTextMessage(update.Message.From.Id, "What would you like to do?",
                replyMarkup: menu);
        }
Ejemplo n.º 9
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);
     }
 }
Ejemplo n.º 10
0
 public static void Test(Update update, string[] args)
 {
     var reply = "";
     using (var db = new WWContext())
     {
         reply = Enumerable.Aggregate(db.v_PreferredGroups, "", (current, g) => current + $"{GetLanguageName(g.Language)}{(String.IsNullOrEmpty(g.Description) ? "" : $" - {g.Description}")}\n<a href=\"{g.GroupLink}\">{g.Name}</a>\n\n");
     }
Ejemplo n.º 11
0
 private static Player GetDBPlayer(int id, WWContext db)
 {
     return db.Players.FirstOrDefault(x => x.TelegramId == id);
 }
Ejemplo n.º 12
0
        private static void StartGame(bool chaos, Update update)
        {
            if (update.Message.Chat.Title == null)
            {
                //PM....  can't do that here
                Bot.Send("You must start a game from within a group chat!", update.Message.Chat.Id);
                return;
            }
            Group grp;
            using (var db = new WWContext())
            {
                grp = db.Groups.FirstOrDefault(x => x.GroupId == update.Message.Chat.Id);
                if (grp == null)
                {
                    grp = MakeDefaultGroup(update.Message.Chat.Id, update.Message.Chat.Title, "StartGame");
                    db.Groups.Add(grp);
                }
                grp.Name = update.Message.Chat.Title;
                grp.UserName = update.Message.Chat.Username;
                grp.BotInGroup = true;
                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 (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.ToBold() ), update.Message.Chat.Id);
                        return;
                    }
                }

                //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;
            }
            //no game found, start one
            node = Bot.GetBestAvailableNode();
            if (node != null)
            {
                node.StartGame(update, chaos);
                //notify waiting players
                using (var db = new WWContext())
                {
                    var notify = db.NotifyGames.Where(x => x.GroupId == update.Message.Chat.Id).ToList();
                    foreach (var n in notify)
                    {
                        var groupName = update.Message.Chat.Title.ToBold();
                        if (update.Message.Chat.Username != null)
                            groupName += $" @{update.Message.Chat.Username}";
                        Send(GetLocaleString("NotifyNewGame", grp.Language, groupName), n.UserId);
                        Thread.Sleep(100);
                    }

                    //just to be sure...
                    db.Database.ExecuteSqlCommand($"DELETE FROM NotifyGame WHERE GroupId = {update.Message.Chat.Id}");
                    db.SaveChanges();
                }
            }
            else
            {
                Send("There are no nodes online right now, please try again in a few seconds", update.Message.Chat.Id);
            }
        }
Ejemplo n.º 13
0
 public static void SendOnline()
 {
     #if !DEBUG
     List<long> ids = new List<long>();
     using (var db = new WWContext())
         ids.AddRange(db.Database.SqlQuery<long>("select distinct groupid from [group] where groupid not in (select distinct groupid from[group] where BotInGroup = 0)"));
     foreach (var id in ids)
     {
         Api.SendTextMessage(id, "Werewolf Bot 3.0 online.  Join the dev channel for live updates: https://telegram.me/werewolfdev\nTo disable this message or change other settings, use /config (admin only)");
     }
     #else
     Api.SendTextMessage(Settings.MainChatId, "Bot 2.0 Test online (I should be named Mr. Spammy)");
     #endif
 }
Ejemplo n.º 14
0
        internal static void HandleUpdate(Update update)
        {
            {
                Bot.MessagesReceived++;

                //ignore previous messages
                if ((update.Message?.Date ?? DateTime.MinValue) < Bot.StartTime.AddSeconds(-10))
                    return; //toss it

                var id = update.Message.Chat.Id;

            #if DEBUG
                if (update.Message.Chat.Title != "Werewolf Beta Testing" && !String.IsNullOrEmpty(update.Message.Chat.Title) && update.Message.Chat.Title != "Werewolf Mod / Dev chat (SFW CUZ YOUNGENS)")
                {
                    try
                    {
                        Bot.Api.LeaveChat(update.Message.Chat.Id);
                    }
                    catch
                    {
                        // ignored
                    }
                }
            #endif
                //Settings.Main.LogText += update?.Message?.Text + Environment.NewLine;
                bool block = (id == Settings.SupportChatId);

            #if !DEBUG
                try
            #endif
                {
                    Group grp;
                    switch (update.Message.Type)
                    {
                        case MessageType.UnknownMessage:
                            break;
                        case MessageType.TextMessage:
                            if (update.Message.Text.StartsWith("!") || update.Message.Text.StartsWith("/"))
                            {
                                if (PermaBanList.Contains(update.Message?.From?.Id ?? 0))
                                {
                                    Bot.Api.SendTextMessage(id, "*You have been permanently banned from Werewolf.*",
                                        replyToMessageId: update.Message.MessageId, parseMode: ParseMode.Markdown);
                                    if (update.Message.From != null)
                                        Program.Log($"@{update.Message.From.Username} has been notified of ban");
                                    return;
                                }
                                var args = GetParameters(update.Message.Text);
                                args[0] = args[0].ToLower().Replace("@" + Bot.Me.Username.ToLower(), "");

                                //check for the command

                                #region More optimized code, but slow as hell

                                var command = Bot.Commands.FirstOrDefault(
                                        x =>
                                            String.Equals(x.Trigger, args[0],
                                                StringComparison.InvariantCultureIgnoreCase));
                                if (command != null)
                                {
                                    //check that we should run the command
                                    if (block && command.Blockable)
                                        return;
                                    if (command.DevOnly && update.Message.From.Id != Para)
                                    {
                                        Send("You aren't the developer...", id);
                                        return;
                                    }
                                    if (command.GlobalAdminOnly)
                                    {
                                        using (var DB = new WWContext())
                                        {
                                            if (!DB.Admins.Any(x => x.UserId == update.Message.From.Id))
                                            {
                                                Send($"You aren't a global admin...", id);
                                                return;
                                            }
                                        }
                                    }
                                    if (command.GroupAdminOnly & !UpdateHelper.IsGroupAdmin(update))
                                    {
                                        Send(GetLocaleString("GroupAdminOnly", GetLanguage(update.Message.Chat.Id)), id);
                                        return;
                                    }
                                    if (command.InGroupOnly & update.Message.Chat.Type == ChatType.Private)
                                    {
                                        Send($"You must run this command in a group", id);
                                        return;
                                    }
                                    Bot.CommandsReceived++;
                                    command.Method.Invoke(update, args);
                                }

                                //Bot.CommandsReceived++;
                                //switch (args[0].ToLower())
                                //{

                                //    #region Admin Commands

                                //    case "smite":
                                //        if (UpdateHelper.IsGroupAdmin(update))
                                //            Commands.Smite(update, args);
                                //        break;
                                //    case "config":
                                //        if (UpdateHelper.IsGroupAdmin(update))
                                //            Commands.Config(update, args);
                                //        break;
                                //    case "uploadlang":
                                //        using (var DB = new WWContext())
                                //        {
                                //            if (!DB.Admins.Any(x => x.UserId == update.Message.From.Id))
                                //            {
                                //                Send($"You aren't a global admin...", id);
                                //                return;
                                //            }
                                //        }
                                //        Commands.UploadLang(update, args);
                                //        break;
                                //    case "validatelangs":
                                //        using (var DB = new WWContext())
                                //        {
                                //            if (!DB.Admins.Any(x => x.UserId == update.Message.From.Id))
                                //            {
                                //                Send($"You aren't a global admin...", id);
                                //                return;
                                //            }
                                //        }
                                //        Commands.ValidateLangs(update, args);
                                //        break;

                                //    #endregion
                                //    #region Dev Commands
                                //    case "winchart":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.WinChart(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "learngif":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.LearnGif(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "update":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.Update(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "sendonline":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.SendOnline(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "replacenodes":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.ReplaceNodes(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "playtime":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.PlayTime(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "getroles":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.GetRoles(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "skipvote":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.SkipVote(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    case "test":
                                //        if (update.Message.From.Id == Para)
                                //        {
                                //            Commands.Test(update, args);
                                //        }
                                //        else
                                //        {
                                //            Send("You aren't the developer...", id);
                                //        }
                                //        break;
                                //    #endregion
                                //    #region Game Commands
                                //    case "startgame":
                                //        if (block) return;
                                //        if (update.Message.Chat.Type == ChatType.Private)
                                //        {
                                //            Send($"You must run this command in a group", id);
                                //            return;
                                //        }
                                //        Commands.StartGame(update, args);
                                //        break;
                                //    case "startchaos":
                                //        if (block) return;
                                //        if (update.Message.Chat.Type == ChatType.Private)
                                //        {
                                //            Send($"You must run this command in a group", id);
                                //            return;
                                //        }
                                //        Commands.StartChaos(update, args);
                                //        break;
                                //    case "join":
                                //        if (block) return;
                                //        if (update.Message.Chat.Type == ChatType.Private)
                                //        {
                                //            Send($"You must run this command in a group", id);
                                //            return;
                                //        }
                                //        Commands.Join(update, args);
                                //        break;
                                //    case "forcestart":
                                //        if (block) return;
                                //        if (update.Message.Chat.Type == ChatType.Private)
                                //        {
                                //            Send($"You must run this command in a group", id);
                                //            return;
                                //        }
                                //        if (UpdateHelper.IsGroupAdmin(update))
                                //            Commands.ForceStart(update, args);
                                //        break;
                                //    case "players":
                                //        if (block) return;
                                //        if (update.Message.Chat.Type == ChatType.Private)
                                //        {
                                //            Send($"You must run this command in a group", id);
                                //            return;
                                //        }
                                //        Commands.Players(update, args);
                                //        break;
                                //    case "flee":
                                //        if (block) return;
                                //        if (update.Message.Chat.Type == ChatType.Private)
                                //        {
                                //            Send($"You must run this command in a group", id);
                                //            return;
                                //        }
                                //        Commands.Flee(update, args);
                                //        break;
                                //    #endregion
                                //    #region General Commands
                                //    case "stats":
                                //        Commands.GetStats(update, args);
                                //        break;
                                //    case "ping":
                                //        Commands.Ping(update, args);
                                //        break;
                                //    case "help":
                                //        Commands.Help(update, args);
                                //        break;
                                //    case "chatid":
                                //        Commands.ChatId(update, args);
                                //        break;
                                //    case "changelog":
                                //        Commands.ChangeLog(update, args);
                                //        break;
                                //    case "runinfo":
                                //        Commands.RunInfo(update, args);
                                //        break;
                                //    case "version":
                                //        Commands.Version(update, args);
                                //        break;
                                //    case "start":
                                //        Commands.Start(update, args);
                                //        break;
                                //    case "nextgame":
                                //        if (block) return;
                                //        if (update.Message.Chat.Type == ChatType.Private)
                                //        {
                                //            Send($"You must run this command in a group", id);
                                //            return;
                                //        }
                                //        Commands.NextGame(update, args);
                                //        break;
                                //    case "getlang":
                                //        Commands.GetLang(update, args);
                                //        break;

                                //        #endregion
                                //}

                                #endregion
                            }
                            break;
                        case MessageType.PhotoMessage:
                            break;
                        case MessageType.AudioMessage:
                            break;
                        case MessageType.VideoMessage:
                            break;
                        case MessageType.VoiceMessage:
                            break;
                        case MessageType.DocumentMessage:
                            if (update.Message.From.Id == Para && SendGifIds)
                            {
                                var doc = update.Message.Document;
                                Send(doc.FileId, update.Message.Chat.Id);
                            }
                            break;
                        case MessageType.StickerMessage:
                            break;
                        case MessageType.LocationMessage:
                            break;
                        case MessageType.ContactMessage:
                            break;
                        case MessageType.ServiceMessage:
                            using (var DB = new WWContext())
                            {
                                id = update.Message.Chat.Id;
                                var m = update.Message;
                                if (m.LeftChatMember?.Id == Bot.Me.Id)
                                {
                                    //removed from group
                                    var grps = DB.Groups.Where(x => x.GroupId == id);
                                    if (!grps.Any())
                                    {
                                        return;
                                    }
                                    foreach (var g in grps)
                                    {
                                        g.BotInGroup = false;
                                        g.UserName = update.Message.Chat.Username;
                                        g.Name = update.Message.Chat.Title;
                                    }
                                    DB.SaveChanges();
                                }
                                if (m.NewChatMember?.Id == Bot.Me.Id)
                                {
                                    //added to a group
                                    grp = DB.Groups.FirstOrDefault(x => x.GroupId == id);
                                    if (grp == null)
                                    {
                                        grp = MakeDefaultGroup(id, update.Message.Chat.Title, "NewChatMember");
                                        DB.Groups.Add(grp);
                                        DB.SaveChanges();
                                        grp = DB.Groups.FirstOrDefault(x => x.GroupId == id);
                                    }
                                    grp.BotInGroup = true;
                                    grp.UserName = update.Message.Chat.Username;
                                    grp.Name = update.Message.Chat.Title;
                                    DB.SaveChanges();

                                    var msg =
                                        $"You've just added Werewolf Moderator!  Use /config (group admins) to configure group settings.   If you need assistance, join the support channel @werewolfsupport";
                                    msg += Environment.NewLine +
                                           "For updates on what is happening, join the dev channel @werewolfdev" +
                                           Environment.NewLine +
                                           "Full information is available on the [website](http://werewolf.parawuff.com)";
                                    Bot.Api.SendTextMessage(id, msg, parseMode: ParseMode.Markdown);
                                }
                            }
                            break;
                        case MessageType.VenueMessage:
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
            #if !DEBUG
                catch (Exception ex)
                {
                    Send(ex.Message, id);
                }
            #endif
            }
        }
Ejemplo n.º 15
0
        static void GroupStats(long groupid)
        {
            Console.WriteLine("Group stats for " + groupid);
            try
            {
                var runStats = false;
                using (var db = new WWContext())
                {
                    //first, check that we should even run stats on this group
                    var grp = db.Groups.FirstOrDefault(x => x.GroupId == groupid);
                    var stat = db.GroupStats.FirstOrDefault(x => x.GroupId == groupid);

                    if (grp == null) //that's a problem..
                        return;
                    if (stat == null)
                        runStats = true;
                    else
                    {
                        if ((grp.Games.OrderByDescending(x => x.TimeEnded).FirstOrDefault()?.TimeEnded ??
                             DateTime.MinValue) > (stat.LastRun ?? DateTime.MinValue.AddSeconds(1)))
                        {
                            runStats = true;
                        }
                    }

                    if (!runStats) return;
                    var gamesPlayed = grp.Games.Count;
                    var night1death = db.GroupNight1Death(groupid).FirstOrDefault();
                    var day1lynch = db.GroupDay1Lynch(groupid).FirstOrDefault();
                    var day1death = db.GroupDay1Death(groupid).FirstOrDefault();
                    var survivor = db.GroupSurvivor(groupid).FirstOrDefault();

                    if (stat == null)
                    {
                        stat = db.GroupStats.Create();
                        stat.GroupId = groupid;
                        db.GroupStats.Add(stat);
                    }

                    stat.GroupName = grp.Name;
                    //TODO add this metric later
                    //stat.PlayersKilled = db.GamePlayers.Count(x => !x.Survived);
                    //stat.PlayersSurvived = db.GamePlayers.Count(x => x.Survived);

                    if (survivor != null)
                    {
                        stat.BestSurvivor = survivor.Name;
                        stat.BestSurvivorPercent = (int) survivor.pct;
                    }
                    stat.GamesPlayed = gamesPlayed;
                    stat.LastRun = DateTime.Now;
                    if (day1death != null)
                    {
                        stat.MostDeadFirstDay = day1death.Name;
                        stat.MostDeadFirstPercent = day1death.pct;
                    }
                    if (night1death != null)
                    {
                        stat.MostKilledFirstNight = night1death.Name;
                        stat.MostKilledFirstPercent = night1death.pct;
                    }
                    if (day1lynch != null)
                    {
                        stat.MostLynchedFirstNight = day1lynch.Name;
                        stat.MostLynchFirstPercent = day1lynch.pct;
                    }
                    db.SaveChanges();

                }
            }
            catch
            {
                // ignored
            }
        }
Ejemplo n.º 16
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);
             }
         }
     }
 }
Ejemplo n.º 17
0
        public static void TeamWinChart(string input, Update u)
        {
            //first we need to get the start date / timespan, otherwise default.
            var start = new DateTime(2016, 5, 15);

            if (!String.IsNullOrWhiteSpace(input))
            {
                var args = input.Split(' ');
                int amount = 0;
                if (int.TryParse(args[0], out amount) && args.Length >= 2)
                {
                    //get the interval
                    switch (args[1])
                    {
                        case "weeks":
                        case "week":
                            start = DateTime.Now.AddDays(-(amount * 7));
                            break;
                        case "day":
                        case "days":
                            start = DateTime.Now.AddDays(-amount);
                            break;
                        case "hour":
                        case "hours":
                            start = DateTime.Now.AddHours(-amount);
                            break;
                        default:
                            Bot.Api.SendTextMessage(u.Message.Chat.Id, "Acceptable intervals are: hour(s), day(s), week(s)");
                            break;
                    }
                }

            }

            var query = $@"SELECT x.Players,
             Round((COUNT (x.GameId) * 100.0 / sum (count(x.GameId)) OVER (PARTITION BY Players)), 2) AS Wins
             , X.Winner AS Team
             FROM
             (SELECT DISTINCT [gameid]
             FROM [werewolf].[Dbo].gameplayer gp inner join game g on gp.GameId = g.Id WHERE role = 'Cultist' AND TimeStarted > '{ start.ToString("yyyy-MM-dd HH:mm:ss")}') AS ac
             iNNER JOIN
             (SELECT count (gp.PlayerId) AS Players, gp.GameId, CASE WHEN gm.Winner = 'Wolves' THEN 'Wolf' ELSE gm.Winner END AS Winner
             FROM Game AS gm
             INNER JOIN GamePlayer AS gp ON gp.GameId = gm.Id
             WHERE gm.Winner is not null
             GROUP BY gp.GameId, gm.Winner
             HAVING COUNT (gp.PlayerId)> = 5)
             AS x on ac.gameId = x.gameId
             GROUP BY x.Winner, x.Players
             ORDER BY x.Players, Wins DESC";

            var result = new List<TeamWinResult>();
            using (var db = new WWContext())
            {
                result = db.Database.SqlQuery<TeamWinResult>(query).ToListAsync().Result;
            }

            //we have our results, now chart it...
            //build a datatable
            var dataSet = new DataSet();
            var dt = new DataTable();
            dt.Columns.Add("Players", typeof(int));
            dt.Columns.Add("Wins", typeof(int));
            dt.Columns.Add("Team", typeof(string));
            foreach (var r in result)
            {
                var row = dt.NewRow();
                row[0] = r.Players;
                row[1] = (int)r.Wins;
                row[2] = r.Team;
                dt.Rows.Add(row);
            }

            dataSet.Tables.Add(dt);

            //now build the chart
            Chart chart = new Chart();
            //chart.DataSource = dataSet.Tables[0];
            chart.Width = 1000;
            chart.Height = 400;
            var legend = new Legend();
            //create serie...
            foreach (var team in new[] { "Wolf", "Village", "Tanner", "Cult", "SerialKiller", "Lovers" })
            {
                Series serie1 = new Series();
                //serie1.Label = team;
                serie1.LegendText = team;
                serie1.Name = team;
                switch (team)
                {
                    case "Wolf":
                        serie1.Color = Color.SaddleBrown;
                        break;
                    case "Village":
                        serie1.Color = Color.Green;
                        break;
                    case "Tanner":
                        serie1.Color = Color.Red;
                        break;
                    case "Cult":
                        serie1.Color = Color.Blue;
                        break;
                    case "SerialKiller":
                        serie1.Color = Color.Black;
                        break;
                    case "Lovers":
                        serie1.Color = Color.Pink;
                        break;
                }
                serie1.MarkerBorderWidth = 2;
                serie1.BorderColor = Color.FromArgb(164, 164, 164);
                serie1.ChartType = SeriesChartType.StackedBar100;
                serie1.BorderDashStyle = ChartDashStyle.Solid;
                serie1.BorderWidth = 1;
                //serie1.ShadowColor = Color.FromArgb(128, 128, 128);
                //serie1.ShadowOffset = 1;
                serie1.IsValueShownAsLabel = false;
                serie1.XValueMember = "Players";
                serie1.YValueMembers = "Wins";
                serie1.Font = new Font("Tahoma", 8.0f);
                serie1.BackSecondaryColor = Color.FromArgb(0, 102, 153);
                serie1.LabelForeColor = Color.FromArgb(100, 100, 100);
                //add our values
                var pl = 4;
                foreach (var r in result.Where(x => x.Team == team).OrderBy(x => x.Players))
                {
                    pl++;
                    if (r.Players != pl)
                    {
                        while (pl < r.Players)
                        {
                            serie1.Points.AddXY(pl, 0);
                            pl++;
                        }
                    }
                    serie1.Points.AddXY(r.Players, r.Wins);
                }
                //make sure we filled all the points...
                var top = (int)(serie1.Points.OrderByDescending(x => x.XValue).FirstOrDefault()?.XValue ?? 4);

                if (top < 35)
                {
                    top++;
                    while (top <= 35)
                    {
                        serie1.Points.AddXY(top, 0);
                        top++;
                    }
                }
                //legend.CustomItems.Add(serie1.Color, team);
                chart.Series.Add(serie1);
            }
            //create chartareas...
            ChartArea ca = new ChartArea();
            ca.Name = "ChartArea1";
            ca.BackColor = Color.White;
            ca.BorderColor = Color.FromArgb(26, 59, 105);
            ca.BorderWidth = 0;
            ca.BorderDashStyle = ChartDashStyle.Solid;
            ca.AxisX = new Axis();
            ca.AxisY = new Axis();
            chart.ChartAreas.Add(ca);
            chart.Legends.Add(legend);
            //databind...
            //chart.DataBind();
            //save result

            var path = Path.Combine(Bot.RootDirectory, "myChart.png");
            chart.SaveImage(path, ChartImageFormat.Png);
            SendImage(path, u.Message.Chat.Id);
        }
Ejemplo n.º 18
0
        static void GlobalStats()
        {
            Console.WriteLine("Calculating Global Stats");
            try
            {
                using (var DB = new WWContext())
                {

                    var gamesPlayed = DB.Games.Count();
                    var night1death = DB.GlobalNight1Death().First();
                    var day1lynch = DB.GlobalDay1Lynch().First();
                    var day1death = DB.GlobalDay1Death().First();
                    var survivor = DB.GlobalSurvivor().First();
                    var stat = DB.GlobalStats.FirstOrDefault();
                    if (stat == null)
                    {
                        stat = DB.GlobalStats.Create();
                        DB.GlobalStats.Add(stat);
                    }

                    stat.PlayersKilled = DB.GamePlayers.Count(x => !x.Survived);
                    stat.PlayersSurvived = DB.GamePlayers.Count(x => x.Survived);
                    stat.TotalGroups = DB.Groups.Count();
                    stat.TotalPlayers = DB.Players.Count();
                    stat.BestSurvivor = survivor.Name;
                    stat.BestSurvivorPercent = (int)survivor.pct;
                    stat.BestSurvivorId = survivor.TelegramId;
                    stat.GamesPlayed = gamesPlayed;
                    stat.LastRun = DateTime.Now;
                    stat.MostKilledFirstDay = day1death.Name;
                    stat.MostKilledFirstDayPercent = day1death.pct;
                    stat.MostKilledFirstDayId = day1death.TelegramId;
                    stat.MostKilledFirstNight = night1death.Name;
                    stat.MostKilledFirstPercent = night1death.pct;
                    stat.MostKilledFirstNightId = night1death.TelegramId;
                    stat.MostLynchedFirstDay = day1lynch.Name;
                    stat.MostLynchedFirstPercent = day1lynch.pct;
                    stat.MostLynchedFirstDayId = day1lynch.TelegramId;

                    DB.SaveChanges();

                }

                //now do daily counts
                using (var db = new WWContext())
                {
                    //get daily counts
                    var counts = db.getDailyCounts();
                    db.DailyCounts.RemoveRange(db.DailyCounts);
                    foreach (var count in counts)
                        db.DailyCounts.Add(new DailyCount { Day = count.Day.Value, Games = count.Games.Value, Groups = count.Groups.Value, Users = count.players.Value });
                    db.SaveChanges();

                }
            }
            catch(Exception e)
            {
                while (e.InnerException != null)
                    e = e.InnerException;

                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 19
0
        public void AddPlayer(User u, bool notify = true)
        {
            try
            {
                if (!IsJoining)
                {
                    SendWithQueue(GetLocaleString("NoJoinGameRunning"));
                    return;
                }
                //first check the player hasn't already joined
                if (Players.Any(x => x.Id == u.Id))
                {
                    SendWithQueue(GetLocaleString("AlreadyJoined"));
                    return;
                }

                var p = new IPlayer
                {
                    TeleUser = u,
                    HasPM = false,
                    Name = $"{u.FirstName} {u.LastName}"
                };
                p.Name = p.Name.Trim();
                p.Id = p.TeleUser.Id;
                //if ()
                //{
                //    var dbuser = GetDBPlayer(p);
                //    if (dbuser != null)
                //    {
                //        dbuser.Banned = true;
                //        DB.SaveChanges();
                //        Send(GetLocaleString("BannedForExploit", p.Name));
                //    }
                //}
                if (p.Name.StartsWith("/") || String.IsNullOrEmpty(p.Name) || p.Name.Trim().ToLower() == "skip")
                {
                    SendWithQueue(GetLocaleString("ChangeNameToJoin",
                        String.IsNullOrWhiteSpace(u.Username) ? u.FirstName + " " + u.LastName : "@" + u.Username));
                    return;
                }
                if (Players.Any(x => x.Name == p.Name))
                {
                    SendWithQueue(GetLocaleString("NameExists", p.Name, p.TeleUser.Username));
                    return;
                }
                if (Players.Count >= Settings.MaxPlayers)
                {
                    SendWithQueue(GetLocaleString("PlayerLimitReached"));
                    return;
                }
                Players.Add(p);
                if (!notify) return;

                var msg = GetLocaleString("PlayerJoined", p.Name, Players.Count, Settings.MinPlayers,
                    DbGroup.MaxPlayers ?? Settings.MaxPlayers);
                using (var db = new WWContext())
                {
                    var user = db.Players.FirstOrDefault(x => x.TelegramId == u.Id);
                    if (user == null)
                    {
                        user = new Player
                        {
                            TelegramId = u.Id,
                            HasPM = false
                        };
                        db.Players.Add(user);
                    }

                    user.UserName = u.Username;
                    user.Name = $"{u.FirstName} {u.LastName}".Trim();

                    db.SaveChanges();
                    var botname =
            #if DEBUG
                        "@serastestbot";
            #else
                "@werewolfbot";
            #endif
                    if (user.HasPM != true)
                        msg += Environment.NewLine + GetLocaleString("PMTheBot", p.Name, botname);
                }
                SendWithQueue(msg);
                if (Players.Count == (DbGroup.MaxPlayers ?? Settings.MaxPlayers))
                    KillTimer = true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error in AddPlayer: {e.Message}");
            }
        }
Ejemplo n.º 20
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.ToBold()), 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);
            }
        }
Ejemplo n.º 21
-1
        internal static void HandleCallback(CallbackQuery query)
        {
            using (var DB = new WWContext())
            {
                try
                {
                    string[] args = query.Data.Split('|');
                    InlineKeyboardMarkup menu;
                    Group grp;
                    List<InlineKeyboardButton> buttons = new List<InlineKeyboardButton>();
                    long groupid = 0;
                    if (args[0] == "vote")
                    {
                        var node = Bot.Nodes.FirstOrDefault(x => x.ClientId.ToString() == args[1]);
                        node?.SendReply(query);
                        return;
                    }

                    groupid = long.Parse(args[1]);
                    grp = DB.Groups.FirstOrDefault(x => x.GroupId == groupid);
                    if (grp == null && args[0] != "getlang" && args[0] != "validate")
                        return;
                    var command = args[0];
                    var choice = "";
                    if (args.Length > 2)
                        choice = args[2];
                    if (choice == "cancel")
                    {
                        Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                            $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                        return;
                    }
                    if (!nonCommandsList.Contains(command.ToLower()))
                        if (!UpdateHelper.IsGroupAdmin(query.From.Id, groupid))
                        {
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                "You do not appear to be an admin");
                            return;
                        }

                    switch (command)
                    {
                        case "validate":
                            //choice = args[1];
                            if (choice == "All")
                            {
                                Helpers.LanguageHelper.ValidateFiles(query.Message.Chat.Id, query.Message.MessageId);
                                return;
                            }
                            //var menu = new ReplyKeyboardHide { HideKeyboard = true, Selective = true };
                            //Bot.SendTextMessage(id, "", replyToMessageId: update.Message.MessageId, replyMarkup: menu);
                            var langOptions =
                                Directory.GetFiles(Bot.LanguageDirectory)
                                    .Select(
                                        x =>
                                            new
                                            {
                                                Name =
                                                    XDocument.Load(x)
                                                        .Descendants("language")
                                                        .First()
                                                        .Attribute("name")
                                                        .Value,
                                                FilePath = x
                                            });
                            var option = langOptions.First(x => x.Name == choice);
                            LanguageHelper.ValidateLanguageFile(query.Message.Chat.Id, option.FilePath, query.Message.MessageId);
                            return;
                        case "getlang":
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId, "One moment...");
                            if (choice == "All")
                                LanguageHelper.SendAllFiles(query.Message.Chat.Id);
                            else
                                LanguageHelper.SendFile(query.Message.Chat.Id, choice);

                            break;
                        case "upload":
                            Console.WriteLine(choice);
                            if (choice == "current")
                            {
                                Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId, "No action taken.");
                                return;
                            }
                            Helpers.LanguageHelper.UseNewLanguageFile(choice, query.Message.Chat.Id, query.Message.MessageId);
                            return;

                        case "vote":
                            //send it back to the game;
                            var node = Bot.Nodes.FirstOrDefault(x => x.ClientId.ToString() == args[1]);
                            node?.SendReply(query);
                            break;
                        case "lang":
                            //load up each file and get the names
                            var langs =
                                Directory.GetFiles(Bot.LanguageDirectory)
                                    .Select(
                                        x =>
                                            new
                                            {
                                                Name =
                                                        XDocument.Load(x)
                                                            .Descendants("language")
                                                            .First()
                                                            .Attribute("name")
                                                            .Value,
                                                Base = XDocument.Load(x)
                                                            .Descendants("language")
                                                            .First()
                                                            .Attribute("base")
                                                            .Value,
                                                Variant = XDocument.Load(x)
                                                            .Descendants("language")
                                                            .First()
                                                            .Attribute("variant")
                                                            .Value,
                                                FileName = Path.GetFileNameWithoutExtension(x)
                                            });

                            buttons.Clear();
                            buttons.AddRange(langs.Select(x => x.Base).Distinct().OrderBy(x => x).Select(x => new InlineKeyboardButton(x, $"setlang|{groupid}|{x}|null|base")));

                            var baseMenu = new List<InlineKeyboardButton[]>();
                            for (var i = 0; i < buttons.Count; i++)
                            {
                                if (buttons.Count - 1 == i)
                                {
                                    baseMenu.Add(new[] { buttons[i] });
                                }
                                else
                                    baseMenu.Add(new[] { buttons[i], buttons[i + 1] });
                                i++;
                            }

                            menu = new InlineKeyboardMarkup(baseMenu.ToArray());

                            var curLang = langs.First(x => x.FileName == grp.Language);
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What Language?\nCurrent: {curLang.Base}",
                                replyMarkup: menu);
                            break;
                        case "setlang":
                            //first, is this the base or variant?
                            var isBase = args[4] == "base";
                            //ok, they picked a language, let's set it.
                            var validlangs =
                                Directory.GetFiles(Bot.LanguageDirectory)
                                        .Select(
                                            x =>
                                                new
                                                {
                                                    Name =
                                                        XDocument.Load(x)
                                                            .Descendants("language")
                                                            .First()
                                                            .Attribute("name")
                                                            .Value,
                                                    Base = XDocument.Load(x)
                                                            .Descendants("language")
                                                            .First()
                                                            .Attribute("base")
                                                            .Value,
                                                    Variant = XDocument.Load(x)
                                                            .Descendants("language")
                                                            .First()
                                                            .Attribute("variant")
                                                            .Value,
                                                    FileName = Path.GetFileNameWithoutExtension(x)
                                                });
                            //ok, if base we need to check for variants....
                            var lang = validlangs.First(x => x.Base == choice);
                            if (isBase)
                            {
                                var variants = validlangs.Where(x => x.Base == choice);
                                if (variants.Count() > 1)
                                {
                                    buttons.Clear();
                                    buttons.AddRange(variants.Select(x => new InlineKeyboardButton(x.Variant, $"setlang|{groupid}|{x.Base}|{x.Variant}|v")));

                                    var twoMenu = new List<InlineKeyboardButton[]>();
                                    for (var i = 0; i < buttons.Count; i++)
                                    {
                                        if (buttons.Count - 1 == i)
                                        {
                                            twoMenu.Add(new[] { buttons[i] });
                                        }
                                        else
                                            twoMenu.Add(new[] { buttons[i], buttons[i + 1] });
                                        i++;
                                    }

                                    menu = new InlineKeyboardMarkup(twoMenu.ToArray());

                                    var curVariant = validlangs.First(x => x.FileName == grp.Language);
                                    Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                        $"What Variant?\nCurrent: {curVariant.Variant}",
                                        replyMarkup: menu);
                                    return;
                                }
                                //only one variant, move along
                            }
                            else
                            {
                                lang = validlangs.First(x => x.Base == choice && x.Variant == args[3]);
                            }

                            if (
                                Directory.GetFiles(Bot.LanguageDirectory)
                                    .Any(
                                        x =>
                                            String.Equals(Path.GetFileNameWithoutExtension(x), lang.FileName,
                                                StringComparison.InvariantCultureIgnoreCase)))
                            {
                                //now get the group

                                grp.Language = lang.FileName;
                                //check for any games running
                                var ig = GetGroupNodeAndGame(groupid);

                                ig?.LoadLanguage(lang.FileName);
                                menu = GetConfigMenu(groupid);
                                Bot.Api.AnswerCallbackQuery(query.Id, $"Language set to {lang.Base}{(String.IsNullOrWhiteSpace(lang.Variant) ? "" : ": " + lang.Variant)}");
                                Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId, $"What would you like to do?", replyMarkup: menu);
                            }
                            DB.SaveChanges();
                            break;
                        case "online":
                            buttons.Add(new InlineKeyboardButton("Yes", $"setonline|{groupid}|show"));
                            buttons.Add(new InlineKeyboardButton("No", $"setonline|{groupid}|hide"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setonline|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Do you want your group to be notified when the bot is online?\nCurrent: {grp.DisableNotification != false}",
                                replyMarkup: menu);
                            break;
                        case "setonline":

                            grp.DisableNotification = (choice == "hide");
                            Bot.Api.AnswerCallbackQuery(query.Id,
                                $"Notification will {(grp.DisableNotification == true ? "not " : "")}be shown on startup");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "flee":
                            buttons.Add(new InlineKeyboardButton("Yes", $"setflee|{groupid}|enable"));
                            buttons.Add(new InlineKeyboardButton("No", $"setflee|{groupid}|disable"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setflee|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Do you want to allow fleeing once the game has started?\nNote: players can still flee during join phase\nCurrent: Players can {(grp.DisableFlee == false ? "" : "not ")}flee",
                                replyMarkup: menu);
                            break;
                        case "setflee":

                            grp.DisableFlee = (choice == "disable");
                            Bot.Api.AnswerCallbackQuery(query.Id,
                                $"Players will {(grp.DisableFlee == true ? "not " : "")}be allowed to flee after game start");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "maxplayer":
                            buttons.Add(new InlineKeyboardButton("10", $"setmaxplayer|{groupid}|10"));
                            buttons.Add(new InlineKeyboardButton("15", $"setmaxplayer|{groupid}|15"));
                            buttons.Add(new InlineKeyboardButton("20", $"setmaxplayer|{groupid}|20"));
                            buttons.Add(new InlineKeyboardButton("25", $"setmaxplayer|{groupid}|25"));
                            buttons.Add(new InlineKeyboardButton("30", $"setmaxplayer|{groupid}|30"));
                            buttons.Add(new InlineKeyboardButton("35", $"setmaxplayer|{groupid}|35"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setmaxplayer|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"How many players would like to set as the maximum?\nCurrent: {grp.MaxPlayers ?? Settings.MaxPlayers}",
                                replyMarkup: menu);
                            break;
                        case "setmaxplayer":

                            grp.MaxPlayers = int.Parse(choice);
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Max players set to {choice}");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "roles":
                            buttons.Add(new InlineKeyboardButton("Show", $"setroles|{groupid}|show"));
                            buttons.Add(new InlineKeyboardButton("Hide", $"setroles|{groupid}|hide"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setroles|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Show or Hide roles on death?\nCurrent: {(grp.ShowRoles == false ? "Hidden" : "Shown")}",
                                replyMarkup: menu);
                            break;
                        case "setroles":

                            grp.ShowRoles = (choice == "show");
                            Bot.Api.AnswerCallbackQuery(query.Id,
                                $"Roles will be {(grp.ShowRoles == false ? "hidden" : "shown")} on death.");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "mode":
                            buttons.Add(new InlineKeyboardButton("Normal Only", $"setmode|{groupid}|Normal"));
                            buttons.Add(new InlineKeyboardButton("Chaos Only", $"setmode|{groupid}|Chaos"));
                            buttons.Add(new InlineKeyboardButton("Player Choice", $"setmode|{groupid}|Player"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setmode|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What game mode will the group be?\nCurrent: {grp.Mode}", replyMarkup: menu);
                            break;
                        case "setmode":

                            grp.Mode = choice;
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Game mode set to {choice}");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "endroles":
                            buttons.Add(new InlineKeyboardButton("Don't show any", $"setendroles|{groupid}|None"));
                            buttons.Add(new InlineKeyboardButton("Show only living players",
                                $"setendroles|{groupid}|Living"));
                            buttons.Add(new InlineKeyboardButton("Show all players", $"setendroles|{groupid}|All"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setendroles|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"How do you want roles to be shown at the end?\nCurrent: {grp.ShowRolesEnd}",
                                replyMarkup: menu);
                            break;
                        case "setendroles":

                            grp.ShowRolesEnd = choice;
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Roles shown at end set to: {choice}");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "day":
                            buttons.Add(new InlineKeyboardButton("30", $"setday|{groupid}|30"));
                            buttons.Add(new InlineKeyboardButton("60", $"setday|{groupid}|60"));
                            buttons.Add(new InlineKeyboardButton("90", $"setday|{groupid}|90"));
                            buttons.Add(new InlineKeyboardButton("120", $"setday|{groupid}|120"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setday|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Choose the base time (in seconds) for day time.   This will still be modified based on number of players.\nMinimum time added based on players is 60 seconds.  Default setting: {Settings.TimeDay}\nCurrent: {grp.DayTime ?? Settings.TimeDay}",
                                replyMarkup: menu);
                            break;
                        case "setday":

                            grp.DayTime = int.Parse(choice);
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Base day time set to {choice} seconds");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "night":
                            buttons.Add(new InlineKeyboardButton("30", $"setnight|{groupid}|30"));
                            buttons.Add(new InlineKeyboardButton("60", $"setnight|{groupid}|60"));
                            buttons.Add(new InlineKeyboardButton("90", $"setnight|{groupid}|90"));
                            buttons.Add(new InlineKeyboardButton("120", $"setnight|{groupid}|120"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setnight|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Choose the time (in seconds) for night time. Default setting: {Settings.TimeNight}\nCurrent:{grp.NightTime ?? Settings.TimeNight}",
                                replyMarkup: menu);
                            break;
                        case "setnight":

                            grp.NightTime = int.Parse(choice);
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Night time set to {choice} seconds");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "lynch":
                            buttons.Add(new InlineKeyboardButton("30", $"setlynch|{groupid}|30"));
                            buttons.Add(new InlineKeyboardButton("60", $"setlynch|{groupid}|60"));
                            buttons.Add(new InlineKeyboardButton("90", $"setlynch|{groupid}|90"));
                            buttons.Add(new InlineKeyboardButton("120", $"setlynch|{groupid}|120"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setlynch|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Choose the time (in seconds) for lynch voting. Default setting: {Settings.TimeLynch}\nCurrent:{grp.LynchTime ?? Settings.TimeLynch}",
                                replyMarkup: menu);
                            break;
                        case "setlynch":

                            grp.LynchTime = int.Parse(choice);
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Lynch voting time set to {choice} seconds");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "fool":
                            buttons.Add(new InlineKeyboardButton("Allow", $"setfool|{groupid}|true"));
                            buttons.Add(new InlineKeyboardButton("Disallow", $"setfool|{groupid}|false"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setfool|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Allow fool as a role option?\nCurrent: {grp.AllowFool}", replyMarkup: menu);
                            break;
                        case "setfool":

                            grp.AllowFool = (choice == "true");
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Fool as a role set to: {choice}");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "tanner":
                            buttons.Add(new InlineKeyboardButton("Allow", $"settanner|{groupid}|true"));
                            buttons.Add(new InlineKeyboardButton("Disallow", $"settanner|{groupid}|false"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"settanner|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Allow tanner as a role option?\nCurrent: {grp.AllowTanner}", replyMarkup: menu);
                            break;
                        case "settanner":

                            grp.AllowTanner = (choice == "true");
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Tanner as a role set to: {choice}");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "cult":
                            buttons.Add(new InlineKeyboardButton("Allow", $"setcult|{groupid}|true"));
                            buttons.Add(new InlineKeyboardButton("Disallow", $"setcult|{groupid}|false"));
                            buttons.Add(new InlineKeyboardButton("Cancel", $"setcult|{groupid}|cancel"));
                            menu = new InlineKeyboardMarkup(buttons.Select(x => new[] { x }).ToArray());
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"Allow cult as a role option?\nCurrent: {grp.AllowCult}", replyMarkup: menu);
                            break;
                        case "setcult":

                            grp.AllowCult = (choice == "true");
                            Bot.Api.AnswerCallbackQuery(query.Id, $"Cult as a role set to: {choice}");
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                $"What would you like to do?", replyMarkup: GetConfigMenu(groupid));
                            DB.SaveChanges();
                            break;
                        case "done":
                            Bot.Api.EditMessageText(query.Message.Chat.Id, query.Message.MessageId,
                                "Thank you, have a good day :)");
                            break;
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }