|
@@ -702,6 +702,18 @@ async def chess_undo_handler(chess, id):
|
|
return ["Последний ход отменён.", svg2png(chess.svg(id))]
|
|
return ["Последний ход отменён.", svg2png(chess.svg(id))]
|
|
|
|
|
|
|
|
|
|
|
|
+async def chess_undo2_handler(chess, id):
|
|
|
|
+ try:
|
|
|
|
+ chess.undo(id)
|
|
|
|
+ chess.undo(id)
|
|
|
|
+ except KeyError:
|
|
|
|
+ return ["Нет активной игры."]
|
|
|
|
+ except IndexError:
|
|
|
|
+ return ["Нечего отменять."]
|
|
|
|
+
|
|
|
|
+ return ["Последние два хода отменены.", svg2png(chess.svg(id))]
|
|
|
|
+
|
|
|
|
+
|
|
async def chess_skip_handler(chess, id):
|
|
async def chess_skip_handler(chess, id):
|
|
try:
|
|
try:
|
|
await chess.skip(id)
|
|
await chess.skip(id)
|
|
@@ -766,10 +778,13 @@ async def chess_board_handler(chess, id):
|
|
|
|
|
|
async def chess_moves_handler(chess, id):
|
|
async def chess_moves_handler(chess, id):
|
|
try:
|
|
try:
|
|
- moves = f"Последние два хода: {chess.moves(id, 2)}\nВсе ходы (первый ход - игрока): {chess.moves(id)}"
|
|
|
|
|
|
+ if not chess.has_moves(id):
|
|
|
|
+ moves = "Ходов ещё не сделано."
|
|
|
|
+ else:
|
|
|
|
+ moves = f"Последние два хода: {chess.moves(id, 2)}\nВсе ходы (первый ход - игрока): {chess.moves(id)}"
|
|
|
|
|
|
- if chess.is_check(id):
|
|
|
|
- moves = f"Шах.\n{moves}"
|
|
|
|
|
|
+ if chess.is_check(id):
|
|
|
|
+ moves = f"Шах!\n{moves}"
|
|
except KeyError:
|
|
except KeyError:
|
|
return ["Нет активной игры."]
|
|
return ["Нет активной игры."]
|
|
|
|
|
|
@@ -781,12 +796,25 @@ CHESS_COMMANDS = {
|
|
"end": (chess_stop_handler, "Завершить игру", 0),
|
|
"end": (chess_stop_handler, "Завершить игру", 0),
|
|
"move": (chess_move_handler, "Сделать ход", 1),
|
|
"move": (chess_move_handler, "Сделать ход", 1),
|
|
"undo": (chess_undo_handler, "Отменить ход", 0),
|
|
"undo": (chess_undo_handler, "Отменить ход", 0),
|
|
|
|
+ "undo2": (chess_undo2_handler, "Отменить последние два хода", 0),
|
|
"skip": (chess_skip_handler, "Пропустить ход", 0),
|
|
"skip": (chess_skip_handler, "Пропустить ход", 0),
|
|
"pass": (chess_pass_handler, "Сделать ход вместо вас", 0),
|
|
"pass": (chess_pass_handler, "Сделать ход вместо вас", 0),
|
|
"board": (chess_board_handler, "Показать состояние доски", 0),
|
|
"board": (chess_board_handler, "Показать состояние доски", 0),
|
|
"moves": (chess_moves_handler, "Показать историю ходов", 0),
|
|
"moves": (chess_moves_handler, "Показать историю ходов", 0),
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+CHESS_ALIASES = {
|
|
|
|
+ "s": "start",
|
|
|
|
+ "m": "move",
|
|
|
|
+ "b": "board",
|
|
|
|
+ "u": "undo",
|
|
|
|
+ "u2", "undo2",
|
|
|
|
+ "uu": "undo2",
|
|
|
|
+ "s": "skip",
|
|
|
|
+ "p": "pass",
|
|
|
|
+ "ms": "moves"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
async def chess_handler(bot, event, command):
|
|
async def chess_handler(bot, event, command):
|
|
if not bot.chess:
|
|
if not bot.chess:
|
|
@@ -804,15 +832,18 @@ async def chess_handler(bot, event, command):
|
|
|
|
|
|
return
|
|
return
|
|
|
|
|
|
- if command.args[0] not in CHESS_COMMANDS:
|
|
|
|
- await event.reply(f"Неизвестная субкоманда: '{command.args[0]}'.")
|
|
|
|
|
|
+ name = command.args[0]
|
|
|
|
+ if name in CHESS_ALIASES:
|
|
|
|
+ name = CHESS_ALIASES[name]
|
|
|
|
+ elif name not in CHESS_COMMANDS:
|
|
|
|
+ await event.reply(f"Неизвестная субкоманда: '{name}'.")
|
|
|
|
|
|
return
|
|
return
|
|
|
|
|
|
- subcommand = CHESS_COMMANDS[command.args[0]]
|
|
|
|
|
|
+ subcommand = CHESS_COMMANDS[name]
|
|
if command.argc - 1 != subcommand[2]:
|
|
if command.argc - 1 != subcommand[2]:
|
|
await event.reply(
|
|
await event.reply(
|
|
- f"Некорректное количество аргументов для субкоманды '{command.args[0]}'."
|
|
|
|
|
|
+ f"Некорректное количество аргументов для субкоманды '{name}': требуется {subcommand[2]}, а получено {command.argc - 1}."
|
|
)
|
|
)
|
|
|
|
|
|
return
|
|
return
|