diff options
author | 2021-09-03 14:35:26 -0400 | |
---|---|---|
committer | 2021-10-05 16:40:44 +0100 | |
commit | 32b06208a2212f8d596591f50fc8759049fc78e1 (patch) | |
tree | f4f4e2ada3d4771c76c60cbe862b38a1bf7b9a6a /bot | |
parent | Start from upstream main branch (diff) |
Create draft body of file
This is a large empty file with lots of comments. My general proposal
is outlined in the code stumps. Details will need to be hashed out and
decided on with CyberCitizen01.
In particular:
- How to use URLs that has list of color names? Read those into a
dictionary?
- How to handle the command call with options? `discord-flags`,
parsing, function call like:
.colour cmyk(49, 50, 0, 22)
.colour hsl(241, 47, 58)
.colour rgb 101 99 199
- How to implement fuzzy matching with rapidfuzz based on the color
names from those URLs?
- How to generate colors in other formats? Is this all possible in
pillow?
- How to generate photo to use in the embed? Do we temporarily create a
file in a cache, send it in embed, then delete?
This will be a fun project, and my first collab!
Co-authored-by: Mohammad Rafivulla
<[email protected]>
Diffstat (limited to 'bot')
-rw-r--r-- | bot/exts/fun/color.py | 113 |
1 files changed, 112 insertions, 1 deletions
diff --git a/bot/exts/fun/color.py b/bot/exts/fun/color.py index 5d86f002..32a25b0d 100644 --- a/bot/exts/fun/color.py +++ b/bot/exts/fun/color.py @@ -1 +1,112 @@ -# initial creation +# imports +import logging + +import pillow +from discord import Embed +# ! need to install discord-flags and add to poetry.lock file +from discord.ext import commands, flags +from rapidfuzz import process + +from bot.bot import Bot +from bot.constants import Colours + +logger = logging.getLogger(__name__) + +# constants if needed +# TODO Will the color conversions be done only from pillow or will an API / URL be needed? +# Color URLs +COLOR_URL_XKCD = "https://xkcd.com/color/rgb/" +COLOR_URL_NAME_THAT_COLOR = "https://github.com/ryanzec/name-that-color/blob/master/lib/ntc.js#L116-L1681" + + +COLOR_ERROR = Embed( + title="Input color is not possible", + description="The color code {user_color} is not a possible color combination." + "\nThe range of possible values are: " + "\nRGB & HSV: 0-255" + "\nCMYK: 0-100%" + "\nHSL: 0-360 degrees" + "\nHex: #000000-#FFFFFF" +) +COLOR_EMBED = Embed( + title="{color_name}", + description="RGB" + "\n{RGB}" + "\nHSV" + "\n{HSV}" + "\nCMYK" + "\n{CMYK}" + "\nHSL" + "\n{HSL}" + "\nHex" + "\n{Hex}" +) + + +# define color command +class Color(commands.cog): + """User initiated command to receive color information.""" + + def __init__(self, bot: Bot): + self.bot = bot + + # ? possible to use discord-flags to allow user to decide on color + # https://pypi.org/project/discord-flags/ + # @flags.add_flag("--rgb", type=str) + # @flags.add_flag("--hsv", type=str) + # @flags.add_flag("--cmyk", type=str) + # @flags.add_flag("--hsl", type=str) + # @flags.add_flag("--hex", type=str) + # @flags.add_flag("--name", type=str) + # @flags.command() + @commands.command(aliases=["color", "colour"]) + @commands.cooldown(1, 10, commands.cooldowns.BucketType.user) + async def color(self, ctx: commands.Context, *, 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? + # should discord tags be used? + # need to review discord.py V2.0 + + # TODO code to check if color code is possible + await ctx.send(embed=COLOR_ERROR.format(color=user_color)) + # await ctx.send(embed=COLOR_EMBED.format( + # RGB=color_dict["RGB"], + # HSV=color_dict["HSV"], + # HSL=color_dict["HSL"], + # CMYK=color_dict["CMYK"], + # HSL=color_dict["HSL"], + # Hex=color_dict["Hex"], + # color_name=color_dict["color_name"] + # ) + # ) + + # TODO pass for now + pass + + # if user_color in color_lists: + # # TODO fuzzy match for color + # pass + + async def color_converter(self, color: str, code_type: str) -> dict: + """Generate alternative color codes for use in the embed.""" + # TODO add code to take color and code type and return other types + # color_dict = { + # "RGB": color_RGB, + # "HSV": color_HSV, + # "HSL": color_HSL, + # "CMYK": color_CMYK, + # "HSL": color_HSL, + # "Hex": color_Hex, + # "color_name": color_name, + # } + pass + + async def photo_generator(self, color: str) -> None: + """Generate photo to use in embed.""" + # TODO need to find a way to store photo in cache to add to embed, then remove + + +def setup(bot: Bot) -> None: + """Load the Color Cog.""" + bot.add_cog(Color(bot)) |