added stop command to restart round

This commit is contained in:
Bibin Muttappillil 2020-04-15 02:04:37 +02:00
parent 240ad44e4c
commit caca8bc2e5
2 changed files with 23 additions and 4 deletions

View File

@ -70,12 +70,21 @@ async def setup(ctx):
await send_friendly(ctx, "This channel can now play Werewolf") await send_friendly(ctx, "This channel can now play Werewolf")
def game_running(command): def channel_setup(command):
@functools.wraps(command) @functools.wraps(command)
async def wrapper(ctx): async def wrapper(ctx):
if ctx.channel not in game_instances: if ctx.channel not in game_instances:
await send_wrong(ctx, 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: else:
await command(ctx)
return wrapper
def game_running(command):
@functools.wraps(command)
@channel_setup
async def wrapper(ctx):
if game_instances[ctx.channel].running:
await send_wrong(ctx, "Sorry! A game is already running") await send_wrong(ctx, "Sorry! A game is already running")
else: else:
await command(ctx) await command(ctx)
@ -98,7 +107,17 @@ def error_handling(command):
@game_running @game_running
@error_handling @error_handling
async def start(ctx): async def start(ctx):
await game_instances[ctx.channel].game() game_instances[ctx.channel].game = bot.loop.create_task(game_instances[ctx.channel].round())
@game.command()
@channel_setup
async def stop(ctx):
if not game_instances[ctx.channel].running:
await send_wrong(ctx, "No game is running")
else:
game_instances[ctx.channel].game.cancel()
await send_friendly(ctx, "Game canceled")
@game.command() @game.command()

View File

@ -165,7 +165,7 @@ class Game:
def end(self): def end(self):
self.running = False self.running = False
async def game(self): async def round(self):
try: try:
self.check() self.check()
self.running = True self.running = True