Skip to content

Commit

Permalink
fix: Colour
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Jul 26, 2023
1 parent 9ac52a5 commit e62602d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/zibot/exts/info/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import datetime as dt
import re
import unicodedata
from contextlib import suppress
from typing import Union
Expand All @@ -25,6 +26,9 @@
from ...utils.format import formatDiscordDT, renderBar


COLOUR_REGEX = re.compile("^(?:0x|#)?([0-9a-fA-F]{1,6})$")


class Info(commands.Cog, CogMixin):
"""Commands that gives you information."""

Expand Down Expand Up @@ -114,17 +118,13 @@ async def weather(self, ctx: Context, *, city: str):
)
@commands.cooldown(1, 5, commands.BucketType.user)
async def colour(self, ctx: Context, value: str):
# Pre processing
value = value.lstrip("#")[:6]
value = value.ljust(6, "0")

try:
h = str(hex(int(value, 16)))[2:]
h = h.lstrip("0x")
h = "0x" + h.rjust(6, "0")
except ValueError:
match = COLOUR_REGEX.match(value)
if not match:
return await ctx.error(_("color-error"))

h = match.group(1)
h = h.ljust(6, "0")

# Convert HEX into RGB
RGB = tuple(int(h[i : i + 2], 16) for i in (0, 2, 4))

Expand Down

0 comments on commit e62602d

Please sign in to comment.