Skip to content

Commit

Permalink
Allow command.regex hooks to opt-in to being triggered from a /me
Browse files Browse the repository at this point in the history
closes #68
  • Loading branch information
jesopo committed Jun 16, 2019
1 parent 18004c2 commit 98e1202
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
16 changes: 9 additions & 7 deletions modules/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,15 @@ def _command_prefix(self, server, channel):

@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()
Expand All @@ -286,6 +282,9 @@ def channel_message(self, event):
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:
Expand All @@ -295,8 +294,11 @@ def channel_message(self, event):
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
Expand Down
2 changes: 1 addition & 1 deletion modules/ducks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _activity(self, channel):
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: .+
Expand Down
2 changes: 1 addition & 1 deletion modules/factoids.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def factoid(self, event):
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
Expand Down
4 changes: 2 additions & 2 deletions modules/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _auto_github_cooldown(self, channel, ref):
else:
return True

@utils.hook("command.regex")
@utils.hook("command.regex", ignore_action=False)
def url_regex(self, event):
"""
:command: github
Expand All @@ -272,7 +272,7 @@ def url_regex(self, event):
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
Expand Down
4 changes: 2 additions & 2 deletions modules/imgur.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def _prefix(self, data):
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
"""
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
Expand Down
2 changes: 1 addition & 1 deletion modules/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_title(self, channel, url):
else:
return None

@utils.hook("command.regex",
@utils.hook("command.regex", ignore_action=False,
priority=EventManager.PRIORITY_MONITOR)
def channel_message(self, event):
"""
Expand Down
2 changes: 1 addition & 1 deletion modules/tweets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def tweet(self, event):
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
Expand Down
2 changes: 1 addition & 1 deletion modules/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def yt(self, event):
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):
"""
Expand Down

0 comments on commit 98e1202

Please sign in to comment.