Fix debounce
Some checks are pending
ptero-push / build (push) Waiting to run

This commit is contained in:
Christopher Cookman 2025-05-26 01:14:22 -06:00
parent 5039f566ea
commit 5f3fc0a85d

View file

@ -361,6 +361,7 @@ const handleDiscord = function (data) {
const rawBody = data.data.body;
const text = data.data.productText;
const product_id_raw = data.data.raw
const product_id = data.data.product_data;
const fromChannel = data.data.channel.room;
const body = data.data.body;
@ -432,16 +433,16 @@ const handleDiscord = function (data) {
thisMsg.content = row.custommessage || null;
// Debounce by channel id and pil to prevent duplicate alerts
if (!sent[row.channelid]) sent[row.channelid] = {};
if (sent[row.channelid][product_id.pil]) {
if (sent[row.channelid][product_id_raw]) {
// Already sent this pil to this channel recently, skip
console.log(`${colors.yellow("[WARN]")} Already sent ${product_id.pil} to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id}), skipping...`);
console.log(`${colors.yellow("[WARN]")} Already sent ${product_id_raw} to ${channel.guild.name}/${channel.name} (${channel.guild.id}/${channel.id}), skipping...`);
return;
}
sent[row.channelid][product_id.pil] = Date.now();
sent[row.channelid][product_id_raw] = Date.now();
// Optionally, clean up old entries after some time (e.g., 10 minutes)
setTimeout(() => {
if (sent[row.channelid]) {
delete sent[row.channelid][product_id.pil];
delete sent[row.channelid][product_id_raw];
if (Object.keys(sent[row.channelid]).length === 0) {
delete sent[row.channelid];
}