From 9b6b59005fe650f26e032887a4a9a7dfebbfc39d Mon Sep 17 00:00:00 2001 From: Robert Hafner Date: Sat, 7 Apr 2018 17:07:52 -0700 Subject: [PATCH] Normalize digits in message history to prevent spam --- js/Notify.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/js/Notify.js b/js/Notify.js index 8fa1a76..b4d026f 100644 --- a/js/Notify.js +++ b/js/Notify.js @@ -11,27 +11,26 @@ var Notify = function (message, limit=false, groups=false) { return } - // In cases where there are limits we have to record the history. - - var queue_message = message + '::' + groups.join('_') + // Save message history, normalizing digits to prevent notification spam. + const history_message = (message + '::' + groups.join('_')).replace(/\s(\d+)/g, 'X') if(!Memory.__notify_history) { Memory.__notify_history = {} } // If the message was sent in the last LIMIT ticks then don't send again. - if(!!Memory.__notify_history[queue_message]) { - var lastSent = Memory.__notify_history[queue_message] + if(!!Memory.__notify_history[history_message]) { + var lastSent = Memory.__notify_history[history_message] if(lastSent >= Game.time - limit) { return } else { // History is older than limit so delete it. - delete Memory.__notify_history[message] + delete Memory.__notify_history[history_message] } } // Record message in history and send it. - Memory.__notify_history[queue_message] = Game.time + Memory.__notify_history[history_message] = Game.time Notify.queueMessage(message, groups) return 0 }