add utils.irc.hash_colorize() to color a string by the string's hash

This commit is contained in:
jesopo 2019-11-11 12:06:16 +00:00
parent dc52200af8
commit 2ad8623eb3

View file

@ -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)