more refactoring
This commit is contained in:
parent
b85c20b65a
commit
13064a3af0
8 changed files with 51 additions and 40 deletions
|
|
@ -1,25 +1,23 @@
|
|||
"""This (abstract) module is a template for Discord Cog's for game specific channel commands"""
|
||||
"""Has a single class: Game_cog"""
|
||||
|
||||
# standard library imports
|
||||
from typing import Dict
|
||||
from typing import Dict, Type
|
||||
|
||||
# discord imports
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
# local imports
|
||||
from ..send_message import Send_message
|
||||
from .game import Game
|
||||
|
||||
|
||||
# TODO: take group as argument to add subcommands
|
||||
|
||||
class Game_cog(Send_message, commands.Cog):
|
||||
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_instances: Dict[discord.TextChannel, Game]):
|
||||
def __init__(self, bot, game_cls: Type[Game]):
|
||||
self.bot = bot
|
||||
self.game_instances = game_instances
|
||||
self.game_cls = game_cls
|
||||
self.game_instances = Dict[discord.TextChannel, self.game_cls]
|
||||
|
||||
async def setup_check(self, ctx):
|
||||
if ctx.channel not in self.game_instances:
|
||||
|
|
@ -36,17 +34,13 @@ class Game_cog(Send_message, commands.Cog):
|
|||
await self.send_wrong(ctx, "No game is running")
|
||||
return self.game_instances[ctx.channel].running
|
||||
|
||||
|
||||
class Setup_game_cog(Game_cog):
|
||||
"""This (abstract) class is a template for Discord Cog's for game specific channel commands for setting up the channel"""
|
||||
|
||||
async def setup(self, ctx, game: Game):
|
||||
async def setup(self, ctx):
|
||||
"""This function creates an game instance for this channel"""
|
||||
if ctx.channel in self.game_instances:
|
||||
await self.send_wrong(ctx, f"A game '{game.name}' is already setup in this channel")
|
||||
await self.send_wrong(ctx, f"A game '{self.game_cls.name}' is already setup in this channel")
|
||||
else:
|
||||
self.game_instances[ctx.channel] = game(self.bot, ctx.channel)
|
||||
await self.send_friendly(ctx, f"This channel can now play: {game.name}")
|
||||
self.game_instances[ctx.channel] = self.game_cls(self.bot, ctx.channel)
|
||||
await self.send_friendly(ctx, f"This channel can now play: {self.game_cls.name}")
|
||||
|
||||
async def reset(self, ctx):
|
||||
"""This function deletes the game instance for this channel"""
|
||||
|
|
@ -54,10 +48,10 @@ class Setup_game_cog(Game_cog):
|
|||
del self.game_instances[ctx.channel]
|
||||
|
||||
# TODO: better info message
|
||||
async def info(self, ctx, game: Game):
|
||||
async def info(self, ctx):
|
||||
"""Send information about the subcommands for the game"""
|
||||
embed = discord.Embed(title="How to play?", description="You will need to set up the game and its information in a channel and start the game there. Afterwards the player mainly interact with the bot in DM.", color=0x00ffff)
|
||||
embed.set_author(name=f"With this bot you can play {game.name}")
|
||||
embed.set_author(name=f"With this bot you can play {self.game_cls.name}")
|
||||
# embed.set_thumbnail(url="https://images-na.ssl-images-amazon.com/images/I/717GrDtFKCL._AC_SL1000_.jpg")
|
||||
embed.add_field(name="$w game setup", value="Make this channel playable.", inline=False)
|
||||
embed.add_field(name="$w game players", value="Set mentioned users as players", inline=False)
|
||||
|
|
@ -66,10 +60,7 @@ class Setup_game_cog(Game_cog):
|
|||
embed.set_footer(text="Have fun!")
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
class Pre_game_cog(Game_cog):
|
||||
"""This (abstract) class is a template for Discord Cog's for game specific channel commands for setting up the game rounds"""
|
||||
async def cog_check(self, ctx):
|
||||
async def pre_game_check(self, ctx):
|
||||
return self.setup_check(ctx) and self.not_running_check(ctx)
|
||||
|
||||
async def players(self, ctx):
|
||||
|
|
@ -79,10 +70,7 @@ class Pre_game_cog(Game_cog):
|
|||
self.game_instances[ctx.channel].game = self.bot.loop.create_task(self.game_instances[ctx.channel].round())
|
||||
await self.game_instances[ctx.channel].game
|
||||
|
||||
|
||||
class In_game_goc(Game_cog):
|
||||
"""This (abstract) class is a template for Discord Cog's for game specific channel commands during the game"""
|
||||
async def cog_check(self, ctx):
|
||||
async def in_game_check(self, ctx):
|
||||
return self.setup_check(ctx) and self.running_check(ctx)
|
||||
|
||||
async def stop(self, ctx):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue