Converted botlist to a spell, fixed lock in summon
This commit is contained in:
parent
88454cc137
commit
f1a5c00c8d
69
bot.js
69
bot.js
|
@ -3,7 +3,8 @@
|
|||
const fs = require("fs");
|
||||
const irc = require("irc");
|
||||
const Summon = require("./spells/summon");
|
||||
// const Banish = require("./spells/summon");
|
||||
const BotList = require("./spells/botlist");
|
||||
// const Banish = require("./spells/banish");
|
||||
|
||||
const botName = "BabiliBot"
|
||||
const client = new irc.Client("localhost", botName, {
|
||||
|
@ -26,9 +27,29 @@ client.config.botName = botName;
|
|||
|
||||
client.spells = [
|
||||
Summon,
|
||||
BotList,
|
||||
// Banish
|
||||
];
|
||||
|
||||
client.triggers = {
|
||||
"!cast": {
|
||||
vars: " <spell>",
|
||||
description: "Used to issue an Esperanto spell."
|
||||
},
|
||||
"!summon": {
|
||||
vars: " <user> <reason:optional>",
|
||||
description: "Used to send a summoning email to <user>@tilde.team."
|
||||
},
|
||||
"!help BabiliBot": {
|
||||
vars: "",
|
||||
description: "PMs user this message."
|
||||
},
|
||||
// "!spells": {
|
||||
// vars: "",
|
||||
// description: "PMs spell list to user"
|
||||
// }
|
||||
};
|
||||
|
||||
// NOTE - For my personal copy, jan6 will remain here until #chaos is mine
|
||||
client.blacklist = JSON.parse(fs.readFileSync("blacklist.json", "utf8"));
|
||||
|
||||
|
@ -90,6 +111,12 @@ const castSpell = (client, from, to, incantation) => {
|
|||
// Note: Handle variables in spells
|
||||
const spellName = spell.spell;
|
||||
const splitIncantation = incantation.split(spellName);
|
||||
|
||||
// Skip if could not split
|
||||
if (!splitIncantation[1]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const variable = splitIncantation[1].trim().split(" ");
|
||||
spell.incantation = incantation.split(splitIncantation[1])[0];
|
||||
response = spell.test.apply(spell, variable.splice(0, vars));
|
||||
|
@ -130,7 +157,10 @@ const useCheatCode = (client, from, to, cheatCode) => {
|
|||
// Generate cheat code
|
||||
client.spells.forEach((_spell) => {
|
||||
const spell = new _spell(client, from, "");
|
||||
cheatCodes[spell.cheatCode] = `${spell.spell} ${variables}`;
|
||||
cheatCodes[spell.cheatCode] = spell.spell;
|
||||
if (variables.length > 0) {
|
||||
cheatCodes[spell.cheatCode] += ` ${variables}`;
|
||||
}
|
||||
});
|
||||
|
||||
if (contains(Object.keys(cheatCodes), cheatCode)) {
|
||||
|
@ -180,25 +210,7 @@ client.addListener("message", (from, to, _message) => {
|
|||
const message = _message.toLowerCase();
|
||||
const triggerWord = client.config.triggerWord;
|
||||
const address = botName.toLowerCase();
|
||||
const triggers = {
|
||||
"!cast": {
|
||||
vars: " <spell>",
|
||||
description: "Used to issue an Esperanto spell."
|
||||
},
|
||||
"!summon": {
|
||||
vars: " <user> <reason:optional>",
|
||||
description: "Used to send a summoning email to <user>@tilde.team."
|
||||
},
|
||||
"!help BabiliBot": {
|
||||
vars: "",
|
||||
description: "PMs user this message."
|
||||
},
|
||||
// "!spells": {
|
||||
// vars: "",
|
||||
// description: "PMs spell list to user"
|
||||
// }
|
||||
};
|
||||
const triggerNames = Object.keys(triggers);
|
||||
const triggerNames = Object.keys(client.triggers);
|
||||
|
||||
if (message.startsWith(triggerWord)) {
|
||||
// NOTE: entry for !cast <spell>
|
||||
|
@ -233,17 +245,18 @@ client.addListener("message", (from, to, _message) => {
|
|||
useCheatCode(client, from, to, cheatCode);
|
||||
}
|
||||
} else if (message.startsWith("!botlist")) {
|
||||
// NOTE: To adhere to https://tilde.team/wiki/?page=irc-bots
|
||||
let botlist = `${botName} | <${client.config.author}>`;
|
||||
botlist = `${botlist} | the Esperanto speaking chat bot`;
|
||||
botlist = `${botlist} | ${triggerNames.join(", ")}`;
|
||||
client.say(to, botlist);
|
||||
// NOTE: alias for !cast lerta bots - to adhere to chat standards
|
||||
const cheatCode = message.slice(1).trim();
|
||||
const check = checkBlacklist(client, from, to, cheatCode);
|
||||
if (check) {
|
||||
useCheatCode(client, from, to, cheatCode);
|
||||
}
|
||||
} else if (message.startsWith(`!help ${address}`)) {
|
||||
// NOTE: Help information PM'd to requester
|
||||
client.say(to, `Komprenita, sending help info to ${from}`);
|
||||
client.say(from, `I answer have ${triggers.length} commands:`);
|
||||
client.say(from, `I answer have ${client.triggers.length} commands:`);
|
||||
triggerNames.forEach((name) => {
|
||||
const trigger = triggers[name];
|
||||
const trigger = client.triggers[name];
|
||||
let helpText = `${name} ${trigger.vars}`;
|
||||
helpText = `${helpText} | ${trigger.description}`;
|
||||
client.say(from, helpText);
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
// To adhere to https://tilde.team/wiki/?page=irc-bots
|
||||
module.exports = class BotList {
|
||||
constructor(client, from, to, incantation) {
|
||||
this.name = "BotList";
|
||||
this.client = client;
|
||||
this.summoner = from;
|
||||
this.channel = to;
|
||||
this.incantation = incantation;
|
||||
this.spell = "lerta bots";
|
||||
this.cheatCode = "botlist";
|
||||
this.varsUsed = 0;
|
||||
this.casted = false;
|
||||
this.locked = false;
|
||||
}
|
||||
|
||||
test() {
|
||||
if (this.incantation === this.spell) {
|
||||
this.casted = true;
|
||||
return this.cast();
|
||||
}
|
||||
|
||||
console.log(`[${this.incantation}][${this.spell}]`);
|
||||
|
||||
|
||||
return { say: false };
|
||||
}
|
||||
|
||||
cast() {
|
||||
let response = {
|
||||
say: false,
|
||||
debug: {},
|
||||
content: ""
|
||||
};
|
||||
|
||||
const author = this.client.config.author;
|
||||
const email = this.client.config.email;
|
||||
const maker = `${author} <${email}>`;
|
||||
const triggerNames = Object.keys(this.client.triggers);
|
||||
let botlist = `${this.client.config.botName} | ${maker}`;
|
||||
botlist = `${botlist} | the Esperanto speaking chat bot`;
|
||||
botlist = `${botlist} | ${triggerNames.join(", ")}`;
|
||||
|
||||
response.say = true;
|
||||
response.content = botlist;
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ module.exports = class Summon {
|
|||
this.cheatCode = "summon";
|
||||
this.casted = false;
|
||||
this.varsUsed = 2;
|
||||
this.locked = true;
|
||||
this.locked = false;
|
||||
this.transporter = nodemailer.createTransport({
|
||||
sendmail: true,
|
||||
newline: "unix",
|
||||
|
|
Loading…
Reference in New Issue