Skip to content

Commit abda27b

Browse files
author
Cyteon
committedNov 2, 2024
new command: color
1 parent cdc1aee commit abda27b

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
 

‎bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(self) -> None:
9393
)
9494
self.logger = logger
9595
self.config = config
96-
self.version = "2.1.7"
96+
self.version = "2.1.8"
9797
self.start_time = time.time()
9898
self.prefixDB = prefixDB
9999
self.statsDB = statsDB

‎cogs/utility.py

+47
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This project is licensed under the terms of the GPL v3.0 license. Copyright 2024 Cyteon
22

3+
import io
4+
35
from asteval import Interpreter
46
aeval = Interpreter()
57

@@ -11,6 +13,8 @@
1113

1214
from utils import Checks
1315

16+
from PIL import ImageColor, Image
17+
1418
class Utility(commands.Cog, name="⚡ Utility"):
1519
def __init__(self, bot) -> None:
1620
self.bot = bot
@@ -143,5 +147,48 @@ async def translate(self, context: Context, language, *, text: str) -> None:
143147
embed.set_footer(text=f"Translated to {language}")
144148
await context.send(embed=embed)
145149

150+
@commands.hybrid_command(
151+
name="color",
152+
description="Get information about a color.",
153+
usage="color <color>"
154+
)
155+
@commands.check(Checks.is_not_blacklisted)
156+
@commands.check(Checks.command_not_disabled)
157+
@app_commands.allowed_installs(guilds=True, users=True)
158+
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
159+
async def color(self, context: Context, color: str) -> None:
160+
try:
161+
rgb = ImageColor.getrgb(color)
162+
rgba = ImageColor.getcolor(color, "RGBA")
163+
hex = hex_value = "#{:02x}{:02x}{:02x}".format(*rgb)
164+
165+
166+
embed = discord.Embed(
167+
title="Color Information",
168+
description="\n".join(
169+
[
170+
f"Color: **{color}**",
171+
f"Hex: **{hex}**",
172+
f"RGB: **{rgb}**",
173+
f"RGBA: **{rgba}**",
174+
]
175+
),
176+
color=0xBEBEFE,
177+
)
178+
179+
img = Image.new("RGB", (100, 100), rgb)
180+
181+
with io.BytesIO() as image_binary:
182+
img.save(image_binary, "PNG")
183+
image_binary.seek(0)
184+
185+
file = discord.File(fp=image_binary, filename="color.png")
186+
embed.set_image(url="attachment://color.png")
187+
188+
await context.send(embed=embed, file=file)
189+
except ValueError:
190+
await context.send("Invalid color")
191+
return
192+
146193
async def setup(bot) -> None:
147194
await bot.add_cog(Utility(bot))

0 commit comments

Comments
 (0)
Please sign in to comment.