diff options
author | xultist <xultist@proton.me> | 2023-02-19 16:16:45 -0800 |
---|---|---|
committer | xultist <xultist@proton.me> | 2023-02-19 16:16:45 -0800 |
commit | 2820ff93eb138c56edcf2b260c9ea43f2b934001 (patch) | |
tree | bc95c100455c2e5af2e2e285682cc8ce01bb1126 | |
parent | 322d4fe6ed7d2aecee06c4c2e40b4cfe51d3d052 (diff) |
Added styling
Signed-off-by: xultist <xultist@proton.me>
-rw-r--r-- | cogs/syntax.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/cogs/syntax.py b/cogs/syntax.py index c426c2e..73d8142 100644 --- a/cogs/syntax.py +++ b/cogs/syntax.py @@ -1,4 +1,5 @@ import discord +from discord import option from discord.ext import commands from discord.ext.commands import Context from main import config @@ -7,7 +8,7 @@ from pygments.token import * from PIL import Image from pygments import highlight from pygments.lexers import get_lexer_by_name -from pygments.styles.onedark import OneDarkStyle +from pygments.styles import * from pygments.formatters import ImageFormatter import io import secrets @@ -39,8 +40,27 @@ class Syntax(commands.Cog, name="syntax"): global color color = int(config["bot_color"], base=16) + @discord.slash_command(guild_ids=config['main_guilds'], description="Gets a list of available styles.") + async def styles(self, ctx: Context): + stylesList = list(get_all_styles()) + result = "A list of styles that you can use with `/holyc` are:\n" + for item in stylesList: + result += f"`{item}`, " + embed = discord.Embed(title="Available Styles", description=result) + await ctx.respond(embed=embed, ephemeral=True) + + @discord.slash_command(guild_ids=config['main_guilds'], description="Converts your last message to HolyC Code") - async def holyc(self, ctx): + @option("style", description="Picks the style to use. Otherwise leave blank for OneDark. (Hint: for a list run /styles)") + @option("delete", description="Whether or not your original message is deleted") + async def holyc(self, ctx: Context, style: str = None, delete: bool = True): + if style == None: + style = "github-dark" + try: + styleClass = get_style_by_name(style) + except ClassNotFound: + await ctx.respond(f"I cannot find the '{style}' style. You can obtain a list of avaliable styles with /styles.", ephemeral=True) + channel = ctx.channel user: discord.Member = ctx.author async for message in channel.history(limit=100): @@ -50,7 +70,7 @@ class Syntax(commands.Cog, name="syntax"): lexer = HolyCLexer() formatter = ImageFormatter(font_name='JetBrainsMono-Medium.ttf', font_size=20, line_numbers=False, - style=OneDarkStyle) + style=styleClass) highlighted_code = highlight(code, lexer, formatter) image_data = io.BytesIO(highlighted_code) @@ -70,7 +90,8 @@ class Syntax(commands.Cog, name="syntax"): embed = discord.Embed(title=f"HolyC Snippet", description=f"Requested by {user.mention}") embed.set_footer(text="You can create your own HolyC snippets by sending code in chat and then typing /holyc.") embed.set_image(url="attachment://image.png") - await message.delete() + if delete == True: + await message.delete() await ctx.respond(file=file, embed=embed) break @@ -82,4 +103,4 @@ class Syntax(commands.Cog, name="syntax"): def setup(bot): - bot.add_cog(Syntax(bot))
\ No newline at end of file + bot.add_cog(Syntax(bot)) |