From 25e0a4433071e2d7899ba2a686a9df4dd2b0233c Mon Sep 17 00:00:00 2001 From: aewens Date: Thu, 26 Jul 2018 15:41:19 -0400 Subject: [PATCH] Added whois --- bot.js | 40 +++++++++++++++++++++++++++----- package-lock.json | 32 +++++++++++++++++++++++++ package.json | 1 + spells/banish.js | 4 +++- spells/whois.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 7 deletions(-) create mode 100644 spells/whois.js diff --git a/bot.js b/bot.js index f0dc763..51b93ac 100644 --- a/bot.js +++ b/bot.js @@ -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: "", + 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}`); diff --git a/package-lock.json b/package-lock.json index e1f41a7..c92725e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 5758917..ba209b1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/spells/banish.js b/spells/banish.js index 5da1fe2..429a5d6 100644 --- a/spells/banish.js +++ b/spells/banish.js @@ -39,6 +39,8 @@ module.exports = class Banish { content: "" }; + if (user === this.client.config.author) return false; + if (!reason) { reason = ""; } 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() }; diff --git a/spells/whois.js b/spells/whois.js new file mode 100644 index 0000000..00e9260 --- /dev/null +++ b/spells/whois.js @@ -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; + } +} \ No newline at end of file