65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
// Used to allow the author to manually banish someone
|
|
module.exports = class Banish {
|
|
constructor(client, from, to, incantation) {
|
|
this.name = "Banish";
|
|
this.client = client;
|
|
this.summoner = from;
|
|
this.channel = to;
|
|
this.incantation = incantation;
|
|
this.spell = "malpermesi";
|
|
this.cheatCode = "banish";
|
|
this.varsUsed = 2;
|
|
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, ...reason) {
|
|
let response = {
|
|
say: false,
|
|
debug: {},
|
|
content: ""
|
|
};
|
|
|
|
reason = reason.join(" ");
|
|
|
|
// Log reason for adding to the blacklist
|
|
const blacklistReason = `${user} was added for ${reason}\n`;
|
|
const dirname = this.client.config.dirname;
|
|
const log = path.resolve(dirname, "blacklist.log");
|
|
fs.appendFile(log, blacklistReason, (err) => {
|
|
if (err) throw err;
|
|
console.log("Blacklist", blacklistReason);
|
|
});
|
|
|
|
// Apply to current session
|
|
this.client.blacklist[user] = {
|
|
reason: `Your actions triggered auto-banishment`,
|
|
when: Date.now()
|
|
};
|
|
|
|
// 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("Added to blacklist:", user);
|
|
});
|
|
|
|
const author = this.client.config.author;
|
|
this.client.say(author, `${user} was banished for reason ${reason}`);
|
|
|
|
return response;
|
|
}
|
|
} |