-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
197 lines (159 loc) · 6.96 KB
/
Copy pathindex.js
File metadata and controls
197 lines (159 loc) · 6.96 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
const example = require('./Structures/files/exemple.json');
const Handler = require('./Structures/files/Handlers');
const { spawn } = require("node:child_process");
const Selfbot = require('./Structures/files/Client');
const config = require('./config.json');
const Discord = require('discord.js');
const crypto = require('crypto');
const os = require('os');
const fs = require('fs');
const runtimeInfo = getRuntimeInfo();
if (runtimeInfo.runtime !== 'bun'){
console.log("Veuillez lancer le script avec BUN !\nInstallation: npm i -g bun\nLancement: pm2 start index.js -n \"nom du projet\" --interpreter bun");
process.exit(0);
}
if (!fs.existsSync('./Structures/backups'))
fs.mkdirSync('./Structures/backups');
const manager = new Discord.Client({
intents: Object.keys(Discord.GatewayIntentBits),
partials: [Discord.Partials.Channel, Discord.Partials.GuildMember, Discord.Partials.GuildScheduledEvent, Discord.Partials.Message, Discord.Partials.Reaction, Discord.Partials.ThreadMember, Discord.Partials.User],
});
if (config.token) manager.login(config.token.includes('.') ? config.token : decrypt(config.token));
global.clients = {};
manager.connected = global.clients;
manager.config = config;
manager.emojis = { cross: "<:off:1327710569184366726>", check: "<:on:1345720302105002036>" }
manager.ms = x => ms(x);
manager.encrypt = x => encrypt(x);
manager.decrypt = x => decrypt(x);
manager.save_codes = () => saveCodes();
manager.token_push = x => pushAndSave(x);
manager.get_database = x => loadDatabase(x);
manager.load_token = async x => { const token = x.includes('.') ? x : decrypt(x); await loadClient(token) }
Handler.loadCommands(manager, "Manager/commands");
Handler.loadEvents(manager, "Manager/events");
for (const encryptToken of config.users.values())
loadClient(encryptToken.includes('.') ? encryptToken : decrypt(encryptToken));
if (config.token.includes('.'))
{
config.token = encrypt(config.token);
fs.writeFileSync('./config.json', JSON.stringify(config, null, 4));
}
function saveCodes()
{
const json_codes = fs.readFileSync('./Structures/files/codes.json', 'utf8');
const codes = JSON.parse(json_codes);
fs.writeFileSync('./Structures/files/codes.json', JSON.stringify(codes, null, 4));
}
function ms(timeString) {
const match = timeString.match(/(\d+)([smhdwy])/);
if (!match) return null;
const value = parseInt(match[1]);
const unit = match[2];
switch (unit) {
case 's': return value * 1000;
case 'm': return value * 60 * 1000;
case 'h': return value * 60 * 60 * 1000;
case 'd': return value * 24 * 60 * 60 * 1000;
case 'w': return value * 7 * 24 * 60 * 60 * 1000;
case 'y': return value * 365 * 24 * 60 * 60 * 1000;
default: return null;
}
}
async function loadDatabase(encrypted_token)
{
const token = Number(encrypted_token) ? encrypted_token : encrypted_token.includes('.') ? encrypted_token : decrypt(encrypted_token);
const userId = Number(encrypted_token) ? encrypted_token : Buffer.from(token.split('.')[0], 'base64').toString();
const dbPath = `./Structures/databases/${userId}.json`;
if (fs.existsSync(dbPath)) {
const content = fs.readFileSync(dbPath, 'utf8');
try {
const parsed = JSON.parse(content);
Object.keys(example)
.filter(key => !Object.keys(parsed).includes(key))
.forEach(key => parsed[key] = example[key]);
Object.keys(example)
.filter(key => typeof example[key] == 'object')
.forEach(key => example[key] && Object.keys(example[key])
.filter(subKey => !Object.keys(parsed[key]).includes(subKey))
.forEach(subKey => parsed[key][subKey] = example[key][subKey])
)
fs.writeFileSync(dbPath, JSON.stringify(parsed, null, 4), 'utf-8');
return parsed;
} catch (e) {
await fs.promises.writeFile(dbPath, JSON.stringify(example, null, 4), 'utf-8');
return JSON.parse(JSON.stringify(example));
}
} else {
await fs.promises.writeFile(dbPath, JSON.stringify(example, null, 4), 'utf-8');
return JSON.parse(JSON.stringify(example));
}
}
function pushAndSave(Encrypt_token)
{
if (config.users.includes(Encrypt_token.includes('.') ? Encrypt_token : decrypt(Encrypt_token)))
config.users = config.users.filter(user => user !== (Encrypt_token.includes('.') ? Encrypt_token : decrypt(Encrypt_token)));
if (!config.users.includes(Encrypt_token.includes('.') ? encrypt(Encrypt_token) : Encrypt_token))
config.users.push(Encrypt_token.includes('.') ? encrypt(Encrypt_token) : Encrypt_token);
fs.writeFileSync('./config.json', JSON.stringify(config, null, 4));
}
async function loadClient(token)
{
const userId = Buffer.from(token.split('.')[0], 'base64').toString();
if (global.clients[userId] && typeof global.clients[userId].destroy === 'function') {
try {
await global.clients[userId].destroy();
} catch (error) {
console.error(`Error destroying existing client for ${userId}:`, error);
}
}
if (!config.users.includes(encrypt(token))) pushAndSave(token);
const database = await loadDatabase(token);
if (database && !database.enable) return;
new Selfbot({ token, database });
}
function decrypt(encryptedData)
{
const key = crypto.pbkdf2Sync('oiizebfdddozuiebfouzebn', 'selUnique', 100000, 32, 'sha256');
const iv = crypto.pbkdf2Sync('oiizebfdddozuiebfouzebn', 'selUnique', 100000, 16, 'sha256');
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv)
let decrypted = decipher.update(encryptedData, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
function encrypt(text)
{
const key = crypto.pbkdf2Sync('oiizebfdddozuiebfouzebn', 'selUnique', 100000, 32, 'sha256');
const iv = crypto.pbkdf2Sync('oiizebfdddozuiebfouzebn', 'selUnique', 100000, 16, 'sha256');
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
function getRuntimeInfo() {
const info = {
runtime: 'unknown',
version: null,
executable: null
};
if (typeof process !== 'undefined') {
if (typeof Bun !== 'undefined' || (process.versions && process.versions.bun)) {
info.runtime = 'bun';
info.version = process.versions?.bun || Bun.version;
}
else if (process.versions && process.versions.node) {
info.runtime = 'node';
info.version = process.versions.node;
}
info.executable = process.argv0;
}
return info;
}
async function errorHandler(error) {
const errors = [ 0, 400, 10062, 10008, 50035, 40032, 50013, 40002]
if (errors.includes(error.code)) return;
console.error(error)
};
process.on("unhandledRejection", errorHandler);
process.on("uncaughtException", errorHandler);
process.on('warning', () => false);