From 9cdc8d742cc5e72e2126045d23b0d91aed7fbf06 Mon Sep 17 00:00:00 2001 From: bibin Date: Sun, 12 Jul 2020 15:54:17 +0200 Subject: [PATCH] added dev cog --- src/developer.py | 59 +++++++++++++++++++++++++++++++++++ src/werewolf_bot.py | 75 +++++++++++++++------------------------------ 2 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 src/developer.py diff --git a/src/developer.py b/src/developer.py new file mode 100644 index 0000000..0ac7522 --- /dev/null +++ b/src/developer.py @@ -0,0 +1,59 @@ +import discord +from discord.ext import commands + + +class Developer(commands.Cog): + + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + 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") + await ctx.send("pong") + + # developer commands + + 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() + @commands.check(is_dev) + async def logout(self, ctx): + await self.bot.logout() + + @commands.command() + @commands.check(is_dev) + async def debug(self, ctx, *args): + embed = discord.Embed(title=f"Village won!", color=0x00ffff) + won_emoji = ":trophy:" + dead_emoji = ":test:" + tab = "\t" + space = "<:space:705863033871663185>" + embed.add_field(name=str("Name"), value=f"{won_emoji}{space}{dead_emoji}{space}{space}{3}:ballot_box:{tab}role: werewolf{tab}(was: drunk){tab}:point_right: someone", inline=False) + await ctx.send(embed=embed) + await ctx.send(":test::skull:") + + for emoji in ctx.guild.emojis: + await ctx.send(emoji) + print(emoji.id) + + @debug.error + async def debug_error(self, ctx, error): + await ctx.send(error) + + +def setup(bot): + bot.add_cog(Developer(bot)) diff --git a/src/werewolf_bot.py b/src/werewolf_bot.py index 84b7b4b..4bcd478 100644 --- a/src/werewolf_bot.py +++ b/src/werewolf_bot.py @@ -18,13 +18,25 @@ PREFIX = '$w ' bot = commands.Bot(command_prefix=commands.when_mentioned_or(PREFIX)) bot.remove_command('help') - -@bot.event -async def on_ready(): - await bot.change_presence(status=discord.Status.online, activity=discord.Game('One Night Ultimate Werewolf')) - print('We have logged in as {0.user}'.format(bot)) +bot.load_extension('developer') +@bot.command() +async def load(ctx, extension): + bot.load_extension(f'{extension}') + + +@bot.command() +async def unload(ctx, extension): + bot.unload_extension(f'{extension}') + + +@bot.command() +async def reload(ctx, extension): + bot.reload_extension(f'{extension}') + + +# TODO: better help message @bot.command() async def help(ctx): 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) @@ -38,6 +50,7 @@ async def help(ctx): await ctx.send(embed=embed) +# TODO: interaction COG async def send_embed(ctx, desc, color): await ctx.send(embed=discord.Embed(description=desc, color=color)) @@ -50,6 +63,7 @@ async def send_wrong(ctx, desc): await send_embed(ctx, desc, 0xff8000) +# TODO: (general) game COG # game commands game_instances = {} @@ -70,6 +84,9 @@ async def setup(ctx): await send_friendly(ctx, "This channel can now play Werewolf") +# checker annotations +# TODO: replace with discord.py error handling? + def channel_setup(command): @functools.wraps(command) async def wrapper(ctx, *args, **kwargs): @@ -137,6 +154,8 @@ async def players(ctx): await game_instances[ctx.channel].set_players(ctx.message) +# TODO: (specifig game) werewolf COG + @game.command() @game_not_running @error_handling @@ -161,51 +180,5 @@ async def time(ctx): # TODO: developer COG # smaller commands -@bot.command() -async def hello(ctx): - await send_friendly(ctx, f"Hello {ctx.message.author.name} :wave:") - - -@bot.command() -async def ping(ctx): - print("pong") - await send_friendly(ctx, "pong") - - -# developer commands - -def developer(command): - @functools.wraps(command) - async def wrapper(ctx, *args, **kwargs): - DEV_ID = 461892912821698562 - if ctx.author.id == DEV_ID: - await command(ctx, *args, **kwargs) - else: - await send_wrong(ctx, "This command is not for you!") - return wrapper - - -@bot.command() -@developer -async def logout(ctx): - await bot.logout() - - -@bot.command() -@developer -async def debug(ctx, *args): - embed = discord.Embed(title=f"Village won!", color=0x00ffff) - won_emoji = ":trophy:" - dead_emoji = ":test:" - tab = "\t" - space = "<:space:705863033871663185>" - embed.add_field(name=str("Name"), value=f"{won_emoji}{space}{dead_emoji}{space}{space}{3}:ballot_box:{tab}role: werewolf{tab}(was: drunk){tab}:point_right: someone", inline=False) - await ctx.send(embed=embed) - await ctx.send(":test::skull:") - - for emoji in ctx.guild.emojis: - await ctx.send(emoji) - print(emoji.id) - bot.run(TOKEN)