feat(color): new command :)

Co-authored-by: neo <email@neoarz.dev>
Co-authored-by: neoarz <tyrantneo740@gmail.com>
This commit is contained in:
Meshal Alharbi
2025-10-18 17:00:34 +03:00
committed by GitHub
parent 6d164033e1
commit 1d681d4fe0
5 changed files with 55 additions and 5 deletions

View File

@@ -15,6 +15,7 @@ from .support import support_command
from .docs import docs_command
from .sigma import sigma_command
from .silly import silly_command
from .color import color_command
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
@@ -32,7 +33,7 @@ class Miscellaneous(commands.GroupCog, name="misc"):
color=0x7289DA
)
embed.set_author(name="Miscellaneous", icon_url="https://yes.nighty.works/raw/YxMC0r.png")
embed.add_field(name="Available", value="dontasktoask, rr, depart, labubu, duck, tryitandsee, piracy, keanu, support, docs, sigma, silly", inline=False)
embed.add_field(name="Available", value="dontasktoask, rr, depart, labubu, duck, tryitandsee, piracy, keanu, support, docs, sigma, silly, color", inline=False)
await context.send(embed=embed)
async def _invoke_hybrid(self, context: Context, name: str):
@@ -100,6 +101,10 @@ class Miscellaneous(commands.GroupCog, name="misc"):
async def miscellaneous_group_silly(self, context: Context, message_type: str = "regular"):
await self._invoke_hybrid(context, "silly", message_type=message_type)
@miscellaneous_group.command(name="color")
async def miscellaneous_group_color(self, context: Context):
await self._invoke_hybrid(context, "color")
@commands.check(_require_group_prefix)
@commands.hybrid_command(
name="dontasktoask",
@@ -203,6 +208,14 @@ class Miscellaneous(commands.GroupCog, name="misc"):
async def silly(self, context, message_type: str = "regular"):
return await silly_command()(self, context, message_type=message_type)
@commands.check(_require_group_prefix)
@commands.hybrid_command(
name="color",
description="Get a random color."
)
async def color(self, context):
return await color_command()(self, context)
async def setup(bot) -> None:
cog = Miscellaneous(bot)
await bot.add_cog(cog)
@@ -219,3 +232,4 @@ async def setup(bot) -> None:
bot.logger.info("Loaded extension 'miscellaneous.docs'")
bot.logger.info("Loaded extension 'miscellaneous.sigma'")
bot.logger.info("Loaded extension 'miscellaneous.silly'")
bot.logger.info("Loaded extension 'miscellaneous.color'")

View File

@@ -0,0 +1,36 @@
import discord
from discord.ext import commands
import random
import colorsys
def color_command():
@commands.hybrid_command(name="color", description="Get a random color.")
async def color(self, context):
"""
Generates a random color and displays information about it.
"""
random_color_int = random.randint(0, 0xFFFFFF)
color = discord.Color(random_color_int)
r, g, b = color.r, color.g, color.b
rgb_decimal = (r / 255, g / 255, b / 255)
h, l, s = colorsys.rgb_to_hls(rgb_decimal[0], rgb_decimal[1], rgb_decimal[2])
h_hsv, s_hsv, v_hsv = colorsys.rgb_to_hsv(rgb_decimal[0], rgb_decimal[1], rgb_decimal[2])
embed = discord.Embed(title="Random Color", color=color)
embed.add_field(name="Hex", value=str(color))
embed.add_field(name="RGB", value=f"rgb({r}, {g}, {b})")
embed.add_field(name="RGB Decimal", value=f"{rgb_decimal[0]:.3f}, {rgb_decimal[1]:.3f}, {rgb_decimal[2]:.3f}")
embed.add_field(name="HSL", value=f"hsl({h*360:.0f}, {s*100:.0f}%, {l*100:.0f}%)")
embed.add_field(name="HSV", value=f"hsv({h_hsv*360:.0f}, {s_hsv*100:.0f}%, {v_hsv*100:.0f}%)")
embed.add_field(name="Integer", value=str(random_color_int))
embed.set_thumbnail(url=f"https://singlecolorimage.com/get/{str(color).replace('#', '')}/150x150")
await context.send(embed=embed)
return color