Skip to content

Commit 24aecdd

Browse files
authored
Merge pull request #375 from kyb3r/development
Development
2 parents 1465f8d + 6284744 commit 24aecdd

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
77
however, insignificant breaking changes does not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319).
88

9+
# v3.2.1
10+
11+
### Fixed
12+
13+
- Can't set hex for main_color, recipient_color, etc.
14+
15+
### Added
16+
17+
- Discord colors by default when addressing them by names.
18+
919
# v3.2.0
1020

1121
### Added

bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.2.0"
1+
__version__ = "3.2.1"
22

33
import asyncio
44
import logging

core/_color_data.py

+32
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,36 @@
1515
"w": "#ffffff",
1616
}
1717

18+
# Discord native colors
19+
DISCORD_COLORS = {
20+
"default": "#000000",
21+
"teal": "#1abc9c",
22+
"dark teal": "#11806a",
23+
"green": "#2ecc71",
24+
"dark green": "#1f8b4c",
25+
"blue": "#3498db",
26+
"dark blue": "#206694",
27+
"purple": "#9b59b6",
28+
"dark purple": "#71368a",
29+
"magenta": "#e91e63",
30+
"dark magenta": "#ad1457",
31+
"gold": "#f1c40f",
32+
"dark gold": "#c27c0e",
33+
"orange": "#e67e22",
34+
"dark orange": "#a84300",
35+
"red": "#e74c3c",
36+
"dark red": "#992d22",
37+
"lighter gray": "#95a5a6",
38+
"darker gray": "#546e7a",
39+
"light gray": "#979c9f",
40+
"dark gray": "#607d8b",
41+
"blurple": "#7289da",
42+
"grayple": "#99aab5"
43+
}
44+
45+
# Normalize name to "discord:<name>" to avoid name collisions.
46+
DISCORD_COLORS_NORM = {"discord:" + name: value for name, value in DISCORD_COLORS.items()}
47+
1848

1949
# These colors are from Tableau
2050
TABLEAU_COLORS = {
@@ -1160,3 +1190,5 @@
11601190
ALL_COLORS.update(XKCD_COLORS_NORM)
11611191
ALL_COLORS.update(TABLEAU_COLORS)
11621192
ALL_COLORS.update(TABLEAU_COLORS_NORM)
1193+
ALL_COLORS.update(DISCORD_COLORS)
1194+
ALL_COLORS.update(DISCORD_COLORS_NORM)

core/config.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import os
5+
import re
56
import typing
67
from copy import deepcopy
78

@@ -168,25 +169,34 @@ async def clean_data(self, key: str, val: typing.Any) -> typing.Tuple[str, str]:
168169

169170
# when setting a color
170171
if key in self.colors:
171-
hex_ = ALL_COLORS.get(val)
172+
try:
173+
hex_ = str(val)
172174

173-
if hex_ is None:
174-
hex_ = str(hex_)
175175
if hex_.startswith("#"):
176176
hex_ = hex_[1:]
177177
if len(hex_) == 3:
178178
hex_ = "".join(s for s in hex_ for _ in range(2))
179179
if len(hex_) != 6:
180180
raise InvalidConfigError("Invalid color name or hex.")
181181
try:
182-
int(val, 16)
182+
int(hex_, 16)
183183
except ValueError:
184184
raise InvalidConfigError("Invalid color name or hex.")
185-
clean_value = "#" + val
186-
value_text = clean_value
187-
else:
185+
hex_ = "#" + hex_
186+
value_text = clean_value = hex_
187+
188+
except InvalidConfigError:
189+
name = str(val).lower()
190+
name = re.sub(r"[\-+|. ]+", " ", name)
191+
hex_ = ALL_COLORS.get(name)
192+
if hex_ is None:
193+
name = re.sub(r"[\-+|. ]+", "", name)
194+
hex_ = ALL_COLORS.get(name)
195+
if hex_ is None:
196+
raise
197+
188198
clean_value = hex_
189-
value_text = f"{val} ({clean_value})"
199+
value_text = f"{name} ({clean_value})"
190200

191201
elif key in self.time_deltas:
192202
try:

0 commit comments

Comments
 (0)