From e7a573bce18a8121b4b8f04bc1ee7f1d5d70b656 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Thu, 13 Sep 2012 12:16:25 -0500 Subject: [PATCH] Karma: allow multiple karma expressions per line --- modules/Karma.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/Karma.py b/modules/Karma.py index 03f3bb5..fc7ccbe 100644 --- a/modules/Karma.py +++ b/modules/Karma.py @@ -35,7 +35,7 @@ class Karma(Module): Module.__init__(self, irc, config, server) - pattern = "(?:\((.+)\)|(\S+))" + pattern = "(?:\((.+?)\)|(\S+))" karmapattern = pattern + '(\+\+|--|\+-|-\+)' + '(\s+|$)' querypattern = '^!rank\s+(.*)' reportpattern = '^!karma\s+report\s+(highest|lowest|positive|negative|top)' @@ -102,19 +102,23 @@ class Karma(Module): """ handle the karma change and storage. """ - match = self.karmare.search(what) - key = match.group(1) if match.group(1) else match.group(2) - value = match.group(3) - if (value == '++'): - return self.karma_modify(key, 1, nick, userhost) - elif (value == '--'): - return self.karma_modify(key, -1, nick, userhost) - elif (value == '+-'): - self.karma_modify(key, 1, nick, userhost) - return self.karma_modify(key, -1, nick, userhost) - elif (value == '-+'): - self.karma_modify(key, -1, nick, userhost) - return self.karma_modify(key, 1, nick, userhost) + + if self.karmare.search(what): + matches = self.karmare.findall(what) + for match in matches: + key = match[0] if match[0] else match[1] + value = match[2] + + if (value == '++'): + self.karma_modify(key, 1, nick, userhost) + elif (value == '--'): + self.karma_modify(key, -1, nick, userhost) + elif (value == '+-'): + 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): """