From 93b937dce7ee5ea30503d4e91f620826250c8294 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Fri, 14 Aug 2020 12:46:25 -0500 Subject: [PATCH] Add util docs and fix abandonall --- src/commands/admin/abandonall.js | 2 +- src/util.js | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/commands/admin/abandonall.js b/src/commands/admin/abandonall.js index 62c128f..257b09c 100644 --- a/src/commands/admin/abandonall.js +++ b/src/commands/admin/abandonall.js @@ -6,7 +6,7 @@ module.exports = class AbaondonAll extends Command { get _options() { return { aliases: ['abanall', 'dropall'], - permissions: ['Admin'], + permissions: ['admin'], minimumArgs: 0 }; } diff --git a/src/util.js b/src/util.js index fcf8683..f3b0892 100644 --- a/src/util.js +++ b/src/util.js @@ -201,6 +201,12 @@ Util.Hastebin = { * @memberof Util. */ Util.LBRY = { + /** + * Find or create a user's account + * @param {Client} client + * @param {string} discordID + * @param {boolean} [create=true] Whether or not to create the account + */ async findOrCreateAccount(client, discordID, create = true) { // Check SQLite const pair = await client.sqlite.get(discordID); @@ -226,14 +232,28 @@ Util.LBRY = { }; } else return { accountID: null }; }, + /** + * Gets the amount of accounts on the SDK + * @param {Client} client + */ async getAccountCount(client) { const response = await client.lbry.listAccounts({ page_size: 1 }).then(r => r.json()); return response.result.total_items; }, + /** + * Gets the amount of supports from an account + * @param {Client} client + * @param {string} accountID + */ async getSupportsCount(client, accountID) { const response = await client.lbry.listSupports({ accountID, page_size: 1 }).then(r => r.json()); return response.result.total_items; }, + /** + * Creates an account + * @param {Client} client + * @param {string} discordID + */ async createAccount(client, discordID) { console.info('Creating account for user', discordID); const account = await client.lbry.createAccount(discordID).then(r => r.json()); @@ -244,11 +264,21 @@ Util.LBRY = { console.info('Funded account', account.result.id, transaction.result.txid); return { account, transaction }; }, + /** + * Ensures a decimal can be used by the SDK + * @param {string} str + */ ensureDecimal(str) { const num = parseFloat(str); if (isNaN(num)) return null; return Number.isInteger(num) ? `${num}.0` : num.toString(); }, + /** + * Deletes an account + * @param {Client} client + * @param {string} discordID + * @param {string} lbryID + */ async deleteAccount(client, discordID, lbryID) { // Abandon supports await Util.LBRY.abandonAllClaims(client, lbryID); @@ -263,6 +293,11 @@ Util.LBRY = { await client.lbry.removeAccount(lbryID); await client.sqlite.remove(discordID); }, + /** + * Abandons all claims from an account + * @param {Client} client + * @param {string} lbryID + */ async abandonAllClaims(client, lbryID) { if (!lbryID) throw new Error('lbryID must be defined!');