This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
55 lines (47 loc) · 1.74 KB
/
index.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
52
53
54
55
import { readdirSync, readFileSync, existsSync } from 'fs';
import fetch from 'node-fetch';
import { join } from 'path';
const config = JSON.parse(readFileSync(new URL('./config.json', import.meta.url)));
const sleep = (time) => new Promise(r => setTimeout(r, time));
if (!process.argv[2]) {
console.error('Please provide a file path pointing to the "messages" folder in your data package.');
process.exit(-1);
}
if (!existsSync(process.argv[2])) {
console.error('The path you provided is not valid or doesn\'t exist.');
process.exit(-1);
}
try {
run();
} catch (e) {
console.log('Failed to open all your DMs: ', e.message);
}
async function run() {
const files = readdirSync(process.argv[2]);
for (const file of files) {
if (file === 'index.json') continue;
try {
const path = join(process.argv[2], file, 'channel.json');
const contents = readFileSync(path);
const data = JSON.parse(contents);
const recipients = (data.recipients ?? []).filter(r => r !== config.userid);
if (recipients.length) {
const res = await fetch('https://canary.discordapp.com/api/v6/users/@me/channels', {
method: 'POST',
body: JSON.stringify({ recipients }),
headers: {
'authorization': config.token,
'User-Agent': config.agent,
'Content-Type': 'application/json'
}
}).then(r => r.json());
const { username, discriminator } = res.recipients[0];
console.log(`Opened DM with ${username}#${discriminator}`);
await sleep(250);
}
} catch (e) {
console.error('Failed to open DM', e.message);
continue;
}
}
}