From 05db7ca20f7be2c673f635546f090a2e22bc0b87 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Thu, 1 Dec 2022 13:02:54 +0200 Subject: [PATCH] configurable ryd url --- squeebot.repo.json | 2 +- urlreply/plugin.json | 2 +- urlreply/plugin.ts | 18 ++++++++++++------ urlreply/schema.json | 10 ++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/squeebot.repo.json b/squeebot.repo.json index 7ed847b..06bd032 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -39,7 +39,7 @@ }, { "name": "urlreply", - "version": "1.0.6" + "version": "1.0.8" }, { "name": "utility", diff --git a/urlreply/plugin.json b/urlreply/plugin.json index 3258124..77881d5 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.6", + "version": "1.0.8", "tags": ["irc"], "dependencies": [], "npmDependencies": ["cheerio@^1.0.0-rc.10"] diff --git a/urlreply/plugin.ts b/urlreply/plugin.ts index ac40094..964df00 100644 --- a/urlreply/plugin.ts +++ b/urlreply/plugin.ts @@ -124,6 +124,7 @@ async function getYoutubeFromVideo( full: urllib.URL, msg: IMessage): Promise { const gtoken = plugin.config.get('tokens.google'); + const dislikeAPIBase = plugin.config.get('api.returnyoutubedislike'); if (!gtoken) { return false; @@ -144,13 +145,15 @@ async function getYoutubeFromVideo( return false; } - const dislikeAPI = `https://returnyoutubedislikeapi.com/votes?videoId=${id}`; let dislikeData; - try { - dislikeData = await httpGET(dislikeAPI); - dislikeData = JSON.parse(dislikeData); - } catch (e) { - dislikeData = null; + if (dislikeAPIBase) { + const dislikeAPI = `${dislikeAPIBase}/votes?videoId=${id}`; + try { + dislikeData = await httpGET(dislikeAPI); + dislikeData = JSON.parse(dislikeData); + } catch (e) { + dislikeData = null; + } } const vid = data.items[0]; @@ -219,6 +222,9 @@ async function getYoutubeFromVideo( tokens: { google: null, soundcloud: null + }, + api: { + returnyoutubedislike: 'https://returnyoutubedislikeapi.com' } }) class URLReplyPlugin extends Plugin { diff --git a/urlreply/schema.json b/urlreply/schema.json index 20cbfd6..62c8d7b 100644 --- a/urlreply/schema.json +++ b/urlreply/schema.json @@ -18,6 +18,16 @@ "description": "Soundcloud API token" } } + }, + "api": { + "type": "object", + "description": "API URLs", + "properties": { + "returnyoutubedislike": { + "type": "string", + "description": "API URL for ReturnYoutubeDislike" + } + } } }, "required": ["tokens"]