clean up karma module

This commit is contained in:
Mike Bloy 2010-10-24 09:36:15 -05:00
parent b1fe99d5a2
commit e453778791

View File

@ -46,10 +46,18 @@ class Karma(Module):
self.queryre = re.compile(querypattern) self.queryre = re.compile(querypattern)
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
"""look for karma strings.""" """look for karma strings at the start of messages"""
if (self.karmare.match(what)): if (self.karmare.match(what)):
self.handle_karma_change(connection, nick, userhost, replypath, what)
elif (self.queryre.match(what)):
self.handle_karma_query(connection, nick, userhost, replypath, what)
def handle_karma_change(self, connection, nick, userhost, replypath, what):
"""
handle the karma change and storage.
"""
match = self.karmare.match(what) match = self.karmare.match(what)
key = match.group(1) key = match.group(1)
value = match.group(2) value = match.group(2)
@ -90,10 +98,8 @@ class Karma(Module):
reply = "karma change for '" + key + "' (" + str(value) + ") by " + nick reply = "karma change for '" + key + "' (" + str(value) + ") by " + nick
self.reply(connection, replypath, reply) self.reply(connection, replypath, reply)
return
if (self.queryre.match(what)): def handle_karma_query(self, connection, nick, userhost, replypath, what):
# tell about karma
match = self.queryre.match(what) match = self.queryre.match(what)
key = match.group(1) key = match.group(1)
@ -107,7 +113,6 @@ class Karma(Module):
karma.close() karma.close()
self.reply(connection, replypath, reply) self.reply(connection, replypath, reply)
return
if __name__ == "__main__": if __name__ == "__main__":
print "Hello World" print "Hello World"