mirror of
https://github.com/progval/Limnoria.git
synced 2025-05-03 00:41:11 -05:00
Add rudimentary blocking of adjusting one's own karma
This commit is contained in:
parent
7fbb6daa15
commit
91a440e6b3
@ -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
|
* Added --nolimit option to Misc.last, which causes it to return all
|
||||||
matches that are in the history.
|
matches that are in the history.
|
||||||
|
|
||||||
|
@ -66,6 +66,9 @@ conf.registerChannelValue(conf.supybot.plugins.Karma, 'rankingDisplay',
|
|||||||
conf.registerChannelValue(conf.supybot.plugins.Karma, 'mostDisplay',
|
conf.registerChannelValue(conf.supybot.plugins.Karma, 'mostDisplay',
|
||||||
registry.Integer(25, """Determines how many karma things are shown when
|
registry.Integer(25, """Determines how many karma things are shown when
|
||||||
the most command is called.'"""))
|
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):
|
class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
|
||||||
addressedRegexps = ['increaseKarma', 'decreaseKarma']
|
addressedRegexps = ['increaseKarma', 'decreaseKarma']
|
||||||
@ -215,11 +218,14 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
|
|||||||
irc.error('I have no karma for this channel.')
|
irc.error('I have no karma for this channel.')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
|
|
||||||
def increaseKarma(self, irc, msg, match):
|
def increaseKarma(self, irc, msg, match):
|
||||||
r"^(\S+)\+\+(|\s+)$"
|
r"^(\S+)\+\+(|\s+)$"
|
||||||
name = match.group(1)
|
name = match.group(1)
|
||||||
normalized = name.lower()
|
normalized = name.lower()
|
||||||
|
if not self.registryValue('allowSelfRating', msg.args[0]):
|
||||||
|
if normalized == msg.nick.lower():
|
||||||
|
return
|
||||||
db = self.getDb(msg.args[0])
|
db = self.getDb(msg.args[0])
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",
|
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",
|
||||||
@ -234,6 +240,9 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
|
|||||||
r"^(\S+)--(|\s+)$"
|
r"^(\S+)--(|\s+)$"
|
||||||
name = match.group(1)
|
name = match.group(1)
|
||||||
normalized = name.lower()
|
normalized = name.lower()
|
||||||
|
if not self.registryValue('allowSelfRating', msg.args[0]):
|
||||||
|
if normalized == msg.nick.lower():
|
||||||
|
return
|
||||||
db = self.getDb(msg.args[0])
|
db = self.getDb(msg.args[0])
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",
|
cursor.execute("""INSERT INTO karma VALUES (NULL, %s, %s, 0, 0)""",
|
||||||
|
@ -99,7 +99,6 @@ if sqlite is not None:
|
|||||||
finally:
|
finally:
|
||||||
conf.supybot.plugins.Karma.response.setValue(orig)
|
conf.supybot.plugins.Karma.response.setValue(orig)
|
||||||
conf.supybot.plugins.Karma.rankingDisplay.setValue(original)
|
conf.supybot.plugins.Karma.rankingDisplay.setValue(original)
|
||||||
|
|
||||||
|
|
||||||
def testMost(self):
|
def testMost(self):
|
||||||
self.assertError('most increased')
|
self.assertError('most increased')
|
||||||
@ -133,6 +132,21 @@ if sqlite is not None:
|
|||||||
finally:
|
finally:
|
||||||
conf.supybot.plugins.Karma.simpleOutput.setValue(orig)
|
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):
|
def testKarmaOutputConfigurable(self):
|
||||||
self.assertNoResponse('foo++', 2)
|
self.assertNoResponse('foo++', 2)
|
||||||
try:
|
try:
|
||||||
@ -160,11 +174,11 @@ if sqlite is not None:
|
|||||||
self.assertRegexp('karma most active', 'bar')
|
self.assertRegexp('karma most active', 'bar')
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.plugins.Karma.mostDisplay.setValue(orig)
|
conf.supybot.plugins.Karma.mostDisplay.setValue(orig)
|
||||||
|
|
||||||
|
|
||||||
def testIncreaseKarmaWithNickNotCallingInvalidCommand(self):
|
def testIncreaseKarmaWithNickNotCallingInvalidCommand(self):
|
||||||
self.assertNoResponse('%s: foo++' % self.irc.nick, 3)
|
self.assertNoResponse('%s: foo++' % self.irc.nick, 3)
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user