From 1fca73b94684eb366e7d183025ef6dba05ac6683 Mon Sep 17 00:00:00 2001 From: Chris Oliver Date: Sun, 7 Mar 2010 19:01:32 -0600 Subject: Added username coloring from cryzed's patch --- logbot.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'logbot.py') diff --git a/logbot.py b/logbot.py index 9852ee4..faf0b27 100644 --- a/logbot.py +++ b/logbot.py @@ -36,9 +36,9 @@ import os.path import shutil from ConfigParser import ConfigParser -from ftplib import FTP from optparse import OptionParser from time import strftime +from hashlib import md5 from irclib import nm_to_n from ircbot import SingleServerIRCBot @@ -60,6 +60,11 @@ html_header = """%s
""" +def gen_color(user): + """Generates a color based on hash of username""" + return '#%s' % md5(user).hexdigest()[:6] + + class LogBot(SingleServerIRCBot): def __init__(self, server, port, channels, owners, nickname, password): """Initialize this badboy""" @@ -86,8 +91,10 @@ class LogBot(SingleServerIRCBot): user = nm_to_n(e.source()) message = e.arguments()[0] channel = e.target() + color = gen_color(user) self.write(channel, self.format["pubmsg"].replace("%user%", user) \ - .replace("%message%", message)) + .replace("%message%", message) \ + .replace("%color%", color)) def on_invite(self, c, e): pass -- cgit v1.2.3