fix code problems
This commit is contained in:
parent
a7796a084b
commit
e46f799d02
@ -136,7 +136,7 @@ async def parse_code(code, game):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if not options:
|
if not options:
|
||||||
raise ValueError("No Match Found")
|
raise IndexError("No Match Found")
|
||||||
|
|
||||||
decode.append(choice(options)(game))
|
decode.append(choice(options)(game))
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from redbot.core import RedContext
|
from redbot.core import RedContext
|
||||||
@ -615,6 +614,11 @@ class Game:
|
|||||||
async def get_day_target(self, target_id, source=None):
|
async def get_day_target(self, target_id, source=None):
|
||||||
return self.players[target_id] # ToDo check source
|
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):
|
async def get_roles(self, ctx, game_code=None):
|
||||||
if game_code is not None:
|
if game_code is not None:
|
||||||
self.game_code = game_code
|
self.game_code = game_code
|
||||||
@ -624,12 +628,11 @@ class Game:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.roles = await parse_code(self.game_code, self)
|
self.roles = await parse_code(self.game_code, self)
|
||||||
except ValueError("Invalid Code"):
|
except ValueError as e:
|
||||||
await ctx.send("Invalid Code")
|
await ctx.send("Invalid Code: Code contains unknown character\n{}".format(e))
|
||||||
return False
|
|
||||||
except ValueError("No Match Found"):
|
|
||||||
await ctx.send("Code contains unknown role")
|
|
||||||
return False
|
return False
|
||||||
|
except IndexError as e:
|
||||||
|
await ctx.send("Invalid Code: Code references unknown role\n{}".format(e))
|
||||||
|
|
||||||
if not self.roles:
|
if not self.roles:
|
||||||
return False
|
return False
|
||||||
|
@ -94,6 +94,21 @@ class Werewolf:
|
|||||||
|
|
||||||
await game.join(ctx.author, ctx.channel)
|
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()
|
@commands.guild_only()
|
||||||
@ww.command()
|
@ww.command()
|
||||||
async def quit(self, ctx: RedContext):
|
async def quit(self, ctx: RedContext):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user