added dev cog

This commit is contained in:
Bibin Muttappillil 2020-07-12 15:54:17 +02:00
parent a4652642d1
commit 9cdc8d742c
2 changed files with 83 additions and 51 deletions

59
src/developer.py Normal file
View File

@ -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))

View File

@ -18,13 +18,25 @@ PREFIX = '$w '
bot = commands.Bot(command_prefix=commands.when_mentioned_or(PREFIX)) bot = commands.Bot(command_prefix=commands.when_mentioned_or(PREFIX))
bot.remove_command('help') bot.remove_command('help')
bot.load_extension('developer')
@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.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() @bot.command()
async def help(ctx): 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) 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) await ctx.send(embed=embed)
# TODO: interaction COG
async def send_embed(ctx, desc, color): async def send_embed(ctx, desc, color):
await ctx.send(embed=discord.Embed(description=desc, color=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) await send_embed(ctx, desc, 0xff8000)
# TODO: (general) game COG
# game commands # game commands
game_instances = {} game_instances = {}
@ -70,6 +84,9 @@ async def setup(ctx):
await send_friendly(ctx, "This channel can now play Werewolf") await send_friendly(ctx, "This channel can now play Werewolf")
# checker annotations
# TODO: replace with discord.py error handling?
def channel_setup(command): def channel_setup(command):
@functools.wraps(command) @functools.wraps(command)
async def wrapper(ctx, *args, **kwargs): async def wrapper(ctx, *args, **kwargs):
@ -137,6 +154,8 @@ async def players(ctx):
await game_instances[ctx.channel].set_players(ctx.message) await game_instances[ctx.channel].set_players(ctx.message)
# TODO: (specifig game) werewolf COG
@game.command() @game.command()
@game_not_running @game_not_running
@error_handling @error_handling
@ -161,51 +180,5 @@ async def time(ctx):
# TODO: developer COG # TODO: developer COG
# smaller commands # 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) bot.run(TOKEN)