aboutsummaryrefslogtreecommitdiff
path: root/modules/youtube.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-05-18 18:35:47 +0100
committerGravatar jesopo2019-05-18 18:35:47 +0100
commit4e0e63e7f8b518190c94b6374e01291e9eda9f69 (patch)
treec936e38c5d823508c9eb23ac8df1a0d23f063a3f /modules/youtube.py
parentgive EventCallbacks their event name (diff)
signature
Hand over regex-based-command responsibilities to `commands` module
Diffstat (limited to 'modules/youtube.py')
-rw-r--r--modules/youtube.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/modules/youtube.py b/modules/youtube.py
index f29250db..8f01fd45 100644
--- a/modules/youtube.py
+++ b/modules/youtube.py
@@ -125,20 +125,17 @@ class Module(ModuleManager.BaseModule):
else:
event["stderr"].write("No search phrase provided")
- @utils.hook("received.message.channel",
+ @utils.hook("command.regex",
priority=EventManager.PRIORITY_LOW)
def channel_message(self, event):
- match = re.search(REGEX_YOUTUBE, event["message"])
- if match and event["channel"].get_setting("auto-youtube", False):
- is_ignored_f = short_url = self.exports.get_one("is-ignored",
- lambda _1, _2: False)
- if is_ignored_f(event["server"], event["user"], "youtube"):
- return
-
- youtube_id = match.group(1)
+ """
+ :command: youtube
+ :-pattern: https?://(?:www.)?
+ (?:youtu.be/|youtube.com/watch\?[\S]*v=)([\w\-]{11})
+ """
+ if event["target"].get_setting("auto-youtube", False):
+ youtube_id = event["match"].group(1)
video_details = self.video_details(youtube_id)
if video_details:
- self.events.on("send.stdout").call(target=event["channel"],
- message=video_details, module_name="Youtube",
- server=event["server"])
+ event["stdout"].write(video_details)
event.eat()