From b32d76bf1663baf28039d1f607751f0be36da496 Mon Sep 17 00:00:00 2001 From: c0de Date: Mon, 24 Oct 2022 20:02:26 -0500 Subject: [PATCH] The decorator should be outside of the class --- GhostBallBot/game.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/GhostBallBot/game.py b/GhostBallBot/game.py index 42ed0ef..1685589 100644 --- a/GhostBallBot/game.py +++ b/GhostBallBot/game.py @@ -8,6 +8,23 @@ import dateparser from database.models import database, GameModel, GuessModel +async def check_is_running(method, start_new_game=True): + """ + Decorator that determines if the game is running or not + """ + + async def wrapper(self): + + if self.is_running and start_new_game: + return await self.message.channel.send("A game is already running") + elif not self.is_running and not start_new_game: + return await self.message.channel.send( + "There is no game running to add guesses to" + ) + + await method(self) + + return await wrapper class Game: """ @@ -52,24 +69,6 @@ class Game: """ database.close() - async def check_is_running(method, start_new_game=True): - """ - Decorator that determines if the game is running or not - """ - - async def wrapper(self): - - if self.is_running and start_new_game: - return await self.message.channel.send("A game is already running") - elif not self.is_running and not start_new_game: - return await self.message.channel.send( - "There is no game running to add guesses to" - ) - - await method(self) - - return await wrapper - @check_is_running async def start(self): self.is_running = True