Skip to content

Commit fabfbd6

Browse files
committed
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
1 parent a4eda4a commit fabfbd6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pydis_site/apps/staff/templatetags/deletedmessage_filters.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
from datetime import datetime
2+
from typing import Union
23

34
from django import template
45

56
register = template.Library()
67

78

89
@register.filter
9-
def hex_colour(color: int) -> str:
10+
def hex_colour(colour: Union[str, int]) -> str:
1011
"""
11-
Converts an integer representation of a colour to the RGB hex value.
12+
Converts the given representation of a colour to its RGB hex string.
1213
1314
As we are using a Discord dark theme analogue, black colours are returned as white instead.
1415
"""
15-
colour = f"#{color:0>6X}"
16+
if isinstance(colour, str):
17+
colour = colour if colour.startswith("#") else f"#{colour}"
18+
else:
19+
colour = f"#{colour:0>6X}"
1620
return colour if colour != "#000000" else "#FFFFFF"
1721

1822

0 commit comments

Comments
 (0)