dankgrinder 5.21.0 → 5.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/inventory.js +7 -1
- package/lib/grinder.js +14 -29
- package/package.json +1 -1
|
@@ -194,7 +194,7 @@ async function enrichItems(items) {
|
|
|
194
194
|
/**
|
|
195
195
|
* Check inventory for all pages and return full item list.
|
|
196
196
|
*/
|
|
197
|
-
async function runInventory({ channel, waitForDankMemer, client, accountId, redis }) {
|
|
197
|
+
async function runInventory({ channel, waitForDankMemer, client, accountId, redis, onPageProgress }) {
|
|
198
198
|
LOG.cmd(`${c.white}${c.bold}pls inv${c.reset}`);
|
|
199
199
|
|
|
200
200
|
await channel.send('pls inv');
|
|
@@ -218,6 +218,9 @@ async function runInventory({ channel, waitForDankMemer, client, accountId, redi
|
|
|
218
218
|
const allItems = [];
|
|
219
219
|
let { page, total } = parsePageInfo(response);
|
|
220
220
|
LOG.info(`[inv] Page ${page}/${total}`);
|
|
221
|
+
if (typeof onPageProgress === 'function') {
|
|
222
|
+
try { onPageProgress({ page, total }); } catch {}
|
|
223
|
+
}
|
|
221
224
|
const visitedPages = new Set([page]);
|
|
222
225
|
|
|
223
226
|
allItems.push(...parseInventoryPage(response));
|
|
@@ -316,6 +319,9 @@ async function runInventory({ channel, waitForDankMemer, client, accountId, redi
|
|
|
316
319
|
visitedPages.add(page);
|
|
317
320
|
pageChanged = true;
|
|
318
321
|
LOG.info(`[inv] Page ${page}/${total}`);
|
|
322
|
+
if (typeof onPageProgress === 'function') {
|
|
323
|
+
try { onPageProgress({ page, total }); } catch {}
|
|
324
|
+
}
|
|
319
325
|
break;
|
|
320
326
|
}
|
|
321
327
|
// Clear CV2 cache again for next retry
|
package/lib/grinder.js
CHANGED
|
@@ -1103,6 +1103,9 @@ class AccountWorker {
|
|
|
1103
1103
|
client: this.client,
|
|
1104
1104
|
accountId: this.account.id,
|
|
1105
1105
|
redis,
|
|
1106
|
+
onPageProgress: ({ page, total }) => {
|
|
1107
|
+
this.log('info', `Inventory pages: ${page}/${total}`);
|
|
1108
|
+
},
|
|
1106
1109
|
});
|
|
1107
1110
|
this.log('success', `Inventory: ${result.items?.length || 0} items, ⏣ ${(result.totalValue || 0).toLocaleString()} net`);
|
|
1108
1111
|
try {
|
|
@@ -2418,36 +2421,18 @@ async function start(apiKey, apiUrl) {
|
|
|
2418
2421
|
log('info', `${c.dim}Checking inventory for all ${workers.length} accounts...${c.reset}`);
|
|
2419
2422
|
let invDone = 0;
|
|
2420
2423
|
let invFailed = 0;
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
workers.length
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
let invCursor = 0;
|
|
2431
|
-
const runInventoryWorker = async (slot) => {
|
|
2432
|
-
while (!shutdownCalled) {
|
|
2433
|
-
const i = invCursor++;
|
|
2434
|
-
if (i >= workers.length) break;
|
|
2435
|
-
const w = workers[i];
|
|
2436
|
-
const label = w?.username || w?.account?.label || w?.account?.id || `account-${i + 1}`;
|
|
2437
|
-
log('info', `${c.dim}[inv-startup] ${i + 1}/${workers.length} ${label} ${c.dim}(runner ${slot})${c.reset}`);
|
|
2438
|
-
try {
|
|
2439
|
-
await w.checkInventory({ force: true, startupProgress: { current: i + 1, total: workers.length } });
|
|
2440
|
-
invDone++;
|
|
2441
|
-
} catch {
|
|
2442
|
-
invFailed++;
|
|
2443
|
-
}
|
|
2444
|
-
const invComplete = invDone + invFailed;
|
|
2445
|
-
log('info', `${c.dim}[inv-startup-progress] ${invComplete}/${workers.length} complete (${invDone} ok, ${invFailed} failed)${c.reset}`);
|
|
2446
|
-
await new Promise(r => setTimeout(r, 200 + Math.floor(Math.random() * 400)));
|
|
2424
|
+
await Promise.all(workers.map(async (w, i) => {
|
|
2425
|
+
const label = w?.username || w?.account?.label || w?.account?.id || `account-${i + 1}`;
|
|
2426
|
+
log('info', `${c.dim}[inv-startup] ${i + 1}/${workers.length} ${label}${c.reset}`);
|
|
2427
|
+
try {
|
|
2428
|
+
await w.checkInventory({ force: true, startupProgress: { current: i + 1, total: workers.length } });
|
|
2429
|
+
invDone++;
|
|
2430
|
+
} catch {
|
|
2431
|
+
invFailed++;
|
|
2447
2432
|
}
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2433
|
+
const invComplete = invDone + invFailed;
|
|
2434
|
+
log('info', `${c.dim}[inv-startup-progress] ${invComplete}/${workers.length} complete (${invDone} ok, ${invFailed} failed)${c.reset}`);
|
|
2435
|
+
}));
|
|
2451
2436
|
const invSummaryColor = invFailed > 0 ? c.yellow : c.green;
|
|
2452
2437
|
log('success', `${c.dim}Inventory phase complete: ${invSummaryColor}${invDone}/${workers.length}${c.reset}${c.dim} done${invFailed > 0 ? `, ${c.yellow}${invFailed} failed${c.reset}${c.dim}` : ''}. Starting grind loops...${c.reset}`);
|
|
2453
2438
|
|