From 42a858595b1a58cae7383ac3ce6d46f43c64192a Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 12 Oct 2014 12:56:43 -0700 Subject: [PATCH 1/2] Karma: add support configurable chars (picks up where #596 left off) --- plugins/Karma/config.py | 6 +++++ plugins/Karma/locales/fi.po | 2 +- plugins/Karma/locales/fr.po | 2 +- plugins/Karma/locales/it.po | 2 +- plugins/Karma/plugin.py | 48 +++++++++++++++++-------------------- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/plugins/Karma/config.py b/plugins/Karma/config.py index fd505c9cf..376348b20 100644 --- a/plugins/Karma/config.py +++ b/plugins/Karma/config.py @@ -45,6 +45,12 @@ Karma = conf.registerPlugin('Karma') conf.registerChannelValue(Karma, 'simpleOutput', registry.Boolean(False, _("""Determines whether the bot will output shorter 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', registry.Boolean(False, _("""Determines whether the bot will reply with a success message when something's karma is increased or decreased."""))) diff --git a/plugins/Karma/locales/fi.po b/plugins/Karma/locales/fi.po index ae0ad03d6..a5f7c1eea 100644 --- a/plugins/Karma/locales/fi.po +++ b/plugins/Karma/locales/fi.po @@ -67,7 +67,7 @@ msgstr "" msgid "%(thing)s's karma is now %(karma)i" msgstr "%(thing)in karma on nyt %(karma)i" -#: plugin.py:248 plugin.py:257 +#: plugin.py:251 msgid "You're not allowed to adjust your own karma." msgstr "Sinä et saa määrittää omaa karmaasi." diff --git a/plugins/Karma/locales/fr.po b/plugins/Karma/locales/fr.po index ff2952661..a9d37fc36 100644 --- a/plugins/Karma/locales/fr.po +++ b/plugins/Karma/locales/fr.po @@ -62,7 +62,7 @@ msgstr "" msgid "%(thing)s's karma is now %(karma)i" msgstr "Le karma de %(thing)s est maintenant %(karma)i" -#: plugin.py:245 plugin.py:254 +#: plugin.py:251 msgid "You're not allowed to adjust your own karma." msgstr "Vous n'êtes pas autorisé à modifier votre propre karma." diff --git a/plugins/Karma/locales/it.po b/plugins/Karma/locales/it.po index 31cee4f9b..1509b5992 100644 --- a/plugins/Karma/locales/it.po +++ b/plugins/Karma/locales/it.po @@ -55,7 +55,7 @@ msgid "" msgstr "" "Determina se il bot aumenterà o diminuirà il karma senza essere richiamato." -#: plugin.py:247 plugin.py:255 +#: plugin.py:251 msgid "You're not allowed to adjust your own karma." msgstr "Non ti è permesso di modificare il tuo karma." diff --git a/plugins/Karma/plugin.py b/plugins/Karma/plugin.py index 6a50f5103..901b20efb 100644 --- a/plugins/Karma/plugin.py +++ b/plugins/Karma/plugin.py @@ -242,34 +242,31 @@ class Karma(callbacks.Plugin): else: irc.noReply() - def _doKarma(self, irc, channel, thing): - assert thing[-2:] in ('++', '--') - if thing.endswith('++'): - thing = thing[:-2] - if ircutils.strEqual(thing, irc.msg.nick) and \ - not self.registryValue('allowSelfRating', channel): - irc.error(_('You\'re not allowed to adjust your own karma.')) - elif thing: - self.db.increment(channel, self._normalizeThing(thing)) - karma = self.db.get(channel, self._normalizeThing(thing)) - self._respond(irc, channel, thing, karma[0]-karma[1]) - else: - thing = thing[:-2] - if ircutils.strEqual(thing, irc.msg.nick) and \ - not self.registryValue('allowSelfRating', channel): - irc.error(_('You\'re not allowed to adjust your own karma.')) - elif thing: - self.db.decrement(channel, self._normalizeThing(thing)) - karma = self.db.get(channel, self._normalizeThing(thing)) - self._respond(irc, channel, thing, karma[0]-karma[1]) + def _doKarma(self, irc, msg, channel, thing): + inc = self.registryValue('incrementChars', channel) + dec = self.registryValue('decrementChars', channel) + if thing.endswith(tuple(inc + dec)): + if ircutils.strEqual(thing, msg.nick) and \ + not self.registryValue('allowSelfRating', channel): + irc.error(_('You\'re not allowed to adjust your own karma.'), + Raise=True) + for s in inc: + if thing.endswith(s): + thing = thing[:-len(s)] + self.db.increment(channel, self._normalizeThing(thing)) + karma = self.db.get(channel, self._normalizeThing(thing)) + for s in dec: + if thing.endswith(s): + thing = thing[:-len(s)] + self.db.decrement(channel, self._normalizeThing(thing)) + karma = self.db.get(channel, self._normalizeThing(thing)) + self._respond(irc, channel, thing, karma[0]-karma[1]) def invalidCommand(self, irc, msg, tokens): channel = msg.args[0] - if not irc.isChannel(channel) or not tokens: - return - if tokens[-1][-2:] in ('++', '--'): + if irc.isChannel(channel) and tokens: thing = ' '.join(tokens) - self._doKarma(irc, channel, thing) + self._doKarma(irc, msg, channel, thing) def doPrivmsg(self, irc, msg): # We don't handle this if we've been addressed because invalidCommand @@ -282,8 +279,7 @@ class Karma(callbacks.Plugin): self.registryValue('allowUnaddressedKarma', channel): irc = callbacks.SimpleProxy(irc, msg) thing = msg.args[1].rstrip() - if thing[-2:] in ('++', '--'): - self._doKarma(irc, channel, thing) + self._doKarma(irc, msg, channel, thing) @internationalizeDocstring def karma(self, irc, msg, args, channel, things): From 41fb0f8eca3e0b1e6f44210744f5a639e8502449 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 12 Oct 2014 13:22:56 -0700 Subject: [PATCH 2/2] Karma: fix allowSelfRating --- plugins/Karma/locales/fi.po | 2 +- plugins/Karma/locales/fr.po | 2 +- plugins/Karma/locales/it.po | 2 +- plugins/Karma/plugin.py | 12 ++++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/Karma/locales/fi.po b/plugins/Karma/locales/fi.po index a5f7c1eea..4b2e02588 100644 --- a/plugins/Karma/locales/fi.po +++ b/plugins/Karma/locales/fi.po @@ -67,7 +67,7 @@ msgstr "" msgid "%(thing)s's karma is now %(karma)i" msgstr "%(thing)in karma on nyt %(karma)i" -#: plugin.py:251 +#: plugin.py:254 plugin.py:263 msgid "You're not allowed to adjust your own karma." msgstr "Sinä et saa määrittää omaa karmaasi." diff --git a/plugins/Karma/locales/fr.po b/plugins/Karma/locales/fr.po index a9d37fc36..1f87ec5d5 100644 --- a/plugins/Karma/locales/fr.po +++ b/plugins/Karma/locales/fr.po @@ -62,7 +62,7 @@ msgstr "" msgid "%(thing)s's karma is now %(karma)i" msgstr "Le karma de %(thing)s est maintenant %(karma)i" -#: plugin.py:251 +#: plugin.py:254 plugin.py:263 msgid "You're not allowed to adjust your own karma." msgstr "Vous n'êtes pas autorisé à modifier votre propre karma." diff --git a/plugins/Karma/locales/it.po b/plugins/Karma/locales/it.po index 1509b5992..0ff5f1ba7 100644 --- a/plugins/Karma/locales/it.po +++ b/plugins/Karma/locales/it.po @@ -55,7 +55,7 @@ msgid "" msgstr "" "Determina se il bot aumenterà o diminuirà il karma senza essere richiamato." -#: plugin.py:251 +#: plugin.py:254 plugin.py:263 msgid "You're not allowed to adjust your own karma." msgstr "Non ti è permesso di modificare il tuo karma." diff --git a/plugins/Karma/plugin.py b/plugins/Karma/plugin.py index 901b20efb..70f2cdc94 100644 --- a/plugins/Karma/plugin.py +++ b/plugins/Karma/plugin.py @@ -246,18 +246,22 @@ class Karma(callbacks.Plugin): inc = self.registryValue('incrementChars', channel) dec = self.registryValue('decrementChars', channel) if thing.endswith(tuple(inc + dec)): - if ircutils.strEqual(thing, msg.nick) and \ - not self.registryValue('allowSelfRating', channel): - irc.error(_('You\'re not allowed to adjust your own karma.'), - Raise=True) for s in inc: if thing.endswith(s): thing = thing[:-len(s)] + 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.increment(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing)) for s in dec: if thing.endswith(s): thing = thing[:-len(s)] + 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)) self._respond(irc, channel, thing, karma[0]-karma[1])