Ver Fonte

Timer enable/disable command

Tigran há 4 anos atrás
pai
commit
df61f97a6b

+ 1 - 0
MafiaTelegramBot/Game/GameRoom.cs

@@ -15,6 +15,7 @@ namespace MafiaTelegramBot.Game
         private int _minPlayers = Constants.PLAYER_LIMITS_MIN;
         public virtual bool IsPrivate { get; protected set; } = false;
         public bool IsExtended { get; init; } = false;
+        public bool TimerEnabled { get; set; } = true;
         public string RoomName { get; init; } = "NoNameRoom";
         public User Creator { get; init; } = new();
         

+ 2 - 1
MafiaTelegramBot/Models/Bot.cs

@@ -77,7 +77,8 @@ namespace MafiaTelegramBot.Models
                 new SetPlayersMaximumQuery(),
                 new ConnectToPublicRoomQuery(),
                 new ConnectToSelectedRoomQuery(),
-                new KickSelectedPlayerQuery()
+                new KickSelectedPlayerQuery(),
+                new TimerSwitchQuery(),
             };
         }
         

+ 3 - 2
MafiaTelegramBot/Models/Commands/RoomSettingsCommand.cs

@@ -16,8 +16,9 @@ namespace MafiaTelegramBot.Models.Commands
             var roomKey = user.GetRoomKey();
             var room = await RoomController.GetRoom(roomKey);
             var roomMaxCapacity = room.MaxPlayers;
-            var message = $"{strings.max_capacity_message}: {roomMaxCapacity}";
-            return await Bot.SendWithMarkdown2(ChatId, message, Keyboards.SetMaximumKeyboard(UserId));
+            var status = room.TimerEnabled ? strings.enabled : strings.disabled;
+            await Bot.SendWithMarkdown2(ChatId, $"{strings.timer}: {status}", Keyboards.TimerSwitchKeyboard(UserId, room.TimerEnabled ? strings.disable : strings.enable));
+            return await Bot.SendWithMarkdown2(ChatId, $"{strings.max_capacity_message}: {roomMaxCapacity}", Keyboards.SetMaximumKeyboard(UserId));
         }
     }
 }

+ 23 - 0
MafiaTelegramBot/Models/Inlines/TimerSwitchQuery.cs

@@ -0,0 +1,23 @@
+using System.Threading.Tasks;
+using MafiaTelegramBot.Controllers;
+using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.Resources;
+using Telegram.Bot.Types;
+
+namespace MafiaTelegramBot.Models.Inlines
+{
+    public class TimerSwitchQuery : Query
+    {
+        protected override Callback Name => Callback.SwitchTimer;
+        protected override async Task<Message> Execute(Update update)
+        {
+            await DeletePreviousMessage(ChatId, update.CallbackQuery.Message.MessageId);
+            var user = await UserDao.GetUserById(UserId);
+            var roomKey = user.GetRoomKey();
+            var room = await RoomController.GetRoom(roomKey);
+            room.TimerEnabled = !room.TimerEnabled;
+            var status = room.TimerEnabled ? strings.enabled : strings.disabled;
+            return await Bot.SendWithMarkdown2(ChatId, $"{strings.timer}: {status}");
+        }
+    }
+}

+ 2 - 1
MafiaTelegramBot/Resources/Callback.cs

@@ -15,6 +15,7 @@ namespace MafiaTelegramBot.Resources
         SettingsRoom,
         ConnectToSelectedRoom,
         SetPlayersMaximum,
-        KickUser
+        KickUser,
+        SwitchTimer,
     }
 }

+ 9 - 2
MafiaTelegramBot/Resources/Keyboards.cs

@@ -111,8 +111,7 @@ namespace MafiaTelegramBot.Resources
                 var s = rooms[i].IsExtended ? "Р" : "C";
                 inlineButtons[i] = new InlineKeyboardButton
                 {
-                    Text =
-                        $"{rooms[i].RoomName} ({rooms[i].Players.Values.Count.ToString()}/{rooms[i].MaxPlayers.ToString()})",
+                    Text = $"{rooms[i].RoomName} ({rooms[i].Players.Values.Count.ToString()}/{rooms[i].MaxPlayers.ToString()})",
                     CallbackData = $"{Callback.ConnectToSelectedRoom}|{userId}|{RoomEncrypter.FullToShort(rooms[i].RoomName)}"
                        
                 };
@@ -133,5 +132,13 @@ namespace MafiaTelegramBot.Resources
             }
             return new InlineKeyboardMarkup(inlineButtons);
         }
+
+        public static InlineKeyboardMarkup TimerSwitchKeyboard(long userId, string text)
+        {
+            return new( new[]
+            {
+                InlineKeyboardButton.WithCallbackData(text, $"{Callback.SwitchTimer}|{userId}"), 
+            });
+        }
     }
 }

+ 54 - 9
MafiaTelegramBot/Resources/strings.Designer.cs

@@ -114,6 +114,42 @@ namespace MafiaTelegramBot {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Отключить.
+        /// </summary>
+        internal static string disable {
+            get {
+                return ResourceManager.GetString("disable", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to отключен.
+        /// </summary>
+        internal static string disabled {
+            get {
+                return ResourceManager.GetString("disabled", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Включить.
+        /// </summary>
+        internal static string enable {
+            get {
+                return ResourceManager.GetString("enable", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to включен.
+        /// </summary>
+        internal static string enabled {
+            get {
+                return ResourceManager.GetString("enabled", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Введите код от комнаты.
         /// </summary>
@@ -357,15 +393,6 @@ namespace MafiaTelegramBot {
             }
         }
         
-        /// <summary>
-        ///   Looks up a localized string similar to Режим:.
-        /// </summary>
-        internal static string room_mode {
-            get {
-                return ResourceManager.GetString("room_mode", resourceCulture);
-            }
-        }
-        
         /// <summary>
         ///   Looks up a localized string similar to Комната с именем.
         /// </summary>
@@ -456,6 +483,24 @@ namespace MafiaTelegramBot {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Переключить.
+        /// </summary>
+        internal static string switch_timer {
+            get {
+                return ResourceManager.GetString("switch_timer", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Таймер.
+        /// </summary>
+        internal static string timer {
+            get {
+                return ResourceManager.GetString("timer", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Недостаточно игроков для старта игры.
         /// </summary>

+ 18 - 3
MafiaTelegramBot/Resources/strings.resx

@@ -168,9 +168,6 @@
     <data name="players" xml:space="preserve">
         <value>игроков</value>
     </data>
-    <data name="room_mode" xml:space="preserve">
-        <value>Режим:</value>
-    </data>
     <data name="kick" xml:space="preserve">
         <value>Исключить</value>
     </data>
@@ -186,4 +183,22 @@
     <data name="room_dissolved" xml:space="preserve">
         <value>Комната распущена</value>
     </data>
+    <data name="timer" xml:space="preserve">
+        <value>Таймер</value>
+    </data>
+    <data name="enabled" xml:space="preserve">
+        <value>включен</value>
+    </data>
+    <data name="disabled" xml:space="preserve">
+        <value>отключен</value>
+    </data>
+    <data name="switch_timer" xml:space="preserve">
+        <value>Переключить</value>
+    </data>
+    <data name="enable" xml:space="preserve">
+        <value>Включить</value>
+    </data>
+    <data name="disable" xml:space="preserve">
+        <value>Отключить</value>
+    </data>
 </root>