Allow command.regex hooks to opt-in to being triggered from a /me
closes #68
This commit is contained in:
parent
18004c23e1
commit
98e1202c78
8 changed files with 18 additions and 16 deletions
|
@ -263,19 +263,15 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
@utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW)
|
@utils.hook("received.message.channel", priority=EventManager.PRIORITY_LOW)
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
if event["action"]:
|
|
||||||
return
|
|
||||||
|
|
||||||
commands_enabled = event["channel"].get_setting("commands", True)
|
commands_enabled = event["channel"].get_setting("commands", True)
|
||||||
if not commands_enabled:
|
if not commands_enabled:
|
||||||
return
|
return
|
||||||
prefixed_commands = event["channel"].get_setting("prefixed-commands", True)
|
|
||||||
|
|
||||||
command_prefix = self._command_prefix(event["server"], event["channel"])
|
command_prefix = self._command_prefix(event["server"], event["channel"])
|
||||||
command = None
|
command = None
|
||||||
args_split = None
|
args_split = None
|
||||||
if event["message_split"][0].startswith(command_prefix):
|
if event["message_split"][0].startswith(command_prefix):
|
||||||
if not prefixed_commands:
|
if not event["channel"].get_setting("prefixed-commands",True):
|
||||||
return
|
return
|
||||||
command = event["message_split"][0].replace(
|
command = event["message_split"][0].replace(
|
||||||
command_prefix, "", 1).lower()
|
command_prefix, "", 1).lower()
|
||||||
|
@ -286,6 +282,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
args_split = event["message_split"][2:]
|
args_split = event["message_split"][2:]
|
||||||
|
|
||||||
if command:
|
if command:
|
||||||
|
if event["action"]:
|
||||||
|
return
|
||||||
|
|
||||||
hook, args_split = self._find_command_hook(event["server"], command,
|
hook, args_split = self._find_command_hook(event["server"], command,
|
||||||
True, args_split)
|
True, args_split)
|
||||||
if hook:
|
if hook:
|
||||||
|
@ -295,8 +294,11 @@ class Module(ModuleManager.BaseModule):
|
||||||
command_prefix=command_prefix)
|
command_prefix=command_prefix)
|
||||||
event["channel"].buffer.skip_next()
|
event["channel"].buffer.skip_next()
|
||||||
else:
|
else:
|
||||||
regex_hook = self.events.on("command.regex").get_hooks()
|
regex_hooks = self.events.on("command.regex").get_hooks()
|
||||||
for hook in regex_hook:
|
for hook in regex_hooks:
|
||||||
|
if event["action"] and hook.get_kwarg("ignore_action", True):
|
||||||
|
continue
|
||||||
|
|
||||||
pattern = hook.get_kwarg("pattern", None)
|
pattern = hook.get_kwarg("pattern", None)
|
||||||
if not pattern and hook.get_kwarg("pattern-url", None) == "1":
|
if not pattern and hook.get_kwarg("pattern-url", None) == "1":
|
||||||
pattern = utils.http.REGEX_URL
|
pattern = utils.http.REGEX_URL
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if show_duck:
|
if show_duck:
|
||||||
self._trigger_duck(channel)
|
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):
|
def channel_message(self, event):
|
||||||
"""
|
"""
|
||||||
:pattern: .+
|
:pattern: .+
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
raise utils.EventError("Unknown factoid '%s'" % name)
|
raise utils.EventError("Unknown factoid '%s'" % name)
|
||||||
event["stdout"].write("%s: %s" % (name, value))
|
event["stdout"].write("%s: %s" % (name, value))
|
||||||
|
|
||||||
@utils.hook("command.regex")
|
@utils.hook("command.regex", ignore_action=False)
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
"""
|
"""
|
||||||
:command: factoid
|
:command: factoid
|
||||||
|
|
|
@ -252,7 +252,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@utils.hook("command.regex")
|
@utils.hook("command.regex", ignore_action=False)
|
||||||
def url_regex(self, event):
|
def url_regex(self, event):
|
||||||
"""
|
"""
|
||||||
:command: github
|
:command: github
|
||||||
|
@ -272,7 +272,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
event["stdout"].hide_prefix()
|
event["stdout"].hide_prefix()
|
||||||
event["stdout"].write(result)
|
event["stdout"].write(result)
|
||||||
|
|
||||||
@utils.hook("command.regex")
|
@utils.hook("command.regex", ignore_action=False)
|
||||||
def ref_regex(self, event):
|
def ref_regex(self, event):
|
||||||
"""
|
"""
|
||||||
:command: github
|
:command: github
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
text += "%s " % data["account_url"]
|
text += "%s " % data["account_url"]
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@utils.hook("command.regex", pattern=REGEX_IMAGE)
|
@utils.hook("command.regex", pattern=REGEX_IMAGE, ignore_action=False)
|
||||||
def _regex_image(self, event):
|
def _regex_image(self, event):
|
||||||
"""
|
"""
|
||||||
:command: imgur
|
:command: imgur
|
||||||
|
@ -36,7 +36,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if event["target"].get_setting("auto-imgur", False):
|
if event["target"].get_setting("auto-imgur", False):
|
||||||
event["stdout"].write(self._parse_image(event["match"].group(1)))
|
event["stdout"].write(self._parse_image(event["match"].group(1)))
|
||||||
event.eat()
|
event.eat()
|
||||||
@utils.hook("command.regex", pattern=REGEX_GALLERY)
|
@utils.hook("command.regex", pattern=REGEX_GALLERY, ignore_action=False)
|
||||||
def _regex_gallery(self, event):
|
def _regex_gallery(self, event):
|
||||||
"""
|
"""
|
||||||
:command: imgur
|
:command: imgur
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@utils.hook("command.regex",
|
@utils.hook("command.regex", ignore_action=False,
|
||||||
priority=EventManager.PRIORITY_MONITOR)
|
priority=EventManager.PRIORITY_MONITOR)
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -166,7 +166,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("No tweet provided to get information about")
|
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):
|
def regex(self, event):
|
||||||
"""
|
"""
|
||||||
:command: tweet
|
:command: tweet
|
||||||
|
|
|
@ -130,7 +130,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("No search phrase provided")
|
event["stderr"].write("No search phrase provided")
|
||||||
|
|
||||||
@utils.hook("command.regex",
|
@utils.hook("command.regex", ignore_action=False,
|
||||||
priority=EventManager.PRIORITY_LOW)
|
priority=EventManager.PRIORITY_LOW)
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue