Fix withdraw command

This commit is contained in:
Snazzah 2020-08-12 02:24:01 -05:00
parent 1ef48cc3e7
commit 93a5c5a7b1
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E
2 changed files with 8 additions and 2 deletions

View file

@ -1,4 +1,5 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const Util = require('../../util');
module.exports = class Withdraw extends Command { module.exports = class Withdraw extends Command {
get name() { return 'withdraw'; } get name() { return 'withdraw'; }
@ -10,8 +11,8 @@ module.exports = class Withdraw extends Command {
}; } }; }
async exec(message, { args }) { async exec(message, { args }) {
const amount = args[0]; const amount = Util.LBRY.ensureDecimal(args[0]);
if (isNaN(parseFloat(amount))) if (!amount)
return message.channel.createMessage('The first argument must be a numeric amount of LBC to send!'); return message.channel.createMessage('The first argument must be a numeric amount of LBC to send!');
// Check if the balance is more than requested // Check if the balance is more than requested

View file

@ -208,5 +208,10 @@ Util.LBRY = {
console.info('Created pair', discordID, account.result.id); console.info('Created pair', discordID, account.result.id);
await client.lbry.fundAccount({ to: account.result.id, amount: config.startingBalance }); await client.lbry.fundAccount({ to: account.result.id, amount: config.startingBalance });
return account; return account;
},
ensureDecimal(str) {
const num = parseFloat(str);
if (isNaN(num)) return null;
return Number.isInteger(num) ? `${num}.0` : num.toString();
} }
}; };