diff --git a/src/commands/curator/abandon.ts b/src/commands/curator/abandon.ts new file mode 100644 index 0000000..a895797 --- /dev/null +++ b/src/commands/curator/abandon.ts @@ -0,0 +1,37 @@ +import { stripIndents } from 'common-tags'; +import { CommandContext, DexareClient } from 'dexare'; +import { GeneralCommand } from '../../util/abstracts'; + +export default class AbandonCommand extends GeneralCommand { + constructor(client: DexareClient) { + super(client, { + name: 'abandon', + description: 'Abandon a support on a claim.', + category: 'Curator', + aliases: ['aban', 'drop'], + userPermissions: ['lbry.curatorOrAdmin'], + metadata: { + examples: ['abandon @channel#a/video#b'], + usage: '' + } + }); + + this.filePath = __filename; + } + + async run(ctx: CommandContext) { + const claim = await this.lbryx.resolveClaim(ctx.args[0]); + if (!claim) return "That claim isn't valid."; + const account = await this.lbryx.ensureAccount(ctx.author.id); + + // Drop support + const transaction = await this.lbry.supportAbandon({ + account_id: account.id, + claim_id: claim + }); + return stripIndents` + Abandon successful! + 🔗 https://explorer.lbry.com/tx/${transaction.txid} + `; + } +} diff --git a/src/commands/curator/balance.ts b/src/commands/curator/balance.ts new file mode 100644 index 0000000..830722e --- /dev/null +++ b/src/commands/curator/balance.ts @@ -0,0 +1,45 @@ +import { CommandContext, DexareClient } from 'dexare'; +import { EnsureAccountResult } from '../../modules/lbryx'; +import { resolveUser } from '../../util'; +import { GeneralCommand } from '../../util/abstracts'; + +export default class BalanceCommand extends GeneralCommand { + constructor(client: DexareClient) { + super(client, { + name: 'balance', + description: 'Shows your account balance.', + category: 'Curator', + aliases: ['bal'], + userPermissions: ['lbry.curatorOrAdmin'], + metadata: { + examples: ['balance', 'balance @user'], + usage: '', + details: 'Only LBRY Admins can use this command to check the balance of others.' + } + }); + + this.filePath = __filename; + } + + async run(ctx: CommandContext) { + const isAdmin = this.client.permissions.has({ user: ctx.author }, 'lbry.admin'); + + let username = ctx.author.username, + account: EnsureAccountResult, + other = false; + if (isAdmin && ctx.args[0]) { + const userID = resolveUser(ctx.args[0]); + if (!userID) return "That Discord user isn't valid."; + const member = (await ctx.guild!.fetchMembers({ userIDs: [userID] }))[0]; + username = member ? member.username : userID; + account = await this.lbryx.ensureAccount(userID, false); + if (!account.id) return 'That Discord user does not have an account.'; + other = true; + } else account = await this.lbryx.ensureAccount(ctx.author.id); + + const wallet = await this.lbry.accountBalance({ account_id: account.id }); + return this.displayWallet(wallet, other ? `${username}'s Account Balance` : 'Your Account Balance', { + newAccount: account.new + }); + } +} diff --git a/src/commands/curator/support.ts b/src/commands/curator/support.ts new file mode 100644 index 0000000..f5f44d2 --- /dev/null +++ b/src/commands/curator/support.ts @@ -0,0 +1,50 @@ +import { stripIndents } from 'common-tags'; +import { CommandContext, DexareClient } from 'dexare'; +import { ensureDecimal, wait } from '../../util'; +import { GeneralCommand } from '../../util/abstracts'; + +export default class SupportCommand extends GeneralCommand { + constructor(client: DexareClient) { + super(client, { + name: 'support', + description: 'Support a claim.', + category: 'Curator', + aliases: ['sup'], + userPermissions: ['lbry.curatorOrAdmin'], + metadata: { + examples: ['support @channel#a/video#b 2.0'], + usage: ' ' + } + }); + + this.filePath = __filename; + } + + async run(ctx: CommandContext) { + const claim = await this.lbryx.resolveClaim(ctx.args[0]); + if (!claim) return "That claim isn't valid."; + const amount = ensureDecimal(ctx.args[1]); + if (!amount) return 'You must give a numeric amount of LBC to send!'; + + const account = await this.lbryx.ensureAccount(ctx.author.id); + if (account.new) await wait(3000); + + // Check if the balance is more than requested + const balance = await this.lbry.accountBalance({ account_id: account.id }); + const availableBalance = parseFloat(balance.available); + if (parseFloat(amount) > availableBalance) + return 'There is not enough available LBC in the account to fund that amount!'; + + // Create support + const transaction = await this.lbry.supportCreate({ + account_id: account.id, + funding_account_ids: [account.id], + claim_id: claim, + amount + }); + return stripIndents` + Support created! + 🔗 https://explorer.lbry.com/tx/${transaction.txid} + `; + } +} diff --git a/src/commands/curator/supports.ts b/src/commands/curator/supports.ts new file mode 100644 index 0000000..272905e --- /dev/null +++ b/src/commands/curator/supports.ts @@ -0,0 +1,63 @@ +import { CommandContext, DexareClient } from 'dexare'; +import { EnsureAccountResult } from '../../modules/lbryx'; +import { resolveUser } from '../../util'; +import { GeneralCommand } from '../../util/abstracts'; +import { paginate } from '../../util/pager'; + +export default class SupportsCommand extends GeneralCommand { + constructor(client: DexareClient) { + super(client, { + name: 'supports', + description: 'List supports.', + category: 'Curator', + aliases: ['sups'], + userPermissions: ['lbry.curatorOrAdmin'], + metadata: { + examples: ['supports', 'supports @user', 'supports @user @channel#a/video#b'], + usage: '[user] [claim]' + } + }); + + this.filePath = __filename; + } + + async run(ctx: CommandContext) { + let claim: string | null = null, + username = ctx.author.username, + account: EnsureAccountResult; + if (ctx.args[0]) { + const userID = resolveUser(ctx.args[0]); + if (!userID) return "That Discord user isn't valid."; + const member = (await ctx.guild!.fetchMembers({ userIDs: [userID] }))[0]; + username = member ? member.username : userID; + account = await this.lbryx.ensureAccount(userID, false); + if (!account.id) return 'That Discord user does not have an account.'; + } else account = await this.lbryx.ensureAccount(ctx.author.id); + + if (ctx.args[1]) { + claim = await this.lbryx.resolveClaim(ctx.args[1]); + if (!claim) return "That claim isn't valid."; + } + + const accountID = await this.lbryx.getDefaultAccount(); + const supportsCount = await this.lbryx.getSupportsCount(accountID); + if (supportsCount <= 0) return 'No supports found.'; + + const supports = await this.lbry.supportList({ + account_id: account.id, + page_size: supportsCount, + claim_id: claim || undefined + }); + + await paginate( + ctx, + { + items: supports.items.map((item) => `> ${item.name} \`${item.claim_id}\`\n> ${item.amount} LBC`), + itemSeparator: '\n\n' + }, + { + author: { name: `All supports by ${username}${claim ? ` on claim \`${claim}\`` : ''}` } + } + ); + } +}