Ejemplo n.º 1
0
    async def bulk_delete(self, messages: list[discord.Message]):
        guild = messages[0].guild

        if not guild.me.guild_permissions.view_audit_log:
            return

        if (LoggingEnum.NONE not in (options := self.get_enum(guild.id))
                and (id := self.bot.cache[guild.id].get("logid")) is not None):

            log_channel = guild.get_channel(id)

            entry = None

            if LoggingEnum.MESSAGE not in options or log_channel is None:
                return

            if guild.me.guild_permissions.view_audit_log:
                entry = (await guild.audit_logs(
                    limit=1,
                    action=AuditLogAction.message_bulk_delete).flatten())[0]
                if (datetime.utcnow() - entry.created_at).total_seconds() > 5:
                    entry = None

            embed = CustomEmbed(title=f"{len(messages)} Bulk Deleted",
                                timestamp=datetime.utcnow())

            if entry:
                embed.add_field(
                    name="**Moderator**",
                    value=(f"Moderator: {entry.user} [{entry.user.id}]"),
                    inline=False,
                )

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 2
0
    async def on_guild_emojis_update(self, guild, before, after):
        if not guild.me.guild_permissions.view_audit_log:
            return

        if (
            LoggingEnum.NONE not in (options := self.get_enum(guild.id))
            and (id := self.bot.cache[guild.id].get("logid")) is not None
        ):

            log_channel = guild.get_channel(id)

            entry = None

            if LoggingEnum.GUILD not in options or log_channel is None:
                return

            entry = await get_audit(guild, AuditLogAction.emoji_update)

            embed = CustomEmbed(title="Emojis Updated").add_field(
                name="Basic Info",
                value=(f"Moderator: {entry.user} [{entry.user.id}]\n"),
            )

            embed.add_field(
                name="Advanced Info",
                value="\n".join(
                    f"{title_format(diff[0])}: `{diff[1]}`" for diff in entry.after
                ),
                inline=False,
            )

            embed.set_author(name=entry.user.name, icon_url=entry.user.avatar_url)

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 3
0
    async def on_questionmark(self, payload):
        embed = CustomEmbed(
            title="Help Info",
            description=(
                "```diff\n"
                "- <arg> Required \n"
                "- [arg] Optional \n"
                "- [arg..] Multiple Args\n"
                "```\n"
            ),
        )

        embed.add_field(
            name="What do the emojis do?",
            value=(
                f"{EMOJIS['arrow_left']} - Goes one page backward.\n"
                f"{EMOJIS['double_backward']} - Goes to the first page.\n"
                f"{EMOJIS['stop']} - Stops the menu.\n"
                f"{EMOJIS['double_forward']} - Goes to the last page.\n"
                f"{EMOJIS['arrow_right']} - Goes one page forward\n"
                f"{EMOJIS['information']} - Shows this page.\n"
            ),
        )

        if self.source.get_max_pages() == 1:
            embed.set_footer(text="To get back to the page, use the double arrows.")

        await self.message.edit(embed=embed)
Ejemplo n.º 4
0
    async def on_guild_role_create(self, role: discord.Role):
        guild = role.guild

        if not guild.me.guild_permissions.view_audit_log:
            return

        if (
            LoggingEnum.NONE not in (options := self.get_enum(guild.id))
            and (id := self.bot.cache[guild.id].get("logid")) is not None
        ):

            log_channel = guild.get_channel(id)

            entry = None

            if LoggingEnum.GUILD not in options or log_channel is None:
                return

            entry = await get_audit(guild, AuditLogAction.role_create)

            embed = CustomEmbed(title="Role Created").add_field(
                name="Basic Info",
                value=(
                    f"Moderator: {entry.user} [{entry.user.id}]\n"
                    f"Role: {role.name} [{role.id}]"
                ),
            )

            embed.add_field(
                name="Advanced Info",
                value="\n".join(
                    f"{title_format(diff[0])}: `{diff[1]}`"
                    for diff in entry.after
                    if diff[0] not in ("permissions", "permissions_new")
                ),
                inline=False,
            )

            for diff in entry.after:
                if diff[0] in ("permissions"):
                    embed.add_field(
                        name=title_format(diff[0]),
                        value=await self.bot.utils.paste(
                            (
                                f"{role.name}\n"
                                + "\n".join(
                                    f"{perm} : {value}"
                                    for perm, value in dict(diff[1]).items()
                                )
                            )
                        ),
                    )

            embed.set_author(name=entry.user.name, icon_url=entry.user.avatar_url)

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 5
0
    async def on_msg_delete(self, message: discord.Message):

        if message.author.bot:
            return

        guild = message.guild

        if not guild.me.guild_permissions.view_audit_log:
            return

        if (LoggingEnum.NONE not in (options := self.get_enum(guild.id))
                and (id := self.bot.cache[guild.id].get("logid")) is not None):

            log_channel = guild.get_channel(id)

            entry = None

            if LoggingEnum.MESSAGE not in options or log_channel is None:
                return

            entry = await get_audit(message.guild,
                                    AuditLogAction.message_delete)

            embed = CustomEmbed(
                title="Message Deleted",
                description=(
                    f"Author: {message.author} [{message.author.id}] \n"
                    f"Channel: {message.channel} [{message.channel.id}] \n"),
                timestamp=datetime.utcnow(),
            )

            embed.add_field(
                name="**Content**",
                value=discord.utils.escape_markdown(message.content) or "None"
                if not message.embeds else "Message had embeds.",
                inline=False,
            )

            if entry:
                embed.add_field(
                    name="**Moderator**",
                    value=(f"Moderator: {entry.user} [{entry.user.id}]"),
                    inline=False,
                )

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 6
0
    async def reload_all(self, ctx):
        successful = []
        unsuccessful = []
        extensions = list(self.bot.extensions.keys())

        for cog in extensions:
            try:
                self.bot.reload_extension(cog)
                successful.append(cog)
            except:
                unsuccessful.append(cog)

        embed = CustomEmbed(title="Reloaded all extensions")

        embed.add_field(name="Successful",
                        value="\t".join(successful) or "None")
        embed.add_field(name="Unsuccessful",
                        value="\t".join(unsuccessful) or "None",
                        inline=False)

        await ctx.send(embed=embed)
Ejemplo n.º 7
0
    async def send_command_help(self, command):
        command = await self.filter_commands([command])
        command = safe_get(command, 0)

        if command is None:
            return

        embed = CustomEmbed(title="Help")

        embed.add_field(name="Help", value=command.help or "None", inline=False)
        embed.add_field(
            name="Aliases",
            value=" ".join("`" + alias + "`" for alias in command.aliases) or "None",
            inline=False,
        )
        embed.add_field(
            name="Arguments",
            value=getattr(
                command, "usage", getattr(command, "old_signature", command.signature)
            )
            or "None",
            inline=False,
        )

        await self.get_destination().send(embed=embed)
Ejemplo n.º 8
0
    async def guild_update(self, before: discord.Guild, after: discord.Guild):

        if not after.me.guild_permissions.view_audit_log:
            return

        if (
            LoggingEnum.NONE not in (options := self.get_enum(after.id))
            and (id := self.bot.cache[after.id].get("logid")) is not None
        ):

            log_channel = after.get_channel(id)

            if LoggingEnum.GUILD not in options or log_channel is None:
                return

            entry = await get_audit(after, AuditLogAction.guild_update)

            if entry is None:
                return

            embed = CustomEmbed(title="Guild Updated")

            embed.add_field(
                name="Basic Info", value=(f"Moderator: {entry.user} [{entry.user.id}]")
            )

            embed.add_field(
                name="Advanced Info",
                value="\n".join(
                    [f"{title_format(diff[0])}: `{diff[1]}`" for diff in entry.after]
                ),
            )

            embed.set_author(name=entry.user.name, icon_url=entry.user.avatar_url)

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 9
0
    async def on_msg_edit(self, before: discord.Message,
                          after: discord.Message):
        if before.author.bot:
            return

        guild = before.guild

        if not guild.me.guild_permissions.view_audit_log:
            return

        if (LoggingEnum.NONE not in (options := self.get_enum(guild.id))
                and (id := self.bot.cache[guild.id].get("logid")) is not None):

            log_channel = guild.get_channel(id)

            if LoggingEnum.MESSAGE not in options or log_channel is None:
                return

            embed = CustomEmbed(title="Message Edited",
                                timestamp=datetime.utcnow())

            embed.add_field(
                name="Before Content",
                value=discord.utils.escape_markdown(before.content)
                or "Message only contained embeds.",
                inline=False,
            )

            embed.add_field(
                name="After Content",
                value=discord.utils.escape_markdown(after.content)
                or "Message only contained embeds.",
                inline=False,
            )

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 10
0
    def format_page(self, menu, entries):

        offset = menu.current_page * self.per_page

        embed = CustomEmbed(
            title="Help",
            description=(
                f"Use `{self.prefix}help[command]` for more info on a command.\n"
                f"You can also use `{self.prefix}help[category]` for more info on a category.\n"
            ),
        )

        for index, category in enumerate(entries, start=offset):

            cate = list(category.keys())[0]

            category_name = getattr(cate, "qualified_name", "None")

            commands = category.get(list(category.keys())[0])

            embed.add_field(
                name=f"**{category_name}** [{' | '.join(alias for alias in cate.aliases)}]"
                if getattr(cate, "aliases", None) is not None
                else f"**{category_name}**",
                value=f"{getattr(cate, 'description', '')}"
                + "\n"
                + " ".join(f"`{command.qualified_name}`" for command in commands)
                or "`None`",
                inline=False,
            )
        embed.set_footer(
            text=f"Page {menu.current_page + 1} / {self.get_max_pages()}"
            if self.get_max_pages() > 0
            else "Page 0/0"
        )

        return embed
Ejemplo n.º 11
0
    async def on_channel_create(self, channel):
        guild = channel.guild

        if not channel.guild.me.guild_permissions.view_audit_log:
            return

        if (LoggingEnum.NONE not in (options := self.get_enum(guild.id))
                and (id := self.bot.cache[guild.id].get("logid")) is not None):

            log_channel = guild.get_channel(id)

            if LoggingEnum.CHANNELS not in options or log_channel is None:
                return

            entry = await get_audit(channel.guild,
                                    AuditLogAction.channel_create)

            if entry is None:
                return

            embed = CustomEmbed(title="Channel Created",
                                timestamp=datetime.utcnow())

            embed.add_field(
                name="**Basic Info**",
                value=
                (f"Name: `{channel}` [{channel.id}]\n"
                 f"Type: `{channel.type}`\n"
                 f"Position: `{channel.position}`\n"
                 f"Created At: `{channel.created_at.strftime(TIME_TEMPLATE)}` (UTC)\n"
                 f"Category: `{channel.category}`"
                 f"Moderator: {entry.user} [{entry.user.id}]\n"),
            )

            embed.add_field(
                name="Advanced Info",
                value="\n".join([
                    title_format(diff[0] + f"`{diff[1]}`"
                                 for diff in entry.after
                                 if diff[0] != "overwrites")
                ]),
            )

            for diff in entry.after:
                if diff[0] == "overwrites":
                    embed.add_field(
                        name="Overwrites",
                        value=await
                        self.bot.utils.paste(format_overwrites(diff[1])),
                    )

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 12
0
    async def on_channel_update(self, before, after):

        guild = after.guild

        if not after.guild.me.guild_permissions.view_audit_log:
            return

        if (LoggingEnum.NONE not in (options := self.get_enum(guild.id))
                and (id := self.bot.cache[guild.id].get("logid")) is not None):

            log_channel = guild.get_channel(id)

            if LoggingEnum.CHANNELS not in options or log_channel is None:
                return

            if guild.me.guild_permissions.view_audit_log:
                entry = (await guild.audit_logs(
                    limit=1,
                    action=AuditLogAction.channel_update).flatten())[0]

            embed = CustomEmbed(title="Channel Edited",
                                timestamp=datetime.utcnow())

            embed.add_field(
                name="Basic Info",
                value=(f"Channel: {after.mention} [{after.id}] \n"
                       f"Moderator: {entry.user} [{entry.user.id}]\n"),
            )

            embed.add_field(
                name="Advanced Info",
                value="\n".join([
                    title_format(diff[0] + f"`{diff[1]}`"
                                 for diff in entry.after
                                 if diff[0] != "overwrites")
                ]),
            )

            for diff in entry.after:
                if diff[0] == "overwrites":
                    embed.add_field(
                        name="Overwrites",
                        value=await
                        self.bot.utils.paste(format_overwrites(diff[1])),
                    )

            embed.set_author(name=entry.user.name, url=entry.user.avatar_url)

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)
Ejemplo n.º 13
0
    async def on_channel_delete(self, channel):
        guild = channel.guild

        if not channel.guild.me.guild_permissions.view_audit_log:
            return

        if (LoggingEnum.NONE not in (options := self.get_enum(guild.id))
                and (id := self.bot.cache[guild.id].get("logid")) is not None):

            log_channel = guild.get_channel(id)

            entry = None

            if LoggingEnum.CHANNELS not in options or log_channel is None:
                return

            if guild.me.guild_permissions.view_audit_log:
                entry = (await guild.audit_logs(
                    limit=1,
                    action=AuditLogAction.channel_delete).flatten())[0]

            embed = CustomEmbed(title="Channel Deleted",
                                timestamp=datetime.utcnow())

            embed.add_field(
                name="**Channel**",
                value=
                (f"Name: `{channel}` [{channel.id}]\n"
                 f"Type: `{channel.type}`\n"
                 f"Position: `{channel.position}`\n"
                 f"Created At: `{channel.created_at.strftime(TIME_TEMPLATE)}` (UTC)"
                 ),
            )

            if entry is not None:

                for diff in entry.after:
                    if diff[0] == "overwrites":
                        if diff[1] is None:
                            continue
                        url = await self.bot.utils.paste(format_overwrites(
                            diff[1]),
                                                         syntax=None)
                        embed.add_field(name="Overwrites", value=url or "None")
                    else:
                        embed.add_field(
                            name=title_format(diff[0]),
                            value=f"`{diff[1]}`",
                            inline=False,
                        )

                embed.add_field(name="**Moderator**",
                                value=(f"{entry.user}"),
                                inline=False)
            else:
                embed.add_field(
                    embed.add_field(
                        name="**Moderator**",
                        value="Cannot access the audit log to get more info.",
                    ))

            with suppress(discord.Forbidden):
                await log_channel.send(embed=embed)