Update data deletion to require a reset command instead of guildDelete

guildDelete apparently gets called whenever Discord has an outage - we don't want to delete server data whenever there is a temporary outage!
This commit is contained in:
benji7425 2018-01-27 00:03:47 +00:00
parent 672c07f5b0
commit f1f81a9ba4
2 changed files with 18 additions and 7 deletions

View File

@ -32,7 +32,6 @@ module.exports = class Client extends Discord.Client {
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));
}
@ -58,12 +57,6 @@ module.exports = class Client extends Discord.Client {
CoreUtil.dateLog(`Added to guild ${guild.name}`);
}
_onGuildDelete(guild) {
this.guildDataModel.findOneAndDelete({ guildID: guild.id });
CoreUtil.dateLog(`Removed from guild ${guild.name}, removing data for this guild`);
}
_onUnhandledException(client, err) {
CoreUtil.dateError("Unhandled exception!\n", err);
CoreUtil.dateLog("Destroying existing client...");

View File

@ -0,0 +1,18 @@
const Command = require("../command.js");
module.exports = new Command({
name: "reset",
description: "Reset all data for this Discord server. WARNING: YOU WILL LOSE ALL YOUR SETTINGS!",
syntax: "reset",
admin: false,
invoke
});
function invoke({ guildData }) {
return new Promise((resolve, reject) => {
guildData
.delete()
.then(() => resolve("Data for this server successfully deleted"))
.catch(() => reject("Error deleting data for this server"));
});
}