Add allsupports command

This commit is contained in:
Snazzah 2021-06-10 21:46:02 -05:00
parent 1b12d7be7e
commit d3ac0b6399
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E
4 changed files with 64 additions and 3 deletions

View file

@ -0,0 +1,60 @@
const Command = require('../../structures/Command');
const Util = require('../../util');
const GenericPager = require('../../structures/GenericPager');
module.exports = class AllSupports extends Command {
get name() { return 'allsupports'; }
get _options() { return {
aliases: ['asups', 'allsups'],
permissions: ['admin'],
minimumArgs: 1
}; }
async exec(message, { args }) {
let givenClaim;
if (args[0]) {
givenClaim = Util.resolveToClaimID(args[0]);
if (!givenClaim)
// @TODO use claim_search for invalid claim ids
return message.channel.createMessage('That Claim ID isn\'t valid.');
}
await Util.LBRY.syncPairs(this.client);
const pairs = await this.client.sqlite.getAll();
if (pairs.length <= 0)
return message.channel.createMessage('No users found in the database.');
const allSupports = [];
for (const pair of pairs) {
const supportsCount = await Util.LBRY.getSupportsCount(this.client, pair.lbryID);
if (supportsCount <= 0) continue;
const supportsResponse = await this.client.lbry.listSupports({
accountID: pair.lbryID, page_size: supportsCount, claimID: givenClaim });
const supports = (await supportsResponse.json()).result.items;
for (const support of supports)
allSupports.push({
...support,
pair
});
}
if (allSupports.length <= 0)
return message.channel.createMessage('No supports found.');
const paginator = new GenericPager(this.client, message, {
items: allSupports,
header: `All supports${
givenClaim ? ` on claim \`${givenClaim}\`` : ''}`, itemTitle: 'Supports',itemsPerPage: 5,
display: item => `> ${item.name} \`${item.claim_id}\`\n> <@${item.pair.discordID}> ${item.amount} LBC\n`
});
return paginator.start(message.channel.id, message.author.id);
}
get metadata() { return {
category: 'Admin',
description: 'List all supports from all users.',
usage: '[claimID]'
}; }
};

View file

@ -43,6 +43,7 @@ module.exports = class ListAll extends Command {
} }
get metadata() { return { get metadata() { return {
category: 'Admin', category: 'Admin',
description: 'List all users in the database.' description: 'List all users in the database.',
usage: '[page]'
}; } }; }
}; };

View file

@ -49,7 +49,7 @@ module.exports = class Supports extends Command {
items: supports, items: supports,
header: `All supports for <@${discordID || message.author.id}>${ header: `All supports for <@${discordID || message.author.id}>${
givenClaim ? ` on claim \`${givenClaim}\`` : ''}`, itemTitle: 'Supports',itemsPerPage: 5, givenClaim ? ` on claim \`${givenClaim}\`` : ''}`, itemTitle: 'Supports',itemsPerPage: 5,
display: item => `> ${item.name} #\`${item.claim_id}\`\n> ${item.amount} LBC\n` display: item => `> ${item.name} \`${item.claim_id}\`\n> ${item.amount} LBC\n`
}); });
return paginator.start(message.channel.id, message.author.id); return paginator.start(message.channel.id, message.author.id);
} }

View file

@ -30,7 +30,7 @@ module.exports = class TSupports extends Command {
items: supports, items: supports,
header: `All supports for the trusted account${ header: `All supports for the trusted account${
givenClaim ? ` on claim \`${givenClaim}\`` : ''}`, itemTitle: 'Supports', itemsPerPage: 5, givenClaim ? ` on claim \`${givenClaim}\`` : ''}`, itemTitle: 'Supports', itemsPerPage: 5,
display: item => `> ${item.name} #\`${item.claim_id}\`\n> ${item.amount} LBC\n` display: item => `> ${item.name} \`${item.claim_id}\`\n> ${item.amount} LBC\n`
}); });
return paginator.start(message.channel.id, message.author.id); return paginator.start(message.channel.id, message.author.id);
} }