From 15e871f670d673be58104ea2e83e52bf064539fd Mon Sep 17 00:00:00 2001 From: "Ralph S. (Coolguy3289)" Date: Fri, 14 Aug 2020 11:01:04 -0400 Subject: [PATCH] Fixed typo in deleteAccount, Added Fund command --- src/commands/admin/deleteaccount.js | 2 +- src/commands/admin/fund.js | 36 ++++++++++++ src/commands/curator/supports.js | 90 ++++++++++++++--------------- 3 files changed, 82 insertions(+), 46 deletions(-) create mode 100644 src/commands/admin/fund.js diff --git a/src/commands/admin/deleteaccount.js b/src/commands/admin/deleteaccount.js index 8f6e52f..3f79430 100644 --- a/src/commands/admin/deleteaccount.js +++ b/src/commands/admin/deleteaccount.js @@ -18,7 +18,7 @@ module.exports = class DeleteAccount extends Command { if (account.accountID) { const supportsCount = await Util.LBRY.getSupportsCount(this.client, account.accountID); if (!await this.client.messageAwaiter.confirm(message, { - header: `Are you sure you delete that account? *(${supportsCount.toLocaleString()} support[s])*` + header: `Are you sure you want to delete that account? *(${supportsCount.toLocaleString()} support[s])*` })) return; await Util.LBRY.deleteAccount(this.client, discordID, account.accountID); return message.channel.createMessage('Deleted account.'); diff --git a/src/commands/admin/fund.js b/src/commands/admin/fund.js new file mode 100644 index 0000000..6fc6bf9 --- /dev/null +++ b/src/commands/admin/fund.js @@ -0,0 +1,36 @@ +const Command = require('../../structures/Command'); +const Util = require('../../util'); + +module.exports = class FundAccount extends Command { + get name() { return 'fundaccount'; } + + get _options() { return { + aliases: ['fund', 'fundacc'], + permissions: ['admin'], + 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 discordID = Util.resolveToUserID(args[0]); + if (!discordID) + message.channel.createMessage('That Discord user isn\'t valid.'); + const account = await Util.LBRY.findOrCreateAccount(this.client, discordID, true); + if (!await this.client.messageAwaiter.confirm(message, { + header: `Are you sure you want to fund this account? *(${givenAmount} LBC)*` + })) return; + const response = await this.client.lbry.fundAccount({to: account.accountID, amount: givenAmount}); + const transaction = await response.json(); + console.info('Funded account', account.result.id, transaction.result.txid); + const txid = transaction.result.txid; + return message.channel.createMessage(`Successfully funded account! https://explorer.lbry.com/tx/${txid}`); + } + + get metadata() { return { + category: 'Admin', + description: 'Funds a given Discord user\'s Curation account with the specified amount of LBC.', + usage: ' ' + }; } +}; diff --git a/src/commands/curator/supports.js b/src/commands/curator/supports.js index b758a7e..bf6ecdb 100644 --- a/src/commands/curator/supports.js +++ b/src/commands/curator/supports.js @@ -2,54 +2,54 @@ const Command = require('../../structures/Command'); const Util = require('../../util'); module.exports = class Supports extends Command { -get name() { return 'supports'; } -get _options() { return { - aliases: ['sups'], - permissions: ['curatorOrAdmin'], - minimumArgs: 0 -}; } -async exec(message, { args }) { - if(args.count = 2) { - 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 discordID = Util.resolveToUserID(args[1]); - if (!discordID) - message.channel.createMessage('That Discord user isn\'t valid.'); - const account = await Util.LBRY.findOrCreateAccount(this.client, discordID, false); - } else if (args.count = 1) { - const discordID = Util.resolveToUserID(args[0]); - if (!discordID) - message.channel.createMessage('That Discord user isn\'t valid.'); - const account = await Util.LBRY.findOrCreateAccount(this.client, discordID, false); - } else { - const account = await Util.LBRY.findOrCreateAccount(this.client, message.author.id); - } - const supportsCount = await Util.LBRY.getSupportsCount(client, account.accountID); - if(!givenClaim) { + get name() { return 'supports'; } + get _options() { return { + aliases: ['sups'], + permissions: ['curatorOrAdmin'], + minimumArgs: 0 + }; } + async exec(message, { args }) { + if(args.count = 2) { + 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 discordID = Util.resolveToUserID(args[1]); + if (!discordID) + message.channel.createMessage('That Discord user isn\'t valid.'); + const account = await Util.LBRY.findOrCreateAccount(this.client, discordID, false); + } else if (args.count = 1) { + const discordID = Util.resolveToUserID(args[0]); + if (!discordID) + message.channel.createMessage('That Discord user isn\'t valid.'); + const account = await Util.LBRY.findOrCreateAccount(this.client, discordID, false); + } else { + const account = await Util.LBRY.findOrCreateAccount(this.client, message.author.id); + } + const supportsCount = await Util.LBRY.getSupportsCount(client, account.accountID); + if(!givenClaim) { + const supportsResponse = await client.lbry.listSupports({ + accountID: account.accountID, page_size: supportsCount }); + console.debug(`Displaying supports for ${account.accountID} (${supportsCount})`); + const supports = (await supportsResponse.json()).result.items; + for (let i = 0, len = supports.length; i < len; i++) { + const support = supports[i]; + message.channel.createMessage(`ClaimID: \`${support.claim_id}\`\nClaim Name: \`${support.name}\`\nClaim URL: \`${support.permanent_url}\`\nSupport Ammount: \`${support.amount}\`\n`); + } + }else { const supportsResponse = await client.lbry.listSupports({ - accountID: account.accountID, page_size: supportsCount }); - console.debug(`Displaying supports for ${account.accountID} (${supportsCount})`); + accountID: account.accountID, page_size: supportsCount, claim_id: givenClaim }); + console.debug(`Displaying supports for ${account.accountID} and claimID ${givenClaim}, (${supportsCount})`); const supports = (await supportsResponse.json()).result.items; for (let i = 0, len = supports.length; i < len; i++) { const support = supports[i]; message.channel.createMessage(`ClaimID: \`${support.claim_id}\`\nClaim Name: \`${support.name}\`\nClaim URL: \`${support.permanent_url}\`\nSupport Ammount: \`${support.amount}\`\n`); - } - }else { - const supportsResponse = await client.lbry.listSupports({ - accountID: account.accountID, page_size: supportsCount, claim_id: givenClaim }); - console.debug(`Displaying supports for ${account.accountID} and claimID ${givenClaim}, (${supportsCount})`); - const supports = (await supportsResponse.json()).result.items; - for (let i = 0, len = supports.length; i < len; i++) { - const support = supports[i]; - message.channel.createMessage(`ClaimID: \`${support.claim_id}\`\nClaim Name: \`${support.name}\`\nClaim URL: \`${support.permanent_url}\`\nSupport Ammount: \`${support.amount}\`\n`); - } - } -} -get metadata() { return { - category: 'Curator', - description: 'Shows the user\'s list of supports.', - usage: '[claimID] [mention/discordID]' -}; } + } + } + } + get metadata() { return { + category: 'Curator', + description: 'Shows the user\'s list of supports.', + usage: '[claimID] [mention/discordID]' + }; } };