mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-03 08:04: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',
|
conf.registerChannelValue(Karma, 'allowUnaddressedKarma',
|
||||||
registry.Boolean(True, _("""Determines whether the bot will
|
registry.Boolean(True, _("""Determines whether the bot will
|
||||||
increase/decrease karma without being addressed.""")))
|
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:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -246,25 +246,34 @@ class Karma(callbacks.Plugin):
|
|||||||
def _doKarma(self, irc, msg, channel, thing):
|
def _doKarma(self, irc, msg, channel, thing):
|
||||||
inc = self.registryValue('incrementChars', channel)
|
inc = self.registryValue('incrementChars', channel)
|
||||||
dec = self.registryValue('decrementChars', channel)
|
dec = self.registryValue('decrementChars', channel)
|
||||||
if thing.endswith(tuple(inc + dec)):
|
onlynicks = self.registryValue('onlyNicks', channel)
|
||||||
for s in inc:
|
karma = ''
|
||||||
if thing.endswith(s):
|
for s in inc:
|
||||||
thing = thing[:-len(s)]
|
if thing.endswith(s):
|
||||||
if ircutils.strEqual(thing, msg.nick) and \
|
thing = thing[:-len(s)]
|
||||||
not self.registryValue('allowSelfRating', channel):
|
# 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.'))
|
irc.error(_('You\'re not allowed to adjust your own karma.'))
|
||||||
return
|
return
|
||||||
self.db.increment(channel, self._normalizeThing(thing))
|
self.db.increment(channel, self._normalizeThing(thing))
|
||||||
karma = self.db.get(channel, self._normalizeThing(thing))
|
karma = self.db.get(channel, self._normalizeThing(thing))
|
||||||
for s in dec:
|
for s in dec:
|
||||||
if thing.endswith(s):
|
if thing.endswith(s):
|
||||||
thing = thing[:-len(s)]
|
thing = thing[:-len(s)]
|
||||||
if ircutils.strEqual(thing, msg.nick) and \
|
if onlynicks and thing.lower() not in map(ircutils.toLower,
|
||||||
not self.registryValue('allowSelfRating', channel):
|
irc.state.channels[channel].users):
|
||||||
irc.error(_('You\'re not allowed to adjust your own karma.'))
|
return
|
||||||
return
|
if ircutils.strEqual(thing, msg.nick) and \
|
||||||
self.db.decrement(channel, self._normalizeThing(thing))
|
not self.registryValue('allowSelfRating', channel):
|
||||||
karma = self.db.get(channel, self._normalizeThing(thing))
|
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])
|
self._respond(irc, channel, thing, karma[0]-karma[1])
|
||||||
|
|
||||||
def invalidCommand(self, irc, msg, tokens):
|
def invalidCommand(self, irc, msg, tokens):
|
||||||
|
@ -204,4 +204,21 @@ class KarmaTestCase(ChannelPluginTestCase):
|
|||||||
karma.response.setValue(resp)
|
karma.response.setValue(resp)
|
||||||
karma.allowUnaddressedKarma.setValue(unaddressed)
|
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:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
Reference in New Issue
Block a user