Last active
October 25, 2019 21:20
-
-
Save fl4ke/b39eb7ad471c3c05a0e6f14ffa7128f5 to your computer and use it in GitHub Desktop.
Cordless script to log deleted messages into the console.
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
var MAX_CACHE_SIZE = 50; | |
var messages = []; | |
function onMessageReceive(message) { | |
if (messages.length >= MAX_CACHE_SIZE) messages.shift(); | |
messages.push(message); | |
} | |
function onMessageDelete(message){ | |
var msg = getMessageById(message.ID); | |
if (msg) { | |
var content = msg.Content; | |
var author = msg.Author.Username; | |
return printLineToConsole(author + ": " + content); | |
} | |
printLineToConsole("Cannot find deleted message with id: " + message.ID); | |
} | |
function getMessageById(id){ | |
for (var i = messages.length - 1; i >= 0; i--) { | |
if (messages[i].ID === id) return messages[i]; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment