Added bbj integration
This commit is contained in:
parent
2d283cf240
commit
8b6635917e
18
bot.js
18
bot.js
|
@ -14,15 +14,13 @@ const Whois = require("./spells/whois");
|
|||
|
||||
// Tasks
|
||||
const RSS = require("./tasks/rss");
|
||||
const BBJ = require("./tasks/bbj");
|
||||
|
||||
const debug = false;
|
||||
|
||||
const botName = `BabiliBot${debug ? "Demo" : ""}`;
|
||||
const client = new irc.Client("localhost", botName, {
|
||||
channels: [
|
||||
"#bots",
|
||||
// "#meta"
|
||||
],
|
||||
channels: ["#bots"],
|
||||
localAddress: "127.0.0.1",
|
||||
port: 6667,
|
||||
userName: "aewens",
|
||||
|
@ -36,7 +34,8 @@ const client = new irc.Client("localhost", botName, {
|
|||
|
||||
if (!debug) {
|
||||
client.opt.channels = client.opt.channels.concat([
|
||||
"#meta",
|
||||
"#meta",
|
||||
"#team",
|
||||
"#chaos",
|
||||
"#tildeverse"
|
||||
]);
|
||||
|
@ -87,6 +86,13 @@ client.tasks = debug ? [] : [
|
|||
"summary",
|
||||
["#tildeverse"],
|
||||
5000
|
||||
),
|
||||
new BBJ(
|
||||
client,
|
||||
"bbj",
|
||||
"http://localhost:7099/api",
|
||||
["#team"],
|
||||
5000
|
||||
)
|
||||
];
|
||||
|
||||
|
@ -426,7 +432,7 @@ client.addListener("-mode", (channel, by, mode, argument, message) => {
|
|||
client.say("ChanServ", `REGISTER ${channel}`);
|
||||
client.say("ChanServ", `SET Founder ${channel} ${author}`);
|
||||
client.say("ChanServ", `SET Successor ${channel} ${botName}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.addListener("error", (message) => {
|
||||
|
|
|
@ -47,8 +47,8 @@ module.exports = class Whois {
|
|||
"Authorization": `${apiKey}`
|
||||
}
|
||||
}).then((res) => {
|
||||
// const data = JSON.stringify(res.data);
|
||||
// console.log(`${self.name} :: ${data}`);
|
||||
const data = JSON.stringify(res.data);
|
||||
console.log(`${self.name} :: ${data}`);
|
||||
const nameservers = res.data.nameservers.length;
|
||||
const registrar = res.data.registrar;
|
||||
const registered = res.data.registered;
|
||||
|
@ -57,8 +57,7 @@ module.exports = class Whois {
|
|||
const status = logic ? "registered" : "available";
|
||||
self.client.say(self.channel, `${domain} is "${status}"`);
|
||||
} else {
|
||||
const zipper = `${this.summoner}, vi zipro, ${domain}`;
|
||||
self.client.say(self.channel, `${zipper} is not a domain!`);
|
||||
self.client.say(self.channel, `${domain} might be available`);
|
||||
}
|
||||
}).catch((error) => {
|
||||
const zipper = `${this.summoner}, vi zipro, ${domain}`;
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
const axios = require("axios");
|
||||
|
||||
// For pushing updates from bbj
|
||||
module.exports = class BBJ {
|
||||
constructor(client, alias, source, channels, interval) {
|
||||
this.name = "BBJ";
|
||||
this.client = client;
|
||||
this.alias = alias;
|
||||
this.source = source;
|
||||
this.channels = channels;
|
||||
this.interval = interval;
|
||||
|
||||
const task_memories = this.client.memory.tasks;
|
||||
task_memories[this.alias] = task_memories[this.alias] || {};
|
||||
this.memory = task_memories[this.alias];
|
||||
}
|
||||
|
||||
start() {
|
||||
this.memory.status = "running";
|
||||
this.memory.timestamp = Date.now();
|
||||
this.memory.known = {};
|
||||
this.fetch(this.cache.bind(this));
|
||||
this.job = setInterval(this.run.bind(this), this.interval);
|
||||
}
|
||||
|
||||
stop(ack) {
|
||||
clearInterval(this.job);
|
||||
this.client.say(ack, `Stopping task "${this.alias}"`);
|
||||
}
|
||||
|
||||
run() {
|
||||
this.fetch(this.mirror.bind(this));
|
||||
}
|
||||
|
||||
cache(item) {
|
||||
this.memory.known[item.thread_id] = item.last_mod;
|
||||
}
|
||||
|
||||
mirror(item) {
|
||||
const thread_id = item.thread_id;
|
||||
const last_mod = this.memory.known[thread_id];
|
||||
if (last_mod === item.last_mod) return;
|
||||
|
||||
this.memory.known[thread_id] = item.last_mod;
|
||||
|
||||
this.get_thread(thread_id, (thread) => {
|
||||
const title = thread.data.title;
|
||||
const replies = thread.data.reply_count;
|
||||
const messages = thread.data.messages;
|
||||
const usermap = thread.usermap;
|
||||
const reply = messages[replies];
|
||||
const author = reply.author;
|
||||
const username = usermap[author].user_name;
|
||||
const body = reply.body.replace(/>>\d\n\n/, "").replace(/\n/, " ");
|
||||
const client = `https://bbj.tilde.team/index.php`;
|
||||
const link = `${client}?thread_id=${thread_id}`;
|
||||
this.channels.forEach((channel) => {
|
||||
const response = `"${title}" (${username}) : ${body} <${link}>`;
|
||||
this.client.say(channel, `[${this.alias}] ${response}`);
|
||||
});
|
||||
});
|
||||
// const use = item[this.use].replace(/(<\/?[^>]+>)|\\n/g, "");
|
||||
// const post = `${use} <${item.guid}>`;
|
||||
// const response = `[${this.alias}] New submission: ${post}`;
|
||||
}
|
||||
|
||||
handle_errors(response) {
|
||||
if (response.error) {
|
||||
const err = `<${response.code}> ${response.description}`;
|
||||
console.error(`${this.name}::error: [axios] ${err}`);
|
||||
return false;
|
||||
} else {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
get_thread(id, callback) {
|
||||
axios.post(`${this.source}/thread_load`, {
|
||||
"thread_id": id
|
||||
}).then((res) => {
|
||||
const response = this.handle_errors(res.data);
|
||||
if (response) {
|
||||
callback(response);
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error(`${this.name}::error: [axios] ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
fetch(callback) {
|
||||
axios.get(`${this.source}/thread_index`).then((res) => {
|
||||
const response = this.handle_errors(res.data);
|
||||
if (response) {
|
||||
const threads = response.data;
|
||||
threads.forEach((thread) => {
|
||||
callback(thread);
|
||||
});
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error(`${this.name}::error: [axios] ${error}`);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ module.exports = class RSS {
|
|||
|
||||
stop(ack) {
|
||||
clearInterval(this.job);
|
||||
client.say(ack, `Stopping task "${this.alias}"`);
|
||||
this.client.say(ack, `Stopping task "${this.alias}"`);
|
||||
}
|
||||
|
||||
run() {
|
||||
|
@ -46,7 +46,7 @@ module.exports = class RSS {
|
|||
|
||||
const use = item[this.use].replace(/(<\/?[^>]+>)|\\n/g, "");
|
||||
const post = `${use} <${item.guid}>`;
|
||||
const response = `[${this.alias}] New submission: ${post}`;
|
||||
const response = `[${this.alias}] ${post}`;
|
||||
this.channels.forEach((channel) => {
|
||||
this.client.say(channel, response);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue