commit 086778e0c93515289372da794339ac5017789022
parent 704f0b6984c8bd12b6234212ece779513b186f9c
Author: Agastya Chandrakant <acagastya@outlook.com>
Date: Thu, 4 Jun 2020 20:06:59 +0530
implement under review
Diffstat:
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/config.js b/config.js
@@ -12,6 +12,8 @@ const config = {
shortURL:
'https://meta.wikimedia.org/w/api.php?action=shortenurl&format=json&url=',
URL: 'https://en.wikinews.org/w/index.php?title=',
+ URAPI:
+ 'https://en.wikinews.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Under%20review&format=json&cmsort=timestamp&cmprop=title',
};
module.exports = config;
diff --git a/irc.js b/irc.js
@@ -10,6 +10,7 @@ const {
report,
RQAPI,
server,
+ URAPI,
} = require('./config');
const { fetchData, fullUrl, getFullLink, getFullTemplate } = require('./utils');
@@ -58,7 +59,13 @@ async function announceRQ(sender, channel) {
}
}
-async function sayShortUrls(urlList, channel, titles = [], times = []) {
+async function sayShortUrls(
+ urlList,
+ channel,
+ titles = [],
+ times = [],
+ pending = []
+) {
const shortUrls = await Promise.all(urlList.map(short));
shortUrls.forEach(({ url, err }, idx) => {
@@ -66,6 +73,7 @@ async function sayShortUrls(urlList, channel, titles = [], times = []) {
let msg = `${url} sumbitted for review`;
if (times.length) msg += ` *${times[idx]}*`;
if (titles.length) msg += ` -- ${titles[idx]}`;
+ if (pending[idx]) msg += ' *under review*';
client.say(channel, msg);
} else console.log(err);
});
@@ -106,6 +114,10 @@ async function announceSubmitted() {
const res = await fetch(RQAPI);
const parsed = await res.json();
+ const underReview = await fetch(URAPI);
+ const urParsed = await underReview.json();
+ const urTitles = urParsed.query.categorymembers.map(({ title }) => title);
+
const titleTime = parsed.query.categorymembers.map(({ title, timestamp }) => {
return { timestamp, title };
});
@@ -113,9 +125,7 @@ async function announceSubmitted() {
const pending = titleTime.filter(
({ title }) => !submittedState.announced.includes(title)
);
- // const purgedGlobal = submittedState.announced.filter((el) =>
- // allTitles.includes(el)
- // );
+ const pendingRev = pending.map((el) => urTitles.includes(el.title));
const titles = pending.map(({ title }) => title);
submittedState.announced = [...allTitles];
const urls = titles.map(fullUrl);
@@ -123,7 +133,9 @@ async function announceSubmitted() {
if (urls.length) {
channels.forEach((channel) => client.say(channel, 'Review Queue:'));
- channels.forEach((channel) => sayShortUrls(urls, channel, titles, times));
+ channels.forEach((channel) =>
+ sayShortUrls(urls, channel, titles, times, pendingRev)
+ );
}
}