Beispiel #1
0
    async def _unpinall(self, ctx: Context):
        """Unpin all messages in channel."""
        with ctx.typing():
            for msg in await ctx.bot.channel.pins():
                await msg.unpin()

        await safe_send(ctx, "Unpinned all messages.")
Beispiel #2
0
    def info(self, ctx: Context) -> Generator[str, None, None]:
        """Return a generator with information about the script."""
        # maybe we should do more specific message length handling here than in safe_send

        with ctx.typing():
            message_text = f"**__{self.name}:__**"
            message_text += self._character_type_info(Townsfolk)
            yield message_text  # we want to separate townsfolk from other characters

            message_text = ""
            for cls in (Outsider, Minion, Demon):
                message_text += self._character_type_info(cls)
            yield message_text

            message_text = "__First Night:__\nDusk\nMinion Info\nDemon Info"
            for character in self.first_night:
                message_text += "\n" + character.name
            message_text += "\nDawn"

            message_text += "\n\n__Other Nights:__\nDusk"
            for character in self.other_nights:
                message_text += "\n" + character.name
            message_text += "\nDawn"

            yield message_text
Beispiel #3
0
    async def list(self, ctx: Context):
        """List the scripts available from this bot."""

        with ctx.typing():
            for script in script_list(ctx,
                                      playtest=ctx.author
                                      in ctx.bot.playtest_role.members):
                await safe_send(ctx, script.short_info(ctx))
Beispiel #4
0
    async def endgame(self, ctx: Context, winner: str):
        """End the game.

        winner: 'good' or 'evil'. Can be 'neutral' in the event of a rerack.

        This command often takes a long time, as it unpins a large number of messages.
        """
        with ctx.typing():

            # verify valid winner
            winner = winner.lower()
            if winner not in ["good", "evil", "neutral"]:
                raise commands.BadArgument(
                    "The winner must be 'good,' 'evil,' or 'neutral,' exactly."
                )

            # set winner
            ctx.bot.game.winner = winner

            # endgame message
            if winner != "neutral":
                await safe_send(
                    ctx.bot.channel,
                    f"{ctx.bot.player_role.mention}, {winner} has won. Good game!",
                )
            else:
                await safe_send(
                    ctx.bot.channel,
                    f"{ctx.bot.player_role.mention}, the game is being remade.",
                )

            # unpin messages
            # TODO: unpin the script messages as well
            for msg in await ctx.bot.channel.pins():
                if msg.created_at >= ctx.bot.game.seating_order_message.created_at:
                    await msg.unpin()

            # backup
            i = 1
            while isfile(f"{ctx.bot.bot_name}/old/game_{i}.pckl"):
                i += 1
            ctx.bot.backup(f"old/game_{i}.pckl")

            # thank storytellers
            for st in ctx.bot.game.storytellers:
                await safe_send(
                    st.member,
                    "Thank you for storytelling! We appreciate you <3")

            # delete game
            ctx.bot.game = None

            # complete
            await safe_send(ctx, "Ended the game successfully.")
            return
Beispiel #5
0
    async def new(self, ctx: Context, mode: str = "json", *, name: str):
        """Create a new custom script.

        mode: How to input characters on the script.
            json: Enter the script's json file from the script creator.
            text: Enter the characters in a line break-separated message.
        name: The script's name.
        """
        with ctx.typing():

            for script in script_list(ctx, playtest=True):

                # Check duplicate names
                if script.name.lower() == name.lower():
                    if _permission_to_edit(ctx, ctx.author.id, script):
                        # _permission_to_edit raises a BadArgument exception if the check
                        # fails, which is handled in Events.on_command_error, so we don't
                        # have to do any handling of that case here
                        await safe_send(
                            ctx,
                            (f"There is already a script named {name}. "
                             "You can modify it or delete it:"),
                        )
                        await ctx.send_help(ctx.bot.get_command("script"))
                        return

        # Get the characters
        if mode == "json":
            raw_characters = (await get_input(
                ctx,
                ("What characters are on the script? "
                 "Send the text of the json from the script creator."),
            ))[8:-3].split('"},{"id":"')
        elif mode == "text":
            raw_characters = (await get_input(
                ctx,
                ("What characters are on the script? "
                 "Separate characters by line breaks."),
            )).split("\n")
        else:
            raise commands.BadArgument(f"{mode} is not an accepted mode.")

        # Character list
        with ctx.typing():

            character_list = to_character_list(ctx, raw_characters)
            playtest = False
            for char_class in character_list:
                if char_class(None).playtest:
                    playtest = True
                    break

            # Make the script
            script = Script(
                name,
                character_list,
                editors=[ctx.message.author.id],
                playtest=playtest,
            )

        # First night order
        raw_first_night = (await get_input(
            ctx,
            "What is the first night order? Separate characters by line breaks.",
        )).split("\n")

        with ctx.typing():

            first_night_list = []  # Here we're ok with duplicates
            for char in raw_first_night:
                char_class = to_character(ctx, char, script)
                first_night_list.append(char_class)

            script.first_night = first_night_list

        # Other nights order
        raw_other_nights = (await get_input(
            ctx,
            ("What is the order for other nights?"
             "Separate characters by line breaks."),
        )).split("\n")

        with ctx.typing():

            other_nights_list = []  # Here we're ok with duplicates
            for char in raw_other_nights:
                char_class = to_character(ctx, char, script)
                other_nights_list.append(char_class)

            script.other_nights = other_nights_list

        # save
        script.save()

        # Wrap up
        await safe_send(
            ctx,
            "Successfully created a new {playtest}script called {name}:".
            format(playtest=["", "playtest "][playtest], name=script.name),
        )
        for x in script.info(ctx):
            await safe_send(ctx, x)
        return