Added whois

This commit is contained in:
aewens 2018-07-26 15:41:19 -04:00
parent a24c352e8e
commit 25e0a44330
5 changed files with 129 additions and 7 deletions

40
bot.js
View File

@ -10,6 +10,7 @@ const BotList = require("./spells/botlist");
const Banish = require("./spells/banish");
const Pardon = require("./spells/pardon");
const Hmm = require("./spells/hmm");
const Whois = require("./spells/whois");
// Tasks
const RSS = require("./tasks/rss");
@ -34,7 +35,11 @@ const client = new irc.Client("localhost", botName, {
});
if (!debug) {
client.opt.channels = client.opt.channels.concat(["#meta", "#tildeverse"]);
client.opt.channels = client.opt.channels.concat([
"#meta",
"#chaos",
"#tildeverse"
]);
}
client.config = JSON.parse(fs.readFileSync("config.json", "utf8"));
@ -46,7 +51,8 @@ client.spells = [
BotList,
Banish,
Pardon,
Hmm
Hmm,
Whois
];
// NOTE - For my personal copy, jan6 will remain here until #chaos is mine
@ -101,6 +107,10 @@ client.triggers = {
vars: "",
description: "Displays the leaderboard for hmmscores."
},
"!whois": {
vars: "<domain>",
description: "Displays the status of a domain name."
},
"!help BabiliBot": {
vars: "",
description: "PMs user this message."
@ -290,7 +300,7 @@ const runLogic = (client, from, to, message) => {
const parsedMessage = message.split(tildebridge);
from = parsedMessage[1];
message = parsedMessage[2];
} else if (from === "TildeBot") {
} else if (from === "TildeBot" || from === "sedbot") {
// This bot is a monster
return false;
}
@ -298,7 +308,10 @@ const runLogic = (client, from, to, message) => {
const hmm = new RegExp(/hm+/g);
const hmms = message ? message.match(hmm) : null;
if (hmms && !message.startsWith("!hmmscore")) {
if (hmms && !message.startsWith("!hmmscore") && to !== "#bots") {
const blacklisters = Object.keys(client.blacklist);
if (contains(blacklisters, from)) return false;
client.brain.memories.hmmscores = client.brain.memories.hmmscores || {};
let hmmscore = client.brain.memories.hmmscores[from];
if (!hmmscore) {
@ -366,6 +379,7 @@ const runLogic = (client, from, to, message) => {
} else if (
message.startsWith("!summon ") ||
message.startsWith("!hmmscore") ||
message.startsWith("!whois ") ||
message.startsWith("!botlist")
) {
const cheatCode = message.slice(1).trim();
@ -405,14 +419,28 @@ client.addListener("invite", (channel, from, message) => {
// client.say("ChanServ", `INFO ${channel}`);
});
client.addListener("error", (message) => {
console.error(`error: ${message}`, message);
client.addListener("-mode", (channel, by, mode, argument, message) => {
console.log(`${channel}: *${by}* <${mode}> [${argument}] | ${message}`);
if (by === "ChanServ" && mode === "r") {
const author = client.config.author;
client.say("ChanServ", `REGISTER ${channel}`);
client.say("ChanServ", `SET Founder ${channel} ${author}`);
client.say("ChanServ", `SET Successor ${channel} ${botName}`);
}
});
client.addListener("error", (message) => {
console.error(`error: ${message}`, message);
});
client.addListener("join", (channel) => {
const author = client.config.author;
if (channel === "#chaos") {
client.say("ChanServ", `SET Founder ${channel} ${author}`);
client.say("ChanServ", `SET Successor ${channel} ${botName}`);
}
});
client.addListener("registered", () => {
// client.say("NickServ", `RECOVER ${botName} ${client.config.password}`);
client.say("NickServ", `IDENTIFY ${client.config.password}`);

32
package-lock.json generated
View File

@ -50,6 +50,15 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.7.0.tgz",
"integrity": "sha512-32NDda82rhwD9/JBCCkB+MRYDp0oSvlo2IL6rQWA10PQi7tDUM3eqMSltXmY+Oyl/7N3P3qNtAlv7X0d9bI28w=="
},
"axios": {
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": {
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
}
},
"bcrypt-pbkdf": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
@ -153,6 +162,24 @@
"sax": "^1.2.4"
}
},
"follow-redirects": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.1.tgz",
"integrity": "sha512-v9GI1hpaqq1ZZR6pBD1+kI7O24PhDvNGNodjS3MdcEqyrahCp8zbtpv+2B/krUnSmUH80lbAS7MrdeK5IylgKg==",
"requires": {
"debug": "^3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"forever-agent": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
@ -229,6 +256,11 @@
"resolved": "https://registry.npmjs.org/irc-colors/-/irc-colors-1.4.2.tgz",
"integrity": "sha512-QZ1g4d9XTGKgBAp7lrltCetefqd3zfYs3SFQ4YyRSORORCmy/9EkU/r8LJrlSnaWc3Z+54EgHXBRlOHaCvpyHA=="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"is-typedarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",

View File

@ -19,6 +19,7 @@
"author": "aewens",
"license": "BSD-3-Clause",
"dependencies": {
"axios": "^0.18.0",
"feedparser": "^2.2.9",
"irc": "^0.5.2",
"nodemailer": "^4.6.7",

View File

@ -39,6 +39,8 @@ module.exports = class Banish {
content: ""
};
if (user === this.client.config.author) return false;
if (!reason) {
reason = "<none>";
} else {
@ -56,7 +58,7 @@ module.exports = class Banish {
// Apply to current session
this.client.blacklist[user] = {
reason: `Your actions triggered auto-banishment`,
reason: reason,
when: Date.now()
};

59
spells/whois.js Normal file
View File

@ -0,0 +1,59 @@
const axios = require("axios");
// For reason: we should get "tilde.TLD"!
module.exports = class Whois {
constructor(client, from, to, incantation) {
this.name = "Whois";
this.client = client;
this.summoner = from;
this.channel = to;
this.incantation = incantation;
this.spell = "kiu estas";
this.cheatCode = "whois";
this.varsUsed = 1;
this.casted = false;
this.locked = false;
}
test() {
if (this.incantation === this.spell) {
// Only the author can use these spells
if (this.locked && this.summoner !== this.client.config.author) {
const say = "Blasfemo! That spell is forbidden to you."
this.client.say(this.channel, say);
return false;
}
this.casted = true;
return this.cast.apply(this, arguments);
}
return { say: false };
}
cast(domain) {
let response = {
say: false,
debug: {},
content: ""
};
const apiKey = this.client.config.api.jsonwhoisapi;
const apiURL = "https://api.jsonwhoisapi.com/v1/whois";
const self = this;
axios.get(`${apiURL}?identifier=${domain}`, {
headers: {
"Authorization": `${apiKey}`
}
}).then((res) => {
const status = res.data.registrar.id ? "registered" : "available";
self.client.say(self.channel, `${domain} is "${status}"`);
}).catch((error) => {
const zipper = `${this.summoner}, vi zipro, ${domain}`;
self.client.say(self.channel, `${zipper} cansnot exist!`);
});
return response;
}
}