diff --git a/Pipfile b/Pipfile index f271d28c..ea27617f 100644 --- a/Pipfile +++ b/Pipfile @@ -13,6 +13,7 @@ aiohttp = "*" alembic = "*" pydrocsid = "*" "discord.py" = "*" +pillow = "*" [dev-packages] flake8 = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 04f45db1..7858c709 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d0c97a92a57889529187b8168ab6353f94ba5b78684166e6327e0b85215daac9" + "sha256": "069a3acdaf8778d95a6caa3868484ec6233001dc7b0cc445183db5503d63e9a5" }, "pipfile-spec": 6, "requires": { @@ -71,6 +71,7 @@ "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f", "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3" ], + "markers": "python_full_version >= '3.5.3'", "version": "==3.0.1" }, "attrs": { @@ -78,6 +79,7 @@ "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6", "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==20.3.0" }, "certifi": { @@ -107,12 +109,14 @@ "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6", "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.10" }, "mako": { "hashes": [ "sha256:17831f0b7087c313c0ffae2bcbbd3c1d5ba9eeac9c38f2eb7b50e8c99fe9d5ab" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.1.4" }, "markupsafe": { @@ -170,6 +174,7 @@ "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be", "sha256:feb7b34d6325451ef96bc0e36e1a6c0c1c64bc1fbec4b854f4529e51887b1621" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.1.1" }, "multidict": { @@ -212,8 +217,48 @@ "sha256:f21756997ad8ef815d8ef3d34edd98804ab5ea337feedcd62fb52d22bf531281", "sha256:fc13a9524bc18b6fb6e0dbec3533ba0496bbed167c56d0aabefd965584557d80" ], + "markers": "python_version >= '3.6'", "version": "==5.1.0" }, + "pillow": { + "hashes": [ + "sha256:01bb0a34f1a6689b138c0089d670ae2e8f886d2666a9b2f2019031abdea673c4", + "sha256:07872f1d8421db5a3fe770f7480835e5e90fddb58f36c216d4a2ac0d594de474", + "sha256:1022f8f6dc3c5b0dcf928f1c49ba2ac73051f576af100d57776e2b65c1f76a8d", + "sha256:14415e9e28410232370615dbde0cf0a00e526f522f665460344a5b96973a3086", + "sha256:172acfaf00434a28dddfe592d83f2980e22e63c769ff4a448ddf7b7a38ffd165", + "sha256:1c5e3c36f02c815766ae9dd91899b1c5b4652f2a37b7a51609f3bd467c0f11fb", + "sha256:292f2aa1ae5c5c1451cb4b558addb88c257411d3fd71c6cf45562911baffc979", + "sha256:2a40d7d4b17db87f5b9a1efc0aff56000e1d0d5ece415090c102aafa0ccbe858", + "sha256:2f0d7034d5faae9a8d1019d152ede924f653df2ce77d3bba4ce62cd21b5f94ae", + "sha256:33fdbd4f5608c852d97264f9d2e3b54e9e9959083d008145175b86100b275e5b", + "sha256:3b13d89d97b551e02549d1f0edf22bed6acfd6fd2e888cd1e9a953bf215f0e81", + "sha256:3e759bcc03d6f39bc751e56d86bc87252b9a21c689a27c5ed753717a87d53a5b", + "sha256:3ec87bd1248b23a2e4e19e774367fbe30fddc73913edc5f9b37470624f55dc1f", + "sha256:436b0a2dd9fe3f7aa6a444af6bdf53c1eb8f5ced9ea3ef104daa83f0ea18e7bc", + "sha256:43b3c859912e8bf754b3c5142df624794b18eb7ae07cfeddc917e1a9406a3ef2", + "sha256:4fe74636ee71c57a7f65d7b21a9f127d842b4fb75511e5d256ace258826eb352", + "sha256:59445af66b59cc39530b4f810776928d75e95f41e945f0c32a3de4aceb93c15d", + "sha256:69da5b1d7102a61ce9b45deb2920a2012d52fd8f4201495ea9411d0071b0ec22", + "sha256:7094bbdecb95ebe53166e4c12cf5e28310c2b550b08c07c5dc15433898e2238e", + "sha256:8211cac9bf10461f9e33fe9a3af6c5131f3fdd0d10672afc2abb2c70cf95c5ca", + "sha256:8cf77e458bd996dc85455f10fe443c0c946f5b13253773439bcbec08aa1aebc2", + "sha256:924fc33cb4acaf6267b8ca3b8f1922620d57a28470d5e4f49672cea9a841eb08", + "sha256:99ce3333b40b7a4435e0a18baad468d44ab118a4b1da0af0a888893d03253f1d", + "sha256:a7d690b2c5f7e4a932374615fedceb1e305d2dd5363c1de15961725fe10e7d16", + "sha256:b9af590adc1e46898a1276527f3cfe2da8048ae43fbbf9b1bf9395f6c99d9b47", + "sha256:bb18422ad00c1fecc731d06592e99c3be2c634da19e26942ba2f13d805005cf2", + "sha256:c10af40ee2f1a99e1ae755ab1f773916e8bca3364029a042cd9161c400416bd8", + "sha256:c143c409e7bc1db784471fe9d0bf95f37c4458e879ad84cfae640cb74ee11a26", + "sha256:c448d2b335e21951416a30cd48d35588d122a912d5fe9e41900afacecc7d21a1", + "sha256:d30f30c044bdc0ab8f3924e1eeaac87e0ff8a27e87369c5cac4064b6ec78fd83", + "sha256:df534e64d4f3e84e8f1e1a37da3f541555d947c1c1c09b32178537f0f243f69d", + "sha256:f6fc18f9c9c7959bf58e6faf801d14fafb6d4717faaf6f79a68c8bb2a13dcf20", + "sha256:ff83dfeb04c98bb3e7948f876c17513a34e9a19fd92e292288649164924c1b39" + ], + "index": "pypi", + "version": "==8.1.1" + }, "pydrocsid": { "hashes": [ "sha256:02c8421f22734c0aaefc2285feebe7cfd4286a74e52e63b29bd5c8dadfad15c9", @@ -235,13 +280,16 @@ "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", "version": "==2.8.1" }, "python-editor": { "hashes": [ "sha256:1bf6e860a8ad52a14c3ee1252d5dc25b2030618ed80c022598f00176adc8367d", "sha256:51fda6bcc5ddbbb7063b2af7509e43bd84bfc32a4ff71349ec7847713882327b", - "sha256:5f98b069316ea1c2ed3f67e7f5df6c0d8f10b689964a4a811ff64f0106819ec8" + "sha256:5f98b069316ea1c2ed3f67e7f5df6c0d8f10b689964a4a811ff64f0106819ec8", + "sha256:c3da2053dbab6b29c94e43c486ff67206eafbe7eb52dbec7390b5e2fb05aac77", + "sha256:ea87e17f6ec459e780e4221f295411462e0d0810858e055fc514684350a2f522" ], "version": "==1.0.4" }, @@ -293,6 +341,7 @@ "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'", "version": "==1.15.0" }, "sqlalchemy": { @@ -352,6 +401,7 @@ "sha256:1b465e494e3e0d8939b50680403e3aedaa2bc434b7d5af64dfd3c958d7f5ae80", "sha256:de3eedaad74a2683334e282005cd8d7f22f4d55fa690a2a1020a416cb0a47e73" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "version": "==1.26.3" }, "yarl": { @@ -394,6 +444,7 @@ "sha256:f0b059678fd549c66b89bed03efcabb009075bd131c248ecdf087bdb6faba24a", "sha256:fcbb48a93e8699eae920f8d92f7160c03567b421bc17362a9ffbbd706a816f71" ], + "markers": "python_version >= '3.6'", "version": "==1.6.3" } }, @@ -418,6 +469,7 @@ "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367", "sha256:c58a7d2815e0e8d7972bf1803331fb0152f867bd89adf8a01dfd55085434192e" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.6.0" }, "pyflakes": { @@ -425,6 +477,7 @@ "sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92", "sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.2.0" } } diff --git a/README.md b/README.md index ec41cb3f..031acb25 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ Project - Click on `Pipenv Environment` - Select `Python 3.9` as `Base interpreter` - Confirm with `OK` +- Change the working directory to root path ➔ `Edit Configurations` ➔ `Working directory` + Finally, please remember to mark the `morpheushelper` directory as `Sources Root` (right click on `morpheushelper` ➔ `Mark Directory as` ➔ `Sources Root`). diff --git a/morpheushelper/cogs/__init__.py b/morpheushelper/cogs/__init__.py index a5812c66..9055b938 100644 --- a/morpheushelper/cogs/__init__.py +++ b/morpheushelper/cogs/__init__.py @@ -20,6 +20,7 @@ from cogs.run_code import RunCodeCog from cogs.verification import VerificationCog from cogs.voice_channel import VoiceChannelCog +from cogs.color_picker import ColorPickerCog COGS = [ RunCodeCog, @@ -44,4 +45,5 @@ PollsCog, DiscordpyDocumentationCog, AdventOfCodeCog, + ColorPickerCog, ] diff --git a/morpheushelper/cogs/color_picker.py b/morpheushelper/cogs/color_picker.py new file mode 100644 index 00000000..75a5f55f --- /dev/null +++ b/morpheushelper/cogs/color_picker.py @@ -0,0 +1,57 @@ +from PyDrocsid.translations import translations +from discord import Embed, File, Colour +from discord.ext import commands +from discord.ext.commands import Cog, Bot +import re +from PIL import ImageColor, Image +import io +import colorsys + + +class ColorPickerCog(Cog): + RE_HEX = re.compile(r'^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$') + RE_RGB = re.compile(r'^rgb\(([0-9]{1,3})\, ?([0-9]{1,3})\, ?([0-9]{1,3})\)$') + RE_HSV = re.compile(r'^hsv\(([0-9]{1,3})\, ?([0-9]{1,3})\, ?([0-9]{1,3})\)$') + RE_HSL = re.compile(r'^hsl\(([0-9]{1,3})\, ?([0-9]{1,3})\, ?([0-9]{1,3})\)$') + + def __init__(self, bot: Bot): + self.bot = bot + + @commands.command(name="colorpicker", aliases=["cp", "color"]) + async def colorpicker(self, ctx, *, color: str): + if color_re := self.RE_HEX.match(color): + color_hex = color_re.group(1) + rgb: tuple[int] = ImageColor.getcolor(color, "RGB") + hsv: tuple[int] = ImageColor.getcolor(color, "HSV") + hsl = tuple(map(int, colorsys.rgb_to_hls(*rgb))) # skipcq: PYL-E1120 + elif color_re := self.RE_RGB.match(color): + rgb = (int(color_re.group(1)), int(color_re.group(2)), int(color_re.group(3))) + color_hex = '%02x%02x%02x' % rgb + hsv: tuple[int] = ImageColor.getcolor(f'#{color_hex}', "HSV") + hsl = tuple(map(int, colorsys.rgb_to_hls(*rgb))) # skipcq: PYL-E1120 + elif color_re := self.RE_HSV.match(color): + hsv: tuple[int] = (int(color_re.group(1)), int(color_re.group(2)), int(color_re.group(3))) + rgb = tuple(map(int, colorsys.hsv_to_rgb(*hsv))) # skipcq: PYL-E1120 + color_hex = '%02x%02x%02x' % rgb + hsl = tuple(map(int, colorsys.rgb_to_hls(*rgb))) # skipcq: PYL-E1120 + elif color_re := self.RE_HSL.match(color): + hsl: tuple[int] = (int(color_re.group(1)), int(color_re.group(2)), int(color_re.group(3))) + rgb = tuple(map(int, colorsys.hls_to_rgb(*hsl))) # skipcq: PYL-E1120 + hsv = tuple(map(int, colorsys.rgb_to_hsv(*rgb))) # skipcq: PYL-E1120 + color_hex = '%02x%02x%02x' % rgb + else: + embed: Embed = Embed(title=translations.f_error_parse_color(color), + description=translations.error_parse_color_example) + await ctx.send(embed=embed) + return + img: Image = Image.new('RGB', (100, 100), rgb) + with io.BytesIO() as image_binary: + img.save(image_binary, 'PNG') + image_binary.seek(0) + embed: Embed = Embed(title='Colorpicker', color=Colour(int(color_hex, 16))) + embed.add_field(name='HEX', value=f'#{color_hex}') + embed.add_field(name='RGB', value=f'rgb{rgb}') + embed.add_field(name='HSV', value=f'hsv{hsv}') + embed.add_field(name='HSL', value=f'hsl{hsl}') + embed.set_image(url="attachment://color.png") + await ctx.send(embed=embed, file=File(fp=image_binary, filename='color.png')) diff --git a/translations/en.yml b/translations/en.yml index 614ad1b5..3395fb92 100644 --- a/translations/en.yml +++ b/translations/en.yml @@ -771,3 +771,17 @@ run_usage: | your code `​`​` run_output: Run Output + +# color picker +error_parse_color: "Error cant parse HEX/RGB/HSV/HSL Color Code(\"{}\")" +error_parse_color_example: > + **Examples:** + - #fff + - #ffffff + - #000000 + - rgb(255, 0, 0) + - rgb(255, 255, 255) + - hsv(0, 0, 0) + - hsv(0, 0, 255) + - hsl(0, 106, 0) + - hsl(0, 191, 0)