Merge branch 'master' of git.incorporeal.org:dr.botzo

This commit is contained in:
Brian S. Stephan 2012-09-17 16:27:00 -05:00
commit 97259eb6b3
1 changed files with 22 additions and 16 deletions

View File

@ -35,7 +35,7 @@ class Karma(Module):
Module.__init__(self, irc, config, server) Module.__init__(self, irc, config, server)
pattern = "(?:\((.+)\)|(\S+))" pattern = "(?:\((.+?)\)|(\S+))"
karmapattern = pattern + '(\+\+|--|\+-|-\+)' + '(\s+|$)' karmapattern = pattern + '(\+\+|--|\+-|-\+)' + '(\s+|$)'
querypattern = '^!rank\s+(.*)' querypattern = '^!rank\s+(.*)'
reportpattern = '^!karma\s+report\s+(highest|lowest|positive|negative|top)' reportpattern = '^!karma\s+report\s+(highest|lowest|positive|negative|top)'
@ -89,9 +89,11 @@ class Karma(Module):
def do(self, connection, event, nick, userhost, what, admin_unlocked): def do(self, connection, event, nick, userhost, what, admin_unlocked):
"""look for karma strings at the start of messages""" """look for karma strings at the start of messages"""
# don't return anything, do this attempt regardless
if (self.karmare.search(what)): if (self.karmare.search(what)):
return self.reply(connection, event, self.handle_karma_change(connection, nick, userhost, what)) self.handle_karma_change(connection, nick, userhost, what)
elif (self.queryre.search(what)):
if (self.queryre.search(what)):
return self.reply(connection, event, self.handle_karma_query(connection, nick, userhost, what)) return self.reply(connection, event, self.handle_karma_query(connection, nick, userhost, what))
elif (self.statre.search(what)): elif (self.statre.search(what)):
return self.reply(connection, event, self.handle_stat_query(connection, nick, userhost, what)) return self.reply(connection, event, self.handle_stat_query(connection, nick, userhost, what))
@ -102,19 +104,23 @@ class Karma(Module):
""" """
handle the karma change and storage. handle the karma change and storage.
""" """
match = self.karmare.search(what)
key = match.group(1) if match.group(1) else match.group(2) if self.karmare.search(what):
value = match.group(3) matches = self.karmare.findall(what)
if (value == '++'): for match in matches:
return self.karma_modify(key, 1, nick, userhost) key = match[0] if match[0] else match[1]
elif (value == '--'): value = match[2]
return self.karma_modify(key, -1, nick, userhost)
elif (value == '+-'): if (value == '++'):
self.karma_modify(key, 1, nick, userhost) self.karma_modify(key, 1, nick, userhost)
return self.karma_modify(key, -1, nick, userhost) elif (value == '--'):
elif (value == '-+'): self.karma_modify(key, -1, nick, userhost)
self.karma_modify(key, -1, nick, userhost) elif (value == '+-'):
return self.karma_modify(key, 1, nick, userhost) self.karma_modify(key, 1, nick, userhost)
self.karma_modify(key, -1, nick, userhost)
elif (value == '-+'):
self.karma_modify(key, -1, nick, userhost)
self.karma_modify(key, 1, nick, userhost)
def karma_modify(self, key, value, nick, userhost): def karma_modify(self, key, value, nick, userhost):
""" """