aboutsummaryrefslogtreecommitdiff
path: root/src/utils/irc.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-11-11 12:06:16 +0000
committerGravatar jesopo2019-11-11 12:06:16 +0000
commit2ad8623eb3491a05d2780b2b8c8590b706844d75 (patch)
tree735f337e3a7cfcb805e3f782056e3a2ee0c3e1b6 /src/utils/irc.py
parenthandle .connect() failure in bitbotctl (diff)
signature
add utils.irc.hash_colorize() to color a string by the string's hash
Diffstat (limited to 'src/utils/irc.py')
-rw-r--r--src/utils/irc.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/utils/irc.py b/src/utils/irc.py
index 81db0113..59151a75 100644
--- a/src/utils/irc.py
+++ b/src/utils/irc.py
@@ -41,6 +41,11 @@ def color(s: str, foreground: consts.IRCColor,
return "%s%s%s%s%s" % (consts.COLOR, foreground_s, background_s, s,
consts.COLOR)
+HASH_COLORS = list(range(2, 16))
+def hash_colorize(s: str):
+ code = hash(s)%len(HASH_COLORS)
+ return color(s, consts.COLOR_CODES[code])
+
def bold(s: str) -> str:
return "%s%s%s" % (consts.BOLD, s, consts.BOLD)