-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages_count.js
51 lines (46 loc) · 1.66 KB
/
messages_count.js
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
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// make API request
let messageslist = await lib.discord.channels['@0.2.2'].messages.list({
channel_id: `${context.params.event.channel_id}`,
limit: 1
});
//While loop init
let latestmessageID = `${messageslist[0].id}`;
let messageslistlength = 100;
let messagecounter = 1;
let whileloopcounter = 0;
let sleep = async (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
//While loop execute
while (messageslistlength === 100 && messagecounter < 2500) {
whileloopcounter = whileloopcounter + 1;
await sleep(630);
//Retrieve the 100max messages
messageslist = await lib.discord.channels['@0.2.2'].messages.list({
channel_id: `${context.params.event.channel_id}`,
before: `${latestmessageID}`,
limit: 100
});
messagecounter = messagecounter + messageslist.length;
console.log(messagecounter);
//While loop readjust
messageslistlength = messageslist.length;
latestmessageID = `${messageslist[(messageslistlength-1)].id}`;
}
if (messagecounter > 2499){
let result = await lib.discord.channels['@0.2.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `<@!${context.params.event.member.user.id}> : il y a sur ce fil plus de 2500 messages.`
});
}
else {
let result = await lib.discord.channels['@0.2.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `<@!${context.params.event.member.user.id}> : il y a sur ce fil ${messagecounter} messages.`
});
}