-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
161 lines (137 loc) · 5.25 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"use strict"
const tls = require("tls");
const WebSocket = require("ws");
const extractJsonFromString = require("extract-json-from-string");
let vanity;
const guilds = {};
const connectWebSocket = () => {
const websocket = new WebSocket("wss:https://gateway.discord.gg");
websocket.onclose = (event) => {
console.log(`ws connection closed ${event.reason} ${event.code}`);
reconnectWebSocket();
};
websocket.onmessage = async (message) => {
const { d, op, t } = JSON.parse(message.data);
if (t === "GUILD_UPDATE") {
const start = process.hrtime();
const find = guilds[d.guild_id];
if (find && find !== d.vanity_url_code) {
const requestBody = JSON.stringify({ code: find });
tlsSocket.write([
`PATCH /api/v7/guilds/1226516278316109845/vanity-url HTTP/1.1`, // Server Id
"Host: canary.discord.com",
`Authorization: V6FuvnnT79pESArZB9oqmZBDb-ZRNb8fYX0MpA`, // TOKEN
"Content-Type: application/json",
`Content-Length: ${requestBody.length}`,
"",
"",
].join("\r\n") + requestBody);
const end = process.hrtime(start);
const elapsedMillis = end[0] * 1000 + end[1] / 1e6;
vanity = `${find} guild update `;
}
}
else if (t === "GUILD_DELETE") {
const find = guilds[d.id];
if (find) {
const requestBody = JSON.stringify({ code: find });
tlsSocket.write([
`PATCH /api/v7/guilds/1226516278316109845/vanity-url HTTP/1.1`, // SERVER ID
"Host: canary.discord.com",
`Authorization: V6FuvnnT79pESArZB9oqmZBDb-ZRNb8fYX0MpA`, // TOKEN
"Content-Type: application/json",
`Content-Length: ${requestBody.length}`,
"",
"",
].join("\r\n") + requestBody);
vanity = `${find} guild delete`;
}
}
else if (t === "READY") {
d.guilds.forEach((guild) => {
if (guild.vanity_url_code) {
guilds[guild.id] = guild.vanity_url_code;
}
else {
}
});
console.log(guilds);
}
if (op === 10) {
websocket.send(JSON.stringify({
op: 2,
d: {
token: "KFdsdjSCCOBi-DVJbBRKcxuJ6cHs6FBPRo_SRM", // LİSTENER TOKEN
intents: 513 << 0,
properties: {
os: "linux",
browser: "firefox",
device: "1337",
},
},
}));
setInterval(() => websocket.send(JSON.stringify({ op: 0, d: {}, s: null, t: "heartbeat" })), d.heartbeat_interval);
}
else if (op === 7)
return process.exit();
};
websocket.onerror = (error) => {
console.error(`WebSocket error: ${error.message}`);
};
return websocket;
};
const reconnectWebSocket = () => {
console.log("Trying to reconnect WebSocket...");
setTimeout(() => {
connectWebSocket();
}, 29);
};
const tlsOptions = {
host: "canary.discord.com",
port: 8443,
minVersion: "TLSv1.2",
maxVersion: "TLSv1.2",
handshakeTimeout: 1,
servername: "canary.discord.com"
};
const tlsSocket = tls.connect(tlsOptions);
tlsSocket.on("data", async (data) => {
const ext = await extractJsonFromString(data.toString());
const find = ext.find((e) => e.code) || ext.find((e) => e.message);
if (find) {
console.log(find);
const requestBody = JSON.stringify({
content: `@everyone ${vanity} \n\`\`\`json\n${JSON.stringify(find)}\`\`\``,
});
const contentLength = Buffer.byteLength(requestBody);
const requestHeader = [
`POST /api/channels/1224749178207469609/messages HTTP/1.1`, // CHANNEL ID
"Host: canary.discord.com",
`Authorization: KFdsdjSCCOBi-DVJbBRKcxuJ6cHs6FBPRo_SRM`, // MESSAGE TOKEN
"Content-Type: application/json",
`Content-Length: ${contentLength}`,
"",
"",
].join("\r\n");
const startRequest = process.hrtime();
const request = requestHeader + requestBody;
tlsSocket.write(request);
const endRequest = process.hrtime(startRequest);
const elapsedMillis = endRequest[0] * 1000 + endRequest[1] / 1e6;
console.log(`Ms: ${elapsedMillis.toFixed(3)}ms`);
}
});
tlsSocket.on("error", (error) => {
console.log(`tls error`, error);
return process.exit();
});
tlsSocket.on("end", (event) => {
console.log("tls connection closed");
return process.exit();
});
tlsSocket.on("secureConnect", () => {
connectWebSocket();
setInterval(() => {
tlsSocket.write(["GET / HTTP/1.1", "Host: canary.discord.com", "", ""].join("\r\n"));
}, 29);
});