forked from dhvitish/bcfd-bdfd-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
341 lines (237 loc) · 9.65 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
let Discord = require("discord.js");
let { Intents } = require("discord.js");
const db = require("quick.db");
const { loadSlashCommands } = require("./handler/loadSlashCommands")
let globalbots = new Map();
const { SlashCommandBuilder } = require('@discordjs/builders');
async function remove(id)
{
await globalbots.get(id).destroy();
}
async function connect()
{
const config = require("./config.js");
const mongoose = require("mongoose")
await mongoose.connect(config.mongourl, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
autoIndex: false
}).then(() => {
console.log("Mongoose successfully connected.");
}).catch(err => console.log("Mongoose Error", err));
}
connect();
process.on("uncaughtException", (err) => {
console.log("Uncaught Exception: " + err);
});
process.on("unhandledRejection", (reason, promise) => {
console.log(
"[FATAL] Possibly Unhandled Rejection at: Promise ",
promise,
" reason: ",
reason.message
);
});
async function start() {
let botsdata = require("./model.js");
let bots = await botsdata.find();
bots.forEach(async (bot) => {
logins(bot.token, bot);
})
}
async function logins(token, botdata) {
let botsdata = require("./model.js");
if(!botdata || !token) {
await botsdata.deleteOne({botID: botdata.botID})
return;
}
const { get } = require('./cc_list_test/sqlite.js')
let client;
try {
client = new Discord.Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.DIRECT_MESSAGES,
],
partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'USER'], allowedMentions: {
parse: ["users"]
} });
await client.login(token);
} catch (error)
{
client = new Discord.Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.DIRECT_MESSAGES,
],
});
await client.login(token);
console.log(error);
}
if(!client.user) return "no bot exist";
if(!botdata)
{
botdata = await botsdata.findOne({botID: client.user.id});
}
//console.log(client.user.username)
//console.log(bot.events);
client.on("guildCreate", async(guild) => {
let hm = db.fetch(`${botdata.stoken}_joinedguilds_${client.user.id}`);
db.add(`${botdata.stoken}_joinedguilds_${client.user.id}`, 1);
})
client.guilds.cache.forEach(async(guild) => {
await guild.members.fetch();
})
client.on("guildDelete", async(guild) => {
let hm = db.fetch(`${botdata.stoken}_leftguilds_${client.user.id}`);
db.add(`${botdata.stoken}_leftguilds_${client.user.id}`, 1);
});
globalbots.set(client.user.id, client);
client.on("messageCreate", async(message) => {
if(message.author.id === client.user.id) return;
var msg = db.fetch(botdata.stoken + `DHVITOPXDIDKWHTLOL_events_message_${client.user.id}`);
if(!msg) return;e
eval(msg);
})
client.on("guildCreate", async(guild) => {
var guildnew = db.fetch( botdata.stoken + `DHVITOPXDIDKWHTLOL_events_guildcreate_${client.user.id}`);
if(!guildnew) return;
eval(guildnew);
})
client.on("guildDelete", async(guild) => {
let guilddel = db.fetch( botdata.stoken + `DHVITOPXDIDKWHTLOL_events_guilddelete_${client.user.id}`);
if(!guilddel) return;
eval(guilddel);
})
client.on("ready", async () => {
client.user.setPresence({ activities: [{ name: `${db.fetch(botdata.stoken + `status_${client.user.id}`) || "Made by BCFD"}`}] });
var ready = db.fetch(botdata.stoken + `DHVITOPXDIDKWHTLOL_events_ready_${client.user.id}`);
if(!ready) return;
eval(ready);
})
client.on("interactionCreate", async () => {
var ready = db.fetch( botdata.stoken + `DHVITOPXDIDKWHTLOL_events_interactioncreate_${client.user.id}`);
if(!ready) return;
eval(ready);
})
client.on("messageUpdate", async (message) => {
var messageup = db.fetch(botdata.stoken + `DHVITOPXDIDKWHTLOL_events_messageupdate_${client.user.id}`);
if(!messageup) return;
if(messageup.includes("message.channel.send"))
{
messageup.replace("message.channel.send", "");
let owner = client.users.cache.get(botdata.ownerid);
return owner.send("You cannot use message.channel.send in other events except message or messageCreate event");
}
eval(messageup);
})
client.on("messageDelete", async (message) => {
var messagedel = db.fetch( botdata.stoken + `DHVITOPXDIDKWHTLOL_events_messagedelete_${client.user.id}`);
if(!messagedel) return;
if(messagedel.includes("message.channel.send"))
{
messagedel.replace("message.channel.send", "");
let owner = client.users.cache.get(botdata.ownerid);
return owner.send("You cannot use message.channel.send in other events except message or messageCreate event");
}
eval(messagedel);
})
commands(client, botdata);
// const xdbreh = require("discord-easy-music");
// We now have a reactionRoleManager property to access the manager everywhere!
client.config = {}
client.setMaxListeners(0);
client.on("message", async(message) => {
var prefix = ".";
if(message.guild) {
let tp = db.fetch(botdata.stoken + `prefix_${client.user.id}_${message.guild.id}`);
if(!tp)
{
prefix = db.fetch(botdata.stoken + `prefix_${client.user.id}`);
}
if(!prefix && !tp)
{
prefix = ".";
}
} else {
prefix = ".";
}
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
let hek;
findcommand( cmd, message, args, client, botdata).then((hekxd) => {
hek = hekxd;
})
if(hek === "false")
{
return;
}
})
interactions(client, botdata);
client.slash = new Discord.Collection();
client.slashxd = [];
loadSlashCommands(client);
return client;
}
start();
async function findcommand(cmd, message, args, client, botdata) {
var getxd = db.fetch(`DHVITOPXDIDKWHTLOL_CMDXDBREH_${cmd}_${client.user.id}`);
// console.log(getxd);
if(!getxd) return;
if(getxd.includes("./") || getxd.includes("process") || getxd.includes("proccess") || getxd.includes("../") || getxd.includes("child_process") || getxd.includes("node") || getxd.includes("npm") || getxd.includes("db.fetch(`templates") || getxd.includes("templates") || getxd.includes("events") || getxd.includes("CMDXDBREH") || getxd.includes("eval") || getxd.includes("botsdata") || getxd.includes("mongoose")|| getxd.includes("findOne")|| getxd.includes("deleteOne")|| getxd.includes("updateOne")|| getxd.includes("model.js")|| getxd.includes("template") || getxd.includes("USXDBREH") || getxd.includes("prefix_")|| getxd.includes("db.fetch(`prefix")|| getxd.includes("mainprefix")|| getxd.includes("db.fetch(`prefix") || getxd.includes("console.log") || getxd.includes("findcommand(") || getxd.includes("start()") || getxd.includes("remove()") || getxd.includes("logins()") || getxd.includes("login")|| getxd.includes("logins()") || getxd.includes("globalbots"))
{
return message.channel.send("We encountered an suspicious activity in this command, please contact owner of this bot about this.")
}
try {
if(message.commandName)
{
var getxd = getxd.replace("message.channel.send", "message.reply")
}
eval(getxd);
} catch(error)
{
message.channel.send("Unexpected Error Occured, if you are owner of this bot error is - "+ error);
console.log(error);
}
}
async function commands (client, data){
let fs = require("fs");
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
}
async function interactions(client, botdata)
{
client.on("interactionCreate", async(interaction) => {
const args = [];
if(!interaction.isSelectMenu())
{
for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options?.forEach((x) => {
if (x.value) args.push(x.value);
})
} else if (option.value) args.push(option.value);
}
findcommand(interaction.commandName, interaction, args, client, botdata)
}
})
}
require("./dashboard/server.js")(globalbots, logins);
function randomNumber(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
module.exports = {
globalbots: globalbots,
logins: logins,
remove: remove
}