Add support command

This commit is contained in:
Snazzah 2020-08-12 23:20:45 -05:00
parent 5680a6b729
commit 0da58d190c
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E
3 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,52 @@
const Command = require('../../structures/Command');
const Util = require('../../util');
module.exports = class Support extends Command {
get name() { return 'support'; }
get _options() { return {
aliases: ['sup'],
permissions: ['curatorOrAdmin'],
minimumArgs: 2
}; }
async exec(message, { args }) {
const givenAmount = Util.LBRY.ensureDecimal(args[1]);
if (!givenAmount)
return message.channel.createMessage('The second argument must be a numeric amount of LBC to send!');
const givenClaim = args[0];
if (!/^[a-f0-9]{40}$/.test(givenClaim))
// @TODO use claim_search for invalid claim ids
return message.channel.createMessage('That Claim ID isn\'t valid.');
const account = await Util.LBRY.findOrCreateAccount(this.client, message.author.id);
if (account.newAccount) {
// Wait for the blockchain to complete the funding
await message.channel.sendTyping();
await Util.halt(3000);
}
// Get and check balance
const walletResponse = await this.client.lbry.accountBalance(account.accountID);
const wallet = await walletResponse.json();
if (await this.handleResponse(message, walletResponse, wallet)) return;
const balance = wallet.result.available;
if (parseFloat(givenAmount) > parseFloat(balance))
return message.channel.createMessage('You don\'t have enough LBC to do this!');
// Create support
const response = await this.client.lbry.createSupport({
accountID: account, claimID: givenClaim, amount: givenAmount });
const transaction = await response.json();
if (await this.handleResponse(message, response, transaction)) return;
const txid = transaction.result.txid;
message.channel.createMessage(`Support successful! https://explorer.lbry.com/tx/${txid}`);
}
get metadata() { return {
category: 'Curator',
description: 'Support a given claim.',
usage: '<claim> <amount>'
}; }
};

View file

@ -147,7 +147,7 @@ class LBRY {
createSupport({ accountID, claimID, amount }) {
return this._sdkRequest('support_create', {
account_id: accountID, claim_id: claimID,
amount, funding_account_ids: accountID });
amount: Util.LBRY.ensureDecimal(amount), funding_account_ids: accountID });
}
/**

View file

@ -145,6 +145,16 @@ Util.resolveToUserID = (arg) => {
else return null;
};
/**
* Make a promise that resolves after some time
* @memberof Util.
* @param {string} arg
* @returns {?string}
*/
Util.halt = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
};
/**
* Hastebin-related functions
* @memberof Util.