Skip to content

Instantly share code, notes, and snippets.

@fl4ke
Last active October 25, 2019 21:20
Show Gist options
  • Save fl4ke/b39eb7ad471c3c05a0e6f14ffa7128f5 to your computer and use it in GitHub Desktop.
Save fl4ke/b39eb7ad471c3c05a0e6f14ffa7128f5 to your computer and use it in GitHub Desktop.
Cordless script to log deleted messages into the console.
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