mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add util docs and fix abandonall
This commit is contained in:
parent
f4f7e19f95
commit
93b937dce7
2 changed files with 36 additions and 1 deletions
|
@ -6,7 +6,7 @@ module.exports = class AbaondonAll extends Command {
|
||||||
|
|
||||||
get _options() { return {
|
get _options() { return {
|
||||||
aliases: ['abanall', 'dropall'],
|
aliases: ['abanall', 'dropall'],
|
||||||
permissions: ['Admin'],
|
permissions: ['admin'],
|
||||||
minimumArgs: 0
|
minimumArgs: 0
|
||||||
}; }
|
}; }
|
||||||
|
|
||||||
|
|
35
src/util.js
35
src/util.js
|
@ -201,6 +201,12 @@ Util.Hastebin = {
|
||||||
* @memberof Util.
|
* @memberof Util.
|
||||||
*/
|
*/
|
||||||
Util.LBRY = {
|
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) {
|
async findOrCreateAccount(client, discordID, create = true) {
|
||||||
// Check SQLite
|
// Check SQLite
|
||||||
const pair = await client.sqlite.get(discordID);
|
const pair = await client.sqlite.get(discordID);
|
||||||
|
@ -226,14 +232,28 @@ Util.LBRY = {
|
||||||
};
|
};
|
||||||
} else return { accountID: null };
|
} else return { accountID: null };
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Gets the amount of accounts on the SDK
|
||||||
|
* @param {Client} client
|
||||||
|
*/
|
||||||
async getAccountCount(client) {
|
async getAccountCount(client) {
|
||||||
const response = await client.lbry.listAccounts({ page_size: 1 }).then(r => r.json());
|
const response = await client.lbry.listAccounts({ page_size: 1 }).then(r => r.json());
|
||||||
return response.result.total_items;
|
return response.result.total_items;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Gets the amount of supports from an account
|
||||||
|
* @param {Client} client
|
||||||
|
* @param {string} accountID
|
||||||
|
*/
|
||||||
async getSupportsCount(client, accountID) {
|
async getSupportsCount(client, accountID) {
|
||||||
const response = await client.lbry.listSupports({ accountID, page_size: 1 }).then(r => r.json());
|
const response = await client.lbry.listSupports({ accountID, page_size: 1 }).then(r => r.json());
|
||||||
return response.result.total_items;
|
return response.result.total_items;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Creates an account
|
||||||
|
* @param {Client} client
|
||||||
|
* @param {string} discordID
|
||||||
|
*/
|
||||||
async createAccount(client, discordID) {
|
async createAccount(client, discordID) {
|
||||||
console.info('Creating account for user', discordID);
|
console.info('Creating account for user', discordID);
|
||||||
const account = await client.lbry.createAccount(discordID).then(r => r.json());
|
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);
|
console.info('Funded account', account.result.id, transaction.result.txid);
|
||||||
return { account, transaction };
|
return { account, transaction };
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Ensures a decimal can be used by the SDK
|
||||||
|
* @param {string} str
|
||||||
|
*/
|
||||||
ensureDecimal(str) {
|
ensureDecimal(str) {
|
||||||
const num = parseFloat(str);
|
const num = parseFloat(str);
|
||||||
if (isNaN(num)) return null;
|
if (isNaN(num)) return null;
|
||||||
return Number.isInteger(num) ? `${num}.0` : num.toString();
|
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) {
|
async deleteAccount(client, discordID, lbryID) {
|
||||||
// Abandon supports
|
// Abandon supports
|
||||||
await Util.LBRY.abandonAllClaims(client, lbryID);
|
await Util.LBRY.abandonAllClaims(client, lbryID);
|
||||||
|
@ -263,6 +293,11 @@ Util.LBRY = {
|
||||||
await client.lbry.removeAccount(lbryID);
|
await client.lbry.removeAccount(lbryID);
|
||||||
await client.sqlite.remove(discordID);
|
await client.sqlite.remove(discordID);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Abandons all claims from an account
|
||||||
|
* @param {Client} client
|
||||||
|
* @param {string} lbryID
|
||||||
|
*/
|
||||||
async abandonAllClaims(client, lbryID) {
|
async abandonAllClaims(client, lbryID) {
|
||||||
if (!lbryID)
|
if (!lbryID)
|
||||||
throw new Error('lbryID must be defined!');
|
throw new Error('lbryID must be defined!');
|
||||||
|
|
Loading…
Add table
Reference in a new issue