mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add listall command
Co-authored-by: Coolguy3289 <Coolguy3289@users.noreply.github.com>
This commit is contained in:
parent
58a5cd1995
commit
a1725ec01b
1 changed files with 44 additions and 0 deletions
44
src/commands/admin/listall.js
Normal file
44
src/commands/admin/listall.js
Normal file
|
@ -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.'
|
||||
}; }
|
||||
};
|
Loading…
Add table
Reference in a new issue