aboutsummaryrefslogtreecommitdiff
path: root/src/utils/irc.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/irc.py')
-rw-r--r--src/utils/irc.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/utils/irc.py b/src/utils/irc.py
index 30a3126e..cdaa61eb 100644
--- a/src/utils/irc.py
+++ b/src/utils/irc.py
@@ -38,19 +38,29 @@ def color(s: str, foreground: consts.IRCColor,
if background:
background_s = ",%s" % str(background.irc).zfill(2)
- return "%s%s%s%s%s" % (consts.COLOR, foreground_s, background_s, s,
- consts.COLOR)
+ return f"{consts.COLOR}{foreground_s}{background_s}{s}{consts.COLOR}"
-HASH_COLORS = list(range(2, 16))
+HASH_STOP = ["_", "|", "["]
+HASH_COLORS = [consts.CYAN, consts.PURPLE, consts.GREEN, consts.ORANGE,
+ consts.LIGHTBLUE, consts.TRANSPARENT, consts.LIGHTCYAN, consts.PINK,
+ consts.LIGHTGREEN, consts.BLUE]
def hash_colorize(s: str):
- hash_code = sum(ord(c) for c in s.lower())%len(HASH_COLORS)
- return color(s, consts.COLOR_CODES[HASH_COLORS[hash_code]])
+ hash = 5381
+ non_stop = False
+ for i, char in enumerate(s):
+ if not char in HASH_STOP:
+ non_stop = True
+ elif non_stop:
+ break
+ hash ^= ((hash<<5)+(hash>>2)+ord(char))&0xFFFFFFFFFFFFFFFF
+
+ return color(s, HASH_COLORS[hash%len(HASH_COLORS)])
def bold(s: str) -> str:
- return "%s%s%s" % (consts.BOLD, s, consts.BOLD)
+ return f"{consts.BOLD}{s}{consts.BOLD}"
def underline(s: str) -> str:
- return "%s%s%s" % (consts.UNDERLINE, s, consts.UNDERLINE)
+ return f"{consts.UNDERLINE}{s}{consts.UNDERLINE}"
def strip_font(s: str) -> str:
s = s.replace(consts.BOLD, "")