mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Add sync functions and command
This commit is contained in:
parent
de8169af32
commit
342e288624
4 changed files with 38 additions and 2 deletions
|
@ -19,9 +19,9 @@ module.exports = {
|
||||||
guildID: "",
|
guildID: "",
|
||||||
// [string] sdk_url
|
// [string] sdk_url
|
||||||
sdkURL: "",
|
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",
|
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/",
|
walletBackupFolder: "~/.lbryum_backup/",
|
||||||
// [string] Amount to auto-fund upon account creation
|
// [string] Amount to auto-fund upon account creation
|
||||||
startingBalance: "",
|
startingBalance: "",
|
||||||
|
|
|
@ -37,6 +37,7 @@ module.exports = class AbaondonAll extends Command {
|
||||||
header: 'Are you sure you want to abandon **all supports** from **all accounts**?'
|
header: 'Are you sure you want to abandon **all supports** from **all accounts**?'
|
||||||
})) return;
|
})) return;
|
||||||
await this.client.startTyping(message.channel);
|
await this.client.startTyping(message.channel);
|
||||||
|
await Util.LBRY.syncPairs();
|
||||||
const pairs = await this.client.sqlite.getAll();
|
const pairs = await this.client.sqlite.getAll();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (let i = 0, len = pairs.length; i < len; i++) {
|
for (let i = 0, len = pairs.length; i < len; i++) {
|
||||||
|
|
20
src/commands/admin/sync.js
Normal file
20
src/commands/admin/sync.js
Normal 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.'
|
||||||
|
}; }
|
||||||
|
};
|
15
src/util.js
15
src/util.js
|
@ -222,6 +222,21 @@ Util.Hastebin = {
|
||||||
* @memberof Util.
|
* @memberof Util.
|
||||||
*/
|
*/
|
||||||
Util.LBRY = {
|
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) {
|
async findSDKAccount(client, fn) {
|
||||||
const response = await client.lbry.listAccounts({ page_size: await Util.LBRY.getAccountCount(client) });
|
const response = await client.lbry.listAccounts({ page_size: await Util.LBRY.getAccountCount(client) });
|
||||||
const accounts = await response.json();
|
const accounts = await response.json();
|
||||||
|
|
Loading…
Add table
Reference in a new issue