def _check_valid_nominator(ctx: Context, nominator: Player, nominee: Player): """Check that nominator is a valid nominator, else raise an exception.""" if not ( nominator.can_nominate(ctx) or nominee.character_type(ctx) == "traveler" or nominator.character_type(ctx) == "storyteller" ): raise ValueError("nominator already nominated")
def _check_valid_nominee(ctx: Context, nominator: Player, nominee: Player): """Check that the nominee is a valid nominee, else raise an exception.""" if nominee.character_type(ctx) == "storyteller": # atheist nominations for st in ctx.bot.game.storytellers: if not st.can_be_nominated(ctx, nominator): raise commands.BadArgument( "The storytellers cannot be nominated today." ) elif not nominee.can_be_nominated(ctx, nominator): raise commands.BadArgument(f"{nominee.nick} cannot be nominated today.")
async def _effect_adder( ctx: Context, player: Player, effect: Type[Effect.Effect], source: Player = None ): """Add effect to player.""" source = source or player effect_object = player.add_effect(ctx, effect, source) if source == player or source.character_type(ctx) == "storyteller": source_text = "" else: source_text = f"with source {source.nick} " await safe_send( ctx, f"Successfully added effect {effect_object.name} {source_text}to {player.nick}.", )
async def addtraveler( self, ctx: Context, traveler: str, upwards_neighbor: str, alignment: str, *, character: str, ): """Add a traveler to the game. traveler: The player to join the game. character: Their traveler character. upwards_neighbor: The player above them in the seating order. alignment: The traveler's alignment; 'good' or 'evil'. """ # convert the traveler traveler_actual = await to_member(ctx, traveler) # check alignment is valid if not alignment.lower() in ["good", "evil"]: raise commands.BadArgument( "The alignment must be 'good' or 'evil' exactly.") # check if person is in the game try: get_player(ctx.bot.game, traveler_actual.id) raise commands.BadArgument( f"{load_preferences(traveler_actual).nick} is already in the game." ) except ValueError as e: if str(e) == "player not found": # find the character character_actual = to_character(ctx, character) # determine the position upwards_neighbor_actual = await to_player( ctx, upwards_neighbor) # make the Player player = Player( traveler_actual, character_actual, upwards_neighbor_actual.position + 1, ) # check that the character is a traveler if not player.character_type(ctx) == "traveler": raise commands.BadArgument( f"{player.character.name} is not a traveler.") # add the alignment if alignment.lower() == "good": player.add_effect(ctx, Good, player) elif alignment.lower() == "evil": player.add_effect(ctx, Evil, player) # add the player role await traveler_actual.add_roles(ctx.bot.player_role) # add them to the seating order ctx.bot.game.seating_order.insert( upwards_neighbor_actual.position + 1, player) # announcement await safe_send( ctx.bot.channel, ("{townsfolk}, {player} has joined the town as the {traveler}. " "Let's tell {pronoun} hello!").format( traveler=player.character.name, pronoun=load_preferences(player).pronouns[1], townsfolk=ctx.bot.player_role.mention, player=player.nick, ), ) # rules msg = await safe_send( ctx.bot.channel, f"\n**{player.character.name}** - {player.character.rules_text}", ) await msg.pin() await safe_send( ctx, f"Successfully added {player.nick} as the {player.character.name}.", ) else: raise