Exemple #1
0
        public void DeleteRoom(BunkerUser user)
        {
            var  tmp     = new List <Room>();
            bool catched = false;

            for (int i = 0; i < rooms.Count; i++)
            {
                if (rooms[i].Host == user)
                {
                    rooms[i].ClearRoom();
                    user.IsHost = false;
                    catched     = true;
                }
                else
                {
                    tmp.Add(rooms[i]);
                }
            }
            if (catched)
            {
                rooms = tmp;
                Program.SendMessage(user, "Room has been deleted.");
            }
            else
            {
                Program.SendMessage(user, "You are not a host");
            }
        }
Exemple #2
0
        public override async Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            List <Room> roomList = Program.GetRooms.Rooms;

            if (roomList == null || roomList.Count == 0)
            {
                await client.SendTextMessageAsync(user.ChatID, "There are no rooms to join at the moment.");

                return;
            }

            BunkerUser[] admins = new BunkerUser[roomList.Count];

            int count = 0;

            foreach (Room room in roomList)
            {
                admins[count] = room.Host;
                count++;
            }

            InlineKeyboardButton[] buttons = new InlineKeyboardButton[admins.Length];

            for (int i = 0; i < admins.Length; i++)
            {
                buttons[i] = InlineKeyboardButton.WithCallbackData($"{admins[i].NickName}");
            }

            var keyboard = new InlineKeyboardMarkup(buttons);

            await client.SendTextMessageAsync(user.ChatID, "Choose your host", replyMarkup : keyboard);
        }
Exemple #3
0
        public override async Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            //TODO Clear all the lists, remove all isHost flags (if its necessary, idk)
            Program.bunkerUsers.CLearBunkerUsersList();
            Program.rooms.ClearRoomList();

            await client.SendTextMessageAsync(user.ChatID, "All users has been deleted from the bot memory");
        }
Exemple #4
0
 public bool CheckExistance(BunkerUser user)
 {
     foreach (var us in users)
     {
         if (us.Equals(user))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #5
0
        public async override Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            foreach (var room in Program.GetRooms.Rooms)
            {
                if (room.Players.Contains(user))
                {
                    room.RemovePlayer(user);
                }
            }

            await client.SendTextMessageAsync(user.ChatID, "You have quited the room.\nJoin new one or create yours");
        }
Exemple #6
0
        public Room GetRoomByPlayer(BunkerUser player)
        {
            foreach (Room room in rooms)
            {
                if (room.ContainsUser(player))
                {
                    return(room);
                }
            }

            return(null);
        }
Exemple #7
0
 public override async Task Execute(BunkerUser user, ITelegramBotClient client)
 {
     if (Program.rooms.CreateRoom(user))
     {
         user.IsHost = true;
         await client.SendTextMessageAsync(user.ChatID, "You are now a host");
     }
     else
     {
         await client.SendTextMessageAsync(user.ChatID, "Error!");
     }
 }
Exemple #8
0
        public async override Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            if (user.IsHost)
            {
                foreach (var room in Program.GetRooms.Rooms)
                {
                    if (room.Host == user)
                    {
                        var netclient = new HttpClient();

                        var cataclysm = await netclient.GetStringAsync("https://randomall.ru/api/custom/gen/1422/");

                        var cataclysm2 = cataclysm.Substring(9, cataclysm.Length - 11);
                        cataclysm2 += "\n";
                        string[] cataclysm3 = cataclysm2.Split("\\n");

                        foreach (var player in room.players)
                        {
                            string card_result = "+______Your___Card______+\n";

                            var characteristics = await netclient.GetStringAsync("https://randomall.ru/api/custom/gen/758/");//1440, 758 (choose the best one)

                            card_result += "-----CHARACTERISTICS-----\n";

                            string characteristics2 = characteristics.Substring(9, characteristics.Length - 11);
                            characteristics2 += "\n";
                            String[] characteristics3 = characteristics2.Split("\\n");
                            foreach (var word in characteristics3)
                            {
                                card_result += word + "\n";
                            }
                            card_result += "-------------------------\n";

                            card_result += "--------CATACLYSM--------\n";

                            foreach (var word in cataclysm3)
                            {
                                card_result += word + "\n";
                            }
                            card_result += "-------------------------\n";

                            card_result += "+_______________________+\n";
                            Program.SendMessage(player, card_result);
                        }
                    }
                }
            }
        }
Exemple #9
0
        public override async Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            Room room = Program.rooms.GetRoomByPlayer(user);

            int size = room.Players.Count;

            if (size == 1)
            {
                Program.SendMessage(user, "You must have at least 2 players to start a poll!");
            }
            else
            {
                string[] options = new string[size];

                for (int i = 0; i < size; i++)
                {
                    options[i] = $"{room.Players[i].NickName}";
                }

                var pollInt = await client.SendPollAsync(room.Players[0].ChatID, "Whom to quit", options);

                for (int i = 1; i < size; i++)
                {
                    await client.ForwardMessageAsync(room.Players[i].ChatID, pollInt.Chat.Id, pollInt.MessageId);
                }

                await Task.Delay(20000);

                var stoppedPoll = await client.StopPollAsync(pollInt.Chat.Id, pollInt.MessageId);

                int max = 0;

                string name = "";

                foreach (PollOption option in stoppedPoll.Options)
                {
                    if (option.VoterCount > max)
                    {
                        max  = option.VoterCount;
                        name = option.Text;
                    }
                }

                BunkerUser player = room.GetPlayerByName(name);
                room.RemovePlayer(player);
            }
        }
Exemple #10
0
        public override async Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            CommandService         commandsInstance = Program.GetCommands;
            List <TelegramCommand> commands;

            if (user.IsHost)
            {
                commands = commandsInstance.GetAdmin();
            }
            else if (user.IsPlayer)
            {
                commands = commandsInstance.GetPlayer();
            }
            else
            {
                commands = commandsInstance.GetNew();
            }


            int b = commands.Count % 2 == 0 ? commands.Count / 2 : commands.Count / 2 + 1;

            int count = 0;

            KeyboardButton[][] buttons = new KeyboardButton[b][];

            for (int i = 0; i < b; i++)
            {
                if (commands.Count % 2 != 0 && i == b - 1)
                {
                    buttons[i] = new[] { new KeyboardButton($"{commands[count].Name}") };
                }
                else
                {
                    buttons[i] = new[] {
                        new KeyboardButton($"{commands[count].Name}"),
                        new KeyboardButton($"{commands[count+1].Name}")
                    };
                    count += 2;
                }
            }

            var keyboard = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup(buttons);

            await client.SendTextMessageAsync(user.ChatID, "Choose option", replyMarkup : keyboard);
        }
Exemple #11
0
        public override async Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            List <Room> rooms = Program.rooms.Rooms;

            foreach (Room room in rooms)
            {
                if (room.ContainsUser(user))
                {
                    string message = "Players in your room:";

                    foreach (BunkerUser player in room.Players)
                    {
                        message += $"\n{player.NickName}";
                    }

                    await client.SendTextMessageAsync(user.ChatID, message);
                }
            }
        }
Exemple #12
0
        public override async Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            string message; //= " /start - start a bot \n /host - to became a host of the game \n /join - to join the game \n /quit - deletes you from bot memory \n /end - deletes all users from bot memory ";

            if (user.IsHost)
            {
                message = " /players - show players in your room\n /vote - choose who to expel\n /quit - leave the room\n /end - delete all users from bot memory\n /gameover - close room\n /createcards - create cards for all players in the room";
            }
            else if (user.IsPlayer)
            {
                message = " /players - show players in your room\n /quit - leave the room\n /end - delete all users from bot memory";
            }
            else
            {
                message = " /end - delete all users from bot memory\n /host - create a room and become a host\n /join - join the room";
            }

            await client.SendTextMessageAsync(user.ChatID, message);
        }
Exemple #13
0
        public bool CreateRoom(BunkerUser user)
        {
            bool hasRoom = false;

            foreach (var room in Rooms)
            {
                if (room.Host == user)
                {
                    Program.SendMessage(user, "You already have a room. Use it or delete it.");
                    hasRoom = true;
                }
            }
            if (!hasRoom)
            {
                rooms.Add(new Room(user));
                Program.SendMessage(user, "The room has been created.");
                return(true);
            }
            return(false);
        }
Exemple #14
0
        public override async Task Execute(BunkerUser user, ITelegramBotClient client)
        {
            CommandService commands = Program.GetCommands;

            await client.SendTextMessageAsync(user.ChatID, "Welcome to the game");

            if (!Program.GetBunkerUsers.CheckExistance(user))
            {
                Program.GetBunkerUsers.Add(user);
                await commands.GetDisplayCommand().Execute(user, client);
            }

            var    tmp     = Program.GetBunkerUsers.Users;
            string message = "Users Online:";

            foreach (var us in tmp)
            {
                message += $"\n{us.NickName}";
            }
            await client.SendTextMessageAsync(user.ChatID, message);
        }
Exemple #15
0
        private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            var message = messageEventArgs.Message;
            var newUser = new BunkerUser(message.From.FirstName, message.Chat.Id);

            if (bunkerUsers.CheckExistance(newUser))
            {
                newUser = bunkerUsers.GetUserById(message.Chat.Id);
            }
            else
            {
                if (message.Text == "/start")
                {
                    await commands.GetStartCommand().Execute(newUser, client);

                    await commands.GetDisplayBtnCommand().Execute(newUser, client);

                    return;
                }
                else
                {
                    await client.SendTextMessageAsync(newUser.ChatID, "You are not in system.\nUse /start to jump into the game.");

                    return;
                }
            }

            if (message?.Type == MessageType.Text)
            {
                foreach (TelegramCommand command in commands.GetAll())
                {
                    if (command.Contains(message.Text))
                    {
                        await command.Execute(newUser, client);

                        await commands.GetDisplayBtnCommand().Execute(newUser, client);
                    }
                }
            }
        }
 public override async Task Execute(BunkerUser user, ITelegramBotClient client)
 {
     user.IsPlayer = false;
     Program.rooms.DeleteRoom(user);
 }
Exemple #17
0
 public override Task Execute(BunkerUser user, ITelegramBotClient client)
 {
     throw new NotImplementedException();
 }
 public abstract Task Execute(BunkerUser user, ITelegramBotClient client);
Exemple #19
0
 public void RemoveUser(BunkerUser user)
 {
     users.Remove(user);
 }
Exemple #20
0
 public void Add(BunkerUser user)
 {
     users.Add(user);
 }
Exemple #21
0
 public static async void SendMessage(BunkerUser user, string message)
 {
     await client.SendTextMessageAsync(user.ChatID, message);
 }