Пример #1
0
 async def snippet_raw(self, ctx, *, name: str.lower):
     """
     View the raw content of a snippet.
     """
     val = self.bot.snippets.get(name)
     if val is None:
         embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
         return await ctx.send(embed=embed)
     return await ctx.send(escape_markdown(escape_mentions(val)).replace("<", "\\<"))
Пример #2
0
    async def snippet(self, ctx, *, name: str.lower = None):
        """
        Create pre-defined messages for use in threads.

        When `{prefix}snippet` is used by itself, this will retrieve
        a list of snippets that are currently set. `{prefix}snippet-name` will show what the
        snippet point to.

        To create a snippet:
        - `{prefix}snippet add snippet-name A pre-defined text.`

        You can use your snippet in a thread channel
        with `{prefix}snippet-name`, the message "A pre-defined text."
        will be sent to the recipient.

        Currently, there is not a built-in anonymous snippet command; however, a workaround
        is available using `{prefix}alias`. Here is how:
        - `{prefix}alias add snippet-name anonreply A pre-defined anonymous text.`

        See also `{prefix}alias`.
        """

        if name is not None:
            val = self.bot.snippets.get(name)
            if val is None:
                embed = create_not_found_embed(
                    name, self.bot.snippets.keys(), "Snippet"
                )
                return await ctx.send(embed=embed)
            return await ctx.send(escape_mentions(val))

        if not self.bot.snippets:
            embed = discord.Embed(
                color=discord.Color.red(),
                description="You dont have any snippets at the moment.",
            )
            embed.set_footer(
                text=f"Do {self.bot.prefix}help snippet for more commands."
            )
            embed.set_author(name="Snippets", icon_url=ctx.guild.icon_url)
            return await ctx.send(embed=embed)

        embeds = []

        for i, names in enumerate(
            zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)
        ):
            description = format_description(i, names)
            embed = discord.Embed(color=self.bot.main_color, description=description)
            embed.set_author(name="Snippets", icon_url=ctx.guild.icon_url)
            embeds.append(embed)

        session = EmbedPaginatorSession(ctx, *embeds)
        await session.run()
Пример #3
0
    async def anon(self, ctx, name: str.lower = None):
        """Anon snippets"""
        if name is not None:
            snippet = self.bot.snippets.get(name, None)

            if snippet is None:
                embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
                return await ctx.send(embed=embed)

            ctx.message.content = snippet

            async with ctx.typing():
                await ctx.thread.reply(ctx.message, anonymous=True)
Пример #4
0
    async def snippet_remove(self, ctx, *, name: str.lower):
        """Remove a snippet."""

        if name in self.bot.snippets:
            embed = discord.Embed(
                title="Removed snippet",
                color=self.bot.main_color,
                description=f"Snippet `{name}` is now deleted.",
            )
            self.bot.snippets.pop(name)
            await self.bot.config.update()
        else:
            embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
        await ctx.send(embed=embed)
Пример #5
0
    async def snippet_edit(self, ctx, name: str.lower, *, value):
        """
        Edit a snippet.

        To edit a multi-word snippet name, use quotes: ```
        {prefix}snippet edit "two word" this is a new two word snippet.
        ```
        """
        if name in self.bot.snippets:
            self.bot.snippets[name] = value
            await self.bot.config.update()

            embed = discord.Embed(
                title="Edited snippet",
                color=self.bot.main_color,
                description=f'`{name}` will now send "{value}".',
            )
        else:
            embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
        await ctx.send(embed=embed)