From faed102ebb9157e02f9d059f119f719eb683b6fa Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 25 Jan 2024 16:27:21 +0200 Subject: [PATCH] join/leave log debounce --- src/client/components/observers/GuildLogging.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/client/components/observers/GuildLogging.ts b/src/client/components/observers/GuildLogging.ts index a8a390b..1ad3ba0 100644 --- a/src/client/components/observers/GuildLogging.ts +++ b/src/client/components/observers/GuildLogging.ts @@ -39,6 +39,11 @@ const CONSTANTS: { WEEK: 7 * 24 * 60 * 60 }; +const debounce: { + joins: { [key: string]: number }, + leaves: { [key: string]: number }, +} = { joins: {}, leaves: {} }; + class GuildLogger extends Observer { #attachmentWebhook: WebhookClient; @@ -858,6 +863,11 @@ class GuildLogger extends Observer if (!setting.channel || !setting.enabled || !setting.join) return; + if (!debounce.joins[member.id] || debounce.joins[member.id] < (Date.now() - 60_000)) + debounce.joins[member.id] = Date.now(); + else + return; + const logChannel = await wrapper.resolveChannel(setting.channel); if (!logChannel) return; @@ -879,6 +889,11 @@ class GuildLogger extends Observer if (!setting.channel || !setting.enabled || !setting.leave) return; + if (!debounce.leaves[member.id] || debounce.leaves[member.id] < (Date.now() - 60_000)) + debounce.leaves[member.id] = Date.now(); + else + return; + const logChannel = await wrapper.resolveChannel(setting.channel); if (!logChannel) return;