From fd88f949229885f0588a5f94f02d79268caa3471 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Wed, 8 Apr 2020 12:58:48 +0300 Subject: (Minesweeper): Added raising `UserNotPlayingError`, attached flag command to error handler. --- bot/exts/evergreen/minesweeper.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'bot/exts/evergreen/minesweeper.py') 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): -- cgit v1.2.3