Snippets
Created by
killerspaz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | const BEFORE_MSG_ID = '';
const AUTH_TOKEN = '';
const BATCH_SIZE = 1;
/**
* Discord Chanel Wiper
*
* Completely wipes a channel starting at a message ID.
*
* Automatically throttles based on responses from Discord servers.
*/
class DiscordChannelWiper {
constructor({beforeMsgId, authToken, batchSize, channelId}) {
this.beforeMsgId = beforeMsgId;
this.authToken = authToken;
this.batchSize = batchSize;
this.baseUrl = `https://discordapp.com/api/channels/${channelId}/messages`;
}
wipe() {
let messages;
return this._getMessages()
.then(_messages => {
messages = _messages;
return this._deleteMessageBatch(_messages);
})
.then(result => this._determineCompletion(result, messages))
.then(() => console.info('[DiscordChannelWiper] - Done Wiping Channel!'))
.catch(err => console.error('[DiscordChannelWiper] - Serious Failure: ', err));
}
_getHeaders() {
return {
headers: {
Authorization: this.authToken
}
};
}
_getMessages() {
return fetch(
`${this.baseUrl}?before=${this.beforeMsgId}&limit=10`,
this._getHeaders()
)
.then(resp => resp.json());
}
_deleteMessageBatch(messages) {
let initPromise = Promise.resolve();
// Iterate over every message and SEQUENTIALLY DELETE!
messages.forEach(msg => {
initPromise = initPromise
.then(() => this._deleteMessage(msg))
.then(result => this._determineDeleteSuccess(result, msg))
});
return initPromise;
}
_deleteMessage(message) {
console.log(`[DiscordChannelWiper] - Deleting Message from ${message.author.username}, ${message.id}`);
return fetch(`${this.baseUrl}/${message.id}`, Object.assign(
this._getHeaders(),
{ method: 'DELETE' }
))
.then(resp => {
return resp.text().then(text => {
return text ? JSON.parse(text) : {}
});
});
}
_determineDeleteSuccess(result, lastMsg) {
if (result.retry_after) {
return this._delayAndRetry(result.retry_after);
}
this.beforeMsgId = lastMsg.id;
return true;
}
_determineCompletion(result, messages) {
if (messages.length > 0) {
return this.wipe();
}
return result;
}
_delayAndRetry(delay) {
return new Promise(resolve => {
console.log(`[DiscordChannelWiper] - Delaying batch for ${delay / 1000} seconds`);
setTimeout(resolve, delay);
}).then(() => this.wipe());
}
}
const initConfig = {
beforeMsgId: BEFORE_MSG_ID,
authToken: AUTH_TOKEN,
batchSize: BATCH_SIZE,
channelId: window.location.href.split('/').pop()
};
console.info(initConfig);
new DiscordChannelWiper(initConfig).wipe();
|
Comments (8)
You can clone a snippet to your computer for local editing. Learn more.
How to get a message ID: https://support.discordapp.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-
Need for Speed Mobile Game in 2022 let's go a nuns mobile game from Timmy Studios and EA in 2022 after a long wait we might finally catch a glimpse of a news game as per various leaks which we will discuss more on timmy studios and EA plan to bring a newt's mobile game to the mark Need for Speed Mobile
Nowadays many organizations are inviting to take customer feedback surveys. CVSHealthSurvey.Com Survey is one of the best ones in the entire united states. They announced a $1000 reward to their customers who have finished the survey on the official survey page https://www.cvshealthsurvey.blog/. So, don’t miss the chance to take the survey, All the best!
Nowadays many organizations are inviting to take customer feedback surveys. CVSHealthSurvey.Com Survey is one of the best ones in the entire united states. They announced a $1000 reward to their customers who have finished the survey on the official survey page https://www.cvshealthsurvey.blog/survey. So, don’t miss the chance to take the survey, All the best!
This Certensure’s product provides you a select SY0-601 exam dumps number of real exam questions. They have been taken from the previous CompTIA Exam SY0-601 whereas the answers are written by the IT experts.
Optimized Code:
const BEFORE_MSG_ID = '';
const AUTH_TOKEN = '';
const BATCH_SIZE = 1;
const DiscordChannelWiper = ({beforeMsgId, authToken, batchSize, channelId}) => {
this.beforeMsgId = beforeMsgId;
this.authToken = authToken;
this.batchSize = batchSize;
this.baseUrl =
<https://discordapp.com/api/channels/${channelId}/messages
;>this.wipe = async () => {
let messages;
};
this._getHeaders = () => ({
headers: {
Authorization: this.authToken
}
});
this._getMessages = async () => await fetch(
${this.baseUrl}?before=${this.beforeMsgId}&limit=10
,this._getHeaders()
).then(resp => resp.json());
this._deleteMessageBatch = async messages => {
for (const msg of messages) {
await this._deleteMessage(msg);
}
};
this._deleteMessage = async message => {
console.log(
[DiscordChannelWiper] - Deleting Message from ${message.author.username}, ${message.id}
);};
};
const initConfig = {
beforeMsgId: BEFORE_MSG_ID,
authToken: AUTH_TOKEN,
batchSize: BATCH_SIZE,
channelId: window.location.href.split('/').pop()
};
new DiscordChannelWiper(initConfig).wipe();
Thanks,
ClearHolidays™ | clearholidays.com
Amalgamating class and timelessness, Petersign is a gateway to the most charismatic fashion merchandise. Whether one wishes to make their style appealing and smart or learn to get savvy when it comes to everything “FASHION,” B3 Bomber Jacket Women
Your academic success is our priority at My Law Tutor. Trust our seasoned professional’ law writers for top-notch law essay writing services and stress-free support. So who are you waiting for? Grab this opportunity and ace your law academics with us.