diff options
author | 2022-04-21 09:27:50 +0100 | |
---|---|---|
committer | 2022-04-21 13:31:35 +0100 | |
commit | fabfbd63dc1055ba28742e7819107fa2b201fb1c (patch) | |
tree | 726587cf6de1aa166205f792d6b102ba07863de7 | |
parent | Adjust filtering settings for the AoC link viewset (diff) |
Support color string being when converting to hex code
Int he latest version of discord.py Embed colours could be sent to site as hex strings, if set using a discord.Color, rather tha an int.
Closes #715 Closes SITE-25
-rw-r--r-- | pydis_site/apps/staff/templatetags/deletedmessage_filters.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/pydis_site/apps/staff/templatetags/deletedmessage_filters.py b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py index 8e14ced6..5026068e 100644 --- a/pydis_site/apps/staff/templatetags/deletedmessage_filters.py +++ b/pydis_site/apps/staff/templatetags/deletedmessage_filters.py @@ -1,4 +1,5 @@ from datetime import datetime +from typing import Union from django import template @@ -6,13 +7,16 @@ register = template.Library() @register.filter -def hex_colour(color: int) -> str: +def hex_colour(colour: Union[str, int]) -> str: """ - Converts an integer representation of a colour to the RGB hex value. + Converts the given representation of a colour to its RGB hex string. As we are using a Discord dark theme analogue, black colours are returned as white instead. """ - colour = f"#{color:0>6X}" + if isinstance(colour, str): + colour = colour if colour.startswith("#") else f"#{colour}" + else: + colour = f"#{colour:0>6X}" return colour if colour != "#000000" else "#FFFFFF" |