Allow command.regex hooks to opt-in to being triggered from a /me

closes #68
This commit is contained in:
jesopo 2019-06-16 18:40:25 +01:00
parent 18004c23e1
commit 98e1202c78
8 changed files with 18 additions and 16 deletions

View file

@ -263,19 +263,15 @@ class Module(ModuleManager.BaseModule):
@utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW)
def channel_message(self, event):
if event["action"]:
return
commands_enabled = event["channel"].get_setting("commands", True)
if not commands_enabled:
return
prefixed_commands = event["channel"].get_setting("prefixed-commands", True)
command_prefix = self._command_prefix(event["server"], event["channel"])
command = None
args_split = None
if event["message_split"][0].startswith(command_prefix):
if not prefixed_commands:
if not event["channel"].get_setting("prefixed-commands",True):
return
command = event["message_split"][0].replace(
command_prefix, "", 1).lower()
@ -286,6 +282,9 @@ class Module(ModuleManager.BaseModule):
args_split = event["message_split"][2:]
if command:
if event["action"]:
return
hook, args_split = self._find_command_hook(event["server"], command,
True, args_split)
if hook:
@ -295,8 +294,11 @@ class Module(ModuleManager.BaseModule):
command_prefix=command_prefix)
event["channel"].buffer.skip_next()
else:
regex_hook = self.events.on("command.regex").get_hooks()
for hook in regex_hook:
regex_hooks = self.events.on("command.regex").get_hooks()
for hook in regex_hooks:
if event["action"] and hook.get_kwarg("ignore_action", True):
continue
pattern = hook.get_kwarg("pattern", None)
if not pattern and hook.get_kwarg("pattern-url", None) == "1":
pattern = utils.http.REGEX_URL

View file

@ -44,7 +44,7 @@ class Module(ModuleManager.BaseModule):
if show_duck:
self._trigger_duck(channel)
@utils.hook("command.regex", expect_output=False)
@utils.hook("command.regex", expect_output=False, ignore_action=False)
def channel_message(self, event):
"""
:pattern: .+

View file

@ -26,7 +26,7 @@ class Module(ModuleManager.BaseModule):
raise utils.EventError("Unknown factoid '%s'" % name)
event["stdout"].write("%s: %s" % (name, value))
@utils.hook("command.regex")
@utils.hook("command.regex", ignore_action=False)
def channel_message(self, event):
"""
:command: factoid

View file

@ -252,7 +252,7 @@ class Module(ModuleManager.BaseModule):
else:
return True
@utils.hook("command.regex")
@utils.hook("command.regex", ignore_action=False)
def url_regex(self, event):
"""
:command: github
@ -272,7 +272,7 @@ class Module(ModuleManager.BaseModule):
event["stdout"].hide_prefix()
event["stdout"].write(result)
@utils.hook("command.regex")
@utils.hook("command.regex", ignore_action=False)
def ref_regex(self, event):
"""
:command: github

View file

@ -28,7 +28,7 @@ class Module(ModuleManager.BaseModule):
text += "%s " % data["account_url"]
return text
@utils.hook("command.regex", pattern=REGEX_IMAGE)
@utils.hook("command.regex", pattern=REGEX_IMAGE, ignore_action=False)
def _regex_image(self, event):
"""
:command: imgur
@ -36,7 +36,7 @@ class Module(ModuleManager.BaseModule):
if event["target"].get_setting("auto-imgur", False):
event["stdout"].write(self._parse_image(event["match"].group(1)))
event.eat()
@utils.hook("command.regex", pattern=REGEX_GALLERY)
@utils.hook("command.regex", pattern=REGEX_GALLERY, ignore_action=False)
def _regex_gallery(self, event):
"""
:command: imgur

View file

@ -47,7 +47,7 @@ class Module(ModuleManager.BaseModule):
else:
return None
@utils.hook("command.regex",
@utils.hook("command.regex", ignore_action=False,
priority=EventManager.PRIORITY_MONITOR)
def channel_message(self, event):
"""

View file

@ -166,7 +166,7 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No tweet provided to get information about")
@utils.hook("command.regex", pattern=REGEX_TWITTERURL)
@utils.hook("command.regex", pattern=REGEX_TWITTERURL, ignore_action=False)
def regex(self, event):
"""
:command: tweet

View file

@ -130,7 +130,7 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No search phrase provided")
@utils.hook("command.regex",
@utils.hook("command.regex", ignore_action=False,
priority=EventManager.PRIORITY_LOW)
def channel_message(self, event):
"""