Added username coloring from cryzed's patch

This commit is contained in:
Chris Oliver 2010-03-07 19:01:32 -06:00
parent 399ccb25ec
commit 1fca73b946
2 changed files with 10 additions and 3 deletions

View file

@ -22,7 +22,7 @@ kick = -!- <span class="kick">%user%</span> was kicked from %channel% by %kicker
mode = -!- mode/<span class="mode">%channel%</span> [%modes% %person%] by %giver% mode = -!- mode/<span class="mode">%channel%</span> [%modes% %person%] by %giver%
nick = <span class="nick">%old%</span> is now known as <span class="nick">%new%</span> nick = <span class="nick">%old%</span> is now known as <span class="nick">%new%</span>
part = -!- <span class="part">%user%</span> has parted %channel% part = -!- <span class="part">%user%</span> has parted %channel%
pubmsg = <span class="person">&lt;%user%&gt;</span> %message% pubmsg = <span class="person" style="color:%color%">&lt;%user%&gt;</span> %message%
pubnotice = <span class="notice">-%user%:%channel%-</span> %message% pubnotice = <span class="notice">-%user%:%channel%-</span> %message%
quit = -!- <span class="quit">%user%</span> has quit [%reason%] quit = -!- <span class="quit">%user%</span> has quit [%reason%]
topic = <span class="topic">%user%</span> changed topic of <span class="topic">%channel%</span> to: %topic% topic = <span class="topic">%user%</span> changed topic of <span class="topic">%channel%</span> to: %topic%

View file

@ -36,9 +36,9 @@ import os.path
import shutil import shutil
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
from ftplib import FTP
from optparse import OptionParser from optparse import OptionParser
from time import strftime from time import strftime
from hashlib import md5
from irclib import nm_to_n from irclib import nm_to_n
from ircbot import SingleServerIRCBot from ircbot import SingleServerIRCBot
@ -60,6 +60,11 @@ html_header = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
index_header = """<h1>%s</h1><br />""" index_header = """<h1>%s</h1><br />"""
def gen_color(user):
"""Generates a color based on hash of username"""
return '#%s' % md5(user).hexdigest()[:6]
class LogBot(SingleServerIRCBot): class LogBot(SingleServerIRCBot):
def __init__(self, server, port, channels, owners, nickname, password): def __init__(self, server, port, channels, owners, nickname, password):
"""Initialize this badboy""" """Initialize this badboy"""
@ -86,8 +91,10 @@ class LogBot(SingleServerIRCBot):
user = nm_to_n(e.source()) user = nm_to_n(e.source())
message = e.arguments()[0] message = e.arguments()[0]
channel = e.target() channel = e.target()
color = gen_color(user)
self.write(channel, self.format["pubmsg"].replace("%user%", 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): def on_invite(self, c, e):
pass pass