mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add withdraw command
This commit is contained in:
parent
fb536a7529
commit
c7f7abe49f
4 changed files with 54 additions and 8 deletions
|
@ -10,10 +10,7 @@ module.exports = class AdminBalance extends Command {
|
||||||
|
|
||||||
async exec(message) {
|
async exec(message) {
|
||||||
const response = await this.client.lbry.walletBalance();
|
const response = await this.client.lbry.walletBalance();
|
||||||
if (response.status !== 200) {
|
if (this.handleResponse(message, response)) return;
|
||||||
console.error('SDK error in adminbalance', response, await response.text());
|
|
||||||
return message.channel.createMessage(`LBRY-SDK returned ${response.status}, check console.`);
|
|
||||||
}
|
|
||||||
const wallet = await response.json();
|
const wallet = await response.json();
|
||||||
return message.channel.createMessage({ embed: {
|
return message.channel.createMessage({ embed: {
|
||||||
description: `**Available:** ${wallet.result.available} LBC\n\n` +
|
description: `**Available:** ${wallet.result.available} LBC\n\n` +
|
||||||
|
|
|
@ -10,10 +10,7 @@ module.exports = class Deposit extends Command {
|
||||||
|
|
||||||
async exec(message) {
|
async exec(message) {
|
||||||
const response = await this.client.lbry.listAddresses();
|
const response = await this.client.lbry.listAddresses();
|
||||||
if (response.status !== 200) {
|
if (this.handleResponse(message, response)) return;
|
||||||
console.error('SDK error in deposit', response, await response.text());
|
|
||||||
return message.channel.createMessage(`LBRY-SDK returned ${response.status}, check console.`);
|
|
||||||
}
|
|
||||||
const address = await response.json();
|
const address = await response.json();
|
||||||
return message.channel.createMessage(`Address: ${address.result.items[0].address}`);
|
return message.channel.createMessage(`Address: ${address.result.items[0].address}`);
|
||||||
}
|
}
|
||||||
|
|
38
src/commands/admin/withdraw.js
Normal file
38
src/commands/admin/withdraw.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
const Command = require('../../structures/Command');
|
||||||
|
|
||||||
|
module.exports = class Withdraw extends Command {
|
||||||
|
get name() { return 'withdraw'; }
|
||||||
|
|
||||||
|
get _options() { return {
|
||||||
|
aliases: ['wd'],
|
||||||
|
permissions: ['admin'],
|
||||||
|
minimumArgs: 2
|
||||||
|
}; }
|
||||||
|
|
||||||
|
async exec(message, { args }) {
|
||||||
|
const amount = args[0];
|
||||||
|
if (isNaN(parseFloat(amount)))
|
||||||
|
return message.channel.createMessage('The first argument must be a numeric amount of LBC to send!');
|
||||||
|
|
||||||
|
// Check if the balance is more than requested
|
||||||
|
const balance = await this.client.lbry.walletBalance();
|
||||||
|
if (this.handleResponse(message, balance)) return;
|
||||||
|
const availableBalance = parseFloat((await balance.json()).result.available);
|
||||||
|
if (parseFloat(amount) > availableBalance)
|
||||||
|
return message.channel.createMessage(
|
||||||
|
'There is not enough available LBC in the wallet to send that amount!');
|
||||||
|
|
||||||
|
// Send to wallet
|
||||||
|
const response = await this.client.lbry.sendToWallet({ amount, to: args[1] });
|
||||||
|
if (this.handleResponse(message, response)) return;
|
||||||
|
const txid = (await response.json()).result.inputs[0].txid;
|
||||||
|
return message.channel.createMessage(`Sent ${parseFloat(amount)} LBC to ${args[1]}.\n` +
|
||||||
|
`https://explorer.lbry.com/tx/${txid}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
get metadata() { return {
|
||||||
|
category: 'Admin',
|
||||||
|
description: 'Sends funds to an address from the master wallet.',
|
||||||
|
usage: '<amount> <address>'
|
||||||
|
}; }
|
||||||
|
};
|
|
@ -78,6 +78,20 @@ class Command {
|
||||||
// eslint-disable-next-line no-empty-function, no-unused-vars
|
// eslint-disable-next-line no-empty-function, no-unused-vars
|
||||||
exec(Message, opts) { }
|
exec(Message, opts) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
async handleResponse(message, response) {
|
||||||
|
if (response.status !== 200) {
|
||||||
|
const error = response.status === 500 ?
|
||||||
|
{ message: 'Internal server error' } : (await response.json()).error;
|
||||||
|
console.error(`SDK error in ${this.name}:${message.author.id}`, response, error);
|
||||||
|
await message.channel.createMessage(`LBRY-SDK returned ${response.status}.\n${error.message}`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The options for the command
|
* The options for the command
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
|
|
Loading…
Add table
Reference in a new issue