diff --git a/CHANGELOG.md b/CHANGELOG.md index bf0820128e..7d601f839e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html); however, insignificant breaking changes does not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319). +# v3.2.1 + +### Fixed + +- Can't set hex for main_color, recipient_color, etc. + +### Added + +- Discord colors by default when addressing them by names. + # v3.2.0 ### Added diff --git a/bot.py b/bot.py index bea7adadbb..afe7a547cc 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,4 @@ -__version__ = "3.2.0" +__version__ = "3.2.1" import asyncio import logging diff --git a/core/_color_data.py b/core/_color_data.py index 13346e903e..997a6a1d25 100644 --- a/core/_color_data.py +++ b/core/_color_data.py @@ -15,6 +15,36 @@ "w": "#ffffff", } +# Discord native colors +DISCORD_COLORS = { + "default": "#000000", + "teal": "#1abc9c", + "dark teal": "#11806a", + "green": "#2ecc71", + "dark green": "#1f8b4c", + "blue": "#3498db", + "dark blue": "#206694", + "purple": "#9b59b6", + "dark purple": "#71368a", + "magenta": "#e91e63", + "dark magenta": "#ad1457", + "gold": "#f1c40f", + "dark gold": "#c27c0e", + "orange": "#e67e22", + "dark orange": "#a84300", + "red": "#e74c3c", + "dark red": "#992d22", + "lighter gray": "#95a5a6", + "darker gray": "#546e7a", + "light gray": "#979c9f", + "dark gray": "#607d8b", + "blurple": "#7289da", + "grayple": "#99aab5" +} + +# Normalize name to "discord:" to avoid name collisions. +DISCORD_COLORS_NORM = {"discord:" + name: value for name, value in DISCORD_COLORS.items()} + # These colors are from Tableau TABLEAU_COLORS = { @@ -1160,3 +1190,5 @@ ALL_COLORS.update(XKCD_COLORS_NORM) ALL_COLORS.update(TABLEAU_COLORS) ALL_COLORS.update(TABLEAU_COLORS_NORM) +ALL_COLORS.update(DISCORD_COLORS) +ALL_COLORS.update(DISCORD_COLORS_NORM) diff --git a/core/config.py b/core/config.py index b2109a94da..ad1a42d2f9 100644 --- a/core/config.py +++ b/core/config.py @@ -2,6 +2,7 @@ import json import logging import os +import re import typing from copy import deepcopy @@ -168,10 +169,9 @@ async def clean_data(self, key: str, val: typing.Any) -> typing.Tuple[str, str]: # when setting a color if key in self.colors: - hex_ = ALL_COLORS.get(val) + try: + hex_ = str(val) - if hex_ is None: - hex_ = str(hex_) if hex_.startswith("#"): hex_ = hex_[1:] if len(hex_) == 3: @@ -179,14 +179,24 @@ async def clean_data(self, key: str, val: typing.Any) -> typing.Tuple[str, str]: if len(hex_) != 6: raise InvalidConfigError("Invalid color name or hex.") try: - int(val, 16) + int(hex_, 16) except ValueError: raise InvalidConfigError("Invalid color name or hex.") - clean_value = "#" + val - value_text = clean_value - else: + hex_ = "#" + hex_ + value_text = clean_value = hex_ + + except InvalidConfigError: + name = str(val).lower() + name = re.sub(r"[\-+|. ]+", " ", name) + hex_ = ALL_COLORS.get(name) + if hex_ is None: + name = re.sub(r"[\-+|. ]+", "", name) + hex_ = ALL_COLORS.get(name) + if hex_ is None: + raise + clean_value = hex_ - value_text = f"{val} ({clean_value})" + value_text = f"{name} ({clean_value})" elif key in self.time_deltas: try: