Browse Source

Forwarding messages when in game room

Tigran 4 năm trước cách đây
mục cha
commit
d0f972541b

+ 6 - 5
MafiaTelegramBot/Game/GameRooms/GameRoom.MessageHandler.cs

@@ -30,7 +30,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                 else if (text == keyboard.end_turn)
                 {
                     if (_room.IsDay && player.IsSpeaker) player.CurrentRole.TalkingActionComplete.Set();
-                    else await Bot.SendWithMarkdown2(player.ChatId, strings.now_is_not_your_turn);
+                    else await _room.PlayersCh.SendTo(player.ChatId, strings.now_is_not_your_turn);
                 }
                 else await ForwardMessage(player, text);
                 return update.Message;
@@ -38,9 +38,10 @@ namespace MafiaTelegramBot.Game.GameRooms
 
             private async Task ForwardMessage(Player player, string message)
             {
-                if (!player.IsAlive) await Bot.SendWithMarkdown2(player.ChatId, strings.you_now_died);
-                else if (player.IsBlocked) await Bot.SendWithMarkdown2(player.ChatId, strings.you_blocked);
-                else if (!player.IsSpeaker) await Bot.SendWithMarkdown2(player.ChatId, strings.now_you_cant_speak);
+                if(!_room.IsRunning) await _room.PlayersCh.SendExcept(player.Id, $"({player.TurnOrder}) {player.NickName}: {message}");
+                if (!player.IsAlive) await _room.PlayersCh.SendTo(player.Id, strings.you_now_died);
+                else if (player.IsBlocked) await _room.PlayersCh.SendTo(player.Id, strings.you_blocked);
+                else if (!player.IsSpeaker) await _room.PlayersCh.SendTo(player.Id, strings.now_you_cant_speak);
                 else if (_room.IsDay) await _room.PlayersCh.SendExcept(player.Id, $"({player.TurnOrder}) {player.NickName}: {message}");
                 else await _room._mafiaCh.SendExcept(player.Id, $"({player.TurnOrder}) {player.NickName}: {message}");
             }
@@ -76,7 +77,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                         $"({(item.IsAlive ? strings.alive : strings.died)}) " +
                         $"{role}";
                 }
-                await Bot.SendWithMarkdown2(player.ChatId, message);
+                await _room.PlayersCh.SendTo(player.Id, message);
             }
 
             private async Task Leave(Player player)

+ 1 - 1
MafiaTelegramBot/Game/Player.cs

@@ -135,7 +135,7 @@ namespace MafiaTelegramBot.Game
         {
             CurrentRole = new NoneRole();
             IsAlive = true;
-            IsSpeaker = false;
+            IsSpeaker = true;
             IsPlaying = false;
             IsFirst = false;
             CanBeHealed = true;

+ 7 - 1
MafiaTelegramBot/Models/Commands/Command.cs

@@ -53,7 +53,13 @@ namespace MafiaTelegramBot.Models.Commands
                 return await ((Command?) CustomHandlers["UsersThatCreatesRoom"].Clone(chatId, userId))!.Execute(update);
             if (Bot.UserThatEntersPrivateCode.Remove(userId))
                 return await ((Command?) CustomHandlers["UserThatEntersPrivateCode"].Clone(chatId, userId))!.Execute(update);
-            return await Bot.SendWithMarkdown2(chatId, $"{strings.command_not_found} _*({message})*_");
+            if (user.GetRoomName() == "")
+                return await Bot.SendWithMarkdown2(chatId, $"{strings.command_not_found} _*({message})*_");
+            {
+                var roomKey = RoomEncrypter.GetCode(user.GetRoomName());
+                var room = RoomController.GetRoom(roomKey);
+                return await room.MHandler.Handle(update);
+            }
         }
     }
 }