more refactoring
This commit is contained in:
parent
b85c20b65a
commit
13064a3af0
Binary file not shown.
Binary file not shown.
|
@ -13,22 +13,25 @@ class Developer(commands.Cog):
|
|||
await self.bot.change_presence(status=discord.Status.online, activity=discord.Game('One Night Ultimate Werewolf'))
|
||||
print('We have logged in as {0.user}'.format(self.bot))
|
||||
|
||||
@commands.command()
|
||||
async def hello(self, ctx):
|
||||
await ctx.send(f"Hello {ctx.message.author.name} :wave:")
|
||||
|
||||
@commands.command()
|
||||
async def ping(self, ctx):
|
||||
print("pong", self.bot.owner_id, await self.bot.application_info())
|
||||
print(await self.bot.is_owner(ctx.author))
|
||||
await ctx.send("pong")
|
||||
|
||||
async def is_dev(ctx):
|
||||
if ctx.author.id == 461892912821698562:
|
||||
return True
|
||||
await ctx.send("This command is not for you!")
|
||||
return False
|
||||
|
||||
@commands.command()
|
||||
async def hello(self, ctx):
|
||||
await ctx.send(f"Hello {ctx.message.author.name} :wave:")
|
||||
|
||||
@commands.group(name="gg")
|
||||
async def group(self, ctx):
|
||||
pass
|
||||
|
||||
@group.command()
|
||||
@commands.check(is_dev)
|
||||
async def ping(self, ctx):
|
||||
await ctx.send("pong")
|
||||
|
||||
@commands.command()
|
||||
@commands.check(is_dev)
|
||||
async def logout(self, ctx):
|
||||
|
|
Binary file not shown.
|
@ -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):
|
||||
|
|
Binary file not shown.
|
@ -1,3 +1,5 @@
|
|||
"""Has a single class: Werewolf_Cog"""
|
||||
|
||||
# discord imports
|
||||
from discord.ext import commands
|
||||
|
||||
|
@ -6,12 +8,12 @@ from ..game_cog import Game_cog
|
|||
from .game import Werewolf_game
|
||||
|
||||
|
||||
class Werewolf_cog(Game_cog):
|
||||
class Werewolf_cog(Game_cog, commands.Cog):
|
||||
"""This singleton class is a Discord Cog for the interaction in the werewolf game"""
|
||||
|
||||
@commands.group(invoke_without_command=True)
|
||||
async def werewolf(self, ctx):
|
||||
# TODO: isn't there a better way to have a default subcommand?
|
||||
# TODO: isn't there a better way to have a default subcommand? Maybe invoke super().info()?
|
||||
await ctx.invoke(self.bot.get_command('werewolf info'))
|
||||
|
||||
@werewolf.command()
|
||||
|
@ -29,6 +31,24 @@ class Werewolf_cog(Game_cog):
|
|||
"""This function deletes the game instance for this channel"""
|
||||
await super().reset(ctx)
|
||||
|
||||
@werewolf.command()
|
||||
@commands.check(Game_cog.pre_game_check)
|
||||
async def players(self, ctx):
|
||||
"""registers all mentioned players for the game"""
|
||||
await super().players(ctx)
|
||||
|
||||
@werewolf.command()
|
||||
@commands.check(Game_cog.pre_game_check)
|
||||
async def start(self, ctx):
|
||||
"""starts a round of werewolf"""
|
||||
await super().start(ctx)
|
||||
|
||||
@werewolf.command()
|
||||
@commands.check(Game_cog.in_game_check)
|
||||
async def stop(self, ctx):
|
||||
"""aborts the current round of werewolf"""
|
||||
await super().stop(ctx)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Werewolf_cog(bot, None))
|
||||
bot.add_cog(Werewolf_cog(bot, Werewolf_game))
|
||||
|
|
|
@ -31,7 +31,7 @@ bot.load_extension('package.games.werewolf.cog')
|
|||
@bot.command()
|
||||
@commands.is_owner()
|
||||
async def reload(ctx, extension):
|
||||
bot.reload_extension(f'{extension}')
|
||||
bot.reload_extension(f'package.{extension}')
|
||||
|
||||
|
||||
# checker annotations
|
||||
|
|
Loading…
Reference in New Issue