From a80fb80319611e290d7a9bad72fd23353478bb94 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 29 Jul 2017 21:13:32 +0100 Subject: [PATCH] Allow matching in middle of sentence --- dave/modules/reddit.py | 8 ++++++-- dave/modules/speedtest.py | 2 +- dave/modules/youtube.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dave/modules/reddit.py b/dave/modules/reddit.py index d3a50e7..1d519e9 100644 --- a/dave/modules/reddit.py +++ a/dave/modules/reddit.py @@ -7,8 +7,8 @@ from requests import get from humanize import naturaltime, naturaldelta, intcomma -@dave.module.match(r'(?:https?://(?:www\.)?reddit.com)?(/r/(.+)/comments/([^\s]+))') -@dave.module.match(r'https?://(?:www\.)?redd.it/([^\s]+)') +@dave.module.match(r'.*(?:https?://(?:www\.)?reddit.com)?(/r/(.+)/comments/([^\s]+)).*') +@dave.module.match(r'.*https?://(?:www\.)?redd.it/([^\s]+).*') @dave.module.dont_always_run_if_run() def post(bot, args, sender, source): """Ran whenever a reddit post is sent""" @@ -43,7 +43,7 @@ ] )) -@dave.module.match(r'(?:https?://(?:www\.)?reddit.com)?/?r/(([^\s/]+))/?(?: |$)') +@dave.module.match(r'.*(?:https?://(?:www\.)?reddit.com)?/?r/(([^\s/]+))/?(?: |$).*') @dave.module.dont_always_run_if_run() def subreddit(bot, args, sender, source): """Ran whenever a subreddit is mentioned""" @@ -82,7 +82,7 @@ )) -@dave.module.match(r'(?:https?://(?:www\.)?reddit.com)?/?(?:u|user)/(([^\s]+)/?)(?: |$)') +@dave.module.match(r'.*(?:https?://(?:www\.)?reddit.com)?/?(?:u|user)/(([^\s]+)/?)(?: |$).*') @dave.module.dont_always_run_if_run() def user(bot, args, sender, source): if not dave.config.redis.exists("reddit:user:{}".format(args[0])): diff --git a/dave/modules/speedtest.py b/dave/modules/speedtest.py index 77123d9..8c520ee 100644 --- a/dave/modules/speedtest.py +++ a/dave/modules/speedtest.py @@ -1,10 +1,10 @@ """Read details from a speedtest test and print them to the channel.""" from requests import get from bs4 import BeautifulSoup import dave.module from twisted.words.protocols.irc import assembleFormattedText, attributes as A -@dave.module.match(r'https?://(?:www\.|beta\.)?speedtest\.net/(?:my-)?result/([0-9]+)(?:.png)?') +@dave.module.match(r'.*https?://(?:www\.|beta\.)?speedtest\.net/(?:my-)?result/([0-9]+)(?:.png)?.*') @dave.module.dont_always_run_if_run() def speedtest(bot, args, sender, source): res = get("http://www.speedtest.net/result/{}".format(args[0]), timeout=3) diff --git a/dave/modules/youtube.py b/dave/modules/youtube.py index 17ebdf3..a438f69 100644 --- a/dave/modules/youtube.py +++ a/dave/modules/youtube.py @@ -11,7 +11,7 @@ BASE_URL = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet," \ "statistics&key={}".format(dave.config.config["api_keys"]["youtube"]) -@dave.module.match(r'http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?‌​[\w\?‌​=]*)?') +@dave.module.match(r'.*https?://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)([\w\-\_]*)(&(amp;)?[\w\=]*)?.*') @dave.module.dont_always_run_if_run() def youtubevideo(bot, args, sender, source): """Ran whenever a YouTube video is sent""" -- rgit 0.1.3