mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 23:54:07 +01:00
Merge pull request #1004 from GLolol/karma/nicks-only
Karma: add an option to limit Karma to nicks
This commit is contained in:
commit
fa7ef570c0
@ -66,5 +66,8 @@ conf.registerChannelValue(Karma, 'allowSelfRating',
|
||||
conf.registerChannelValue(Karma, 'allowUnaddressedKarma',
|
||||
registry.Boolean(True, _("""Determines whether the bot will
|
||||
increase/decrease karma without being addressed.""")))
|
||||
conf.registerChannelValue(Karma, 'onlyNicks',
|
||||
registry.Boolean(False, _("""Determines whether the bot will
|
||||
only increase/decrease karma for nicks in the current channel.""")))
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
@ -246,10 +246,15 @@ class Karma(callbacks.Plugin):
|
||||
def _doKarma(self, irc, msg, channel, thing):
|
||||
inc = self.registryValue('incrementChars', channel)
|
||||
dec = self.registryValue('decrementChars', channel)
|
||||
if thing.endswith(tuple(inc + dec)):
|
||||
onlynicks = self.registryValue('onlyNicks', channel)
|
||||
karma = ''
|
||||
for s in inc:
|
||||
if thing.endswith(s):
|
||||
thing = thing[:-len(s)]
|
||||
# Don't reply if the target isn't a nick
|
||||
if onlynicks and thing.lower() not in map(ircutils.toLower,
|
||||
irc.state.channels[channel].users):
|
||||
return
|
||||
if ircutils.strEqual(thing, msg.nick) and \
|
||||
not self.registryValue('allowSelfRating', channel):
|
||||
irc.error(_('You\'re not allowed to adjust your own karma.'))
|
||||
@ -259,12 +264,16 @@ class Karma(callbacks.Plugin):
|
||||
for s in dec:
|
||||
if thing.endswith(s):
|
||||
thing = thing[:-len(s)]
|
||||
if onlynicks and thing.lower() not in map(ircutils.toLower,
|
||||
irc.state.channels[channel].users):
|
||||
return
|
||||
if ircutils.strEqual(thing, msg.nick) and \
|
||||
not self.registryValue('allowSelfRating', channel):
|
||||
irc.error(_('You\'re not allowed to adjust your own karma.'))
|
||||
return
|
||||
self.db.decrement(channel, self._normalizeThing(thing))
|
||||
karma = self.db.get(channel, self._normalizeThing(thing))
|
||||
if karma:
|
||||
self._respond(irc, channel, thing, karma[0]-karma[1])
|
||||
|
||||
def invalidCommand(self, irc, msg, tokens):
|
||||
|
@ -204,4 +204,21 @@ class KarmaTestCase(ChannelPluginTestCase):
|
||||
karma.response.setValue(resp)
|
||||
karma.allowUnaddressedKarma.setValue(unaddressed)
|
||||
|
||||
def testOnlyNicks(self):
|
||||
# We use this to join a dummy user to test upon
|
||||
msg = ircmsgs.join(self.channel, prefix='hello!foo@bar')
|
||||
self.irc.feedMsg(msg)
|
||||
karma = conf.supybot.plugins.Karma
|
||||
resp = karma.response()
|
||||
onlynicks = karma.onlyNicks()
|
||||
try:
|
||||
karma.onlynicks.setValue(True)
|
||||
karma.response.setValue(True)
|
||||
self.assertSnarfNoResponse('abcd++')
|
||||
self.assertSnarfRegexp('hello--', 'is now')
|
||||
self.assertSnarfNoResponse('abcd--')
|
||||
self.assertSnarfRegexp('hello++', 'is now')
|
||||
finally:
|
||||
karma.onlynicks.setValue(onlynicks)
|
||||
karma.response.setValue(resp)
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
Reference in New Issue
Block a user