예제 #1
0
파일: notes.py 프로젝트: Picowchew/BOTC-Bot
    async def info_add(self, ctx, *, args: str):
        invoking_player = BOTCUtils.get_player_from_id(ctx.author.id)

        args = re.split(' +', args)

        # Ensure that we have enough values in the list
        args += ['', '']

        try:
            target_phase = int(args[0])
            target_player = None
            args.pop(0)
        except ValueError:
            target_player = BOTCUtils.get_player_from_string(args[0])
            if target_player is not None:
                args.pop(0)

            try:
                target_phase = int(args[0])
                args.pop(0)
            except ValueError:
                target_phase = None

        # Remove the two dummy elements
        args.pop()
        args.pop()

        rem = ' '.join(args)

        if not rem.strip():
            if target_phase is None:
                if target_player is None:
                    raise commands.MissingRequiredArgument(Parameter('info', Parameter.POSITIONAL_ONLY))
                else:
                    # Added info was a player name
                    rem = str(target_player)
                    target_player = None
            else:
                # Added info was a number (empath for example)
                rem = str(target_phase)
                target_phase = None

        if target_phase is not None and target_phase > globvars.master_state.game._chrono.cycle:
            raise commands.BadArgument()

        if target_player is not None:
            globvars.master_state.game.note_manager.info(target_player, rem, invoking_player, target_phase)
        else:
            if globvars.master_state.game._chrono.phase == Phase.night:
                raise NotNight("Command is allowed during night phase only (BoTC)")
            globvars.master_state.game.note_manager.info(invoking_player, rem, None, target_phase)

        await ctx.send(info_add_feedback_str.format(BotEmoji.check))
예제 #2
0
 async def reveal_roles(self, ctx, target: str):
     if target == 'all':
         msg = ""
         for player in globvars.master_state.game.sitting_order:
             msg += player.game_nametag + " is the **" + player.role.true_self.name + \
                 (" " + player.role.ego_self.name if player.role.true_self.name != player.role.ego_self.name else "") + "**\n"
     else:
         target = BOTCUtils.get_player_from_string(target)
         if target is None:
             raise PlayerNotFound(f"Player {target} not found")
         msg = target.game_nametag + " is the **" + target.role.true_self.name + \
                 (" " + target.role.ego_self.name if target.role.true_self.name != target.role.ego_self.name else "") + "**"
     await ctx.send(msg)
예제 #3
0
파일: notes.py 프로젝트: Picowchew/BOTC-Bot
    async def notes_add(self, ctx, *, args):
        invoking_player = BOTCUtils.get_player_from_id(ctx.author.id)

        args = re.split(' +', args)

        target_player = BOTCUtils.get_player_from_string(args[0])
        if target_player is None:
            target_player = invoking_player
            note = ' '.join(args)
        else:
            args.pop(0)
            note = ' '.join(args)

        globvars.master_state.game.note_manager.note(target_player, note, invoking_player)
        await ctx.send(notes_add_feedback_str.format(BotEmoji.check))
예제 #4
0
파일: notes.py 프로젝트: Picowchew/BOTC-Bot
    async def claim_add(self, ctx, player_or_claim: str, claim: str = None):
        invoking_player = BOTCUtils.get_player_from_id(ctx.author.id)

        # Overloading a command
        temp = botutils.find_role_in_all(player_or_claim)
        if temp is not None:
            if temp.gm_of_appearance != globvars.master_state.game.gamemode:
                raise RoleNotFound(role_not_found_str.format(ctx.author.mention, BotEmoji.x_emoji))
            player_or_claim = temp
        else:
            temp = BOTCUtils.get_player_from_string(player_or_claim)
            player_or_claim = (temp if temp is not None else player_or_claim)

        if claim is not None:
            temp = botutils.find_role_in_all(claim)
            if temp is not None:
                if temp.gm_of_appearance != globvars.master_state.game.gamemode:
                    raise RoleNotFound(role_not_found_str.format(ctx.author.mention, BotEmoji.x_emoji))
                claim = temp


        if isinstance(player_or_claim, Player):
            if claim is None:
                raise MissingRequiredArgument(Parameter('claim', Parameter.POSITIONAL_ONLY))

            if isinstance(claim, Character):
                claimed_character = claim
                claimed_category = claimed_character.category
            else:
                claimed_character = None

                claim = claim.lower()
                if claim in ('town', 'townsfolk'):
                    claimed_category = Category.townsfolk
                elif claim in ('os', 'outsider'):
                    claimed_category = Category.outsider
                elif claim in ('minion'):
                    claimed_category = Category.minion
                elif claim in ('demon'):
                    claimed_category = Category.demon
                else:
                    raise RoleNotFound(role_not_found_str.format(ctx.author.mention, BotEmoji.x_emoji))

        elif isinstance(player_or_claim, Character):
            claimed_character = player_or_claim
            claimed_category = claimed_character.category
            player_or_claim = None
        else:
            claimed_character = None

            player_or_claim = player_or_claim.lower()
            if player_or_claim in ('town', 'townsfolk'):
                claimed_category = Category.townsfolk
            elif player_or_claim in ('os', 'outsider'):
                claimed_category = Category.outsider
            elif player_or_claim in ('minion'):
                claimed_category = Category.minion
            elif player_or_claim in ('demon'):
                claimed_category = Category.demon
            else:
                raise RoleNotFound(role_not_found_str.format(ctx.author.mention, BotEmoji.x_emoji))

            player_or_claim = None

        if player_or_claim is None:
            if globvars.master_state.game._chrono.phase == Phase.night:
                raise NotNight("Command is allowed during night phase only (BoTC)")

            old_claim_role = globvars.master_state.game.note_manager.public_notes().get_entry(invoking_player).claimed_role
            old_claim_category = globvars.master_state.game.note_manager.public_notes().get_entry(invoking_player).claimed_category

            globvars.master_state.game.note_manager.claim(invoking_player, claimed_category, claimed_character)

            an_a_the = "the"
            if claimed_character == None:
                if claimed_category == Category.outsider:
                    an_a_the = "an"
                else:
                    an_a_the = "a"

            if old_claim_role != claimed_character or old_claim_category != claimed_category:
                await botutils.send_lobby(claim_role_str.format(ctx.author.mention, an_a_the, (claimed_character.name if claimed_character else claimed_category.value)), delete_after=CLAIM_SHOW_TIME)
        else:
            globvars.master_state.game.note_manager.claim(player_or_claim, claimed_category, claimed_character, invoking_player)

        await ctx.send(private_claim_role_str.format(BotEmoji.check))