start refactoring again (this time abstracting Discord API and removing dependencies of the game classe
This commit is contained in:
parent
14037bf5d8
commit
a4eaa141ac
8 changed files with 195 additions and 50 deletions
|
|
@ -1,7 +1,7 @@
|
|||
"""Has a single class: Game_cog"""
|
||||
|
||||
# standard library imports
|
||||
from typing import Dict, Type
|
||||
from typing import Dict
|
||||
|
||||
# discord imports
|
||||
import discord
|
||||
|
|
@ -15,9 +15,10 @@ from .game import Game
|
|||
class Game_cog(Send_message):
|
||||
"""This (abstract) class is are common function for the Game Cog's (setup-game, pre-game, in-game), mainly has checker functions"""
|
||||
|
||||
def __init__(self, bot, game_cls: Type[Game]):
|
||||
game_cls = Game
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.game_cls = game_cls
|
||||
self.game_instances = {} # TODO: type hint? Dict[discord.TextChannel, self.game_cls]
|
||||
|
||||
async def setup_check(self, ctx):
|
||||
|
|
@ -45,7 +46,7 @@ class Game_cog(Send_message):
|
|||
|
||||
async def reset(self, ctx):
|
||||
"""This function deletes the game instance for this channel"""
|
||||
if self.setup_check(ctx):
|
||||
if await self.setup_check(ctx):
|
||||
del self.game_instances[ctx.channel]
|
||||
|
||||
# TODO: better info message
|
||||
|
|
@ -61,6 +62,7 @@ class Game_cog(Send_message):
|
|||
embed.set_footer(text="Have fun!")
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
# TODO: can't one access self instead of ctx.cog?
|
||||
def pre_game():
|
||||
async def predicate(ctx):
|
||||
return await ctx.cog.setup_check(ctx) and await ctx.cog.not_running_check(ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue