SpiffyTitles: update userAgents config

This commit is contained in:
oddluck 2020-03-04 18:56:57 +00:00
parent 8148e46953
commit 59952683a4
4 changed files with 30 additions and 30 deletions

View File

@ -23,7 +23,7 @@ The ONLY gluten-free plugin for displaying link titles.
- Rate limiting to mitigate abuse
- Configurable white/black list to control where titles are disabled
- MIME type and size info for file links
- Random selection of current useragents using fake-useragent
- Configurable list of user agents
- Ability to ignore domains using a regular expression
Check out the [available options](#available-options)!
@ -294,6 +294,18 @@ titles will be shown in all channels. Default value: `""`
`badLinkText` - The text to return when unable to retrieve a title from a URL. Default value: `Nice link idiot.`
`userAgents` - A comma separated list of strings of user agents randomly chosen when requesting.
`urlRegularExpression` - A regular expression used to match URLs. You shouldn't need to change this.
`linkMessageIgnorePattern` - If a message matches this pattern, it will be ignored. This differs from ignoredDomainPattern in that it compares against the entire message rather than just the domain.
`ignoreActionLinks` (Boolean) - By default SpiffyTitles will ignore links that appear in an action, like /me.
`requireCapability` (String) - If defined, SpiffyTitles will only acknowledge links from users with this capability. Useful for hostile environments. Refer to [Limnoria's documentation on capabilities](http://doc.supybot.aperio.fr/en/latest/use/capabilities.html) for more information
`ignoredTitlePattern` (Regexp) - If the parsed title matches this regular expression, it will be ignored.
### About white/black lists
- Channel names must be in lowercase
- If `channelWhitelist` and `channelBlacklist` are empty, then titles will be displayed in every channel
@ -318,10 +330,6 @@ titles will be shown in all channels. Default value: `""`
!config supybot.plugins.SpiffyTitles.channelWhitelist ""
`ignoredDomainPattern` - ignore domains matching this pattern. Default value: `""`
`whitelistDomainPattern` - ignore any link without a domain matching this pattern. Default value: `""`
### Pro Tip
You can ignore domains that you know aren't websites. This prevents a request from being made at all.
@ -340,23 +348,13 @@ Ignore all links except youtube, imgur, and reddit
!config supybot.plugins.SpiffyTitles.whitelistDomainPattern /(reddit\.com|youtube\.com|youtu\.be|imgur\.com)/
`urlRegularExpression` - A regular expression used to match URLs. You shouldn't need to change this.
Ignore any message that contains "[tw]".
`linkMessageIgnorePattern` - If a message matches this pattern, it will be ignored. This differs from `ignoredDomainPattern` in that it compares against the entire message rather than just the domain.
!config supybot.plugins.SpiffyTitles.linkMessageIgnorePattern "/\[tw\]/"
Example: `!config supybot.plugins.SpiffyTitles.linkMessageIgnorePattern "/\[tw\]/"`
Ignore any link which results in a title matching a pattern.
This would ignore any message that contains "[tw]".
`ignoreActionLinks` (Boolean) - By default SpiffyTitles will ignore links that appear in an action, like `/me`.
`requireCapability` (String) - If defined, SpiffyTitles will only acknowledge links from users with this capability. Useful for hostile environments. [Refer to Limnoria's documentation on capabilities for more information](http://doc.supybot.aperio.fr/en/latest/use/capabilities.html)
`ignoredTitlePattern` (Regexp) - If the parsed title matches this regular expression, it will be ignored.
Example: `!config channel #example supybot.plugins.SpiffyTitles.ignoredTitlePattern m/^\^ Google$|- Google Search$|^\^ Google Maps$|^\^ Imgur: The most awesome images on the Internet$|^\^ Pastebin \| IRCCloud|^\^ Instagram|^\^ Urban Dictionary:| Wikipedia$|- Wikipedia, the free encyclopedia$|- Wiktionary$| - RationalWiki$|^\^ Meet Google Drive|- Wikia$|^\^ Imgur$|^\^ Google Trends|^\^ reactiongifs/`
This line would ignore any link which results in a title matching the above pattern.
!config channel #example supybot.plugins.SpiffyTitles.ignoredTitlePattern m/^\^ Google$|- Google Search$|^\^ Google Maps$|^\^ Imgur: The most awesome images on the Internet$|^\^ Pastebin \| IRCCloud|^\^ Instagram|^\^ Urban Dictionary:| Wikipedia$|- Wikipedia, the free encyclopedia$|- Wiktionary$| - RationalWiki$|^\^ Meet Google Drive|- Wikia$|^\^ Imgur$|^\^ Google Trends|^\^ reactiongifs/
### FAQ

View File

@ -69,10 +69,14 @@ conf.registerChannelValue(SpiffyTitles, 'useBold',
registry.Boolean(False, _("""Use bold in titles""")))
# User agents
conf.registerGlobalValue(SpiffyTitles, 'userAgents',
registry.CommaSeparatedListOfStrings(["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0"], _("""Reported user agent when fetching links""")))
# Bad link text
conf.registerChannelValue(SpiffyTitles, 'badLinkText',
registry.String("Nice link idiot.", _("""Title to return for bad/unsnarfable links.""")))
# Mime Types
# Mime types
conf.registerGlobalValue(SpiffyTitles, 'mimeTypes',
registry.CommaSeparatedListOfStrings(["text/html"], _("""Acceptable mime types for displaying titles""")))

View File

@ -48,7 +48,6 @@ import unicodedata
import supybot.ircdb as ircdb
import supybot.log as log
import pendulum
from fake_useragent import UserAgent
try:
from supybot.i18n import PluginInternationalization
@ -160,7 +159,7 @@ class SpiffyTitles(callbacks.Plugin):
api_url = "https://api.dailymotion.com/video/%s?fields=%s" % (video_id, fields)
log.debug("SpiffyTitles: looking up dailymotion info: %s", api_url)
headers = self.get_headers()
request = requests.get(api_url, headers=headers)
request = requests.get(api_url, headers=headers, timeout=10)
ok = request.status_code == requests.codes.ok
@ -211,7 +210,7 @@ class SpiffyTitles(callbacks.Plugin):
api_url = "https://vimeo.com/api/v2/video/%s.json" % video_id
log.debug("SpiffyTitles: looking up vimeo info: %s", api_url)
headers = self.get_headers()
request = requests.get(api_url, headers=headers)
request = requests.get(api_url, headers=headers, timeout=10)
ok = request.status_code == requests.codes.ok
@ -273,7 +272,7 @@ class SpiffyTitles(callbacks.Plugin):
api_url = "http://coub.com/api/v2/coubs/%s" % video_id
headers = self.get_headers()
request = requests.get(api_url, headers=headers)
request = requests.get(api_url, headers=headers, timeout=10)
ok = request.status_code == requests.codes.ok
@ -656,7 +655,7 @@ class SpiffyTitles(callbacks.Plugin):
log.debug("SpiffyTitles: requesting %s" % (api_url))
request = requests.get(api_url, headers=headers)
request = requests.get(api_url, headers=headers, timeout=10)
ok = request.status_code == requests.codes.ok
if ok:
@ -1200,7 +1199,7 @@ class SpiffyTitles(callbacks.Plugin):
self.log.debug("SpiffyTitles: requesting %s" % (api_url))
request = requests.get(api_url, headers=headers)
request = requests.get(api_url, headers=headers, timeout=10)
ok = request.status_code == requests.codes.ok
if ok:
@ -1275,7 +1274,7 @@ class SpiffyTitles(callbacks.Plugin):
self.log.debug("SpiffyTitles: requesting %s" % (data_url))
request = requests.get(data_url, headers=headers)
request = requests.get(data_url, headers=headers, timeout=10)
ok = request.status_code == requests.codes.ok
data = {}
extract = ''
@ -1664,8 +1663,8 @@ class SpiffyTitles(callbacks.Plugin):
"""
Returns a random user agent from the ones available
"""
ua = UserAgent(fallback="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0")
return str(ua.random)
agents = self.registryValue("userAgents")
return random.choice(agents)
def message_matches_ignore_pattern(self, input):
"""

View File

@ -7,4 +7,3 @@ requests
timeout-decorator
certifi
pendulum
fake-useragent