diff options
| author | 2021-09-07 12:51:45 -0400 | |
|---|---|---|
| committer | 2021-10-05 16:41:43 +0100 | |
| commit | a97803d05ecadf6621f943c068000f0997c4704a (patch) | |
| tree | f137ced471b50108ce514ac7ceeacc08a31de091 /bot/exts/utilities | |
| parent | Add embed fields for Hex and RGB (diff) | |
Update code to use 'mode' variable
Updated the code to parse user_input depending on the color code
'mode' passed to the command. Added stub code for future color codes
and embeds if mode is None or wrong code.
Diffstat (limited to 'bot/exts/utilities')
| -rw-r--r-- | bot/exts/utilities/color.py | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/bot/exts/utilities/color.py b/bot/exts/utilities/color.py index b1b423e7..1efacead 100644 --- a/bot/exts/utilities/color.py +++ b/bot/exts/utilities/color.py @@ -10,7 +10,7 @@ from discord.ext import commands # from rapidfuzz import process from bot.bot import Bot -# from bot.constants import Colours +from bot.constants import Colours logger = logging.getLogger(__name__) @@ -33,13 +33,12 @@ class Color(commands.Cog): self.bot = bot @commands.command(aliases=["colour"]) - @commands.cooldown(1, 10, commands.cooldowns.BucketType.user) - async def color(self, ctx: commands.Context, *, user_color: str) -> None: + async def color(self, ctx: commands.Context, mode: str, user_color: str) -> None: """Send information on input color code or color name.""" # need to check if user_color is RGB, HSV, CMYK, HSL, Hex or color name # should we assume the color is RGB if not defined? - if "#" in user_color: + if mode.lower() == "hex": logger.info(f"{user_color = }") hex_match = re.search(r"^#(?:[0-9a-fA-F]{3}){1,2}$", user_color) if hex_match: @@ -55,15 +54,32 @@ class Color(commands.Cog): ) ) - elif "RGB" or "rgb" in user_color: - rgb_parse = user_color.split() - rgb = rgb_parse[1:].replace(", ", "") - logger.info(f"{rgb = }") - logger.info(f"{rgb[0] = }") - logger.info(f"{rgb[1] = }") - logger.info(f"{rgb[2] = }") - rgb_color = tuple(rgb) - hex_color = f"0x{int(rgb[0]):02x}{int(rgb[1]):02x}{int(rgb[2]):02x}" + elif mode.lower() == "rgb": + logger.info(f"{user_color = }") + # rgb_color = user_color + + elif mode.lower() == "hsv": + pass + elif mode.lower() == "hsl": + pass + elif mode.lower() == "cmyk": + pass + else: + # mode is either None or an invalid code + if mode is None: + no_mode_embed = Embed( + title="No 'mode' was passed, please define a color code.", + color=Colours.soft_red, + ) + await ctx.send(embed=no_mode_embed) + return + wrong_mode_embed = Embed( + title=f"The color code {mode} is not a valid option", + description="Possible modes are: Hex, RGB, HSV, HSL and CMYK.", + color=Colours.soft_red, + ) + await ctx.send(embed=wrong_mode_embed) + return main_embed = Embed( title=user_color, # need to replace with fuzzymatch color name @@ -83,6 +99,23 @@ class Color(commands.Cog): value=f">>RGB {rgb_color}", inline=False, ) + """ + main_embed.add_field( + name="HSV", + value=f">>HSV {hsv_color}", + inline=False, + ) + main_embed.add_field( + name="HSL", + value=f">>HSL {hsl_color}", + inline=False, + ) + main_embed.add_field( + name="CMYK", + value=f">>CMYK {cmyk_color}", + inline=False, + ) + """ await ctx.send(file=file, embed=main_embed) async def _create_thumbnail_attachment(self, color: str) -> File: |