diff options
author | 2021-11-09 19:44:18 -0500 | |
---|---|---|
committer | 2021-11-09 19:44:18 -0500 | |
commit | 2bb00fbf680d49c92bb40af71659489801cc0f99 (patch) | |
tree | 89624361842673b6af7b63391af55d85ee04d73d /bot/exts/utilities/colour.py | |
parent | fix: type hinting _rgb_to_cmyk (diff) |
fix: handle alpha values in hex code
Co-authored-by: Sn4u <[email protected]>
Diffstat (limited to 'bot/exts/utilities/colour.py')
-rw-r--r-- | bot/exts/utilities/colour.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/bot/exts/utilities/colour.py b/bot/exts/utilities/colour.py index c2a5e7e7..7b128393 100644 --- a/bot/exts/utilities/colour.py +++ b/bot/exts/utilities/colour.py @@ -130,7 +130,13 @@ class Colour(commands.Cog): """Command to create an embed from a HEX input.""" if "#" not in hex_code: hex_code = f"#{hex_code}" + if len(hex_code) not in (4, 5, 7, 9) or any(_ not in string.hexdigits+"#" for _ in hex_code): + raise commands.BadArgument( + message=f"HEX values must be hexadecimal and take the form *#RRGGBB* or *#RGB*. User input was: `{hex_code}`.") + hex_tuple = ImageColor.getrgb(hex_code) + if len(hex_tuple) == 4: + hex_tuple = hex_tuple[:-1] # color must be RGB. If RGBA, we remove the alpha value await self.send_colour_response(ctx, hex_tuple) @colour.command() |