Add curator commands

This commit is contained in:
Snazzah 2021-06-24 19:04:45 -05:00
parent 85b1f9b00d
commit d09c8fa311
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E
4 changed files with 195 additions and 0 deletions

View file

@ -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<any>) {
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: '<claim>'
}
});
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}
`;
}
}

View file

@ -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<any>) {
super(client, {
name: 'balance',
description: 'Shows your account balance.',
category: 'Curator',
aliases: ['bal'],
userPermissions: ['lbry.curatorOrAdmin'],
metadata: {
examples: ['balance', 'balance @user'],
usage: '<user>',
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
});
}
}

View file

@ -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<any>) {
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: '<claim> <amount>'
}
});
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}
`;
}
}

View file

@ -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<any>) {
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}\`` : ''}` }
}
);
}
}