def send_clue(self, ctx, time: int): # Sends clue based on picked_clues value # Find character who the clue has been assigned to for name in ctx.game.clue_assignments: if time in ctx.game.clue_assignments[name]: character = name break else: raise ValueError("Missing clue") # Send clue card channel = utils.get_text_channels( ctx.game.guild)[LOCALIZATION_DATA["channels"]["clues"][character]] choice = ctx.game.picked_clues[time] path = utils.get_image(dirs.CLUE_DIR / str(time), f"{time}-{choice}") utils.send_image(channel, path) # Send suspect/location card to player's clues channel suspect = self.draw_suspect(ctx, time) path = filepaths.MASTER_PATHS[suspect] utils.send_image(channel, path) # Send suspect/location card to respective drawn cards channel if suspect in gamedata.SUSPECTS: channel = LOCALIZATION_DATA["channels"]["cards"]["suspects-drawn"] elif suspect in gamedata.LOCATIONS: channel = LOCALIZATION_DATA["channels"]["cards"]["locations-drawn"] else: channel = LOCALIZATION_DATA["channels"]["bot-channel"] channel = utils.get_text_channels(ctx.game.guild)[channel] # Confirmed culprit/location if time <= 30: if suspect in gamedata.SUSPECTS: asyncio.create_task( channel.send(LOCALIZATION_DATA["messages"]["Culprit"])) elif suspect in gamedata.LOCATIONS: asyncio.create_task( channel.send( LOCALIZATION_DATA["messages"]["AliceLocation"])) else: print("Something has gone very very wrong.") asyncio.create_task( channel.send(LOCALIZATION_DATA["errors"]["UnknownError"])) utils.send_image(channel, path) # Update next_clue unless at end if ctx.game.next_clue != 20: for i in range(len(gamedata.CLUE_TIMES)): if gamedata.CLUE_TIMES[i] == ctx.game.next_clue: ctx.game.next_clue = gamedata.CLUE_TIMES[i + 1] break
async def on_command_error(ctx, error): """Default error catcher for commands""" bot_channel = utils.get_text_channels(ctx.guild)["bot-channel"] ctx.game = bot.games.setdefault(ctx.guild.id, gamedata.Data(ctx.guild)) # Failed a check if isinstance(error, commands.errors.CheckFailure): # Commands must be in bot-channel if ctx.channel.name != "bot-channel" and utils.is_command(ctx.message.clean_content): asyncio.create_task(bot_channel.send(f"{ctx.author.mention} You can only use commands in {bot_channel.mention}!")) return # TODO: Check if running debug command without being in dev_ids.txt # Automatic/manual check if ctx.game.automatic: asyncio.create_task(ctx.send("Can't do that, are you running a manual command in automatic mode?")) return asyncio.create_task(ctx.send("You can't do that!")) # Bad input elif isinstance(error, commands.errors.UserInputError): asyncio.create_task(ctx.send("Can't understand input!")) # Can't find command elif isinstance(error, commands.errors.CommandNotFound): asyncio.create_task(ctx.send("Command not found!")) # Everything else else: asyncio.create_task(ctx.send("Unknown error: check console!")) raise error
def send_clue(self, ctx, time: int): # Sends clue based on picked_clues value # Find character who the clue has been assigned to for name in ctx.game.clue_assignments: if time in ctx.game.clue_assignments[name]: character = name break else: raise ValueError("Missing clue") # Send clue card channel = utils.get_text_channels(ctx.game.guild)[f"{character}-clues"] choice = ctx.game.picked_clues[time] path = utils.CLUE_DIR / str(time) / f"{time}-{choice}.png" utils.send_image(channel, path) # Send suspect/location card to player's clues channel suspect = self.draw_suspect(ctx, time) path = utils.MASTER_PATHS[suspect] utils.send_image(channel, path) # Send suspect/location card to respective drawn cards channel if suspect in gamedata.SUSPECTS: channel = "suspects-drawn" elif suspect in gamedata.LOCATIONS: channel = "locations-drawn" else: channel = "bot-channel" channel = utils.get_text_channels(ctx.game.guild)[channel] # Confirmed culprit/location if time <= 30: if suspect in gamedata.SUSPECTS: asyncio.create_task(channel.send("CULPRIT:")) elif suspect in gamedata.LOCATIONS: asyncio.create_task(channel.send("ALICE'S LOCATION:")) else: asyncio.create_task( channel.send("Something has gone very very wrong.")) utils.send_image(channel, path) # Update next_clue unless at end if ctx.game.next_clue != 20: for i in range(len(gamedata.CLUE_TIMES)): if gamedata.CLUE_TIMES[i] == ctx.game.next_clue: ctx.game.next_clue = gamedata.CLUE_TIMES[i + 1] break
async def on_command_error(ctx, error): """Default error catcher for commands""" bot_channel = utils.get_text_channels(ctx.guild)[BOT_CHANNEL] ctx.game = bot.games.setdefault(ctx.guild.id, gamedata.Data(ctx.guild)) # Failed a check if isinstance(error, commands.errors.CheckFailure): # Check if user is spectator if SPECTATOR_ROLE in [role.name for role in ctx.author.roles]: asyncio.create_task( ctx.send( LOCALIZATION_DATA["errors"]["SpectatorCommandAttempt"] ) ) return # Commands must be in bot-channel if ctx.channel.name != BOT_CHANNEL and utils.is_command(ctx.message.clean_content): asyncio.create_task(bot_channel.send(f"{ctx.author.mention} " + LOCALIZATION_DATA["errors"]["CommandInWrongChannel"])) return # Check if running debug command without being listed as developer # TODO: is there a better way to check this than testing against every command/alias? if ctx.author.id not in bot.dev_ids: message = ctx.message.clean_content for command in DEBUG_COMMAND_LIST: aliases: list = LOCALIZATION_DATA["commands"]["debug"][command]["aliases"] aliases.append(LOCALIZATION_DATA["commands"]["debug"][command]["name"]) for alias in aliases: if message.startswith(constants.COMMAND_PREFIX + alias): asyncio.create_task(ctx.send(LOCALIZATION_DATA["errors"]["MissingDeveloperPermissions"])) return # Automatic/manual check if ctx.game.automatic: asyncio.create_task(ctx.send(LOCALIZATION_DATA["errors"]["ManualCommandInAuto"])) return # Couldn't determine a specific error; tell user to check console asyncio.create_task(ctx.send(LOCALIZATION_DATA["errors"]["GenericCheckFailure"])) # Bad input elif isinstance(error, commands.errors.UserInputError): asyncio.create_task(ctx.send(LOCALIZATION_DATA["errors"]["UserInputError"])) # Can't find command elif isinstance(error, commands.errors.CommandNotFound): asyncio.create_task(ctx.send(LOCALIZATION_DATA["errors"]["CommandNotFound"])) # Everything else else: asyncio.create_task(ctx.send(LOCALIZATION_DATA["errors"]["UnknownError"])) raise error