small fixes + correct checks

This commit is contained in:
Bibin Muttappillil 2020-07-15 18:32:29 +02:00
parent e2b8a20fa6
commit 14037bf5d8
4 changed files with 23 additions and 16 deletions

View file

@ -5,6 +5,7 @@ from typing import Dict, Type
# discord imports
import discord
from discord.ext import commands
# local imports
from ..send_message import Send_message
@ -17,7 +18,7 @@ class Game_cog(Send_message):
def __init__(self, bot, game_cls: Type[Game]):
self.bot = bot
self.game_cls = game_cls
self.game_instances = Dict[discord.TextChannel, self.game_cls]
self.game_instances = {} # TODO: type hint? Dict[discord.TextChannel, self.game_cls]
async def setup_check(self, ctx):
if ctx.channel not in self.game_instances:
@ -60,8 +61,10 @@ class Game_cog(Send_message):
embed.set_footer(text="Have fun!")
await ctx.send(embed=embed)
async def pre_game_check(self, ctx):
return self.setup_check(ctx) and self.not_running_check(ctx)
def pre_game():
async def predicate(ctx):
return await ctx.cog.setup_check(ctx) and await ctx.cog.not_running_check(ctx)
return commands.check(predicate)
async def players(self, ctx):
await self.game_instances[ctx.channel].set_players(ctx.message)
@ -70,8 +73,10 @@ class Game_cog(Send_message):
self.game_instances[ctx.channel].game = self.bot.loop.create_task(self.game_instances[ctx.channel].round())
await self.game_instances[ctx.channel].game
async def in_game_check(self, ctx):
return self.setup_check(ctx) and self.running_check(ctx)
def in_game():
async def predicate(ctx):
return await ctx.cog.setup_check(ctx) and await ctx.cog.running_check(ctx)
return commands.check(predicate)
async def stop(self, ctx):
self.game_instances[ctx.channel].game.cancel()