Add removal of data when bot kicked from guild
Along with join/leave console messages
This commit is contained in:
parent
3cfddd1f58
commit
4bb676d136
|
@ -28,6 +28,8 @@ module.exports = class Client extends Discord.Client {
|
||||||
this.on("ready", this.onReady);
|
this.on("ready", this.onReady);
|
||||||
this.on("message", this.onMessage);
|
this.on("message", this.onMessage);
|
||||||
this.on("debug", this.onDebug);
|
this.on("debug", this.onDebug);
|
||||||
|
this.on("guildCreate", this.onGuildCreate);
|
||||||
|
this.on("guildDelete", this.onGuildDelete);
|
||||||
process.on("uncaughtException", err => this.onUnhandledException(this, err));
|
process.on("uncaughtException", err => this.onUnhandledException(this, err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ module.exports = class Client extends Discord.Client {
|
||||||
|
|
||||||
onMessage(message) {
|
onMessage(message) {
|
||||||
if (message.channel.type === "text" && message.member) {
|
if (message.channel.type === "text" && message.member) {
|
||||||
if(!this.guildsData[message.guild.id])
|
if (!this.guildsData[message.guild.id])
|
||||||
this.guildsData[message.guild.id] = new this.guildDataModel({ id: message.guild.id });
|
this.guildsData[message.guild.id] = new this.guildDataModel({ id: message.guild.id });
|
||||||
HandleMessage(this, message, this.commands, this.guildsData[message.guild.id]);
|
HandleMessage(this, message, this.commands, this.guildsData[message.guild.id]);
|
||||||
}
|
}
|
||||||
|
@ -59,6 +61,16 @@ module.exports = class Client extends Discord.Client {
|
||||||
CoreUtil.dateDebug(info);
|
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) {
|
onUnhandledException(client, err) {
|
||||||
CoreUtil.dateError(err.message || err);
|
CoreUtil.dateError(err.message || err);
|
||||||
CoreUtil.dateLog("Destroying existing client...");
|
CoreUtil.dateLog("Destroying existing client...");
|
||||||
|
|
|
@ -28,19 +28,19 @@ function ask(client, textChannel, member, question) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateLog(...args) {
|
function dateLog(...args) {
|
||||||
doDateLog(Console.log, logWriter, args);
|
doDateLog(Console.log, logWriter, args, "INFO");
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateError(...args) {
|
function dateError(...args) {
|
||||||
doDateLog(Console.error, logWriter, args);
|
doDateLog(Console.error, logWriter, args, "ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateDebug(...args) {
|
function dateDebug(...args) {
|
||||||
doDateLog(null, null, args);
|
doDateLog(null, null, args, "DEBUG");
|
||||||
}
|
}
|
||||||
|
|
||||||
function doDateLog(consoleMethod, fileWriter, args) {
|
function doDateLog(consoleMethod, fileWriter, args, prefix = "") {
|
||||||
args = formatArgs(args);
|
args = formatArgs([`[${prefix}]`].concat(args));
|
||||||
|
|
||||||
if (consoleMethod !== null)
|
if (consoleMethod !== null)
|
||||||
consoleMethod.apply(this, args);
|
consoleMethod.apply(this, args);
|
||||||
|
@ -52,7 +52,7 @@ function doDateLog(consoleMethod, fileWriter, args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatArgs(args) {
|
function formatArgs(args) {
|
||||||
return ["[", new Date().toUTCString(), "] "].concat(args);
|
return [`[${new Date().toUTCString()}]`].concat(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatArgsForFile(args) {
|
function formatArgsForFile(args) {
|
||||||
|
|
Loading…
Reference in a new issue