Some Code Testing

Yo, just wanted to test the syntax highlighting plugin. Have a look at my first ever written discord.py bots’ module, figlet.py:

## figlet.py by freaky
# pip3 install pyfiglet

# TODO: add logging

# Import commands
from discord.ext import commands
from pyfiglet import Figlet

class figlet():

    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def figlet(self, ctx, *args):
        """Write some cool ASCII :)"""

        if(len(args) < 1):
            return

        args = " ".join(args)

        f = Figlet()

        await ctx.send(f"```" + f.renderText(args) + "```")

    @commands.command()
    async def figletf(self, ctx, *args):
        """Write some cool ASCII with different fonts."""

        if(len(args) < 2):
            return

        f = Figlet(font=args[0])
        text = " ".join(args[1:])

        await ctx.send(f"```" + f.renderText(text) + "```")

    @commands.command(aliases=["showfonts"])
    async def listfonts(self, ctx):
        """List the fonts for figletf"""

        f = Figlet()
        fonts = ""

        count = 0

        for font in f.getFonts():
            count+=1

            if(fonts == ""):
                fonts = font
                continue

            fonts = fonts + " " + font

            if (count == 200):
                await ctx.send(f"```" + fonts + "```")
                fonts = ""
                count = 0

        await ctx.send(f"```" + fonts + "```")


def setup(bot):
    bot.add_cog(figlet(bot))

It doesn’t matter if you don’t understand anything, important is, that the syntax of the programming language is highlighted (colored in different ways). ;D

Say something ... :)

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: