'karma-verbose' -> 'karma-pattern'. don't even parse when false

This commit is contained in:
jesopo 2019-09-12 12:09:16 +01:00
parent 8081a014ce
commit e68c5575d1

View file

@ -10,8 +10,8 @@ KARMA_DELAY_SECONDS = 3
REGEX_KARMA = re.compile(r"^(?:(\S+:) )?(.*)(\+{2}|\-{2})$") REGEX_KARMA = re.compile(r"^(?:(\S+:) )?(.*)(\+{2}|\-{2})$")
@utils.export("channelset", utils.BoolSetting("karma-verbose", @utils.export("channelset", utils.BoolSetting("karma-pattern",
"Enable/disable automatically responding to karma changes")) "Enable/disable parsing ++/-- karma format"))
@utils.export("serverset", utils.BoolSetting("karma-nickname-only", @utils.export("serverset", utils.BoolSetting("karma-nickname-only",
"Enable/disable karma being for nicknames only")) "Enable/disable karma being for nicknames only"))
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
@ -77,18 +77,18 @@ class Module(ModuleManager.BaseModule):
@utils.kwarg("command", "karma") @utils.kwarg("command", "karma")
@utils.kwarg("pattern", REGEX_KARMA) @utils.kwarg("pattern", REGEX_KARMA)
def channel_message(self, event): def channel_message(self, event):
verbose = event["target"].get_setting("karma-verbose", False) pattern = event["target"].get_setting("karma-pattern", False)
positive = event["match"].group(3)[0] == "+" if pattern:
positive = event["match"].group(3)[0] == "+"
target = event["match"].group(2).strip().rstrip("".join(WORD_STOP)) target = event["match"].group(2).strip().rstrip("".join(WORD_STOP))
if event["match"].group(1): if event["match"].group(1):
if not event["server"].has_user(event["match"].group(1)[:-1]): if not event["server"].has_user(event["match"].group(1)[:-1]):
target = "%s %s" % (event["match"].group(1), target) target = "%s %s" % (event["match"].group(1), target)
if target: if target:
success, message = self._karma(event["server"], event["user"], success, message = self._karma(event["server"], event["user"],
target, positive) target, positive)
if verbose:
event["stdout" if success else "stderr"].write(message) event["stdout" if success else "stderr"].write(message)
@utils.hook("received.command.addpoint") @utils.hook("received.command.addpoint")