txlyre 18 hours ago
parent
commit
478c891b6f
2 changed files with 18 additions and 1 deletions
  1. 8 0
      chess0.py
  2. 10 1
      commands.py

+ 8 - 0
chess0.py

@@ -199,3 +199,11 @@ class ChessManager:
             moves = session.board.move_stack
             moves = session.board.move_stack
 
 
         return " ".join(map(str, moves))
         return " ".join(map(str, moves))
+
+    def turn(self, id):
+        session = self.sessions.get(id)
+        if not session:
+            raise KeyError(id)
+
+        return session.board.turn
+

+ 10 - 1
commands.py

@@ -809,6 +809,9 @@ async def chess_board_handler(chess, id):
     if chess.is_check(id):
     if chess.is_check(id):
         reply.append("Шах!")
         reply.append("Шах!")
 
 
+    if isinstance(id, str):
+        reply.append(f"Ход {'белых' if chess.turn(id) else 'чёрных'}.")
+
     return reply
     return reply
 
 
 
 
@@ -818,6 +821,9 @@ async def chess_moves_handler(chess, id):
     except KeyError:
     except KeyError:
         return ["Нет активной игры."]
         return ["Нет активной игры."]
 
 
+    if isinstance(id, str):
+        text += f"\nХод {'белых' if chess.turn(id) else 'чёрных'}."
+
     return [text]
     return [text]
 
 
 
 
@@ -865,7 +871,7 @@ async def chess_handler(bot, event, command):
 
 
         return
         return
 
 
-    name = command.args[0]
+    name = command.args[0].lower()
     if name in CHESS_ALIASES:
     if name in CHESS_ALIASES:
         name = CHESS_ALIASES[name]
         name = CHESS_ALIASES[name]
     elif name not in CHESS_COMMANDS:
     elif name not in CHESS_COMMANDS:
@@ -909,6 +915,9 @@ async def chess_handler(bot, event, command):
         else:
         else:
             await event.reply(reply)
             await event.reply(reply)
 
 
+    if name in ("move", "skip", "undo", "pass") and peer_id in bot.chess.sessions:
+        await event.reply(f"Ход {'белых' if bot.chess.turn(peer_id) else 'чёрных'}.")
+
 
 
 _chess_handler = Handler(chess_handler, is_public=True)
 _chess_handler = Handler(chess_handler, is_public=True)