Add support for multi-word karmas

This commit is contained in:
James Vega 2004-09-07 20:28:24 +00:00
parent c77daeac5c
commit 30d36aae1f
3 changed files with 15 additions and 11 deletions

View File

@ -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):

View File

@ -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

View File

@ -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: