aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-04-08 12:58:48 +0300
committerGravatar ks129 <[email protected]>2020-04-08 12:58:48 +0300
commitfd88f949229885f0588a5f94f02d79268caa3471 (patch)
tree963583223fd7213bb0790d10ca8988d3ba941376
parent(Minesweeper): Renamed user not playing error handler, changed `error` type h... (diff)
(Minesweeper): Added raising `UserNotPlayingError`, attached flag command to error handler.
-rw-r--r--bot/exts/evergreen/minesweeper.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/bot/exts/evergreen/minesweeper.py b/bot/exts/evergreen/minesweeper.py
index 4426f0c9..e98e9027 100644
--- a/bot/exts/evergreen/minesweeper.py
+++ b/bot/exts/evergreen/minesweeper.py
@@ -182,6 +182,8 @@ class Minesweeper(commands.Cog):
@minesweeper_group.command(name="flag")
async def flag_command(self, ctx: commands.Context, *coordinates: CoordinateConverter) -> None:
"""Place multiple flags on the board."""
+ if ctx.author.id not in self.games:
+ raise UserNotPlayingError
board: GameBoard = self.games[ctx.author.id].revealed
for x, y in coordinates:
if board[y][x] == "hidden":
@@ -259,6 +261,8 @@ class Minesweeper(commands.Cog):
@minesweeper_group.command(name="reveal")
async def reveal_command(self, ctx: commands.Context, *coordinates: CoordinateConverter) -> None:
"""Reveal multiple cells."""
+ if ctx.author.id not in self.games:
+ raise UserNotPlayingError
game = self.games[ctx.author.id]
revealed: GameBoard = game.revealed
board: GameBoard = game.board
@@ -275,6 +279,8 @@ class Minesweeper(commands.Cog):
@minesweeper_group.command(name="end")
async def end_command(self, ctx: commands.Context) -> None:
"""End your current game."""
+ if ctx.author.id not in self.games:
+ raise UserNotPlayingError
game = self.games[ctx.author.id]
game.revealed = game.board
await self.update_boards(ctx)
@@ -286,6 +292,7 @@ class Minesweeper(commands.Cog):
@reveal_command.error
@end_command.error
+ @flag_command.error
async def user_not_playing_handler(self, ctx: commands.Context, error: Exception) -> None:
"""Handle `KeyError` that is raised in reveal or end command when getting game."""
if isinstance(error, UserNotPlayingError):