From 49b80f6323cd0f66c217bf84c138c5bb1955f2d3 Mon Sep 17 00:00:00 2001 From: q Date: Sat, 27 Apr 2024 15:00:29 -0400 Subject: [PATCH] Add delay to whitelist warning message to prevent spamming --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 213b843..fcf4796 100644 --- a/index.js +++ b/index.js @@ -127,7 +127,14 @@ Searxng.prototype.handleMessage = function(event, room) { return; } else if (this.roomUserWhitelists.has(room.roomId) && this.roomUserWhitelists.get(room.roomId).indexOf(event.getSender()) < 0) { - this.matrixClient.sendNotice(room.roomId, "You are not on the whitelist for this room."); + const lastRoomWarningTime = lastWarningTimes.get(room.roomId); + + const currentTime = Date.now(); + + if (isNaN(lastRoomWarningTime) || (Date.now() - lastRoomWarningTime) > 10000) { + this.matrixClient.sendNotice(room.roomId, "You are not on the whitelist for this room."); + lastWarningTimes.set(room.roomId, currentTime); + } return; } else if (this.cooldownImmuneUsers.indexOf(event.getSender()) < 0) {