Created
March 10, 2024 10:13
-
-
Save Zwiterrion/3b67fe0880dcfad01214f6a824cf48e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const saveMessage = (message) => { | |
const existingMessage = messages[message]; | |
let occurrences = 1; | |
if (existingMessage) { | |
occurrences = existingMessage.occurrences + 1; | |
} | |
if (Date.now() - messages[message]?.last_update > copyPastaIntervalDetectionTime) { | |
occurrences = 1; | |
} | |
messages[message] = { | |
occurrences, | |
last_update: occurrences < maxOccurrences ? Date.now() : messages[message].last_update | |
} | |
} | |
const cleanupOldMessages = () => { | |
messages = Object.fromEntries(Object.entries(messages) | |
.filter(entry => { | |
if (entry[1].occurrences < maxOccurrences) { | |
return Date.now() - entry[1].last_update < copyPastaIntervalDetectionTime; | |
} else { | |
return Date.now() - entry[1].last_update < (copyPastaIntervalDetectionTime + copyPastaPrisonTime); | |
} | |
})) | |
} | |
function isCopyPasta(rawMessage) { | |
const formattedMessage = rawMessage.trim(); | |
saveMessage(formattedMessage); | |
cleanupOldMessages(); | |
return messages[formattedMessage] && messages[formattedMessage].occurrences >= maxOccurrences; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment