Beispiel #1
0
    async def send_dm(
        self,
        member: Member,
        embed: Embed,
        message: Message = None,
        description: str = "",
    ):
        embed.description = f"{description}\n\n" f"Reason: {embed.description}\n\n"
        if message:
            embed.description += f"[Jump To Conversation]({message.jump_url})"

        try:
            await member.send(embed=embed)
            return True
        except nextcord.errors.Forbidden:
            return False
 async def _help_embed(self,
                       title: str,
                       description: Optional[str] = None,
                       mapping: Optional[str] = None,
                       command_set: Optional[Set[commands.Command]] = None,
                       set_author: bool = False) -> Embed:
     embed = Embed(title=title)
     if description:
         embed.description = description
     if set_author:
         avatar = self.context.bot.user.avatar or self.context.bot.user.default_avatar
         embed.set_author(name=self.context.bot.user.name,
                          icon_url=avatar.url)
     if command_set:
         # show help about all commands in the set
         filtered = await self.filter_commands(command_set, sort=True)
         for command in filtered:
             embed.add_field(name=self.get_command_signature(command),
                             value=command.short_doc or "...",
                             inline=False)
     elif mapping:
         # add a short description of commands in each cog
         for cog, command_set in mapping.items():
             filtered = await self.filter_commands(command_set, sort=True)
             if not filtered:
                 continue
             name = cog.qualified_name if cog else "No category"
             emoji = getattr(cog, "COG_EMOJI", None)
             cog_label = f"{emoji} {name}" if emoji else name
             # \u2002 is an en-space
             cmd_list = "\u2002".join(
                 f"`{self.context.clean_prefix}{cmd.name}`"
                 for cmd in filtered)
             value = (f"{cog.description}\n{cmd_list}"
                      if cog and cog.description else cmd_list)
             embed.add_field(name=cog_label, value=value)
     return embed
Beispiel #3
0
    async def attachment_filter(self, message):
        """When a message is sent by normal users ensure it doesn't have any non-image attachments. Delete it and send
        a mod message if it does."""
        if message.author.bot:
            return

        if not message.attachments:
            return

        if os.environ.get("PRODUCTION_BOT", False):
            if message.channel.name.lower() in self.admin_channels:
                return

            if message.channel.permissions_for(message.author).manage_messages:
                return

        allowed, disallowed = self.categorize_attachments(message)

        if not allowed and not disallowed:
            return

        user_message = ("\n".join(f"> {section}"
                                  for section in message.content.split("\n"))
                        if message.content.strip() else "")
        embed = Embed(
            title="File Attachments Not Allowed",
            description=
            f"For safety reasons we do not allow file and video attachments.",
            color=YELLOW,
        )

        if allowed:
            embed.title = f"{message.author.display_name} Uploaded Some Code"
            embed.description = user_message
            files = {}
            name = None
            for attachment in allowed:
                content = (await attachment.read()).decode()
                if len(content) < 1000:
                    file_type = os.path.splitext(
                        attachment.filename)[1].casefold()
                    embed.add_field(
                        name=f"Attachment: {attachment.filename}",
                        value=
                        f"```{self.file_types.get(file_type, '')}\n{content}\n```",
                    )
                else:
                    if not name:
                        name = attachment.filename
                    files[attachment.filename] = content

            if files:
                gist = self.upload_files(files)
                embed.add_field(
                    name="Uploaded the file to a Gist",
                    value=f"[{name}]({gist})",
                )

            embed.set_thumbnail(
                url=
                "https://cdn.discordapp.com/emojis/711749954837807135.png?v=1")

            embed.set_footer(
                text="For safety reasons we do not allow file attachments.")

        else:
            embed.set_thumbnail(
                url=
                "https://cdn.discordapp.com/emojis/651959497698574338.png?v=1")
            if user_message:
                embed.add_field(name=f"{message.author.display_name} Said",
                                value=user_message)
            embed.add_field(
                name="Code Formatting",
                value=
                f"You can share your code using triple backticks like this:\n\\```\nYOUR CODE\n\\```",
                inline=False,
            )
            embed.add_field(
                name="Large Portions of Code",
                value=
                f"For longer scripts use [Hastebin](https://hastebin.com/) or "
                f"[GitHub Gists](https://gist.github.com/) and share the link here",
                inline=False,
            )

        if disallowed:
            embed.add_field(
                name="Ignored these files",
                value="\n".join(f"- {attachment.filename}"
                                for attachment in disallowed) or "*NO FILES*",
            )

        try:
            await message.delete()
        except nextcord.errors.NotFound:
            pass

        await message.channel.send(message.author.mention, embed=embed)