aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxultist <xultist@proton.me>2023-02-19 22:39:10 +1100
committerxultist <xultist@proton.me>2023-02-19 22:39:10 +1100
commita14b7cf1e667f0f17c462206d99b364d20eb76d4 (patch)
tree03cf84794e851d4b9f9f226a9438f9ce78b26696
parentfac04045795e53160269cbbe1cc023473c24d45c (diff)
Added HolyC Snippets
-rw-r--r--codedetec.py16
-rw-r--r--cogs/utils.py81
-rw-r--r--requirements.txt3
3 files changed, 96 insertions, 4 deletions
diff --git a/codedetec.py b/codedetec.py
new file mode 100644
index 0000000..19a4073
--- /dev/null
+++ b/codedetec.py
@@ -0,0 +1,16 @@
+from PIL import Image
+import sys
+
+# Get the file path from the command line argument
+file_path = sys.argv[1]
+
+# Open the file and read its contents
+with open(file_path, 'rb') as f:
+ file_contents = f.read()
+
+# Convert the file contents to an image
+image = Image.frombytes('RGB', (100, 100), file_contents)
+
+# Save the image to a file
+image.save('output.jpg')
+
diff --git a/cogs/utils.py b/cogs/utils.py
index b46f173..0cefc94 100644
--- a/cogs/utils.py
+++ b/cogs/utils.py
@@ -1,10 +1,41 @@
import json
-
import discord
from discord import option
from discord.ext import commands
from discord.ext.commands import Context, MissingPermissions
from main import config, randomMsg
+import re
+from pygments.lexer import RegexLexer
+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.formatters import ImageFormatter
+import io
+import secrets
+
+class HolyCLexer(RegexLexer):
+ name = 'HolyC'
+ aliases = ['holyc']
+ filenames = ['*.hc', '*.hh', '*.zc']
+ tokens = {
+ 'root': [
+ (r'\\b(break|case|continue|default|do|else|for|goto|if|return|switch|while|throw|try|catch|extern|MOV|CALL|PUSH|LEAVE|RET|SUB|SHR|ADD|RETF|CMP|JNE|BTS|INT|XOR|JC|JZ|LOOP|POP|TEST|SHL|ADC|SBB|JMP|INC|asm|const|extern|register|restrict|static|volatile|inline|_extern|_import|IMPORT|public)\b', Keyword),
+ (r'\b(U0|I8|U8|I16|U16|I32|U32|I64|U64|F64|Bool|class|union|DU8|DU16|DU32|DU64|RAX|RCX|RDX|RBX|RSP|RBP|RSI|RDI|EAX|ECX|EDX|EBX|ESP|EBP|ESI|EDI|AX|CX|DX|BX|SP|BP|SI|DI|SS|CS|DS|ES|FS|GS|CH)\b', Keyword.Type),
+ (r'"[^"]*"', String),
+ (r'//.*?\n', Comment.Single),
+ (r'/\*.*?\*/', Comment.Multiline),
+ (r'\d+', Number),
+ (r'\b(true|false)\b', Keyword.Constant),
+ (r'[A-Za-z_]\w*', Name),
+ (r'[~!%^&*+=|?:<>/-]', Operator),
+ (r'[(){}\[\],.;]', Punctuation),
+ (r'\s+', Text),
+ ]
+ }
+
+
class Utils(commands.Cog, name="utils"):
@@ -17,9 +48,12 @@ class Utils(commands.Cog, name="utils"):
# pure aryan technology.
@discord.slash_command(guild_ids=config['main_guilds'], description="Bots help commands.")
async def help(self, ctx: Context):
+ holyc_emoji_id = 1076829357584175146
+ holyc_emoji = discord.PartialEmoji(name="my_emoji", id=holyc_emoji_id)
embed = discord.Embed(color=color)
embed.add_field(name="🥂 Fun Commands", value="`/roll` - rolls a dice... \n`/choose` - makes a choice from a list of options. \n`/coinflip` - flips a coin. \n`/tweet` - gives you a random tweet from Terry. \n`/rate` - rates you (never changes). \n`/godspeak` - allows you to talk to God. \n`/comic` - shows you a random XKCD comic.", inline=False)
embed.add_field(name="📦 Misc Commands", value="`/credits` - provides the bot's credits. \n`/ping` - shows the bot's ping. \n`/invite` - generates a new server invite. \n`/whois` - gives you all the info of a member. \n`/avatar` - gives you any member's avatar. \n`/help` - literally this message lol.", inline=False)
+ embed.add_field(name=f"{holyc_emoji} HolyC Commands", value="`/holyc` - send a piece of HolyC code then send this command to create an image.")
embed.add_field(name="Psst", value="Maybeee you should check out `/credits` especially.", inline=False)
embed.set_footer(text=randomMsg())
await ctx.respond("Check your DMs!", ephemeral=True)
@@ -46,7 +80,7 @@ class Utils(commands.Cog, name="utils"):
@commands.has_permissions(create_instant_invite=True)
async def invite(self, ctx):
invitelink = await ctx.channel.create_invite(max_uses=1, unique=True)
- embed = discord.Embed(title="🍆 **Invite**",
+ embed = discord.Embed(title="**Invite**",
description=f"Invite: {invitelink}. \n\n If anyone raid spams CP, blame {ctx.author.mention}.",
color=color)
embed.set_footer(text=randomMsg())
@@ -94,5 +128,46 @@ class Utils(commands.Cog, name="utils"):
text = "Sorry {}, you do not have permissions to do that!"
await ctx.respond(text)
+ @discord.slash_command(guild_ids=config['main_guilds'], description="Converts your last message to HolyC Code")
+ async def holyc(self, ctx):
+ channel = ctx.channel
+ user: discord.Member = ctx.author
+ async for message in channel.history(limit=100):
+ if message.author == user:
+ if message.content.startswith("```") and message.content.endswith("```"):
+ code = message.content[3:-3]
+
+ lexer = HolyCLexer()
+ formatter = ImageFormatter(font_name='JetBrainsMono-Medium.ttf', font_size=20, line_numbers=False,
+ style=OneDarkStyle)
+
+ highlighted_code = highlight(code, lexer, formatter)
+ image_data = io.BytesIO(highlighted_code)
+ image = Image.open(image_data)
+ # Increase the image resolution
+ width, height = image.size
+ image = image.resize((width * 2, height * 2), resample=Image.LANCZOS)
+
+ with io.BytesIO() as image_binary:
+ image.save(image_binary, 'PNG')
+ image_binary.seek(0)
+ image_data = image_binary.getvalue()
+
+ file = discord.File(io.BytesIO(image_data), filename='image.png')
+
+ # Create the embed and set the image to the file
+ 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()
+ await ctx.respond(file=file, embed=embed)
+ break
+
+ else:
+ await ctx.respond("Your last message contains no code visible to me.", ephemeral=True)
+ break
+ else:
+ await ctx.respond("I was unable to find a message from you.", ephemeral=True)
+
def setup(bot):
- bot.add_cog(Utils(bot)) \ No newline at end of file
+ bot.add_cog(Utils(bot))
diff --git a/requirements.txt b/requirements.txt
index 57859cd..a0d338f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,5 @@
py-cord
requests
Pillow
-openai \ No newline at end of file
+openai
+pygments