Skip to content

Commit

Permalink
Normalize digits in message history to prevent spam
Browse files Browse the repository at this point in the history
  • Loading branch information
tedivm committed Apr 8, 2018
1 parent 2ecd5ae commit 9b6b590
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions js/Notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9b6b590

Please sign in to comment.