dankgrinder 4.9.1 → 4.9.2

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.
Files changed (2) hide show
  1. package/lib/grinder.js +68 -31
  2. package/package.json +1 -1
package/lib/grinder.js CHANGED
@@ -795,6 +795,7 @@ class AccountWorker {
795
795
  if (this._lastInvCheck && Date.now() - this._lastInvCheck < 300_000) return;
796
796
  this._invRunning = true;
797
797
  this._lastInvCheck = Date.now();
798
+ this.busy = true;
798
799
  try {
799
800
  this.log('info', 'Checking inventory...');
800
801
  const result = await commands.runInventory({
@@ -804,25 +805,23 @@ class AccountWorker {
804
805
  accountId: this.account.id,
805
806
  redis,
806
807
  });
807
- if (result.items?.length > 0) {
808
- this.log('success', `Inventory: ${result.items.length} items, ⏣ ${(result.totalValue || 0).toLocaleString()} net`);
809
- // Report inventory to API
810
- try {
811
- await fetch(`${API_URL}/api/grinder/inventory`, {
812
- method: 'POST',
813
- headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
814
- body: JSON.stringify({
815
- account_id: this.account.id,
816
- items: result.items,
817
- totalValue: result.totalValue,
818
- }),
819
- });
820
- } catch {}
821
- }
808
+ this.log('success', `Inventory: ${result.items?.length || 0} items, ⏣ ${(result.totalValue || 0).toLocaleString()} net`);
809
+ try {
810
+ await fetch(`${API_URL}/api/grinder/inventory`, {
811
+ method: 'POST',
812
+ headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
813
+ body: JSON.stringify({
814
+ account_id: this.account.id,
815
+ items: result.items || [],
816
+ totalValue: result.totalValue || 0,
817
+ }),
818
+ });
819
+ } catch {}
822
820
  } catch (e) {
823
821
  this.log('error', `Inventory check failed: ${e.message}`);
824
822
  } finally {
825
823
  this._invRunning = false;
824
+ this.busy = false;
826
825
  }
827
826
  }
828
827
 
@@ -862,23 +861,30 @@ class AccountWorker {
862
861
  bank = parseInt(bankTextMatch[1].replace(/,/g, ''), 10);
863
862
  }
864
863
 
865
- if (wallet > 0 || bank > 0) {
866
- this.stats.balance = wallet;
867
- this.stats.bankBalance = bank;
868
- this.log('bal', `Wallet: ${c.bold}${c.green}⏣ ${wallet.toLocaleString()}${c.reset} Bank: ${c.bold}${c.cyan}⏣ ${bank.toLocaleString()}${c.reset}`);
864
+ this.stats.balance = wallet;
865
+ this.stats.bankBalance = bank;
866
+ this.log('bal', `Wallet: ${c.bold}${c.green}⏣ ${wallet.toLocaleString()}${c.reset} Bank: ${c.bold}${c.cyan}⏣ ${bank.toLocaleString()}${c.reset}`);
867
+
868
+ // Store in Redis for persistence
869
+ if (redis) {
869
870
  try {
870
- await fetch(`${API_URL}/api/grinder/status`, {
871
- method: 'POST',
872
- headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
873
- body: JSON.stringify({
874
- account_id: this.account.id,
875
- balance: wallet,
876
- bank_balance: bank,
877
- total_balance: wallet + bank,
878
- }),
879
- });
880
- } catch { /* silent */ }
871
+ await redis.set(`dkg:bal:${this.account.id}`, JSON.stringify({ wallet, bank, ts: Date.now() }));
872
+ } catch {}
881
873
  }
874
+
875
+ // Always report to dashboard API
876
+ try {
877
+ await fetch(`${API_URL}/api/grinder/status`, {
878
+ method: 'POST',
879
+ headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
880
+ body: JSON.stringify({
881
+ account_id: this.account.id,
882
+ balance: wallet,
883
+ bank_balance: bank,
884
+ total_balance: wallet + bank,
885
+ }),
886
+ });
887
+ } catch { /* silent */ }
882
888
  }
883
889
  }
884
890
 
@@ -1534,8 +1540,39 @@ class AccountWorker {
1534
1540
  this.log('success', `#${chName} · ${enabledCmds.length} cmds`);
1535
1541
  this.setStatus('starting...');
1536
1542
 
1543
+ // Load daily/weekly/monthly done state from Redis
1544
+ if (redis) {
1545
+ for (const cmd of ['daily', 'weekly', 'monthly', 'drops']) {
1546
+ try {
1547
+ const val = await redis.get(`dkg:done:${this.account.id}:${cmd}`);
1548
+ if (val) {
1549
+ const ttlSec = await redis.ttl(`dkg:done:${this.account.id}:${cmd}`);
1550
+ if (ttlSec > 0) {
1551
+ this.doneToday.set(cmd, Date.now() + ttlSec * 1000);
1552
+ this.log('info', `${cmd} already claimed (${Math.round(ttlSec / 3600)}h remaining)`);
1553
+ }
1554
+ }
1555
+ } catch {}
1556
+ }
1557
+ // Load cached balance from Redis
1558
+ try {
1559
+ const balData = await redis.get(`dkg:bal:${this.account.id}`);
1560
+ if (balData) {
1561
+ const { wallet, bank } = JSON.parse(balData);
1562
+ if (wallet > 0 || bank > 0) {
1563
+ this.stats.balance = wallet;
1564
+ this.stats.bankBalance = bank;
1565
+ await fetch(`${API_URL}/api/grinder/status`, {
1566
+ method: 'POST',
1567
+ headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
1568
+ body: JSON.stringify({ account_id: this.account.id, balance: wallet, bank_balance: bank, total_balance: wallet + bank }),
1569
+ }).catch(() => {});
1570
+ }
1571
+ }
1572
+ } catch {}
1573
+ }
1574
+
1537
1575
  await this.checkBalance();
1538
- // Check inventory on startup
1539
1576
  this.checkInventory().catch(() => {});
1540
1577
  this.grindLoop();
1541
1578
  resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dankgrinder",
3
- "version": "4.9.1",
3
+ "version": "4.9.2",
4
4
  "description": "Dank Memer automation engine — grind coins while you sleep",
5
5
  "bin": {
6
6
  "dankgrinder": "bin/dankgrinder.js"