Add sync functions and command

This commit is contained in:
Snazzah 2021-06-10 18:19:21 -05:00
parent de8169af32
commit 342e288624
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E
4 changed files with 38 additions and 2 deletions

View file

@ -19,9 +19,9 @@ module.exports = {
guildID: "",
// [string] sdk_url
sdkURL: "",
// [string] The path to the main wallet file to back up
// [string] The ABSOLUTE path to the main wallet file to back up
walletPath: "~/.lbryum/wallets/default_wallet",
// [string] The folder to store wallet backups after every deletion
// [string] The ABSOLUTE path folder to store wallet backups after every deletion
walletBackupFolder: "~/.lbryum_backup/",
// [string] Amount to auto-fund upon account creation
startingBalance: "",

View file

@ -37,6 +37,7 @@ module.exports = class AbaondonAll extends Command {
header: 'Are you sure you want to abandon **all supports** from **all accounts**?'
})) return;
await this.client.startTyping(message.channel);
await Util.LBRY.syncPairs();
const pairs = await this.client.sqlite.getAll();
let count = 0;
for (let i = 0, len = pairs.length; i < len; i++) {

View file

@ -0,0 +1,20 @@
const Command = require('../../structures/Command');
const Util = require('../../util');
module.exports = class Sync extends Command {
get name() { return 'sync'; }
get _options() { return {
permissions: ['admin']
}; }
async exec(message) {
const synced = Util.LBRY.syncPairs(this.client);
return message.channel.createMessage(`Synced ${synced} new pairs.`);
}
get metadata() { return {
category: 'Admin',
description: 'Sync SDK-Discord pairs.'
}; }
};

View file

@ -222,6 +222,21 @@ Util.Hastebin = {
* @memberof Util.
*/
Util.LBRY = {
async syncPairs(client) {
const response = await client.lbry.listAccounts({ page_size: await Util.LBRY.getAccountCount(client) });
const accounts = await response.json();
let syncedAccounts = 0;
for (const account of accounts.results.items) {
if (/\d{17,19}/.test(account.name)) {
if (await client.sqlite.get(account.name)) continue;
await client.sqlite.pair(account.name, account.id);
syncedAccounts++;
}
}
return syncedAccounts;
},
async findSDKAccount(client, fn) {
const response = await client.lbry.listAccounts({ page_size: await Util.LBRY.getAccountCount(client) });
const accounts = await response.json();