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 return s
_forceRe = re.compile(r'^no[,: -]+', re.I) _forceRe = re.compile(r'^no[,: -]+', re.I)
_karmaRe = re.compile(r'^\S+(?:\+\+|--)(?:\s+)?$') _karmaRe = re.compile(r'^(?:\S+|\(.+\))(?:\+\+|--)(?:\s+)?$')
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
try: try:
if ircmsgs.isCtcp(msg): if ircmsgs.isCtcp(msg):

View File

@ -295,11 +295,11 @@ class Karma(callbacks.PrivmsgCommandAndRegexp):
clear = privmsgs.checkChannelCapability(clear, 'op') clear = privmsgs.checkChannelCapability(clear, 'op')
def increaseKarma(self, irc, msg, match): def increaseKarma(self, irc, msg, match):
r"^(\S+)\+\+\s*$" r"^(\S+|\(.+\))\+\+\s*$"
channel = msg.args[0] channel = msg.args[0]
if not ircutils.isChannel(channel): if not ircutils.isChannel(channel):
return return
name = match.group(1) name = match.group(1).strip('()')
if not self.registryValue('allowSelfRating', msg.args[0]): if not self.registryValue('allowSelfRating', msg.args[0]):
if ircutils.strEqual(name, msg.nick): if ircutils.strEqual(name, msg.nick):
return return
@ -308,11 +308,11 @@ class Karma(callbacks.PrivmsgCommandAndRegexp):
irc.replySuccess() irc.replySuccess()
def decreaseKarma(self, irc, msg, match): def decreaseKarma(self, irc, msg, match):
r"^(\S+)--\s*$" r"^(\S+|\(.+\))--\s*$"
channel = msg.args[0] channel = msg.args[0]
if not ircutils.isChannel(channel): if not ircutils.isChannel(channel):
return return
name = match.group(1) name = match.group(1).strip('()')
if not self.registryValue('allowSelfRating', msg.args[0]): if not self.registryValue('allowSelfRating', msg.args[0]):
if ircutils.strEqual(name, msg.nick): if ircutils.strEqual(name, msg.nick):
return return

View File

@ -190,6 +190,10 @@ if sqlite is not None:
self.assertNotError('load Infobot') self.assertNotError('load Infobot')
self.assertNoResponse('foo++') 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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: