Merge pull request #164 from chiefnoah/master

Improves sentence processing for karma
This commit is contained in:
jesopo 2019-09-27 14:32:59 +01:00 committed by GitHub
commit 2493cfa487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,7 +8,7 @@ from src import EventManager, ModuleManager, utils
WORD_STOP = [",", ":"] WORD_STOP = [",", ":"]
KARMA_DELAY_SECONDS = 3 KARMA_DELAY_SECONDS = 3
REGEX_KARMA = re.compile(r"^(?:(\S+:) )?(.*)(\+{2}|\-{2})$") REGEX_KARMA = re.compile(r'(?:\(([^)]+)\)|(\S+))(\+\+|--)(\s+|$)')
@utils.export("channelset", utils.BoolSetting("karma-pattern", @utils.export("channelset", utils.BoolSetting("karma-pattern",
"Enable/disable parsing ++/-- karma format")) "Enable/disable parsing ++/-- karma format"))
@ -78,20 +78,20 @@ class Module(ModuleManager.BaseModule):
@utils.kwarg("pattern", REGEX_KARMA) @utils.kwarg("pattern", REGEX_KARMA)
def channel_message(self, event): def channel_message(self, event):
pattern = event["target"].get_setting("karma-pattern", False) pattern = event["target"].get_setting("karma-pattern", False)
if pattern: if not pattern:
positive = event["match"].group(3)[0] == "+" return
positive = event["match"].group(3) == "++" # if match group 3 is ++, add karma
target = event["match"].group(2).strip().rstrip("".join(WORD_STOP)) # There are two possible match groups, an arbitrary length text inside (), or a single word followed by ++/--
if event["match"].group(1): # group 1 is the former, group 2 is the latter
if not target: target = event["match"].group(1) or event["match"].group(2)
target = event["match"].group(1)[:-1] target = target.strip().rstrip("".join(WORD_STOP)) # Strips "," " " or ":" from target
elif not event["server"].has_user(event["match"].group(1)[:-1]):
target = "%s %s" % (event["match"].group(1), target)
if target: # if we have a target...
success, message = self._karma(event["server"], event["user"], if target:
target, positive) success, message = self._karma(event["server"], event["user"],
event["stdout" if success else "stderr"].write(message) target, positive)
event["stdout" if success else "stderr"].write(message)
@utils.hook("received.command.addpoint") @utils.hook("received.command.addpoint")
@utils.hook("received.command.rmpoint") @utils.hook("received.command.rmpoint")