Add removal of data when bot kicked from guild

Along with join/leave console messages
This commit is contained in:
benji7425 2017-11-11 01:28:38 +00:00
parent 0047f31770
commit 607a3804bc
2 changed files with 19 additions and 7 deletions

View File

@ -28,6 +28,8 @@ module.exports = class Client extends Discord.Client {
this.on("ready", this.onReady);
this.on("message", this.onMessage);
this.on("debug", this.onDebug);
this.on("guildCreate", this.onGuildCreate);
this.on("guildDelete", this.onGuildDelete);
process.on("uncaughtException", err => this.onUnhandledException(this, err));
}
@ -59,6 +61,16 @@ module.exports = class Client extends Discord.Client {
CoreUtil.dateDebug(info);
}
onGuildCreate(guild) {
CoreUtil.dateLog(`Added to guild ${guild.name}`);
}
onGuildDelete(guild) {
CoreUtil.dateLog(`Removed from guild ${guild.name}, removing data for this guild`);
delete this.guildsData[guild.id];
this.writeFile();
}
onUnhandledException(client, err) {
CoreUtil.dateError(err.message || err);
CoreUtil.dateLog("Destroying existing client...");

View File

@ -28,19 +28,19 @@ function ask(client, textChannel, member, question) {
}
function dateLog(...args) {
doDateLog(Console.log, logWriter, args);
doDateLog(Console.log, logWriter, args, "INFO");
}
function dateError(...args) {
doDateLog(Console.error, logWriter, args);
doDateLog(Console.error, logWriter, args, "ERROR");
}
function dateDebug(...args) {
doDateLog(null, null, args);
doDateLog(null, null, args, "DEBUG");
}
function doDateLog(consoleMethod, fileWriter, args) {
args = formatArgs(args);
function doDateLog(consoleMethod, fileWriter, args, prefix = "") {
args = formatArgs([`[${prefix}]`].concat(args));
if (consoleMethod !== null)
consoleMethod.apply(this, args);
@ -52,7 +52,7 @@ function doDateLog(consoleMethod, fileWriter, args) {
}
function formatArgs(args) {
return ["[", new Date().toUTCString(), "] "].concat(args);
return [`[${new Date().toUTCString()}]`].concat(args);
}
function formatArgsForFile(args) {