From 26535d47d10ca65de1389ca953d9c5e9aa1cdc21 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 26 May 2025 13:55:58 -0600 Subject: [PATCH] Debounce for DMs --- index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.js b/index.js index bafff37..3150c16 100644 --- a/index.js +++ b/index.js @@ -526,6 +526,25 @@ const handleDiscord = function (data) { let user = discord.users.cache.get(row.userid); if (!user) return console.log(`${colors.red("[ERROR]")} User ${row.userid} not found`); + // Debounce by user id and pil to prevent duplicate alerts + if (!sent[row.userid]) sent[row.userid] = {}; + if (sent[row.userid][product_id_raw]) { + // Already sent this pil to this user recently, skip + console.log(`${colors.yellow("[WARN]")} Already sent ${product_id_raw} to ${user.tag} (${user.id}), skipping...`); + return; + } + sent[row.userid][product_id_raw] = Date.now(); + // Optionally, clean up old entries after some time (e.g., 10 minutes) + setTimeout(() => { + if (sent[row.userid]) { + delete sent[row.userid][product_id_raw]; + if (Object.keys(sent[row.userid]).length === 0) { + delete sent[row.userid]; + } + } + }, 10 * 60 * 1000); + + if (!filters.some((filter) => body.string.toLowerCase().includes(filter)) && !filters.some((filter) => text.toLowerCase().includes(filter))) return; thisMsg = JSON.parse(JSON.stringify(discordMsg)); thisMsg.content = row.custommessage || null;