The decorator should be outside of the class

This commit is contained in:
c0de 2022-10-24 20:02:26 -05:00
parent 07ecd2248c
commit b32d76bf16

View File

@ -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