From a1725ec01bb088d4b52c07060ba446f3a65eaae2 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Thu, 10 Jun 2021 18:54:21 -0500 Subject: [PATCH] Add listall command Co-authored-by: Coolguy3289 --- src/commands/admin/listall.js | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/commands/admin/listall.js diff --git a/src/commands/admin/listall.js b/src/commands/admin/listall.js new file mode 100644 index 0000000..2baddbf --- /dev/null +++ b/src/commands/admin/listall.js @@ -0,0 +1,44 @@ +const Command = require('../../structures/Command'); +const GenericPager = require('../../structures/GenericPager'); + +module.exports = class ListAll extends Command { + get name() { return 'listall'; } + get _options() { return { + permissions: ['admin'], + minimumArgs: 0 + }; } + async exec(message) { + const pairs = await this.client.sqlite.getAll(); + if (pairs <= 0) + return message.channel.createMessage('No pairs found in the database.'); + + for (const pair of pairs) { + const response = await this.client.lbry.accountBalance(pair.lbryID); + const wallet = await response.json(); + if (!wallet.code) { + pair.wallet_available = wallet.result.available; + pair.wallet_reserve = wallet.result.reserved_subtotals.supports; + pair.wallet_ok = true; + } else { + console.error([ + 'There was an error while retrieving the balance of an account.', + 'This was likely caused by an old version of the Bot\'s SQLite database file. ' + + 'Run the sync command to avoid this error!' + ].join('\n')); + } + } + + const paginator = new GenericPager(this.client, message, { + items: pairs, itemTitle: 'Pairs', itemsPerPage: 3, + display: pair => `> <@${pair.discordID}> - \`${pair.lbryID}\`\n` + + `> ${pair.wallet_ok + ? `${pair.wallet_available} available, ${pair.wallet_reserve}` + : 'Wallet Unavailable'}\n` + }); + return paginator.start(message.channel.id, message.author.id); + } + get metadata() { return { + category: 'Admin', + description: 'List all users in the database.' + }; } +};