enwnbot

Converts MediaWiki [[links]] and {{templates}} to links on IRC
git clone http://git.hanabi.in/repos/enwnbot.git
Log | Files | Refs | README | LICENSE

commit ea317cf22940d721fd092e9b31829be3771a022f
parent e2d0c229476c1c72e0d32b17809fea4b443295df
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Thu, 28 May 2020 13:54:32 +0530

w.wiki does not work, so using tinyurl for toolforge

Diffstat:
Mirc.js | 4++--
Mpackage.json | 3++-
Mutils.js | 16+++++++++++++++-
Myarn.lock | 5+++++
4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/irc.js b/irc.js @@ -60,8 +60,8 @@ async function announceRQ(sender, channel) { async function sayShortUrls(urlList, channel) { const shortUrls = await Promise.all(urlList.map(urlShortener)); - shortUrls.forEach(({ url }) => { - client.say(channel, url); + shortUrls.forEach(({ url, err }) => { + if (!err) client.say(channel, url); }); } diff --git a/package.json b/package.json @@ -1,7 +1,8 @@ { "dependencies": { "irc": "^0.5.2", - "node-fetch": "^2.6.0" + "node-fetch": "^2.6.0", + "tinyurl": "^1.1.5" }, "scripts": { "start": "node irc.js" diff --git a/utils.js b/utils.js @@ -1,5 +1,6 @@ const fetch = require('node-fetch'); const { shortURL, URL } = require('./config'); +const TUrl = require('tinyurl'); async function fetchData(URI) { const res = {}; @@ -9,6 +10,7 @@ async function fetchData(URI) { res.list = parsed.query.categorymembers; } catch (error) { res.error = true; + console.warn('Error in fetchData:', error); } return res; } @@ -39,7 +41,7 @@ function getFullTemplate(template) { return `${URL}Template:${word}`; } -async function urlShortener(URI) { +async function urlShortener1(URI) { const req = `${shortURL}${URI}`; const res = {}; try { @@ -51,6 +53,18 @@ async function urlShortener(URI) { res.url = parsed.shortenurl.shorturl; } catch (error) { res.err = true; + console.warn('Error in urlShortener1:', error); + } + return res; +} + +async function urlShortener(URI) { + const res = {}; + try { + res.url = await TUrl.shorten(URI); + } catch (error) { + res.err = true; + console.warn('Error in urlShortener:', error); } return res; } diff --git a/yarn.lock b/yarn.lock @@ -40,3 +40,8 @@ node-icu-charset-detector@~0.2.0: integrity sha1-wjINo3Tdy2cfxUy0oOBB4Vb/1jk= dependencies: nan "^2.3.3" + +tinyurl@^1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/tinyurl/-/tinyurl-1.1.5.tgz#b0e7b06e7d3dc578bc8c217880822d95d3817aa4" + integrity sha512-Wy/y0nrP5nvK66R8sWSGyRYzqlwZpGVkaNKLNjQbnWQ1bkkksZQb3zVrTOlLVaJKwiLUjt/Nujz1hjEMci0j2A==