commit 8c0744604e6c8c6437f7ef98bf7f2d97e60dc6f7
parent 1f0b9aabd441e902812d1c78c5dc70c44df02c1f
Author: Agastya Chandrakant <me@hanabi.in>
Date: Wed, 24 Feb 2021 10:30:11 +0530
SASL
Diffstat:
2 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/config.js b/config.js
@@ -1,12 +1,13 @@
module.exports = {
channels: ["#wikinews", "#wikinews-en", "#wikinewsie-group"],
ircBotName: "enwnbot",
- ircServer: "irc.freenode.net",
+ ircServer: "chat.freenode.net",
+ password: "bots-password-here",
RCAPI: "https://stream.wikimedia.org/v2/stream/recentchange",
RQAPI:
"https://en.wikinews.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Review&format=json&cmsort=timestamp&cmprop=timestamp|ids|title",
URAPI:
"https://en.wikinews.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Under%20review&format=json&cmsort=timestamp&cmprop=title|timestamp",
URL: "https://en.wikinews.org/w/index.php?title=",
- wiki: "enwikinews"
+ wiki: "enwikinews",
};
diff --git a/index.js b/index.js
@@ -8,10 +8,11 @@ const {
channels,
ircBotName,
ircServer,
+ password,
RCAPI,
RQAPI,
- URAPI
-} = require("./config");
+ URAPI,
+} = require("./config.js");
const {
fetchData,
@@ -22,33 +23,41 @@ const {
streamError,
streamMessage,
templateRegex,
- thanksRegex
-} = require("./utils");
+ thanksRegex,
+} = require("./utils.js");
const seenLookup = {};
-const ircClient = new irc.Client(ircServer, ircBotName, { channels });
+const ircClient = new irc.Client(ircServer, ircBotName, {
+ channels,
+ userName: "enwnbot",
+ realName: "enwnbot",
+ sasl: true,
+ password,
+ floodProtection: true,
+ floodProtectionDelay: 1000,
+});
console.log("Connecting to the event stream...");
const eventSource = new ES(RCAPI);
-eventSource.onopen = function(event) {
+eventSource.onopen = function (event) {
console.log("--- Opened connection.");
};
eventSource.onerror = streamError;
-eventSource.onmessage = function(event) {
+eventSource.onmessage = function (event) {
let msg = streamMessage(event);
- if (msg) channels.forEach(channel => ircClient.say(channel, msg));
+ if (msg) channels.forEach((channel) => ircClient.say(channel, msg));
};
-ircClient.addListener("error", function(message) {
+ircClient.addListener("error", function (message) {
console.log("error: ", message);
});
-ircClient.addListener("pm", function(sender, msg) {
+ircClient.addListener("pm", function (sender, msg) {
if (
msg == "KILL" &&
["pizero", "pizero|afk", "acagastya"].indexOf(sender) >= 0
@@ -77,7 +86,7 @@ function handleJoin(channel, nick) {
function getNames(channel, nicks) {
seenLookup[channel] = { ...nicks };
Object.keys(seenLookup[channel]).forEach(
- nick => (seenLookup[channel][nick] = "")
+ (nick) => (seenLookup[channel][nick] = "")
);
}
@@ -87,7 +96,7 @@ function handlePart(channel, nick) {
}
function handleQuit(nick, reason, channels) {
- channels.forEach(channel => {
+ channels.forEach((channel) => {
if (seenLookup[channel] !== undefined) {
seenLookup[channel][nick] = +new Date();
}
@@ -95,7 +104,7 @@ function handleQuit(nick, reason, channels) {
}
function handleNickChange(oldNick, newNick, channels) {
- channels.forEach(channel => {
+ channels.forEach((channel) => {
if (seenLookup[channel] !== undefined) {
seenLookup[channel][oldNick] = +new Date();
seenLookup[channel][newNick] = "";
@@ -114,13 +123,13 @@ function groupChat(sender, channel, msg) {
const templates = msg.match(templateRegex);
if (!msg.endsWith("--ignore") && links) {
- const nonEmptyLinks = links.filter(el => el.length > 4);
+ const nonEmptyLinks = links.filter((el) => el.length > 4);
const fullLinks = nonEmptyLinks.map(getFullLink);
if (fullLinks.length) sayUrls(false, fullLinks, channel);
}
if (!msg.endsWith("--ignore") && templates) {
- const nonEmptyTemplates = templates.filter(el => el.length > 4);
+ const nonEmptyTemplates = templates.filter((el) => el.length > 4);
const fullLinks = nonEmptyTemplates.map(getFullTemplate);
if (fullLinks.length) sayUrls(false, fullLinks, channel);
}