beautified output

This commit is contained in:
Bibin Muttappillil 2020-04-13 20:55:17 +02:00
parent 7495336269
commit 42275c7ab5
4 changed files with 233 additions and 192 deletions

View file

@ -13,8 +13,10 @@ if TOKEN is None:
print("Missing discord token!")
exit(1)
PREFIX = '$w '
bot = commands.Bot(command_prefix=commands.when_mentioned_or(PREFIX))
bot.remove_command('help')
@bot.event
@ -23,76 +25,114 @@ async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@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)
embed.set_author(name="With this bot you can play One Night Ultimate Werewolf")
# 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)
embed.add_field(name="$w game roles", value="Set the roles to play with", inline=False)
embed.add_field(name="$w game start", value="Play one round", inline=False)
embed.set_footer(text="Have fun!")
await ctx.send(embed=embed)
async def send_embed(ctx, desc, color):
await ctx.send(embed=discord.Embed(description=desc, color=color))
async def send_friendly(ctx, desc):
await send_embed(ctx, desc, 0x00ff00)
async def send_wrong(ctx, desc):
await send_embed(ctx, desc, 0xff8000)
# game commands
game_instances = {}
@bot.group(help="werewolf game", description="Prefix for the One Night Ultimate Werewolf commands.")
@bot.group()
async def game(ctx):
if ctx.invoked_subcommand is None:
await ctx.send('Invalid sub command passed...')
await send_wrong(ctx, 'Invalid sub command passed...')
@game.command(help="start werewolf game", description="Start One Night Ultimate Werewolf game.")
@game.command()
async def setup(ctx):
if ctx.channel in game_instances:
await ctx.send("Game already setup in this channel")
await send_wrong(ctx, "Game already setup in this channel")
else:
game_instances[ctx.channel] = Werewolf_Game(bot, ctx.channel)
await send_friendly(ctx, "This channel can now play Werewolf")
def game_running(command):
@functools.wraps(command)
async def wrapper(ctx):
if ctx.channel not in game_instances:
await ctx.send(f"No game setup yet. Use {PREFIX}game setup")
await send_wrong(ctx, f"No game setup yet. Use {PREFIX}game setup")
elif game_instances[ctx.channel].running:
await ctx.send("Sorry! A game is already running")
await send_wrong(ctx, "Sorry! A game is already running")
else:
await command(ctx)
return wrapper
@game.command(help="start a round", description="Play one round of One Night Ultimate Werewolf")
def error_handling(command):
@functools.wraps(command)
async def wrapper(ctx):
try:
await command(ctx)
except ValueError as error:
await send_wrong(ctx, str(error))
except asyncio.TimeoutError:
await send_wrong(ctx, "Error: I got bored waiting for your input")
return wrapper
@game.command()
@game_running
@error_handling
async def start(ctx):
await game_instances[ctx.channel].game()
@game.command(help="set players", description="Set the players for the next round.")
@game.command()
@game_running
@error_handling
async def players(ctx):
await game_instances[ctx.channel].set_players(ctx.message)
@game.command(help="set roles", description="Set the roles for the next round.")
@game.command()
@game_running
@error_handling
async def roles(ctx):
try:
await game_instances[ctx.channel].set_roles(ctx.message.content.split()[3:])
except ValueError as error:
await ctx.send(error)
await game_instances[ctx.channel].set_roles(ctx.message.content.split()[3:]) # exclude commands
# ONLY FOR TESTING
@game.command()
@game_running
@error_handling
async def vote(ctx):
await game_instances[ctx.channel].vote()
# smaller commands
@bot.command(help="greets you", description="This just says hello back to the message author.")
@bot.command()
async def hello(ctx):
await ctx.send(f"Hello {ctx.message.author.name} :wave:")
await send_friendly(ctx, f"Hello {ctx.message.author.name} :wave:")
@bot.command(help="test bot responsiveness", description="This is a debug function to see if the bot listens to a command.")
@bot.command()
async def ping(ctx):
print("pong")
await ctx.send("pong")
await send_friendly(ctx, "pong")
# developer commands
@ -105,17 +145,17 @@ def developer(command):
if ctx.author.id == DEV_ID:
await command(ctx)
else:
await ctx.send("This command is not for you!")
await send_wrong(ctx, "This command is not for you!")
return wrapper
@bot.command(help="not for you", description="Shut down the bot.")
@bot.command()
@developer
async def logout(ctx):
await bot.logout()
@bot.command(help="debug")
@bot.command()
@developer
async def debug(ctx):
print("DEBUG")