Skip to content

Development #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.2.0"
__version__ = "3.2.1"

import asyncio
import logging
Expand Down
32 changes: 32 additions & 0 deletions core/_color_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:<name>" to avoid name collisions.
DISCORD_COLORS_NORM = {"discord:" + name: value for name, value in DISCORD_COLORS.items()}


# These colors are from Tableau
TABLEAU_COLORS = {
Expand Down Expand Up @@ -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)
26 changes: 18 additions & 8 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import os
import re
import typing
from copy import deepcopy

Expand Down Expand Up @@ -168,25 +169,34 @@ 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:
hex_ = "".join(s for s in hex_ for _ in range(2))
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:
Expand Down