From 703eb027056135fef9e31e26373741e8541e878f Mon Sep 17 00:00:00 2001 From: Snazzah Date: Thu, 10 Jun 2021 21:17:33 -0500 Subject: [PATCH] Add deleteall command --- src/commands/admin/deleteall.js | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/commands/admin/deleteall.js diff --git a/src/commands/admin/deleteall.js b/src/commands/admin/deleteall.js new file mode 100644 index 0000000..7d3ff39 --- /dev/null +++ b/src/commands/admin/deleteall.js @@ -0,0 +1,39 @@ +const Command = require('../../structures/Command'); +const Util = require('../../util'); + +module.exports = class DeleteAll extends Command { + get name() { return 'deleteall'; } + + get _options() { return { + aliases: ['delall'], + permissions: ['admin'], + minimumArgs: 0 + }; } + + async exec(message) { + await Util.LBRY.syncPairs(this.client); + const pairs = await this.client.sqlite.getAll(); + + if (!await this.client.messageAwaiter.confirm(message, { + header: + `Are you sure you want to delete **all** ${pairs.length} accounts?` + })) return; + + for (const pair of pairs) { + try { + await Util.LBRY.deleteAccount(this.client, pair.discordID, pair.lbryID); + } catch (e) { + return message.channel.createMessage( + 'Failed to delete an account. An error most likely occured while backing up the wallet.' + + `\n\`\`\`\n${e.toString()}\`\`\`` + ); + } + } + return message.channel.createMessage('Deleted all accounts.'); + } + + get metadata() { return { + category: 'Admin', + description: 'Deletes all accounts in the database.' + }; } +};