SpiffyTitles: urlRegularExpression channel config

This commit is contained in:
oddluck 2020-06-25 02:58:20 +00:00
parent 877deb7a08
commit 407d85ad03
3 changed files with 7 additions and 6 deletions

View File

@ -60,6 +60,7 @@ from imp import reload
# In case we're being reloaded. # In case we're being reloaded.
reload(plugin) reload(plugin)
reload(config)
# Add more reloads here if you add third-party modules and want them to be # Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well! # reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -66,7 +66,7 @@ conf.registerGlobalValue(
) )
# URL regex # URL regex
conf.registerGlobalValue( conf.registerChannelValue(
SpiffyTitles, SpiffyTitles,
"urlRegularExpression", "urlRegularExpression",
registry.String( registry.String(
@ -137,7 +137,7 @@ conf.registerGlobalValue(
False, False,
_( _(
""" """
Keep link cache globally. This will use default values for all link templates Keep link cache globally. This will use global values for all link templates.
""" """
), ),
), ),

View File

@ -35,7 +35,7 @@ import supybot.utils as utils
import supybot.ircdb as ircdb import supybot.ircdb as ircdb
import supybot.log as log import supybot.log as log
import re, sys, random, time, json, unicodedata, datetime import re, sys, random, time, json, unicodedata, datetime
from urllib.parse import urlparse, parse_qsl from urllib.parse import urlparse, parse_qsl, quote
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from jinja2 import Template from jinja2 import Template
import requests import requests
@ -171,7 +171,7 @@ class SpiffyTitles(callbacks.Plugin):
% (channel) % (channel)
) )
return return
urls = self.get_urls_from_message(message) urls = self.get_urls_from_message(message, channel)
if not urls: if not urls:
return return
for url in urls: for url in urls:
@ -559,11 +559,11 @@ class SpiffyTitles(callbacks.Plugin):
) )
return match return match
def get_urls_from_message(self, input): def get_urls_from_message(self, input, channel):
""" """
Find the first string that looks like a URL from the message Find the first string that looks like a URL from the message
""" """
url_re = self.registryValue("urlRegularExpression") url_re = self.registryValue("urlRegularExpression", channel)
matches = re.findall(url_re, input) matches = re.findall(url_re, input)
return matches return matches