Browse Source

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!
master
benji7425 3 years ago
parent
commit
80c8f6accd
2 changed files with 18 additions and 7 deletions
  1. 7
      discord-bot-core/client.js
  2. 18
      discord-bot-core/core-commands/reset.js

7
discord-bot-core/client.js

@ -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...");

18
discord-bot-core/core-commands/reset.js

@ -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"));
});
}
Loading…
Cancel
Save