Fixed auto-banish bug, now treats name|context as name
This commit is contained in:
parent
f5190e4e6c
commit
bf486a047b
39
bot.js
39
bot.js
|
@ -6,7 +6,7 @@ const path = require("path");
|
|||
const irc = require("irc");
|
||||
const Summon = require("./spells/summon");
|
||||
const BotList = require("./spells/botlist");
|
||||
// const Banish = require("./spells/banish");
|
||||
const Banish = require("./spells/banish");
|
||||
const Pardon = require("./spells/pardon");
|
||||
const Hmm = require("./spells/hmm");
|
||||
|
||||
|
@ -40,7 +40,7 @@ client.config.dirname = __dirname;
|
|||
client.spells = [
|
||||
Summon,
|
||||
BotList,
|
||||
// Banish,
|
||||
Banish,
|
||||
Pardon,
|
||||
Hmm
|
||||
];
|
||||
|
@ -77,12 +77,15 @@ client.blacklist = JSON.parse(fs.readFileSync(
|
|||
path.resolve(__dirname, "blacklist.json"), "utf8"
|
||||
));
|
||||
|
||||
// Format:
|
||||
// Memory log format:
|
||||
// {
|
||||
// timestamp: Date.now(),
|
||||
// spell: spell.name
|
||||
// }
|
||||
client.memory = [];
|
||||
client.memory = {
|
||||
log: [],
|
||||
users: {}
|
||||
};
|
||||
|
||||
client.brain = {};
|
||||
// Persistent memories
|
||||
|
@ -154,12 +157,6 @@ const castSpell = (client, from, to, incantation) => {
|
|||
const vars = spell.varsUsed;
|
||||
let response = null;
|
||||
|
||||
// Only the author can use these spells
|
||||
if (spell.locked && from !== client.config.author) {
|
||||
client.say(to, "Blasfemo! That spell is forbidden to you.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: Handle variables in spells
|
||||
const spellName = spell.spell;
|
||||
const splitIncantation = incantation.split(spellName);
|
||||
|
@ -174,10 +171,12 @@ const castSpell = (client, from, to, incantation) => {
|
|||
|
||||
if (spell.casted) {
|
||||
casted = true;
|
||||
client.memory.push({
|
||||
client.memory.log.push({
|
||||
timestamp: Date.now(),
|
||||
spell: spell.name
|
||||
});
|
||||
client.memory.users[from] = client.memory.users[from] || {};
|
||||
client.memory.users[from].timestamp = Date.now();
|
||||
|
||||
if (response.say) {
|
||||
client.say(to, response.content);
|
||||
|
@ -194,7 +193,7 @@ const castSpell = (client, from, to, incantation) => {
|
|||
const useCheatCode = (client, from, to, cheatCode) => {
|
||||
let cheatCodes = {};
|
||||
let variables = "";
|
||||
|
||||
|
||||
// Handle variables in cheat code
|
||||
if (cheatCode.indexOf(" ") > -1) {
|
||||
splitCheatCode = cheatCode.split(" ");
|
||||
|
@ -218,7 +217,7 @@ const useCheatCode = (client, from, to, cheatCode) => {
|
|||
|
||||
const checkBlacklist = (client, from, to, message) => {
|
||||
const now = Date.now();
|
||||
const lastUsed = client.memory.slice(-1).pop();
|
||||
const lastUsed = client.memory.users[from];
|
||||
const lastTimestamp = lastUsed ? lastUsed.timestamp : 0;
|
||||
const blacklisters = Object.keys(client.blacklist);
|
||||
|
||||
|
@ -363,7 +362,9 @@ const runLogic = (client, from, to, message) => {
|
|||
|
||||
client.addListener("message", (from, to, message) => {
|
||||
console.log(`${from} => ${to}: ${message}`);
|
||||
runLogic(client, from, to, message.toLowerCase());
|
||||
from = from.split("|")[0];
|
||||
message = message.toLowerCase();
|
||||
runLogic(client, from, to, message);
|
||||
});
|
||||
|
||||
client.addListener("pm", (from, message) => {
|
||||
|
@ -371,6 +372,16 @@ client.addListener("pm", (from, message) => {
|
|||
runLogic(client, from, botName, message.toLowerCase());
|
||||
});
|
||||
|
||||
client.addListener("invite", (channel, from, message) => {
|
||||
console.log(`${from} invites to ${channel}: ${message}`);
|
||||
client.join(channel);
|
||||
// client.say("ChanServ", `INFO ${channel}`);
|
||||
});
|
||||
|
||||
client.addListener("error", (message) => {
|
||||
console.error(`error: ${message}`, message);
|
||||
});
|
||||
|
||||
client.addListener("error", (message) => {
|
||||
console.error(`error: ${message}`, message);
|
||||
});
|
||||
|
|
|
@ -18,6 +18,13 @@ module.exports = class Banish {
|
|||
|
||||
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);
|
||||
}
|
||||
|
@ -32,7 +39,11 @@ module.exports = class Banish {
|
|||
content: ""
|
||||
};
|
||||
|
||||
reason = reason.join(" ");
|
||||
if (!reason) {
|
||||
reason = "<none>";
|
||||
} else {
|
||||
reason = reason.join(" ");
|
||||
}
|
||||
|
||||
// Log reason for adding to the blacklist
|
||||
const blacklistReason = `${user} was added for ${reason}\n`;
|
||||
|
|
|
@ -15,8 +15,15 @@ module.exports = class BotList {
|
|||
|
||||
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();
|
||||
return this.cast.apply(this, arguments);
|
||||
}
|
||||
|
||||
return { say: false };
|
||||
|
|
|
@ -15,6 +15,13 @@ module.exports = class Hmm {
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,13 @@ module.exports = class Pardon {
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,13 @@ module.exports = class Summon {
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue