This commit is contained in:
parent
5f3fc0a85d
commit
26535d47d1
19
index.js
19
index.js
|
@ -526,6 +526,25 @@ const handleDiscord = function (data) {
|
||||||
let user = discord.users.cache.get(row.userid);
|
let user = discord.users.cache.get(row.userid);
|
||||||
if (!user) return console.log(`${colors.red("[ERROR]")} User ${row.userid} not found`);
|
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;
|
if (!filters.some((filter) => body.string.toLowerCase().includes(filter)) && !filters.some((filter) => text.toLowerCase().includes(filter))) return;
|
||||||
thisMsg = JSON.parse(JSON.stringify(discordMsg));
|
thisMsg = JSON.parse(JSON.stringify(discordMsg));
|
||||||
thisMsg.content = row.custommessage || null;
|
thisMsg.content = row.custommessage || null;
|
||||||
|
|
Loading…
Reference in a new issue