3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

relay: use built-in hash() for colorizing text

This is way faster than md5.
This commit is contained in:
James Lu 2016-12-21 23:48:05 -08:00
parent c66c85bc9a
commit 77dd8224ae

View File

@ -25,14 +25,12 @@ default_styles = {'MESSAGE': '\x02[$colored_netname]\x02 <$colored_sender> $text
def color_text(s):
"""
Returns a colorized version of the given text based on a simple hash algorithm
(sum of all characters).
Returns a colorized version of the given text based on a simple hash algorithm.
"""
colors = ('02', '03', '04', '05', '06', '07', '08', '09', '10', '11',
'12', '13', '15')
digest = hashlib.md5(s.encode()).hexdigest()
digest = int(digest, base=16)
num = digest % len(colors)
hash_output = hash(s.encode())
num = hash_output % len(colors)
return "\x03%s%s\x03" % (colors[num], s)
def cb_relay_core(irc, source, command, args):