mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add curator commands
This commit is contained in:
parent
85b1f9b00d
commit
d09c8fa311
4 changed files with 195 additions and 0 deletions
37
src/commands/curator/abandon.ts
Normal file
37
src/commands/curator/abandon.ts
Normal 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}
|
||||
`;
|
||||
}
|
||||
}
|
45
src/commands/curator/balance.ts
Normal file
45
src/commands/curator/balance.ts
Normal 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
|
||||
});
|
||||
}
|
||||
}
|
50
src/commands/curator/support.ts
Normal file
50
src/commands/curator/support.ts
Normal 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}
|
||||
`;
|
||||
}
|
||||
}
|
63
src/commands/curator/supports.ts
Normal file
63
src/commands/curator/supports.ts
Normal 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}\`` : ''}` }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue