aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2019-10-03 13:20:03 +0100
committerGravatar jesopo2019-10-03 13:20:35 +0100
commitcee29ba1a568e684aa03bfe6094c7b1b23fae9fd (patch)
treee218d1fd0766fcecab93f39c8c4e6e119dbfacd8 /modules
parentadd !ghcommit and @commit auto-github syntax (diff)
signature
split words/parens karma in to 2 regexes, only accept non-parens when ^$
closes #169
Diffstat (limited to 'modules')
-rw-r--r--modules/karma.py26
1 files changed, 9 insertions, 17 deletions
diff --git a/modules/karma.py b/modules/karma.py
index 887f18d6..220d2f63 100644
--- a/modules/karma.py
+++ b/modules/karma.py
@@ -5,10 +5,10 @@
import re, time
from src import EventManager, ModuleManager, utils
-WORD_STOP = [",", ":"]
KARMA_DELAY_SECONDS = 3
-REGEX_KARMA = re.compile(r'(?:\(([^)]+)\)|(\S+))\s*(\+\+|--)(\s+|$)')
+REGEX_WORD = re.compile(r"^([^(\s]+)[:,]?\s*(\+\+|--)\s*$")
+REGEX_PARENS = re.compile(r"\(([^)]+)\)\s*(\+\+|--)")
@utils.export("channelset", utils.BoolSetting("karma-pattern",
"Enable/disable parsing ++/-- karma format"))
@@ -73,26 +73,18 @@ class Module(ModuleManager.BaseModule):
else:
return False, "Try again in a couple of seconds"
- @utils.hook("command.regex")
+ @utils.hook("command.regex", pattern=REGEX_WORD)
+ @utils.hook("command.regex", pattern=REGEX_PARENS)
@utils.kwarg("command", "karma")
- @utils.kwarg("pattern", REGEX_KARMA)
- def channel_message(self, event):
- pattern = event["target"].get_setting("karma-pattern", False)
- if not pattern:
- return
- positive = event["match"].group(3) == "++" # if match group 3 is ++, add karma
-
- # There are two possible match groups, an arbitrary length text inside (), or a single word followed by ++/--
- # group 1 is the former, group 2 is the latter
- target = event["match"].group(1) or event["match"].group(2)
- target = target.strip().rstrip("".join(WORD_STOP)) # Strips "," " " or ":" from target
-
- # if we have a target...
- if target:
+ def regex_word(self, event):
+ if event["target"].get_setting("karma-pattern", False):
+ target = event["match"].group(1)
+ positive = event["match"].group(2)=="++"
success, message = self._karma(event["server"], event["user"],
target, positive)
event["stdout" if success else "stderr"].write(message)
+
@utils.hook("received.command.addpoint")
@utils.hook("received.command.rmpoint")
@utils.kwarg("min_args", 1)