From 30d36aae1fecbee5293b79b8c1991ed69e042e06 Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 7 Sep 2004 20:28:24 +0000 Subject: [PATCH] Add support for multi-word karmas --- plugins/Infobot.py | 2 +- plugins/Karma.py | 18 +++++++++--------- test/test_Karma.py | 6 +++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/Infobot.py b/plugins/Infobot.py index b87021263..a58d74c81 100755 --- a/plugins/Infobot.py +++ b/plugins/Infobot.py @@ -494,7 +494,7 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp): return s _forceRe = re.compile(r'^no[,: -]+', re.I) - _karmaRe = re.compile(r'^\S+(?:\+\+|--)(?:\s+)?$') + _karmaRe = re.compile(r'^(?:\S+|\(.+\))(?:\+\+|--)(?:\s+)?$') def doPrivmsg(self, irc, msg): try: if ircmsgs.isCtcp(msg): diff --git a/plugins/Karma.py b/plugins/Karma.py index 558548169..7538d1fda 100644 --- a/plugins/Karma.py +++ b/plugins/Karma.py @@ -131,7 +131,7 @@ class SqliteKarmaDB(object): cursor.execute("""SELECT name, added-subtracted FROM karma ORDER BY added-subtracted ASC LIMIT %s""", limit) return [(t[0], int(t[1])) for t in cursor.fetchall()] - + def rank(self, channel, thing): db = self._getDb(channel) cursor = db.cursor() @@ -150,7 +150,7 @@ class SqliteKarmaDB(object): cursor = db.cursor() cursor.execute("""SELECT COUNT(*) FROM karma""") return int(cursor.fetchone()[0]) - + def increment(self, channel, name): db = self._getDb(channel) cursor = db.cursor() @@ -160,7 +160,7 @@ class SqliteKarmaDB(object): cursor.execute("""UPDATE karma SET added=added+1 WHERE normalized=%s""", normalized) db.commit() - + def decrement(self, channel, name): db = self._getDb(channel) cursor = db.cursor() @@ -194,11 +194,11 @@ class SqliteKarmaDB(object): cursor.execute("""UPDATE karma SET subtracted=0, added=0 WHERE normalized=%s""", normalized) db.commit() - + def KarmaDB(): return SqliteKarmaDB() - + class Karma(callbacks.PrivmsgCommandAndRegexp): addressedRegexps = ['increaseKarma', 'decreaseKarma'] def __init__(self): @@ -295,11 +295,11 @@ class Karma(callbacks.PrivmsgCommandAndRegexp): clear = privmsgs.checkChannelCapability(clear, 'op') def increaseKarma(self, irc, msg, match): - r"^(\S+)\+\+\s*$" + r"^(\S+|\(.+\))\+\+\s*$" channel = msg.args[0] if not ircutils.isChannel(channel): return - name = match.group(1) + name = match.group(1).strip('()') if not self.registryValue('allowSelfRating', msg.args[0]): if ircutils.strEqual(name, msg.nick): return @@ -308,11 +308,11 @@ class Karma(callbacks.PrivmsgCommandAndRegexp): irc.replySuccess() def decreaseKarma(self, irc, msg, match): - r"^(\S+)--\s*$" + r"^(\S+|\(.+\))--\s*$" channel = msg.args[0] if not ircutils.isChannel(channel): return - name = match.group(1) + name = match.group(1).strip('()') if not self.registryValue('allowSelfRating', msg.args[0]): if ircutils.strEqual(name, msg.nick): return diff --git a/test/test_Karma.py b/test/test_Karma.py index 6c1f0e325..e734e9d6b 100644 --- a/test/test_Karma.py +++ b/test/test_Karma.py @@ -185,11 +185,15 @@ if sqlite is not None: self.assertNotError('karma clear foo') self.assertRegexp('karma foo', '0') self.assertNotRegexp('karma foo', '1') - + def testNoKarmaDunno(self): self.assertNotError('load Infobot') self.assertNoResponse('foo++') + def testMultiWordKarma(self): + self.assertNoResponse('(foo bar)++', 1) + self.assertRegexp('karma "foo bar"', '1') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: