Esempio n. 1
0
 internal static void Send(string message, long id, bool clearKeyboard = false, ReplyKeyboardMarkup customMenu = null, Werewolf game = null)
 {
     //message = message.Replace("`",@"\`");
     if (clearKeyboard)
     {
         var menu = new ReplyKeyboardHide { HideKeyboard = true };
         Bot.SendTextMessage(id, message, replyMarkup: menu, disableWebPagePreview: true, parseMode: ParseMode.Html);
     }
     else if (customMenu != null)
     {
         Bot.SendTextMessage(id, message, replyMarkup: customMenu, disableWebPagePreview: true, parseMode: ParseMode.Html);
     }
     else
     {
         Bot.SendTextMessage(id, message, disableWebPagePreview: true, parseMode: ParseMode.Html);
     }
 }
Esempio n. 2
0
        private static void ClientOnDataReceived(object sender, Message message)
        {
            try
            {
                var messages = message.MessageString.Split('\u0013');
                foreach (var msg in messages)
                {
                    if (msg == "ping" || String.IsNullOrWhiteSpace(msg)) return; //ignore

                    string t = null;
                    try
                    {
                        dynamic m = JsonConvert.DeserializeObject(msg);
                        t = m.JType?.ToString();
                    }
                    catch (Exception e)
                    {
                        //Bot.SendTextMessage(Settings.MainChatId, e.Message);
                        continue;
                    }
                    Werewolf game;
                    if (t != null)
                    {
                        Console.WriteLine(t);
                        switch (t)
                        {
                            case "PlayerJoinInfo":
                                var pji = JsonConvert.DeserializeObject<PlayerJoinInfo>(msg);
                                game = Games.FirstOrDefault(x => x.ChatId == pji.GroupId);
                                game?.AddPlayer(pji.User);
                                break;
                            case "GameStartInfo":
                                var gsi = JsonConvert.DeserializeObject<GameStartInfo>(msg);
                                //double check we don't already have a game...
                                game = Games.FirstOrDefault(x => x.ChatId == gsi.Chat.Id);
                                if (game != null)
                                {
                                    game.AddPlayer(gsi.User);
                                }
                                else
                                {
                                    game = new Werewolf(gsi.Chat.Id, gsi.User, gsi.Chat.Title,
                                        gsi.Chaos);
                                    Games.Add(game);
                                    GamesStarted++;
                                }
                                break;
                            case "ForceStartInfo":
                                var fsi = JsonConvert.DeserializeObject<ForceStartInfo>(msg);
                                game = Games.FirstOrDefault(x => x.ChatId == fsi.GroupId);
                                game?.ForceStart();
                                break;
                            //case "ReplyInfo":
                            //    var ri = JsonConvert.DeserializeObject<ReplyInfo>(msg);
                            //    game =
                            //        Games.FirstOrDefault(
                            //            x => x.Players.Any(p => p.TeleUser.Id == ri.Update.Message.From.Id && !p.IsDead));
                            //    game?.HandleReply(ri.Update);
                            //    break;
                            case "CallbackInfo":
                                var ci = JsonConvert.DeserializeObject<CallbackInfo>(msg);
                                game =
                                    Games.FirstOrDefault(
                                        x => x.Players.Any(p => !p.IsDead && p.TeleUser.Id == ci.Query.From.Id));
                                game?.HandleReply(ci.Query);
                                break;
                            case "PlayerListRequestInfo":
                                var plri = JsonConvert.DeserializeObject<PlayerListRequestInfo>(msg);
                                game = Games.FirstOrDefault(x => x.ChatId == plri.GroupId);
                                game?.OutputPlayers();
                                break;
                            case "PlayerFleeInfo":
                                var pfi = JsonConvert.DeserializeObject<PlayerFleeInfo>(msg);
                                game = Games.FirstOrDefault(x => x.ChatId == pfi.GroupId);
                                game?.RemovePlayer(pfi.User);
                                break;
                            case "LoadLangInfo":
                                var lli = JsonConvert.DeserializeObject<LoadLangInfo>(msg);
                                game = Games.FirstOrDefault(x => x.ChatId == lli.GroupId);
                                game?.LoadLanguage(lli.FileName);
                                break;
                            case "PlayerSmiteInfo":
                                var psi = JsonConvert.DeserializeObject<PlayerSmiteInfo>(msg);
                                game = Games.FirstOrDefault(x => x.ChatId == psi.GroupId);
                                game?.FleePlayer(psi.UserId);
                                break;
                            case "UpdateNodeInfo":
                                IsShuttingDown = true;
                                break;
                            case "SkipVoteInfo":
                                var svi = JsonConvert.DeserializeObject<SkipVoteInfo>(msg);
                                game = Games.FirstOrDefault(x => x.ChatId == svi.GroupId);
                                game?.SkipVote();
                                break;
                            default:
                                Console.WriteLine(msg);
                                break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n" + message.MessageString);
            }
        }
Esempio n. 3
0
 public static void RemoveGame(Werewolf werewolf)
 {
     try
     {
         if (werewolf.Players != null)
         {
             TotalPlayers += werewolf.Players.Count();
         }
         Games.Remove(werewolf);
         //kill the game completely
         werewolf.Dispose();
         werewolf = null;
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error in RemoveGame: " + ex.Message);
     }
 }