Skip to content

Instantly share code, notes, and snippets.

@InfiniteRain
Created December 18, 2018 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InfiniteRain/9615e1e32a68ce447bba63a926338c75 to your computer and use it in GitHub Desktop.
Save InfiniteRain/9615e1e32a68ce447bba63a926338c75 to your computer and use it in GitHub Desktop.
Shred Discord
const SC = {};
SC._config = {
searchBefore: '523474136849186826',
userId: '194157930948460544',
token: document.body.appendChild(document.createElement('iframe')).contentWindow.localStorage.token.replace(/"/g, '')
};
SC._fetchedMessages = [];
SC.scanMessages = () => {
if (SC._config.searchBefore == '') {
console.error(`[ShredDisc] Initial message ID is not set! Use \`SC.setSearchBefore('<MESSAGE ID>')\` to set it.`);
return;
}
if (SC._config.userId == '') {
console.error(`[ShredDisc] Initial user ID is not set! Use \`SC.setUserId('<USER ID>')\` to set it.`);
return;
}
const channel = window.location.href.split('/').pop();
const baseUrl = `https://discordapp.com/api/channels/${channel}/messages`;
const headers = {
Authorization: SC._config.token
};
fetch(`${baseUrl}?before=${SC._config.searchBefore}&limit=100`, {
headers
})
.then(response => response.json())
.then(messages => {
if (messages.length === 0) {
console.log('Scan is done.')
return;
}
messages.forEach(message => {
if (message.author.id === SC._config.userId) {
SC._fetchedMessages.push(message);
console.info(`[ShredDisc] Fetching message number ${SC._fetchedMessages.length} from ${message.timestamp}...`)
}
SC._config.searchBefore = message.id;
});
setTimeout(() => {
SC.scanMessages()
}, 0);
});
};
SC.deleteMessages = () => {
const channel = window.location.href.split('/').pop();
const baseUrl = `https://discordapp.com/api/channels/${channel}/messages`;
const headers = {
Authorization: SC._config.token
};
if (SC._fetchedMessages.length <= 0) {
return;
}
let message = SC._fetchedMessages.pop();
fetch(`${baseUrl}/${message.id}`, {
headers,
method: 'DELETE'
}).then(() => {
console.info(`[ShredDisc] Deleted message number ${SC._fetchedMessages.length} from ${message.timestamp}.`);
});
setTimeout(() => {
SC.deleteMessages();
}, 500);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment