more generic youtube matcher
This commit is contained in:
parent
9e0feffc3c
commit
51df207701
@ -39,7 +39,7 @@
|
||||
},
|
||||
{
|
||||
"name": "urlreply",
|
||||
"version": "1.0.5"
|
||||
"version": "1.0.6"
|
||||
},
|
||||
{
|
||||
"name": "utility",
|
||||
|
@ -2,7 +2,7 @@
|
||||
"main": "plugin.js",
|
||||
"name": "urlreply",
|
||||
"description": "Fetch titles from web pages, specifically made for IRC",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"tags": ["irc"],
|
||||
"dependencies": [],
|
||||
"npmDependencies": ["cheerio@^1.0.0-rc.10"]
|
||||
|
@ -245,7 +245,7 @@ class URLReplyPlugin extends Plugin {
|
||||
htmlHandlers = [];
|
||||
|
||||
// YouTube
|
||||
this.registerHandler(this.name, 'youtube.com/', async (url: urllib.URL, msg: IMessage, data: any) => {
|
||||
this.registerHandler(this.name, '/watch\\?v=', async (url: urllib.URL, msg: IMessage, data: any) => {
|
||||
const det = url.searchParams.get('v');
|
||||
|
||||
if (!det) {
|
||||
@ -304,7 +304,7 @@ class URLReplyPlugin extends Plugin {
|
||||
// Find handlers matching this URL
|
||||
for (const handler in urlHandlers) {
|
||||
const obj = urlHandlers[handler];
|
||||
if (url.indexOf(handler) !== -1 || !obj.action) {
|
||||
if (!!url.match(handler) || !obj.action) {
|
||||
try {
|
||||
const urlParsed = new urllib.URL(url);
|
||||
|
||||
@ -313,6 +313,9 @@ class URLReplyPlugin extends Plugin {
|
||||
logger.error(e.stack);
|
||||
matched = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -320,7 +323,9 @@ class URLReplyPlugin extends Plugin {
|
||||
// If there were no matches, pull the title of the website
|
||||
if (!matched) {
|
||||
try {
|
||||
const data = await httpGET(url, {}, true);
|
||||
const data = await httpGET(url, {
|
||||
Accept: 'text/html,application/xhtml+xml,application/xml'
|
||||
}, true);
|
||||
if (!data) { return; }
|
||||
|
||||
const full = cheerio.load(data);
|
||||
|
Loading…
Reference in New Issue
Block a user