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 4cf77430d5ddcf4548fd34dfd083c921d28f5544
parent 4ee2dc06446c93d0f0fc2a01f3c431e86cc07491
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Sat, 30 May 2020 17:22:51 +0530

RSS functionality

Diffstat:
Mirc.js | 25+++++++++++++++++++++++++
Mpackage.json | 3++-
MpromUrlShortener.js | 3+++
Myarn.lock | 5+++++
4 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/irc.js b/irc.js @@ -1,4 +1,6 @@ const irc = require('irc'); +const fetch = require('node-fetch'); +const _ = require('underscore'); const { admins, @@ -95,3 +97,26 @@ function groupChat(sender, channel, msg) { client.addListener('error', err); client.addListener('pm', pm); client.addListener('message', groupChat); + +const submittedState = { + announced: [], +}; + +async function announceSubmitted() { + const res = await fetch(RQAPI); + const parsed = await res.json(); + const titles = parsed.query.categorymembers.map((el) => el.title); + // rm already announced + const yetToAnnounce = _.without(titles, ...submittedState.announced); + submittedState.announced.push(...yetToAnnounce); + const prepped = yetToAnnounce.map(fullUrl); + if (prepped.length) { + channels.forEach((channel) => client.say(channel, 'Submitted for review:')); + channels.forEach((channel) => sayShortUrls(prepped, channel)); + } +} + +setInterval(announceSubmitted, 5 * 60 * 1000); +setInterval(() => { + submittedState.announced = []; +}, 6 * 60 * 60 * 1000); diff --git a/package.json b/package.json @@ -3,7 +3,8 @@ "irc": "^0.5.2", "node-fetch": "^2.6.0", "request": "^2.88.2", - "tinyurl": "^1.1.5" + "tinyurl": "^1.1.5", + "underscore": "^1.10.2" }, "scripts": { "start": "node irc.js" diff --git a/promUrlShortener.js b/promUrlShortener.js @@ -34,6 +34,8 @@ async function getLoginToken() { } catch (error) { console.log(error); res.error = error; + globalState.error = true; + globalState.fallback = true; } return res; } @@ -111,6 +113,7 @@ async function main() { main(); async function short(URI) { + console.log(globalState, botAccount, botPass); if (!globalState.mainExecuted) main(); if (!URI) URI = diff --git a/yarn.lock b/yarn.lock @@ -343,6 +343,11 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= +underscore@^1.10.2: + version "1.10.2" + resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.10.2.tgz#73d6aa3668f3188e4adb0f1943bd12cfd7efaaaf" + integrity sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg== + uri-js@^4.2.2: version "4.2.2" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"