Karma: allow multiple karma expressions per line

This commit is contained in:
Brian S. Stephan 2012-09-13 12:16:25 -05:00
parent c064f6ebe1
commit e7a573bce1
1 changed files with 18 additions and 14 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)'
@ -102,19 +102,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):
""" """