dankgrinder 4.9.7 → 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.
- package/lib/commands/utils.js +7 -1
- package/lib/grinder.js +24 -11
- package/package.json +1 -1
package/lib/commands/utils.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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 <
|
|
861
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
853
862
|
try {
|
|
854
|
-
const recent = await this.channel.messages.fetch({ limit:
|
|
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 -
|
|
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
|
-
|
|
869
|
-
|
|
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:
|
|
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('
|
|
874
|
-
response = await this.waitForDankMemer(
|
|
886
|
+
await this.channel.send('pls bal');
|
|
887
|
+
response = await this.waitForDankMemer(12000);
|
|
875
888
|
}
|
|
876
889
|
|
|
877
890
|
if (response) {
|
|
@@ -888,7 +901,7 @@ class AccountWorker {
|
|
|
888
901
|
|
|
889
902
|
// If we received a stale/irrelevant update, fetch same message fresh.
|
|
890
903
|
if ((!text || !looksLikeBalance(text)) && response.id && this.channel?.messages?.fetch) {
|
|
891
|
-
const fetched = await this.channel.messages.fetch(response.id).catch(() => null);
|
|
904
|
+
const fetched = await Promise.resolve(this.channel.messages.fetch(response.id)).catch(() => null);
|
|
892
905
|
if (fetched) {
|
|
893
906
|
const fetchedText = await readBalanceText(fetched, true);
|
|
894
907
|
if (fetchedText) {
|