From 751b1b2fbcfbab998241e06c507c3da5f59b9c0b Mon Sep 17 00:00:00 2001 From: Snazzah Date: Thu, 10 Jun 2021 21:08:01 -0500 Subject: [PATCH] Add error handling to fundall --- src/commands/admin/fundall.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/commands/admin/fundall.js b/src/commands/admin/fundall.js index 8596859..a0c29b6 100644 --- a/src/commands/admin/fundall.js +++ b/src/commands/admin/fundall.js @@ -35,18 +35,27 @@ module.exports = class FundAll extends Command { header: `Are you sure you want to fund **all** accounts? *(${givenAmount} LBC)*` })) return; - // ID - TXID - await this.client.startTyping(message.channel); const resultLines = []; + let funded = 0, + errored = 0; for (const pair of pairs) { const response = await this.client.lbry.fundAccount({ to: pair.lbryID, amount: givenAmount }); const transaction = await response.json(); - console.info('Funded account', pair.lbryID, transaction.result.txid); - resultLines.push(`${pair.discordID} - https://explorer.lbry.com/tx/${transaction.result.txid}`); + if ('code' in transaction) { + console.info('Failed to fund account', pair.lbryID, transaction.code, transaction.message); + resultLines.push(`${pair.discordID} ! ${transaction.code} - ${transaction.message}`); + errored++; + } else { + console.info('Funded account', pair.lbryID, transaction.result.txid); + resultLines.push(`${pair.discordID} - https://explorer.lbry.com/tx/${transaction.result.txid}`); + funded++; + } } this.client.stopTyping(message.channel); - return message.channel.createMessage(`Successfully funded ${resultLines.length} account(s)!`, { + return message.channel.createMessage(errored + ? `Failed to fund ${errored} accounts! (${funded} funded)` + : `Successfully funded ${funded} account(s)!`, { name: 'result.txt', file: Buffer.from(resultLines.join('\n'), 'utf8') });