Add rudimentary blocking of adjusting one's own karma

This commit is contained in:
James Vega 2004-07-07 18:10:00 +00:00
parent 7fbb6daa15
commit 91a440e6b3
3 changed files with 30 additions and 4 deletions

View File

@ -1,3 +1,6 @@
* Added conf.supybot.plugins.Karma.allowSelfRating, which determines
whether users are allowed to adjust the karma of their current nick.
* Added --nolimit option to Misc.last, which causes it to return all
matches that are in the history.

View File

@ -66,6 +66,9 @@ conf.registerChannelValue(conf.supybot.plugins.Karma, 'rankingDisplay',
conf.registerChannelValue(conf.supybot.plugins.Karma, 'mostDisplay',
registry.Integer(25, """Determines how many karma things are shown when
the most command is called.'"""))
conf.registerChannelValue(conf.supybot.plugins.Karma, 'allowSelfRating',
registry.Boolean(False, """Determines whether users can adjust the karma
of their nick."""))
class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
addressedRegexps = ['increaseKarma', 'decreaseKarma']
@ -215,11 +218,14 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
irc.error('I have no karma for this channel.')
except KeyError:
raise callbacks.ArgumentError
def increaseKarma(self, irc, msg, match):
r"^(\S+)\+\+(|\s+)$"
name = match.group(1)
normalized = name.lower()
if not self.registryValue('allowSelfRating', msg.args[0]):
if normalized == msg.nick.lower():
return
db = self.getDb(msg.args[0])
cursor = db.cursor()
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",
@ -234,6 +240,9 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
r"^(\S+)--(|\s+)$"
name = match.group(1)
normalized = name.lower()
if not self.registryValue('allowSelfRating', msg.args[0]):
if normalized == msg.nick.lower():
return
db = self.getDb(msg.args[0])
cursor = db.cursor()
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",

View File

@ -99,7 +99,6 @@ if sqlite is not None:
finally:
conf.supybot.plugins.Karma.response.setValue(orig)
conf.supybot.plugins.Karma.rankingDisplay.setValue(original)
def testMost(self):
self.assertError('most increased')
@ -133,6 +132,21 @@ if sqlite is not None:
finally:
conf.supybot.plugins.Karma.simpleOutput.setValue(orig)
def testSelfRating(self):
nick = self.nick
try:
orig = conf.supybot.plugins.Karma.allowSelfRating()
conf.supybot.plugins.Karma.allowSelfRating.setValue(False)
self.assertNoResponse('%s++' % nick, 2)
self.assertResponse('karma %s' % nick,
'%s has no karma.' % nick)
conf.supybot.plugins.Karma.allowSelfRating.setValue(True)
self.assertNoResponse('%s++' % nick, 2)
self.assertRegexp('karma %s' % nick,
'Karma for \'%s\'.*increased 1.*total.*1' % nick)
finally:
conf.supybot.plugins.Karma.allowSelfRating.setValue(orig)
def testKarmaOutputConfigurable(self):
self.assertNoResponse('foo++', 2)
try:
@ -160,11 +174,11 @@ if sqlite is not None:
self.assertRegexp('karma most active', 'bar')
finally:
conf.supybot.plugins.Karma.mostDisplay.setValue(orig)
def testIncreaseKarmaWithNickNotCallingInvalidCommand(self):
self.assertNoResponse('%s: foo++' % self.irc.nick, 3)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: