59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
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;
|
|
}
|
|
} |