From f4f7e19f95983297678a1af8f1cb65bfc8bf6340 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Fri, 14 Aug 2020 12:10:44 -0500 Subject: [PATCH] Fix some commands --- src/commands/admin/abandonall.js | 39 ++++++++++++++++---------------- src/commands/admin/fund.js | 2 +- src/commands/curator/abandon.js | 7 +----- src/commands/curator/support.js | 2 +- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/commands/admin/abandonall.js b/src/commands/admin/abandonall.js index 7b0680c..62c128f 100644 --- a/src/commands/admin/abandonall.js +++ b/src/commands/admin/abandonall.js @@ -10,26 +10,27 @@ module.exports = class AbaondonAll extends Command { minimumArgs: 0 }; } - // @TODO: Refactor this command for all abandons. + // @TODO: Refactor this command to be able to abandon all supports on the bot. async exec(message, { args }) { - 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); - } - // Create support - const response = await this.client.lbry.abandonSupport({ - accountID: account.accountID, claimID: givenClaim}); - const transaction = await response.json(); - if (await this.handleResponse(message, response, transaction)) return; - const txid = transaction.result.txid; - message.channel.createMessage(`Abandon successful! https://explorer.lbry.com/tx/${txid}`); + const discordID = Util.resolveToUserID(args[0]); + if (!discordID) + return message.channel.createMessage('That Discord user isn\'t valid.'); + const account = await Util.LBRY.findOrCreateAccount(this.client, discordID, false); + if (!account.accountID) + return message.channel.createMessage('That user does not have an account.'); + + const supportsCount = await Util.LBRY.getSupportsCount(this.client, account.accountID); + if (supportsCount <= 0) + return message.channel.createMessage('That user does not have any supports.'); + + if (!await this.client.messageAwaiter.confirm(message, { + header: + `Are you sure you want to abandon all supports from that account? *(${ + supportsCount.toLocaleString()} support[s])*` + })) return; + const response = await Util.LBRY.abandonAllClaims(this.client, account.accountID); + if (await this.handleResponse(message, response)) return; + return message.channel.createMessage('Abandoned all claims.'); } get metadata() { return { diff --git a/src/commands/admin/fund.js b/src/commands/admin/fund.js index 0e0e660..aef1d39 100644 --- a/src/commands/admin/fund.js +++ b/src/commands/admin/fund.js @@ -19,7 +19,7 @@ module.exports = class Fund extends Command { if (!discordID) return message.channel.createMessage('That Discord user isn\'t valid.'); - const account = await Util.LBRY.findOrCreateAccount(this.client, discordID, true); + const account = await Util.LBRY.findOrCreateAccount(this.client, discordID); if (!await this.client.messageAwaiter.confirm(message, { header: `Are you sure you want to fund this account? *(${givenAmount} LBC)*` })) return; diff --git a/src/commands/curator/abandon.js b/src/commands/curator/abandon.js index c555ca1..ef83207 100644 --- a/src/commands/curator/abandon.js +++ b/src/commands/curator/abandon.js @@ -17,11 +17,6 @@ module.exports = class Abaondon extends Command { 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); - } // Drop support const response = await this.client.lbry.abandonSupport({ @@ -29,7 +24,7 @@ module.exports = class Abaondon extends Command { const transaction = await response.json(); if (await this.handleResponse(message, response, transaction)) return; const txid = transaction.result.txid; - message.channel.createMessage(`Abandon successful! https://explorer.lbry.com/tx/${txid}`); + return message.channel.createMessage(`Abandon successful! https://explorer.lbry.com/tx/${txid}`); } get metadata() { return { diff --git a/src/commands/curator/support.js b/src/commands/curator/support.js index a7f4f1f..4430160 100644 --- a/src/commands/curator/support.js +++ b/src/commands/curator/support.js @@ -41,7 +41,7 @@ module.exports = class Support extends Command { 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}`); + return message.channel.createMessage(`Support successful! https://explorer.lbry.com/tx/${txid}`); } get metadata() { return {