diff --git a/config/_default.js b/config/_default.js index 363f96d..a9884c7 100644 --- a/config/_default.js +++ b/config/_default.js @@ -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: "", diff --git a/src/commands/admin/abandonall.js b/src/commands/admin/abandonall.js index 18fc916..dd92b16 100644 --- a/src/commands/admin/abandonall.js +++ b/src/commands/admin/abandonall.js @@ -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++) { diff --git a/src/commands/admin/sync.js b/src/commands/admin/sync.js new file mode 100644 index 0000000..56806ef --- /dev/null +++ b/src/commands/admin/sync.js @@ -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.' + }; } +}; diff --git a/src/util.js b/src/util.js index 7fcc161..785118f 100644 --- a/src/util.js +++ b/src/util.js @@ -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();