|
@@ -652,10 +652,19 @@ async def roll_handler(bot, event, command):
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
+def chess_render(chess, id, as_list=True):
|
|
|
|
+ board = svg2png(chess.svg(id, shallow=isinstance(id, str)))
|
|
|
|
+
|
|
|
|
+ if as_list:
|
|
|
|
+ return [board]
|
|
|
|
+
|
|
|
|
+ return board
|
|
|
|
+
|
|
|
|
+
|
|
async def chess_start_handler(chess, id):
|
|
async def chess_start_handler(chess, id):
|
|
await chess.begin(id)
|
|
await chess.begin(id)
|
|
|
|
|
|
- return [svg2png(chess.svg(id))]
|
|
|
|
|
|
+ return chess_render(chess, id)
|
|
|
|
|
|
|
|
|
|
def chess_game_stats(chess, id):
|
|
def chess_game_stats(chess, id):
|
|
@@ -671,7 +680,7 @@ def chess_game_stats(chess, id):
|
|
|
|
|
|
|
|
|
|
def chess_game_over(chess, id, e):
|
|
def chess_game_over(chess, id, e):
|
|
- board = svg2png(chess.svg(id))
|
|
|
|
|
|
+ board = chess_render(chess, id, False)
|
|
stats = chess_game_stats(chess, id)
|
|
stats = chess_game_stats(chess, id)
|
|
|
|
|
|
chess.end(id)
|
|
chess.end(id)
|
|
@@ -698,7 +707,7 @@ async def chess_from_handler(chess, id, moves):
|
|
|
|
|
|
return ["Некорректная последовательность ходов."]
|
|
return ["Некорректная последовательность ходов."]
|
|
|
|
|
|
- reply = [svg2png(chess.svg(id))]
|
|
|
|
|
|
+ reply = chess_render(chess, id)
|
|
|
|
|
|
if chess.is_check(id):
|
|
if chess.is_check(id):
|
|
reply.append("Шах!")
|
|
reply.append("Шах!")
|
|
@@ -732,7 +741,7 @@ async def chess_move_handler(chess, id, move):
|
|
except IllegalMove:
|
|
except IllegalMove:
|
|
return ["Некорректный ход."]
|
|
return ["Некорректный ход."]
|
|
|
|
|
|
- reply = [svg2png(chess.svg(id))]
|
|
|
|
|
|
+ reply = chess_render(chess, id)
|
|
|
|
|
|
if chess.is_check(id):
|
|
if chess.is_check(id):
|
|
reply.append("Шах!")
|
|
reply.append("Шах!")
|
|
@@ -769,7 +778,7 @@ async def chess_skip_handler(chess, id):
|
|
except GameOver as e:
|
|
except GameOver as e:
|
|
return chess_game_over(chess, id, e)
|
|
return chess_game_over(chess, id, e)
|
|
|
|
|
|
- reply = [svg2png(chess.svg(id))]
|
|
|
|
|
|
+ reply = chess_render(chess, id)
|
|
|
|
|
|
if chess.is_check(id):
|
|
if chess.is_check(id):
|
|
reply.append("Шах!")
|
|
reply.append("Шах!")
|
|
@@ -790,7 +799,7 @@ async def chess_pass_handler(chess, id):
|
|
except GameOver as e:
|
|
except GameOver as e:
|
|
return chess_game_over(chess, id, e)
|
|
return chess_game_over(chess, id, e)
|
|
|
|
|
|
- reply = [svg2png(chess.svg(id))]
|
|
|
|
|
|
+ reply = chess_render(chess, id)
|
|
|
|
|
|
if chess.is_check(id):
|
|
if chess.is_check(id):
|
|
reply.append("Шах!")
|
|
reply.append("Шах!")
|
|
@@ -800,12 +809,10 @@ async def chess_pass_handler(chess, id):
|
|
|
|
|
|
async def chess_board_handler(chess, id):
|
|
async def chess_board_handler(chess, id):
|
|
try:
|
|
try:
|
|
- board = svg2png(chess.svg(id))
|
|
|
|
|
|
+ reply = chess_render(chess, id)
|
|
except KeyError:
|
|
except KeyError:
|
|
return ["Нет активной игры."]
|
|
return ["Нет активной игры."]
|
|
|
|
|
|
- reply = [board]
|
|
|
|
-
|
|
|
|
if chess.is_check(id):
|
|
if chess.is_check(id):
|
|
reply.append("Шах!")
|
|
reply.append("Шах!")
|
|
|
|
|