irc-bot/spells/pardon.js

60 lines
1.7 KiB
JavaScript

const fs = require("fs");
const path = require("path");
// Used to allow the author to manually banish someone
module.exports = class Pardon {
constructor(client, from, to, incantation) {
this.name = "Pardon";
this.client = client;
this.summoner = from;
this.channel = to;
this.incantation = incantation;
this.spell = "pardonu";
this.cheatCode = "pardon";
this.varsUsed = 1;
this.casted = false;
this.locked = true;
}
test() {
if (this.incantation === this.spell) {
this.casted = true;
return this.cast.apply(this, arguments);
}
return { say: false };
}
cast(user) {
let response = {
say: false,
debug: {},
content: ""
};
// Log pardon from blacklist
const pardonReason = `${user} was pardoned\n`;
const dirname = this.client.config.dirname;
const log = path.resolve(dirname, "blacklist.log");
fs.appendFile(log, pardonReason, (err) => {
if (err) throw err;
console.log("Blacklist", pardonReason);
});
// Apply to current session
delete this.client.blacklist[user];
// Apply to future sessions
const blacklist = JSON.stringify(this.client.blacklist);
const file = path.resolve(dirname, "blacklist.json");
fs.writeFile(file, blacklist, (err) => {
if (err) throw err;
console.log("Removed from blacklist:", user);
});
const author = this.client.config.author;
this.client.say(author, `${user} was pardoned`);
return response;
}
}