From 51df20770179b0e064ee4729f661d49bf7342260 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Tue, 4 Oct 2022 18:51:58 +0300 Subject: [PATCH] more generic youtube matcher --- squeebot.repo.json | 2 +- urlreply/plugin.json | 2 +- urlreply/plugin.ts | 11 ++++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/squeebot.repo.json b/squeebot.repo.json index 4cd01d0..7ed847b 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -39,7 +39,7 @@ }, { "name": "urlreply", - "version": "1.0.5" + "version": "1.0.6" }, { "name": "utility", diff --git a/urlreply/plugin.json b/urlreply/plugin.json index 4f76cd0..3258124 100644 --- a/urlreply/plugin.json +++ b/urlreply/plugin.json @@ -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"] diff --git a/urlreply/plugin.ts b/urlreply/plugin.ts index ac26351..ac40094 100644 --- a/urlreply/plugin.ts +++ b/urlreply/plugin.ts @@ -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);