-
Notifications
You must be signed in to change notification settings - Fork 1
/
Core.js
584 lines (539 loc) · 18.6 KB
/
Core.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/* ---------------------------------------------------------------------------------/
/ /
/ d8888 888 888 888b d888 8888888b. /
/ d88888 888 888 8888b d8888 888 "Y88b /
/ d88P888 888 888 88888b.d88888 888 888 /
/ d88P 888 888888 888 8888b. .d8888b 888Y88888P888 888 888 /
/ d88P 888 888 888 "88b 88K 888 Y888P 888 888 888 /
/ d88P 888 888 888 .d888888 "Y8888b. 888 Y8P 888 888 888 /
/ d8888888888 Y88b. 888 888 888 X88 888 " 888 888 .d88P /
/ d88P 888 "Y888 888 "Y888888 88888P' 888 888 8888888P" /
/ /
/-----------------------------------------------------------------------------------/
/ Author and Main Developer: FantoX /
/ Github: https://github.com/FantoX001/Atlas-MD /
/ Powered By: Team ATLAS /
/-----------------------------------------------------------------------------------/
/ Meet Team ATLAS who holds all rights to this repository: /
/ /
/ 1. Pratyush - https://github.com/pratyush4932 /
/ 2. Ahmii - https://github.com/Ahmii-kun /
/ 3. Kai - https://github.com/Kai0071 /
/ 4. Devime - https://github.com/Devime69 /
/ 5. Jay JayOps - https://github.com/jayjay-ops /
/ /
/ ----------------------------------------------------------------------------------/
/ /
/ With all of our hard work and defication you can enjoy this awesome bot! /
/ /
/----------------------------------------------------------------------------------*/
require("./index.js");
require("./config.js");
require("./BotCharacters.js");
require("./Processes/welcome.js");
const { Collection, Function } = require("./lib");
const { isUrl } = Function;
const axios = require("axios");
const Func = require("./lib");
const chalk = require("chalk");
const { color } = require("./lib/color");
const cool = new Collection();
const { mk, mku, mkchar } = require("./Database/dataschema.js");
const prefix = global.prefa;
global.Levels = require("discord-xp");
Levels.setURL(mongodb);
console.log(color("\nDatabase 1 has been connected Successfully !\n", "aqua"));
console.log(color("\nDatabase 2 has been connected Successfully !\n", "aqua"));
module.exports = async (Miku, m, commands, chatUpdate, store) => {
try {
let { type, isGroup, sender, from } = m;
let body =
type == "buttonsResponseMessage"
? m.message[type].selectedButtonId
: type == "listResponseMessage"
? m.message[type].singleSelectReply.selectedRowId
: type == "templateButtonReplyMessage"
? m.message[type].selectedId
: m.text;
let prat =
type === "conversation" && body?.startsWith(prefix)
? body
: (type === "imageMessage" || type === "videoMessage") &&
body &&
body?.startsWith(prefix)
? body
: type === "extendedTextMessage" && body?.startsWith(prefix)
? body
: type === "buttonsResponseMessage" && body?.startsWith(prefix)
? body
: type === "listResponseMessage" && body?.startsWith(prefix)
? body
: type === "templateButtonReplyMessage" && body?.startsWith(prefix)
? body
: "";
const metadata = isGroup ? await Miku.groupMetadata(from) : {};
const pushname = m.pushName; //|| 'NO name'
const participants = isGroup ? metadata.participants : [sender];
const groupAdmin = isGroup
? participants.filter((v) => v.admin !== null).map((v) => v.id)
: [];
const botNumber = await Miku.decodeJid(Miku.user.id);
const isBotAdmin = m.isGroup ? groupAdmin.includes(Miku.user?.jid) : false;
const isAdmin = isGroup ? groupAdmin.includes(sender) : false;
const isCreator = [botNumber, ...global.owner]
.map((v) => v.replace(/[^0-9]/g, "") + "@s.whatsapp.net")
.includes(m.sender);
const isOwner = global.owner.includes(m.sender);
global.suppL = "https://cutt.ly/AtlasBotSupport";
const isCmd = body.startsWith(prefix);
const quoted = m.quoted ? m.quoted : m;
const mime = (quoted.msg || m.msg).mimetype || " ";
const isMedia = /image|video|sticker|audio/.test(mime);
const budy = typeof m.text == "string" ? m.text : "";
const args = body.trim().split(/ +/).slice(1);
const ar = args.map((v) => v.toLowerCase());
let text = (q = args.join(" "));
const groupName = m.isGroup ? metadata.subject : "";
const cmdName = prat
.slice(prefix.length)
.trim()
.split(/ +/)
.shift()
.toLowerCase();
const cmd =
commands.get(cmdName) ||
Array.from(commands.values()).find((v) =>
v.alias.find((x) => x.toLowerCase() == cmdName)
) ||
"";
const icmd =
commands.get(cmdName) ||
Array.from(commands.values()).find((v) =>
v.alias.find((x) => x.toLowerCase() == cmdName)
);
const mentionByTag =
type == "extendedTextMessage" &&
m.message.extendedTextMessage.contextInfo != null
? m.message.extendedTextMessage.contextInfo.mentionedJid
: [];
if (!isCreator) {
let checkban =
(await mku.findOne({
id: m.sender,
})) ||
(await new mku({
id: m.sender,
name: m.pushName,
}).save());
if (
isCmd &&
checkban.ban !== "false" &&
budy != `${prefix}support` &&
budy != `${prefix}supportgc` &&
budy != `${prefix}owner` &&
budy != `${prefix}mods` &&
budy != `${prefix}mod` &&
budy != `${prefix}modlist`
)
return m.reply(
`You are *Banned* from using commands for *${checkban.reason}* from *${checkban.gcname}*`
);
}
// ------------------------ Character Configuration (Do not modify this part) ------------------------ //
let char = "0"; // default one
let CharacterSelection = "0"; // user selected character
let character = await mkchar.findOne({
id: "1",
});
if (character) {
CharacterSelection = character.seletedCharacter;
} else {
let newCharacter = new mkchar({
id: "1",
seletedCharacter: "0",
});
await newCharacter.save();
}
await mkchar
.findOne({
id: "1",
})
.then(async (res) => {
if (res.seletedCharacter != char) {
CharacterSelection = res.seletedCharacter;
} else {
CharacterSelection = char;
}
});
let idConfig = "charID" + CharacterSelection;
global.botName = global[idConfig].botName;
global.botVideo = global[idConfig].botVideo;
global.botImage1 = global[idConfig].botImage1;
global.botImage2 = global[idConfig].botImage2;
global.botImage3 = global[idConfig].botImage3;
global.botImage4 = global[idConfig].botImage4;
global.botImage5 = global[idConfig].botImage5;
global.botImage6 = global[idConfig].botImage6;
//------------------------------------------- Antilink Configuration --------------------------------------------//
let checkdata = await mk.findOne({
id: m.from,
});
if (!checkdata) {
let newdata = new mk({
id: m.from,
antilink: "false",
});
}
if (checkdata) {
let mongoschema = checkdata.antilink || "false";
if (m.isGroup && mongoschema == "true") {
linkgce = await Miku.groupInviteCode(from);
if (budy.includes(`https://chat.whatsapp.com/${linkgce}`)) {
m.reply(
`\`\`\`「 Antilink System 」\`\`\`\n\nNo action will be taken because you sent this group's link.`
);
} else if (budy.includes(`https://chat.whatsapp`)) {
bvl = `\`\`\`「 Antilink System 」\`\`\`\n\nAdmin has sent a link so no issues.`;
if (isAdmin) return m.reply(bvl);
if (m.key.fromMe) return m.reply(bvl);
if (isCreator) return m.reply(bvl);
kice = m.sender;
await Miku.groupParticipantsUpdate(m.from, [kice], "remove");
await Miku.sendMessage(
from,
{
delete: {
remoteJid: m.from,
fromMe: false,
id: m.id,
participant: m.sender,
},
},
{
quoted: m,
}
);
await mk.updateOne(
{
id: m.from,
},
{
antilink: "true",
}
);
Miku.sendMessage(
from,
{
text: `\`\`\`「 Antilink System 」\`\`\`\n\n@${
kice.split("@")[0]
} Removed for sending WhatsApp group link in this group! Message has been deleted.`,
mentions: [kice],
},
{
quoted: m,
}
);
} else if (isUrl(m.text) && !icmd && !isAdmin && !isCreator) {
await Miku.sendMessage(
from,
{
delete: {
remoteJid: m.from,
fromMe: false,
id: m.id,
participant: m.sender,
},
},
{
quoted: m,
}
);
m.reply(
`Antilink is on ! To use any link related commands use my actual prefix ( ${prefix} ) ! \n\nExample : ${prefix}igdl <link> or ${prefix}ytmp4 <link>`
);
} else {
}
}
}
//---------------------------------- Self/public/Private mode Configuration ------------------------------------//
let modSTATUS = await mku.findOne({
id: m.sender,
});
var modStatus = "false";
if (!modSTATUS) {
await mku.create({ id: m.sender, addedMods: "false" });
modStatus = modSTATUS.addedMods || "false";
}
if (modSTATUS) {
modStatus = modSTATUS.addedMods || "false";
}
let botModeSet = await mkchar.findOne({
id: "1",
});
var workerMode = "false";
if (botModeSet) {
workerMode = botModeSet.privateMode || "false";
if (workerMode == "true") {
if (
!global.owner.includes(`${m.sender.split("@")[0]}`) &&
modStatus == "false" &&
isCmd &&
m.sender != botNumber
) {
console.log("\nCommand Rejected ! Bot is in private mode !\n");
return;
}
}
if (workerMode == "self") {
if (m.sender != botNumber && isCmd) {
console.log("\nCommand Rejected ! Bot is in Self mode !\n");
return;
}
}
}
//-------------------------------------- Group CMD On/OFF Configuration ----------------------------------------//
let botSwitchGC = await mk.findOne({
id: m.from,
});
var botWrokerGC = "true";
if (botSwitchGC) {
botWrokerGC = botSwitchGC.botSwitch || "true";
if (
m.isGroup &&
botWrokerGC == "false" &&
!isAdmin &&
!isOwner &&
modStatus == "false" &&
isCmd
) {
return console.log(
`\nCommand Rejected ! Bot is turned off in ${groupName} !\n`
);
}
}
//------------------------------------------- Chatbot Configuration ---------------------------------------------//
let chatbotStatus = await mk.findOne({
id: m.from,
});
var csts = "false";
if (chatbotStatus) {
csts = chatbotStatus.chatBot || "false";
if (m.isGroup && csts == "true" && !icmd && !isCmd) {
if (m.quoted) {
if (m.quoted.sender == botNumber) {
const botreply = await axios.get(
`http://api.brainshop.ai/get?bid=172352&key=vTmMboAxoXfsKEQQ&uid=[uid]&msg=[${budy}]`
);
txt = `${botreply.data.cnt}`;
setTimeout(function () {
m.reply(txt);
}, 2200);
}
}
}
}
let PMchatBotStatus = await mkchar.findOne({
id: "1",
});
var PMcsts = "false";
if (PMchatBotStatus) {
PMcsts = PMchatBotStatus.PMchatBot || "false";
if (!m.isGroup && PMcsts == "true" && !icmd && !isCmd) {
const botreply = await axios.get(
`http://api.brainshop.ai/get?bid=172352&key=vTmMboAxoXfsKEQQ&uid=[uid]&msg=[${budy}]`
);
txt = `${botreply.data.cnt}`;
setTimeout(function () {
m.reply(txt);
}, 2200);
}
}
//--------------------------------------------- NSFW Configuration -----------------------------------------------//
let nsfwstatus = await mk.findOne({
id: m.from,
});
let NSFWstatus = "false";
if (nsfwstatus) {
NSFWstatus = nsfwstatus.switchNSFW || "false";
}
//---------------------------------------------- Group Banning Configuration --------------------------------------//
let banGCStatus = await mk.findOne({ id: m.from });
var BANGCSTATUS = "false";
if (banGCStatus) {
BANGCSTATUS = banGCStatus.bangroup || "false";
}
if (
BANGCSTATUS == "true" &&
budy != `${prefix}unbangc` &&
budy != `${prefix}unbangroup` &&
body.startsWith(prefix) &&
budy != `${prefix}support` &&
budy != `${prefix}supportgc` &&
budy != `${prefix}owner` &&
budy != `${prefix}mods` &&
budy != `${prefix}mod` &&
budy != `${prefix}modlist`
) {
if (m.isGroup && !isOwner && modStatus == "false") {
return m.reply(
`*${global.botName}* is *Banned* on *${groupName}* group! \n\nType *${prefix}owner* or *${prefix}support* to submit a request to unban the group!`
);
}
}
//----------------------------------------------------------------------------------------------------------------//
const flags = args.filter((arg) => arg.startsWith("--"));
if (body.startsWith(prefix) && !icmd) {
let mikutext = `No such command programmed *${pushname}* senpai! Type *${prefix}help* or press the button below to get my full command list!\n`;
let Button = [
{
buttonId: `${prefix}help`,
buttonText: {
displayText: `${prefix}help`,
},
type: 1,
},
];
let bmffg = {
image: {
url: botImage1,
},
caption: mikutext,
footer: `*${botName}*`,
buttons: Button,
headerType: 4,
};
Miku.sendMessage(m.from, bmffg, {
quoted: m,
});
}
if (m.message) {
// addBalance(m.sender, randomNomor(574), balance)
console.log(
chalk.black(chalk.bgWhite("[ MESSAGE ]")),
chalk.black(chalk.bgGreen(new Date())),
chalk.black(chalk.bgBlue(budy || m.mtype)) +
"\n" +
chalk.magenta("=> From"),
chalk.green(pushname),
chalk.yellow(m.sender) + "\n" + chalk.blueBright("=> In"),
chalk.green(m.isGroup ? m.from : "Private Chat", m.chat)
);
}
if (cmd) {
const randomXp = Math.floor(Math.random() * 3) + 1; //Random amont of XP until the number you want + 1
const haslUp = await Levels.appendXp(m.sender, "bot", randomXp);
}
if (
text.endsWith("--info") ||
text.endsWith("--i") ||
text.endsWith("--?")
) {
let data = [];
if (cmd.alias) data.push(`*Alias :* ${cmd.alias.join(", ")}`);
if (cmd.desc) data.push(`*Description :* ${cmd.desc}\n`);
if (cmd.usage)
data.push(
`*Example :* ${cmd.usage
.replace(/%prefix/gi, prefix)
.replace(/%command/gi, cmd.name)
.replace(/%text/gi, text)}`
);
var buttonss = [
{
buttonId: `${prefix}help`,
buttonText: {
displayText: `${prefix}help`,
},
type: 1,
},
];
let buttonmess = {
text: `*Command Info*\n\n${data.join("\n")}`,
footer: `*${botName}*`,
buttons: buttonss,
headerType: 1,
};
let reactionMess = {
react: {
text: cmd.react,
key: m.key,
},
};
await Miku.sendMessage(m.from, reactionMess).then(() => {
return Miku.sendMessage(m.from, buttonmess, {
react: "🍁",
quoted: m,
});
});
}
if (cmd.react) {
const reactm = {
react: {
text: cmd.react,
key: m.key,
},
};
await Miku.sendMessage(m.from, reactm);
}
if (!cool.has(m.sender)) {
cool.set(m.sender, new Collection());
}
const now = Date.now();
const timestamps = cool.get(m.sender);
const cdAmount = (cmd.cool || 0) * 1000;
if(!isOwner&&modStatus == "false"&&!botNumber.includes(m.sender)){
if (timestamps.has(m.sender)) {
const expiration = timestamps.get(m.sender) + cdAmount;
if (now < expiration) {
let timeLeft = (expiration - now) / 1000;
return await Miku.sendMessage(
m.from,
{
text: `Command Rejected ! Don't Spam ! You can use command after _${timeLeft.toFixed(
1
)} second(s)_`,
},
{
quoted: m,
}
);
}
}
}
timestamps.set(m.sender, now);
setTimeout(() => timestamps.delete(m.sender), cdAmount);
cmd.start(Miku, m, {
name: "Miku",
metadata,
pushName: pushname,
participants,
body,
args,
ar,
groupName,
botNumber,
flags,
isAdmin,
groupAdmin,
text,
quoted,
mentionByTag,
mime,
isBotAdmin,
prefix,
modStatus,
NSFWstatus,
isCreator,
store,
command: cmd.name,
commands,
Function: Func,
toUpper: function toUpper(query) {
return query.replace(/^\w/, (c) => c.toUpperCase());
},
});
} catch (e) {
e = String(e);
if (!e.includes("cmd.start")) console.error(e);
}
};