txlyre 1 day ago
parent
commit
6f0757e9ef
1 changed files with 20 additions and 7 deletions
  1. 20 7
      commands.py

+ 20 - 7
commands.py

@@ -812,7 +812,7 @@ async def chess_moves_handler(chess, id):
 
 CHESS_COMMANDS = {
     "start": (chess_start_handler, "Начать новую игру", 0),
-    "from": (chess_from_handler, "Начать новую игру с доской в указанном состоянии", 1),
+    "from": (chess_from_handler, "Начать новую игру с доской в указанном состоянии", 1, True),
     "end": (chess_stop_handler, "Завершить игру", 0),
     "move": (chess_move_handler, "Сделать ход", 1),
     "undo": (chess_undo_handler, "Отменить ход", 0),
@@ -824,6 +824,7 @@ CHESS_COMMANDS = {
 
 CHESS_ALIASES = {
     "s": "start",
+    "f" "from",
     "m": "move",
     "b": "board",
     "u": "undo",
@@ -858,14 +859,26 @@ async def chess_handler(bot, event, command):
         return
 
     subcommand = CHESS_COMMANDS[name]
-    if command.argc - 1 != subcommand[2]:
-        await event.reply(
-            f"Некорректное количество аргументов для субкоманды '{name}': требуется {subcommand[2]}, а получено {command.argc - 1}."
-        )
+    if len(subcommand) == 4 and subcommand[3]:
+        if command.argc < subcommand[2]:
+            await event.reply(
+                f"Некорректное количество аргументов для субкоманды '{name}': требуется как минимум {subcommand[2]}, а получено {command.argc - 1}."
+            )
 
-        return
+            return
+
+        args = [" ".join(command.args[1:])]
+    else:
+        if command.argc - 1 != subcommand[2]:
+            await event.reply(
+                f"Некорректное количество аргументов для субкоманды '{name}': требуется {subcommand[2]}, а получено {command.argc - 1}."
+            )
+
+            return
+
+        args = command.args[1:]
 
-    result = await subcommand[0](bot.chess, event.sender.id, *command.args[1:])
+    result = await subcommand[0](bot.chess, event.sender.id, *args)
 
     for reply in result:
         if isinstance(reply, bytes):