Skip to content

Commit 872201b

Browse files
authored
Merge pull request #716 from python-discord/support-string-colors
Support color string being when converting to hex code
2 parents a4eda4a + a97d188 commit 872201b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
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

pydis_site/apps/staff/tests/test_logs_view.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,22 @@ def setUpTestData(cls):
9595
"description": "This embed is way too cool to be seen in public channels.",
9696
}
9797

98+
cls.embed_three = {
99+
"description": "This embed is way too cool to be seen in public channels.",
100+
"color": "#e74c3c",
101+
}
102+
103+
cls.embed_four = {
104+
"description": "This embed is way too cool to be seen in public channels.",
105+
"color": "e74c3c",
106+
}
107+
98108
cls.deleted_message_two = DeletedMessage.objects.create(
99109
author=cls.author,
100110
id=614444836291870750,
101111
channel_id=1984,
102112
content='Does that mean this thing will halt?',
103-
embeds=[cls.embed_one, cls.embed_two],
113+
embeds=[cls.embed_one, cls.embed_two, cls.embed_three, cls.embed_four],
104114
attachments=['https://http.cat/100', 'https://http.cat/402'],
105115
deletion_context=cls.deletion_context,
106116
)

0 commit comments

Comments
 (0)