Merge pull request #872 from GLolol/karma-configurable-chars

Karma: support configurable increment/decrement chars (Closes #596)
This commit is contained in:
Valentin Lorentz 2014-10-13 03:28:49 +02:00
commit cd05f47d04
5 changed files with 35 additions and 29 deletions

View File

@ -45,6 +45,12 @@ Karma = conf.registerPlugin('Karma')
conf.registerChannelValue(Karma, 'simpleOutput', conf.registerChannelValue(Karma, 'simpleOutput',
registry.Boolean(False, _("""Determines whether the bot will output shorter registry.Boolean(False, _("""Determines whether the bot will output shorter
versions of the karma output when requesting a single thing's karma."""))) versions of the karma output when requesting a single thing's karma.""")))
conf.registerChannelValue(Karma, 'incrementChars',
registry.SpaceSeparatedListOfStrings(['++'], _("""A space separated list of
characters to increase karma.""")))
conf.registerChannelValue(Karma, 'decrementChars',
registry.SpaceSeparatedListOfStrings(['--'], _("""A space separated list of
characters to decrease karma.""")))
conf.registerChannelValue(Karma, 'response', conf.registerChannelValue(Karma, 'response',
registry.Boolean(False, _("""Determines whether the bot will reply with a registry.Boolean(False, _("""Determines whether the bot will reply with a
success message when something's karma is increased or decreased."""))) success message when something's karma is increased or decreased.""")))

View File

@ -67,7 +67,7 @@ msgstr ""
msgid "%(thing)s's karma is now %(karma)i" msgid "%(thing)s's karma is now %(karma)i"
msgstr "%(thing)in karma on nyt %(karma)i" msgstr "%(thing)in karma on nyt %(karma)i"
#: plugin.py:248 plugin.py:257 #: plugin.py:254 plugin.py:263
msgid "You're not allowed to adjust your own karma." msgid "You're not allowed to adjust your own karma."
msgstr "Sinä et saa määrittää omaa karmaasi." msgstr "Sinä et saa määrittää omaa karmaasi."

View File

@ -62,7 +62,7 @@ msgstr ""
msgid "%(thing)s's karma is now %(karma)i" msgid "%(thing)s's karma is now %(karma)i"
msgstr "Le karma de %(thing)s est maintenant %(karma)i" msgstr "Le karma de %(thing)s est maintenant %(karma)i"
#: plugin.py:245 plugin.py:254 #: plugin.py:254 plugin.py:263
msgid "You're not allowed to adjust your own karma." msgid "You're not allowed to adjust your own karma."
msgstr "Vous n'êtes pas autorisé à modifier votre propre karma." msgstr "Vous n'êtes pas autorisé à modifier votre propre karma."

View File

@ -55,7 +55,7 @@ msgid ""
msgstr "" msgstr ""
"Determina se il bot aumenterà o diminuirà il karma senza essere richiamato." "Determina se il bot aumenterà o diminuirà il karma senza essere richiamato."
#: plugin.py:247 plugin.py:255 #: plugin.py:254 plugin.py:263
msgid "You're not allowed to adjust your own karma." msgid "You're not allowed to adjust your own karma."
msgstr "Non ti è permesso di modificare il tuo karma." msgstr "Non ti è permesso di modificare il tuo karma."

View File

@ -242,34 +242,35 @@ class Karma(callbacks.Plugin):
else: else:
irc.noReply() irc.noReply()
def _doKarma(self, irc, channel, thing): def _doKarma(self, irc, msg, channel, thing):
assert thing[-2:] in ('++', '--') inc = self.registryValue('incrementChars', channel)
if thing.endswith('++'): dec = self.registryValue('decrementChars', channel)
thing = thing[:-2] if thing.endswith(tuple(inc + dec)):
if ircutils.strEqual(thing, irc.msg.nick) and \ for s in inc:
if thing.endswith(s):
thing = thing[:-len(s)]
if ircutils.strEqual(thing, msg.nick) and \
not self.registryValue('allowSelfRating', channel): 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.'))
elif thing: 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))
self._respond(irc, channel, thing, karma[0]-karma[1]) for s in dec:
else: if thing.endswith(s):
thing = thing[:-2] thing = thing[:-len(s)]
if ircutils.strEqual(thing, irc.msg.nick) and \ if ircutils.strEqual(thing, msg.nick) and \
not self.registryValue('allowSelfRating', channel): 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.'))
elif thing: return
self.db.decrement(channel, self._normalizeThing(thing)) self.db.decrement(channel, self._normalizeThing(thing))
karma = self.db.get(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing))
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):
channel = msg.args[0] channel = msg.args[0]
if not irc.isChannel(channel) or not tokens: if irc.isChannel(channel) and tokens:
return
if tokens[-1][-2:] in ('++', '--'):
thing = ' '.join(tokens) thing = ' '.join(tokens)
self._doKarma(irc, channel, thing) self._doKarma(irc, msg, channel, thing)
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):
# We don't handle this if we've been addressed because invalidCommand # We don't handle this if we've been addressed because invalidCommand
@ -282,8 +283,7 @@ class Karma(callbacks.Plugin):
self.registryValue('allowUnaddressedKarma', channel): self.registryValue('allowUnaddressedKarma', channel):
irc = callbacks.SimpleProxy(irc, msg) irc = callbacks.SimpleProxy(irc, msg)
thing = msg.args[1].rstrip() thing = msg.args[1].rstrip()
if thing[-2:] in ('++', '--'): self._doKarma(irc, msg, channel, thing)
self._doKarma(irc, channel, thing)
@internationalizeDocstring @internationalizeDocstring
def karma(self, irc, msg, args, channel, things): def karma(self, irc, msg, args, channel, things):