dankgrinder 4.9.8 → 4.9.9

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.
@@ -395,7 +395,13 @@ function _extractCV2Buttons(components) {
395
395
  function isCV2(msg) {
396
396
  if (!msg) return false;
397
397
  if ((msg.flags?.bitfield & CV2_FLAG) !== 0) return true;
398
- return msg.components?.length > 0 && msg.components.every(c => !c);
398
+ const components = Array.isArray(msg.components) ? msg.components : [];
399
+ if (components.length === 0) return false;
400
+ // Some gateways send placeholder/null components for CV2 while content is empty.
401
+ if (components.every(c => !c)) return true;
402
+ const hasText = (msg.content && msg.content.length > 0) || (msg.embeds && msg.embeds.length > 0);
403
+ if (!hasText) return true;
404
+ return components.some(c => c && (c.type || c.components || c.content || c.customId || c.label));
399
405
  }
400
406
 
401
407
  async function ensureCV2(msg, force = false) {
package/lib/grinder.js CHANGED
@@ -573,7 +573,11 @@ class AccountWorker {
573
573
  function handler(msg) {
574
574
  if (msg.author.id === DANK_MEMER_ID && msg.channel.id === self.channel.id) {
575
575
  // If message has no content and no embeds, Dank Memer may populate via edit
576
- const hasContent = (msg.content && msg.content.length > 0) || (msg.embeds && msg.embeds.length > 0) || (msg.components && msg.components.length > 0);
576
+ const hasComponentPayload = Array.isArray(msg.components)
577
+ && msg.components.some(c => c && (c.components || c.content || c.type || c.label || c.customId));
578
+ const hasContent = (msg.content && msg.content.length > 0)
579
+ || (msg.embeds && msg.embeds.length > 0)
580
+ || hasComponentPayload;
577
581
  if (!hasContent) {
578
582
  // Wait for the edit with actual content (up to 3s)
579
583
  const editTimer = setTimeout(() => { cleanup(); resolve(msg); }, 3000);
@@ -843,17 +847,22 @@ class AccountWorker {
843
847
 
844
848
  const readBalanceText = async (msg, forceCV2 = false) => {
845
849
  if (!msg) return '';
846
- if (isCV2(msg)) await ensureCV2(msg, forceCV2);
850
+ const needsCv2 = forceCV2
851
+ || isCV2(msg)
852
+ || (Array.isArray(msg.components) && msg.components.length > 0
853
+ && (!msg.content || msg.content.length === 0)
854
+ && (!msg.embeds || msg.embeds.length === 0));
855
+ if (needsCv2) await ensureCV2(msg, forceCV2);
847
856
  return stripAnsi(getFullText(msg)).replace(/\s+/g, ' ').trim();
848
857
  };
849
858
 
850
859
  const findRecentBalanceMessage = async () => {
851
860
  if (!this.channel?.messages?.fetch) return null;
852
- for (let attempt = 0; attempt < 4; attempt++) {
861
+ for (let attempt = 0; attempt < 6; attempt++) {
853
862
  try {
854
- const recent = await this.channel.messages.fetch({ limit: 8 });
863
+ const recent = await this.channel.messages.fetch({ limit: 12 });
855
864
  const candidates = [...recent.values()].filter((m) =>
856
- m?.author?.id === DANK_MEMER_ID && (m.createdTimestamp || 0) >= sentAt - 2500
865
+ m?.author?.id === DANK_MEMER_ID && (m.createdTimestamp || 0) >= sentAt - 10000
857
866
  );
858
867
  for (const m of candidates) {
859
868
  const t = await readBalanceText(m, true);
@@ -865,13 +874,17 @@ class AccountWorker {
865
874
  return null;
866
875
  };
867
876
 
868
- await this.channel.send(`${prefix} bal`);
869
- let response = await this.waitForDankMemer(10000);
877
+ if (this.account.use_slash && this.channel?.sendSlash) {
878
+ await this.channel.sendSlash(DANK_MEMER_ID, 'balance').catch(() => this.channel.send('/balance'));
879
+ } else {
880
+ await this.channel.send(`${prefix} bal`);
881
+ }
882
+ let response = await this.waitForDankMemer(12000);
870
883
 
871
- // Fallback for slash setup: sometimes "/ bal" misses and only "/balance" works.
884
+ // Fallback for slash setup: try legacy prefix if no slash response.
872
885
  if (!response && this.account.use_slash) {
873
- await this.channel.send('/balance');
874
- response = await this.waitForDankMemer(10000);
886
+ await this.channel.send('pls bal');
887
+ response = await this.waitForDankMemer(12000);
875
888
  }
876
889
 
877
890
  if (response) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dankgrinder",
3
- "version": "4.9.8",
3
+ "version": "4.9.9",
4
4
  "description": "Dank Memer automation engine — grind coins while you sleep",
5
5
  "bin": {
6
6
  "dankgrinder": "bin/dankgrinder.js"