diff --git a/ChangeLog b/ChangeLog index 07a32b0ec..5d8e9cf1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/plugins/Karma.py b/plugins/Karma.py index bb7812c1c..159dce2fe 100644 --- a/plugins/Karma.py +++ b/plugins/Karma.py @@ -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)""", diff --git a/test/test_Karma.py b/test/test_Karma.py index 9feb28b66..7347bf010 100644 --- a/test/test_Karma.py +++ b/test/test_Karma.py @@ -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: