dankgrinder 8.54.0 → 8.57.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.
Files changed (2) hide show
  1. package/lib/grinder.js +55 -17
  2. package/package.json +1 -1
package/lib/grinder.js CHANGED
@@ -2002,11 +2002,25 @@ class AccountWorker {
2002
2002
 
2003
2003
  // Set up error/disconnect handlers for auto-recovery
2004
2004
  this._attachRecoveryListeners();
2005
- rawLogger.attachRawLogger(this.client, { channelId: this.account.channel_id });
2005
+ rawLogger.attachRawLogger(this.client, { channelId: this.channel?.id || this.account.channel_id || '' });
2006
2006
  rawLogger.attachDmLogger(this.client);
2007
2007
 
2008
- await this.client.login(this.account.discord_token);
2009
- this.channel = await this.client.channels.fetch(this.account.channel_id).catch(() => null);
2008
+ // DM mode: resolve Dank Memer DM after login
2009
+ if (isDMMode) {
2010
+ const recoveryLoginToken = this.account.access_token || this.account.discord_token;
2011
+ await this.client.login(recoveryLoginToken);
2012
+ try {
2013
+ const dankUser = await this.client.users.fetch(DANK_MEMER_ID);
2014
+ this.channel = await dankUser.createDM();
2015
+ this._dmChannelId = this.channel.id;
2016
+ this.log('info', `DM re-opened with Dank Memer`);
2017
+ } catch (err) {
2018
+ this.log('error', `Failed to re-open DM: ${err?.message || err}`);
2019
+ }
2020
+ } else {
2021
+ await this.client.login(this.account.discord_token);
2022
+ this.channel = await this.client.channels.fetch(this.account.channel_id).catch(() => null);
2023
+ }
2010
2024
 
2011
2025
  if (this.channel) {
2012
2026
  this._recoveryAttempts = 0;
@@ -2486,8 +2500,13 @@ class AccountWorker {
2486
2500
  } else {
2487
2501
  process.stdout.write(`[WORKER START] ${this.account.label || this.account.id}\n`);
2488
2502
  }
2489
- if (!this.account.discord_token) { this.log('error', 'No token'); return; }
2490
- if (!this.account.channel_id) { this.log('error', 'No channel'); return; }
2503
+ if (!this.account.discord_token && !this.account.access_token) { this.log('error', 'No token or access token'); return; }
2504
+ if (!this.account.channel_id && this.account.grind_mode !== 'dm') { this.log('error', 'No channel'); return; }
2505
+
2506
+ // Determine login token: OAuth access_token takes priority over discord_token
2507
+ const loginToken = this.account.access_token || this.account.discord_token;
2508
+ const grindMode = this.account.grind_mode || 'channel';
2509
+ const isDMMode = grindMode === 'dm';
2491
2510
 
2492
2511
  const LOGIN_TIMEOUT_MS = 30_000; // 30s max per account login
2493
2512
 
@@ -2512,8 +2531,8 @@ class AccountWorker {
2512
2531
  this.loggedIn = true; // so statusColor/statusText show correct state
2513
2532
 
2514
2533
  // Attach raw gateway logger for CV2 component capture
2515
- rawLogger.attachRawLogger(this.client, { channelId: this.account.channel_id });
2516
- rawLogger.attachDmLogger(this.client);
2534
+ rawLogger.attachRawLogger(this.client, { channelId: this.channel?.id || '' });
2535
+ rawLogger.attachDmLogger(this.client);
2517
2536
 
2518
2537
  // Report status non-blocking
2519
2538
  fetch(`${API_URL}/api/grinder/status`, {
@@ -2522,10 +2541,23 @@ class AccountWorker {
2522
2541
  body: JSON.stringify({ account_id: this.account.id, discord_username: this.username, avatar_url: this.avatarUrl, userId: this.account.userId }),
2523
2542
  }).catch(() => {});
2524
2543
 
2525
- this.channel = await this.client.channels.fetch(this.account.channel_id).catch(() => null);
2526
- if (!this.channel) {
2527
- this.log('error', `Channel not found`);
2528
- done(); return;
2544
+ // Resolve grinding channel: DM mode opens DM with Dank Memer, otherwise use configured channel
2545
+ if (isDMMode) {
2546
+ try {
2547
+ const dankUser = await this.client.users.fetch(DANK_MEMER_ID);
2548
+ this.channel = await dankUser.createDM();
2549
+ this._dmChannelId = this.channel.id;
2550
+ this.log('info', `DM opened with Dank Memer`);
2551
+ } catch (err) {
2552
+ this.log('error', `Failed to open DM: ${err?.message || err}`);
2553
+ done(); return;
2554
+ }
2555
+ } else {
2556
+ this.channel = await this.client.channels.fetch(this.account.channel_id).catch(() => null);
2557
+ if (!this.channel) {
2558
+ this.log('error', `Channel not found`);
2559
+ done(); return;
2560
+ }
2529
2561
  }
2530
2562
 
2531
2563
  const enabledCmds = [
@@ -2574,7 +2606,7 @@ class AccountWorker {
2574
2606
 
2575
2607
  // Attach auto-recovery event listeners before login
2576
2608
  this._attachRecoveryListeners();
2577
- this.client.login(this.account.discord_token).catch((err) => {
2609
+ this.client.login(loginToken).catch((err) => {
2578
2610
  clearTimeout(timeoutId);
2579
2611
  const msg = (err?.message || '').toLowerCase();
2580
2612
  if (msg.includes('token_invalid') || msg.includes('invalid token') || msg.includes('401') || msg.includes('incorrect login')) {
@@ -2638,11 +2670,17 @@ class AccountWorker {
2638
2670
  this.client.destroy();
2639
2671
  this.client = createLeanClient();
2640
2672
  this._attachRecoveryListeners();
2641
- await this.client.login(this.account.discord_token);
2642
- this.channel = await this.client.channels.fetch(this.account.channel_id).catch(() => null);
2643
- if (this.channel) {
2644
- this.username = this.client.user?.tag || this.username;
2645
- this.log('success', `Background login OK`);
2673
+ const retryToken = this.account.access_token || this.account.discord_token;
2674
+ await this.client.login(retryToken);
2675
+ // DM mode: re-open DM with Dank Memer
2676
+ if (this.account.grind_mode === 'dm') {
2677
+ const dankUser = await this.client.users.fetch(DANK_MEMER_ID);
2678
+ this.channel = await dankUser.createDM();
2679
+ this._dmChannelId = this.channel.id;
2680
+ this.log('success', `Background login OK (DM)`);
2681
+ } else {
2682
+ this.channel = await this.client.channels.fetch(this.account.channel_id).catch(() => null);
2683
+ if (this.channel) this.log('success', `Background login OK`);
2646
2684
  }
2647
2685
  } catch (err) {
2648
2686
  this.log('error', `Background login failed: ${err?.message || err}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dankgrinder",
3
- "version": "8.54.0",
3
+ "version": "8.57.0",
4
4
  "description": "Dank Memer automation engine — grind coins while you sleep",
5
5
  "bin": {
6
6
  "dankgrinder": "bin/dankgrinder.js"