diff options
| author | 2021-09-07 07:34:57 -0400 | |
|---|---|---|
| committer | 2021-09-07 07:34:57 -0400 | |
| commit | 1e711f3e04c6e6adb66159ffbdc4f72740b62fd7 (patch) | |
| tree | af1eae3a95b557ee27cf7577b67b8fecf90b1752 /bot/exts/utilities | |
| parent | Added ryanzec_colours.json constructed from ryanzec/name-that-color (diff) | |
| parent | Continue work in progress (diff) | |
Fixing merge conflicts
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/utilities/__init__.py | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/bookmark.py (renamed from bot/exts/evergreen/bookmark.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/cheatsheet.py (renamed from bot/exts/evergreen/cheatsheet.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/color.py | 97 | ||||
| -rw-r--r-- | bot/exts/utilities/conversationstarters.py (renamed from bot/exts/evergreen/conversationstarters.py) | 6 | ||||
| -rw-r--r-- | bot/exts/utilities/emoji.py (renamed from bot/exts/evergreen/emoji.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/githubinfo.py (renamed from bot/exts/evergreen/githubinfo.py) | 2 | ||||
| -rw-r--r-- | bot/exts/utilities/issues.py (renamed from bot/exts/evergreen/issues.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/latex.py (renamed from bot/exts/evergreen/latex.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/pythonfacts.py (renamed from bot/exts/evergreen/pythonfacts.py) | 2 | ||||
| -rw-r--r-- | bot/exts/utilities/realpython.py (renamed from bot/exts/evergreen/realpython.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/reddit.py (renamed from bot/exts/evergreen/reddit.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/stackoverflow.py (renamed from bot/exts/evergreen/stackoverflow.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/timed.py (renamed from bot/exts/evergreen/timed.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/wikipedia.py (renamed from bot/exts/evergreen/wikipedia.py) | 0 | ||||
| -rw-r--r-- | bot/exts/utilities/wolfram.py (renamed from bot/exts/evergreen/wolfram.py) | 0 |
16 files changed, 102 insertions, 5 deletions
diff --git a/bot/exts/utilities/__init__.py b/bot/exts/utilities/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/bot/exts/utilities/__init__.py diff --git a/bot/exts/evergreen/bookmark.py b/bot/exts/utilities/bookmark.py index a91ef1c0..a91ef1c0 100644 --- a/bot/exts/evergreen/bookmark.py +++ b/bot/exts/utilities/bookmark.py diff --git a/bot/exts/evergreen/cheatsheet.py b/bot/exts/utilities/cheatsheet.py index 33d29f67..33d29f67 100644 --- a/bot/exts/evergreen/cheatsheet.py +++ b/bot/exts/utilities/cheatsheet.py diff --git a/bot/exts/utilities/color.py b/bot/exts/utilities/color.py new file mode 100644 index 00000000..1a4f7031 --- /dev/null +++ b/bot/exts/utilities/color.py @@ -0,0 +1,97 @@ +# imports +import colorsys +import logging +import re +from io import BytesIO + +from PIL import Image, ImageColor +from discord import Embed, File +from discord.ext import commands +from rapidfuzz import process + +from bot.bot import Bot +from bot.constants import Colours + + +logger = logging.getLogger(__name__) + + +ERROR_MSG = """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 +""" + + +# define color command +class Color(commands.Cog): + """User initiated command to receive color information.""" + + def __init__(self, bot: Bot): + 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: + """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: + logger.info(f"{user_color = }") + hex_match = re.search(r"^#(?:[0-9a-fA-F]{3}){1,2}$", user_color) + if hex_match: + hex_color = int(hex(int(user_color.replace("#", ""), 16)), 0) + logger.info(f"{hex_color = }") + rgb_color = ImageColor.getcolor(user_color, "RGB") + else: + await ctx.send(embed=Embed( + title="An error has occured.", + description=ERROR_MSG.format(user_color=user_color) + ) + ) + + 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}" + + main_embed = Embed( + title=user_color, + color=hex_color, + ) + async with ctx.typing(): + file = await self._create_thumbnail_attachment(rgb_color) + main_embed.set_thumbnail(url="attachment://color.png") + + await ctx.send(file=file, embed=main_embed) + + async def _create_thumbnail_attachment(self, color: str) -> File: + """Generate a thumbnail from `color`.""" + + thumbnail = Image.new("RGB", (100, 100), color=color) + bufferedio = BytesIO() + thumbnail.save(bufferedio, format="PNG") + bufferedio.seek(0) + + file = File(bufferedio, filename="color.png") + + return file + + + # if user_color in color_lists: + # # TODO fuzzy match for color + # pass + + + +def setup(bot: Bot) -> None: + """Load the Color Cog.""" + bot.add_cog(Color(bot)) diff --git a/bot/exts/evergreen/conversationstarters.py b/bot/exts/utilities/conversationstarters.py index fdc4467a..dd537022 100644 --- a/bot/exts/evergreen/conversationstarters.py +++ b/bot/exts/utilities/conversationstarters.py @@ -11,10 +11,10 @@ from bot.utils.randomization import RandomCycle SUGGESTION_FORM = "https://forms.gle/zw6kkJqv8U43Nfjg9" -with Path("bot/resources/evergreen/starter.yaml").open("r", encoding="utf8") as f: +with Path("bot/resources/utilities/starter.yaml").open("r", encoding="utf8") as f: STARTERS = yaml.load(f, Loader=yaml.FullLoader) -with Path("bot/resources/evergreen/py_topics.yaml").open("r", encoding="utf8") as f: +with Path("bot/resources/utilities/py_topics.yaml").open("r", encoding="utf8") as f: # First ID is #python-general and the rest are top to bottom categories of Topical Chat/Help. PY_TOPICS = yaml.load(f, Loader=yaml.FullLoader) @@ -33,7 +33,7 @@ TOPICS = { class ConvoStarters(commands.Cog): - """Evergreen conversation topics.""" + """General conversation topics.""" @commands.command() @whitelist_override(channels=ALL_ALLOWED_CHANNELS) diff --git a/bot/exts/evergreen/emoji.py b/bot/exts/utilities/emoji.py index 55d6b8e9..55d6b8e9 100644 --- a/bot/exts/evergreen/emoji.py +++ b/bot/exts/utilities/emoji.py diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/utilities/githubinfo.py index bbc9061a..d00b408d 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/utilities/githubinfo.py @@ -8,7 +8,7 @@ from discord.ext import commands from bot.bot import Bot from bot.constants import Colours, NEGATIVE_REPLIES -from bot.exts.utils.extensions import invoke_help_command +from bot.exts.core.extensions import invoke_help_command log = logging.getLogger(__name__) diff --git a/bot/exts/evergreen/issues.py b/bot/exts/utilities/issues.py index 8a7ebed0..8a7ebed0 100644 --- a/bot/exts/evergreen/issues.py +++ b/bot/exts/utilities/issues.py diff --git a/bot/exts/evergreen/latex.py b/bot/exts/utilities/latex.py index 36c7e0ab..36c7e0ab 100644 --- a/bot/exts/evergreen/latex.py +++ b/bot/exts/utilities/latex.py diff --git a/bot/exts/evergreen/pythonfacts.py b/bot/exts/utilities/pythonfacts.py index 80a8da5d..ef190185 100644 --- a/bot/exts/evergreen/pythonfacts.py +++ b/bot/exts/utilities/pythonfacts.py @@ -6,7 +6,7 @@ from discord.ext import commands from bot.bot import Bot from bot.constants import Colours -with open("bot/resources/evergreen/python_facts.txt") as file: +with open("bot/resources/utilities/python_facts.txt") as file: FACTS = itertools.cycle(list(file)) COLORS = itertools.cycle([Colours.python_blue, Colours.python_yellow]) diff --git a/bot/exts/evergreen/realpython.py b/bot/exts/utilities/realpython.py index ef8b2638..ef8b2638 100644 --- a/bot/exts/evergreen/realpython.py +++ b/bot/exts/utilities/realpython.py diff --git a/bot/exts/evergreen/reddit.py b/bot/exts/utilities/reddit.py index e6cb5337..e6cb5337 100644 --- a/bot/exts/evergreen/reddit.py +++ b/bot/exts/utilities/reddit.py diff --git a/bot/exts/evergreen/stackoverflow.py b/bot/exts/utilities/stackoverflow.py index 64455e33..64455e33 100644 --- a/bot/exts/evergreen/stackoverflow.py +++ b/bot/exts/utilities/stackoverflow.py diff --git a/bot/exts/evergreen/timed.py b/bot/exts/utilities/timed.py index 2ea6b419..2ea6b419 100644 --- a/bot/exts/evergreen/timed.py +++ b/bot/exts/utilities/timed.py diff --git a/bot/exts/evergreen/wikipedia.py b/bot/exts/utilities/wikipedia.py index eccc1f8c..eccc1f8c 100644 --- a/bot/exts/evergreen/wikipedia.py +++ b/bot/exts/utilities/wikipedia.py diff --git a/bot/exts/evergreen/wolfram.py b/bot/exts/utilities/wolfram.py index 9a26e545..9a26e545 100644 --- a/bot/exts/evergreen/wolfram.py +++ b/bot/exts/utilities/wolfram.py |