diff --git a/werewolf/builder.py b/werewolf/builder.py index 14d187d..0c3f5d1 100644 --- a/werewolf/builder.py +++ b/werewolf/builder.py @@ -136,7 +136,7 @@ async def parse_code(code, game): pass if not options: - raise ValueError("No Match Found") + raise IndexError("No Match Found") decode.append(choice(options)(game)) diff --git a/werewolf/game.py b/werewolf/game.py index ec3d0ff..8094b6a 100644 --- a/werewolf/game.py +++ b/werewolf/game.py @@ -1,6 +1,5 @@ import asyncio import random -from typing import List import discord from redbot.core import RedContext @@ -615,6 +614,11 @@ class Game: async def get_day_target(self, target_id, source=None): return self.players[target_id] # ToDo check source + async def set_code(self, ctx: RedContext, game_code): + if game_code is not None: + self.game_code = game_code + await ctx.send("Code has been set") + async def get_roles(self, ctx, game_code=None): if game_code is not None: self.game_code = game_code @@ -624,12 +628,11 @@ class Game: try: self.roles = await parse_code(self.game_code, self) - except ValueError("Invalid Code"): - await ctx.send("Invalid Code") - return False - except ValueError("No Match Found"): - await ctx.send("Code contains unknown role") + except ValueError as e: + await ctx.send("Invalid Code: Code contains unknown character\n{}".format(e)) return False + except IndexError as e: + await ctx.send("Invalid Code: Code references unknown role\n{}".format(e)) if not self.roles: return False diff --git a/werewolf/werewolf.py b/werewolf/werewolf.py index 62157de..2c230af 100644 --- a/werewolf/werewolf.py +++ b/werewolf/werewolf.py @@ -94,6 +94,21 @@ class Werewolf: await game.join(ctx.author, ctx.channel) + @commands.guild_only() + @ww.command() + async def code(self, ctx: RedContext, code): + """ + Adjust game code + """ + + game = await self._get_game(ctx) + + if not game: + await ctx.send("No game to join!\nCreate a new one with `[p]ww new`") + return + + await game.set_code(ctx, code) + @commands.guild_only() @ww.command() async def quit(self, ctx: RedContext):