diff options
author | 2021-09-05 18:41:23 -0400 | |
---|---|---|
committer | 2021-10-05 16:41:42 +0100 | |
commit | 6a692f03eface6e87dd5cdc1b1d415d52f9df148 (patch) | |
tree | e2d9af4c7e206602120324404f514152257f761d /bot | |
parent | Fix issues occured while deploying [no ci] (diff) |
Move to utilities folder as recommended by Xith
Diffstat (limited to 'bot')
-rw-r--r-- | bot/exts/utilities/color.py | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/bot/exts/utilities/color.py b/bot/exts/utilities/color.py new file mode 100644 index 00000000..dd922bf9 --- /dev/null +++ b/bot/exts/utilities/color.py @@ -0,0 +1,115 @@ +# imports +import colorsys +import logging + +import PIL +from discord import Embed +from discord.ext import commands +from rapidfuzz import process + +from bot.bot import Bot +from bot.constants import Colours + +# Planning to use discord-flags, hence require changes to poetry.lock file +# from discord.ext import flags + +logger = logging.getLogger(__name__) + +# constants if needed +# Color URLs - will be replaced by JSON file? +COLOR_JSON_PATH = ".bot//exts//resources//evergreen//" +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"] + # ).set_image() # url for image? + # ) + + # 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)) |