コード例 #1
0
    def get_paginator(self):
        embed = self.embed.copy()
        embed.set_footer(
            text=embed.footer.text + "\nPage {current_page}/{total_pages},"
            " showing module {first_field}..{last_field}/{total_fields}")

        return menus.FieldPaginator(self.context.bot, base_embed=embed)
コード例 #2
0
ファイル: webhooks.py プロジェクト: discohook/bot
    async def webhook_list(self, ctx: cmd.Context, channel: discord.TextChannel = None):
        """Lists webhooks for the server or a given channel"""

        if channel:
            channel_perms = channel.permissions_for(ctx.me)
            if not channel_perms.view_channel or not channel_perms.manage_webhooks:
                raise commands.BotMissingPermissions(["manage_webhooks"])

        embed = discord.Embed(
            title="Webhooks",
            description=f"Use {get_command_signature(ctx, self.webhook_get)}"
            " to get more info on a webhook.",
        )
        embed.set_footer(
            text="Page {current_page}/{total_pages}, "
            "showing webhook {first_field}..{last_field}/{total_fields}."
        )
        paginator = menus.FieldPaginator(self.bot, base_embed=embed)

        for webhook in await ctx.guild.webhooks():
            if webhook.type != discord.WebhookType.incoming:
                continue
            if channel and webhook.channel_id != channel.id:
                continue

            paginator.add_field(
                name=webhook.name,
                value=f"Channel: {webhook.channel.mention}\nID: {webhook.id}",
            )

        await paginator.send(ctx)
コード例 #3
0
    async def reactionrole_list(self, ctx: cmd.Context):
        """Lists all messages with reaction roles enabled"""

        embed = discord.Embed(title="Reaction roles")
        embed.set_footer(
            text="Page {current_page}/{total_pages}, "
            "showing message {first_field}..{last_field}/{total_fields}")
        paginator = menus.FieldPaginator(self.bot, base_embed=embed)

        reaction_roles = itertools.groupby(
            await self.db.fetch(
                """
                SELECT channel_id, message_id, role_id, reaction FROM reaction_role
                WHERE guild_id = $1
                ORDER BY message_id
                """,
                ctx.guild.id,
            ),
            key=lambda rr: (rr["channel_id"], rr["message_id"]),
        )

        for (channel_id, message_id), roles in reaction_roles:
            jump_url = (
                f"https://discord.com/channels/{ctx.guild.id}/{channel_id}/{message_id}"
            )

            paginator.add_field(
                name=f"Message {message_id}",
                value=f"In <#{channel_id}> ([go to message]({jump_url}))\n\n" +
                "\n".join(
                    f"{role['reaction']} \N{RIGHTWARDS ARROW} <@&{role['role_id']}>"
                    for role in roles),
            )

        await paginator.send(ctx)
コード例 #4
0
    async def config(
        self,
        ctx: cmd.Context,
        option: typing.Optional[str],
        *,
        new_value: typing.Optional[str],
    ):
        """Manages server configuration for bot"""

        command = f"{get_clean_prefix(ctx)}{self.config.qualified_name}"

        if option:
            configurable = get(config.configurables, name=option.lower())
            if configurable is None:
                raise commands.UserInputError(
                    f"Option {wrap_in_code(option)} not found"
                )

            if new_value:
                await commands.has_guild_permissions(manage_guild=True).predicate(ctx)

                try:
                    parsed_value = config.resolve_value(configurable.type, new_value)
                    await self.cfg.set_value(ctx.guild, configurable, parsed_value)
                except:
                    raise commands.BadArgument(
                        f"Value {wrap_in_code(new_value)} is does not fit"
                        f" expected type {config.type_names[configurable.type]}"
                    )

            value = (
                parsed_value
                if new_value is not None
                else await self.cfg.get_value(ctx.guild, configurable)
            )
            value = (
                ("yes" if value else "no") if isinstance(value, bool) else str(value)
            )
            value = wrap_in_code(value)

            set_signature = wrap_in_code(f"{command} {configurable.name} <new value>")
            message = (
                f"Option {configurable.name} has been set to {value}."
                if new_value is not None
                else f"Option {configurable.name} is currently set to {value}."
                f"\nUse {set_signature} to set it."
            )

            await ctx.prompt(
                embed=discord.Embed(title="Configuration", description=message)
            )
            return

        get_signature = wrap_in_code(f"{command} <option>")
        set_signature = wrap_in_code(f"{command} <option> <new value>")

        embed = discord.Embed(
            title="Configuration",
            description="Command to manage the bot's configuration for a server."
            f"\nTo get the value of an option use {get_signature}."
            f"\nTo set the value of an option use {set_signature}."
            "\nList of options can be found below:",
        )
        embed.set_footer(
            text="Page {current_page}/{total_pages}, "
            "showing option {first_field}..{last_field}/{total_fields}"
        )
        paginator = menus.FieldPaginator(self.bot, base_embed=embed)

        for configurable in config.configurables:
            paginator.add_field(
                name=configurable.name.capitalize(),
                value=configurable.description,
            )

        await paginator.send(ctx)