aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-04-07 20:26:47 +0300
committerGravatar ks129 <[email protected]>2020-04-07 20:26:47 +0300
commit005dfcaa11f4324cff4ef75b440be613e6ae9a3b (patch)
treee5f9ce773a08e6fd9d765842471704341fda5898 /bot/exts
parent(Space): Moved APOD command min date to constant, made changes in error messa... (diff)
(Minesweeper): Reverted KeyError catching in reveal command, made error handler that catch it instead and attached reveal and end command to it.
Diffstat (limited to 'bot/exts')
-rw-r--r--bot/exts/evergreen/minesweeper.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/bot/exts/evergreen/minesweeper.py b/bot/exts/evergreen/minesweeper.py
index 2626b1c4..776501a9 100644
--- a/bot/exts/evergreen/minesweeper.py
+++ b/bot/exts/evergreen/minesweeper.py
@@ -253,11 +253,7 @@ class Minesweeper(commands.Cog):
@minesweeper_group.command(name="reveal")
async def reveal_command(self, ctx: commands.Context, *coordinates: CoordinateConverter) -> None:
"""Reveal multiple cells."""
- try:
- game = self.games[ctx.author.id]
- except KeyError:
- await ctx.author.send("Game don't exist. Can't reveal.")
- return
+ game = self.games[ctx.author.id]
revealed: GameBoard = game.revealed
board: GameBoard = game.board
@@ -282,6 +278,13 @@ class Minesweeper(commands.Cog):
await game.chat_msg.edit(content=new_msg)
del self.games[ctx.author.id]
+ @reveal_command.error
+ @end_command.error
+ async def keyerror_handler(self, ctx: commands.Context, error: typing.Any) -> None:
+ """Handle `KeyError` that is raised in reveal or end command when getting game."""
+ if isinstance(error, KeyError):
+ await ctx.send("Game don't exist.")
+
def setup(bot: commands.Bot) -> None:
"""Load the Minesweeper cog."""