-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
3216 lines (2937 loc) · 108 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
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* --------------------------------- SERVER --------------------------------- */
const express = require("express");
const app = express();
app.use(express.urlencoded({ extended: true }));
const port = process.env.PORT || 8000;
app.get("/", (req, res) => {
res.send("Bot is running fine... no tension :)");
});
app.listen(port, () => {
// console.clear();
console.log("\nWeb-server running!\n");
});
/* -------------------------- delete auth from url -------------------------- */
const authHiddenPath = process.env.authHiddenPath; //to have a hidden path for auth db deletion
const { dropAuth } = require("./DB/dropauthDB");
app.get("/" + authHiddenPath, async (req, res) => {
let response = await dropAuth();
if (response) res.send("Auth DB deleted!");
else res.send("There is some error!");
});
/* ---------------------------------- SONG ---------------------------------- */
const downloadSong = async (randomName, query) => {
try {
const INFO_URL = "https://slider.kz/vk_auth.php?q=";
const DOWNLOAD_URL = "https://slider.kz/download/";
let { data } = await axios.get(INFO_URL + query);
if (data["audios"][""].length <= 1) {
console.log("==[ SONG NOT FOUND! ]==");
return "NOT";
}
//avoid remix,revisited,mix
let i = 0;
let track = data["audios"][""][i];
while (/remix|revisited|mix/i.test(track.tit_art)) {
i += 1;
track = data["audios"][""][i];
}
//if reach the end then select the first song
if (!track) {
track = data["audios"][""][0];
}
let link = DOWNLOAD_URL + track.id + "/";
link = link + track.duration + "/";
link = link + track.url + "/";
link = link + track.tit_art + ".mp3" + "?extra=";
link = link + track.extra;
link = encodeURI(link); //to replace unescaped characters from link
let songName = track.tit_art;
songName =
songName =
songName =
songName.replace(/\?|<|>|\*|"|:|\||\/|\\/g, ""); //removing special characters which are not allowed in file name
// console.log(link);
// download(songName, link);
const res = await axios({
method: "GET",
url: link,
responseType: "stream",
});
data = res.data;
const path = `./${randomName}`;
const writer = fs.createWriteStream(path);
data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on("finish", () => resolve(songName));
writer.on("error", () => reject);
});
} catch (err) {
console.log(err);
return "ERROR";
}
};
/* ------------------------------------ INSTA ----------------------------------- */
const saveInstaVideo = async (randomName, videoDirectLink) => {
const response = await axios({
url: videoDirectLink,
method: "GET",
responseType: "stream",
headers: {
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-IN,en-GB;q=0.9,en-US;q=0.8,en;q=0.7",
"cache-control": "max-age=0",
"sec-ch-ua":
'"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
"sec-ch-ua-mobile": "?1",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
},
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "GET",
mode: "cors",
});
const path = `./${randomName}`;
const writer = fs.createWriteStream(path);
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on("finish", resolve);
writer.on("error", reject);
});
};
/* ------------------------------------ Baiileys ----------------------------------- */
const {
WAConnection,
MessageType,
Presence,
Mimetype,
GroupSettingChange,
MessageOptions,
WALocationMessage,
WA_MESSAGE_STUB_TYPES,
ReconnectMode,
ProxyAgent,
waChatKey,
mentionedJid,
processTime,
} = require("@adiwajshing/baileys");
// LOAD ADDITIONAL NPM PACKAGES
const fs = require("fs");
const ffmpeg = require("fluent-ffmpeg");
const WSF = require("wa-sticker-formatter");
const Tesseract = require("tesseract.js");
const axios = require("axios");
//importing function files
const { getCricketScore } = require("./functions/cricket");
const { getScoreCard } = require("./functions/cricketScoreCard");
const { button } = require("./functions/button");
const { commandList } = require("./functions/list");
const { commandListOwner } = require("./functions/listOwner");
const { countToday, getcount } = require("./DB/countDB");
const {
addBlacklist,
removeBlacklist,
getBlacklist,
} = require("./DB/blacklistDB");
const { addDonation, getDonation } = require("./DB/donationDB");
const {
setCountMember,
getCountGroups,
getCountGroupMembers,
getCountIndividual,
getCountIndividualAllGroup,
getCountIndividualAllGroupWithName,
getCountTop,
} = require("./DB/countMemberDB");
const { setCountWarning, getCountWarning } = require("./DB/warningDB");
const { storeNewsTech } = require("./DB/postTechDB");
const { storeNewsStudy } = require("./DB/postStudyDB");
const { storeNewsSport } = require("./DB/postSportDB");
const { storeNewsMovie } = require("./DB/postMovieDB");
const { setCountVideo, getCountVideo } = require("./DB/countVideoDB");
const { getNews } = require("./functions/news");
const { getInstaVideo } = require("./functions/insta");
const { getFbVideo } = require("./functions/fb");
const { getGender } = require("./functions/gender");
const { getQuote } = require("./functions/quote");
const { takeGroupbackup } = require("./DB/backupDB");
const {
getVotingData,
setVotingData,
stopVotingData,
} = require("./DB/VotingDB");
const {
getVotingAllData,
setVotingAllData,
stopVotingAllData,
} = require("./DB/votingAllDB");
const { setGroupName } = require("./DB/groupNameDB");
let Parser = require("rss-parser");
let parser = new Parser();
const ytdl = require("ytdl-core");
const AdmZip = require("adm-zip");
const { replicationStart } = require("pg-protocol/dist/messages");
let stickertg = false;
let setIntervaltg;
// BASIC SETTINGS
prefix = "!";
require("dotenv").config();
const myNumber = process.env.myNumber;
const pvx = process.env.pvx;
const zeksapi = process.env.zeksapi;
//CRICKET variables
let matchIdGroups = {}; //to store every group name with its match ID
let cricSetIntervalGroups = {}; //to store every group name with its setInterval value so that it can be stopped
let cricStartedGroups = {}; //to store every group name with boolean value to know if cricket score is already started or not
// LOAD CUSTOM FUNCTIONS
const getGroupAdmins = (participants) => {
admins = [];
for (let i of participants) {
i.isAdmin ? admins.push(i.jid) : "";
}
return admins;
};
const more = String.fromCharCode(8206);
const readMore = more.repeat(4001);
const getRandom = (text) => {
return `${Math.floor(Math.random() * 10000)}${text}`;
};
let pvxcommunity = "[email protected]";
let pvxprogrammer = "[email protected]";
let pvxadmin = "[email protected]";
let pvxstudy = "[email protected]";
let pvxmano = "[email protected]";
let pvxtech = "[email protected]";
let pvxsport = "[email protected]";
let pvxmovies = "[email protected]";
let pvxstickeronly1 = "[email protected]";
let pvxstickeronly2 = "[email protected]";
let pvxstickeronly3 = "[email protected]";
let mano = "[email protected]";
let pvxdeals = "[email protected]";
let countSent = 1;
/* ------------------------------ MAIN FUNCTION ----------------------------- */
const main = async () => {
const { connectToWA } = require("./DB/authDB");
const conn = await connectToWA(WAConnection);
let botNumberJid = conn.user.jid;
/* -------------------------------- BIRTHDAY -------------------------------- */
let usedDate = new Date()
.toLocaleString("en-GB", { timeZone: "Asia/kolkata" })
.split(",")[0];
const checkTodayBday = async (todayDate) => {
console.log("CHECKING TODAY BDAY...", todayDate);
todayDate = todayDate.split("/");
let d = todayDate[0];
d = d.startsWith("0") ? d[1] : d;
let m = todayDate[1];
m = m.startsWith("0") ? m[1] : m;
let url = "https://pvxgroup.herokuapp.com/api/bday";
let { data } = await axios.get(url);
let bday = [];
data.data.forEach((member) => {
if (member.month == m && member.date == d) {
bday.push(
`${member.name.toUpperCase()} (${member.username.toUpperCase()})`
);
console.log(`Today is ${member.name} Birthday!`);
}
});
if (bday.length) {
let bdayComb = bday.join(" & ");
conn.sendMessage(
pvxcommunity,
`*─「 🔥 <{PVX}> BOT 🔥 」─* \n\nToday is ${bdayComb} Birthday 🍰 🎉🎉`,
MessageType.text
);
} else {
console.log("NO BIRTHDAY!");
conn.sendMessage(
pvxcommunity,
`*─「 🔥 <{PVX}> BOT 🔥 」─* \n\nThere is no Birthday today!`,
MessageType.text
);
}
try {
await conn.groupUpdateSubject(pvxcommunity, "<{PVX}> COMMUNITY ❤️");
} catch (err) {
console.log(err);
}
};
const postTechNews = async (count) => {
if (count > 20) {
//20 times, already posted news comes up
return;
}
console.log(`TECH NEWS FUNCTION ${count} times!`);
let url = "https://pvx-api-vercel.vercel.app/api/news";
let { data } = await axios.get(url);
delete data["about"];
let newsWeb = [
"gadgets-ndtv",
"gadgets-now",
"xda-developers",
"inshorts",
"beebom",
"india",
"mobile-reuters",
"techcrunch",
"engadget",
];
let randomWeb = newsWeb[Math.floor(Math.random() * newsWeb.length)]; //random website
let index = Math.floor(Math.random() * data[randomWeb].length);
let news = data[randomWeb][index];
let techRes = await storeNewsTech(news);
if (techRes) {
console.log("NEW TECH NEWS!");
conn.sendMessage(pvxtech, `📰 ${news}`, MessageType.text);
} else {
console.log("OLD TECH NEWS!");
postTechNews(count + 1);
}
};
const postStudyInfo = async (count) => {
if (count > 20) {
//20 times already posted news came
return;
}
console.log(`STUDY NEWS FUNCTION ${count} times!`);
let feed;
// let random = Math.floor(Math.random() * 2);
feed = await parser.parseURL(
"https://www.thehindu.com/news/national/feeder/default.rss"
);
let li = feed.items.map((item) => {
return { title: item.title, link: item.link };
});
let index = Math.floor(Math.random() * li.length);
let news = li[index];
let techRes = await storeNewsStudy(news.title);
if (techRes) {
console.log("NEW STUDY NEWS!");
conn.sendMessage(pvxstudy, `📰 ${news.title}`, MessageType.text, {
detectLinks: false,
});
} else {
console.log("OLD STUDY NEWS!");
postStudyInfo(count + 1);
}
};
if (pvx) {
setInterval(() => {
console.log("SET INTERVAL.");
let todayDate = new Date().toLocaleDateString("en-GB", {
timeZone: "Asia/kolkata",
});
let hour = Number(
new Date()
.toLocaleTimeString("en-GB", {
timeZone: "Asia/kolkata",
})
.split(":")[0]
);
//8 to 24 ON
if (hour >= 8) {
postTechNews(0);
postStudyInfo(0);
}
if (usedDate !== todayDate) {
usedDate = todayDate;
checkTodayBday(todayDate);
}
}, 1000 * 60 * 20); //20 min
}
// member left or join
conn.on("group-participants-update", async (anu) => {
try {
const groupMetadata = await conn.groupMetadata(anu.jid);
let groupDesc = groupMetadata.desc;
let groupSubject = groupMetadata.subject;
let blockCommandsInDesc = []; //commands to be blocked
if (groupDesc) {
let firstLineDesc = groupDesc.split("\n")[0];
blockCommandsInDesc = firstLineDesc.split(",");
}
let blacklistRes = await getBlacklist();
blacklistRes = blacklistRes.map((num) => num.number);
// console.log(blacklistRes);
let from = anu.jid;
let numJid = anu.participants[0];
let num_split = `${numJid.split("@s.whatsapp.net")[0]}`;
if (anu.action == "add") {
// other than 91 are blocked from joining when description have written in first line -> only91
if (
!num_split.startsWith(91) &&
blockCommandsInDesc.includes("only91")
) {
conn.sendMessage(
from,
`*─「 🔥 <{PVX}> BOT 🔥 」─* \n\nOnly 91 numbers are allowed !!!!`,
MessageType.text
);
conn.groupRemove(from, anu.participants);
conn.sendMessage(
myNumber + "@s.whatsapp.net",
`${num_split} is removed from ${groupSubject}. Not 91!`,
MessageType.text
);
return;
}
//if number is blacklisted
if (blacklistRes.includes(num_split)) {
conn.sendMessage(
from,
`*─「 🔥 <{PVX}> BOT 🔥 」─* \n\nNumber is blacklisted !!!!`,
MessageType.text
);
conn.groupRemove(from, anu.participants);
conn.sendMessage(
myNumber + "@s.whatsapp.net",
`${num_split} is removed from ${groupSubject}. Blacklisted!`,
MessageType.text
);
return;
}
//for study group
if (from === pvxstudy) {
conn.sendMessage(
from,
`Welcome @${num_split} to PVX Study group.\nhttps://pvxcommunity.com/\n\nKindly fill the Biodata form (mandatory for all)\n\n👇🏻👇🏻👇🏻👇🏻👇🏻\nhttps://forms.gle/uuvUwV5fTk8JAjoTA`,
MessageType.extendedText,
{
contextInfo: { mentionedJid: [numJid] },
detectLinks: false,
}
);
}
//for movies group
if (from === pvxmovies) {
conn.sendMessage(
from,
`Welcome @${num_split} to PVX Movies.\nhttps://pvxcommunity.com/\n\nWhat are your currently watching..?`,
MessageType.extendedText,
{
contextInfo: { mentionedJid: [numJid] },
detectLinks: false,
}
);
}
//for community group
if (from === pvxcommunity) {
conn.sendMessage(
from,
`Welcome @${num_split} to PVX COMMUNITY.\nhttps://pvxcommunity.com/\n\nPlease follow the rules. Send ${prefix}rules to know all rules of PVX\nBe active and Don't spam`,
MessageType.extendedText,
{
contextInfo: { mentionedJid: [numJid] },
detectLinks: false,
}
);
}
//for mano
if (from === pvxmano) {
conn.sendMessage(
from,
`Welcome @${num_split} to PVX MANORANJAN 🔥\n\n1) Send videos regularly especially new members.\n2) Don't Send CP or any other illegal videos.\n 3) A group bot will be counting the number of videos you've sent. \nSend ?pvxv to know video count.\nInactive members will be kicked time to time.`,
MessageType.extendedText,
{
contextInfo: { mentionedJid: [numJid] },
}
);
}
//for programmer group
if (from === pvxprogrammer) {
conn.sendMessage(
from,
`Welcome @${num_split} to PVX Programmers Group.\nhttps://pvxcommunity.com/\n\n*Kindly give your intro like*\nName:\nCollege/Degree:\nInterest:\nSkills:\nCompany(if working):`,
MessageType.extendedText,
{
contextInfo: { mentionedJid: [numJid] },
detectLinks: false,
}
);
}
if (numJid === botNumberJid) {
console.log("Bot is added to new group!");
conn.sendMessage(
from,
`*─「 🔥 <{PVX}> BOT 🔥 」─* \n\nSEND ${prefix}help FOR BOT COMMANDS`,
MessageType.text
);
}
console.log(`[GROUP] ${groupSubject} [JOINED] ${numJid}`);
}
if (anu.action == "remove") {
console.log(`[GROUP] ${groupSubject} [LEAVED] ${numJid}`);
}
} catch (err) {
console.log(err);
}
});
// new message
conn.on("chat-update", async (mek) => {
try {
if (!mek.hasNewMessage) return;
try {
mek = JSON.parse(JSON.stringify(mek)).messages[0];
} catch {
return;
}
if (!mek.message) return;
if (mek.key && mek.key.remoteJid == "status@broadcast") return;
// if (mek.key.fromMe) return;
const content = JSON.stringify(mek.message);
global.prefix;
const from = mek.key.remoteJid;
const type = Object.keys(mek.message)[0];
const {
text,
extendedText,
contact,
location,
liveLocation,
image,
video,
sticker,
document,
audio,
product,
} = MessageType;
//body will have the text message
let body =
type === "conversation" && mek.message.conversation.startsWith(prefix)
? mek.message.conversation
: type == "imageMessage" &&
mek.message.imageMessage.caption &&
mek.message.imageMessage.caption.startsWith(prefix)
? mek.message.imageMessage.caption
: type == "videoMessage" &&
mek.message.videoMessage.caption &&
mek.message.videoMessage.caption.startsWith(prefix)
? mek.message.videoMessage.caption
: type == "extendedTextMessage" &&
mek.message.extendedTextMessage.text &&
mek.message.extendedTextMessage.text.startsWith(prefix)
? mek.message.extendedTextMessage.text
: "";
if (body[1] == " ") body = body[0] + body.slice(2); //remove space when space btw prefix and commandName like "! help"
const command = body.slice(1).trim().split(/ +/).shift().toLowerCase();
const args = body.trim().split(/ +/).slice(1);
const isCmd = body.startsWith(prefix);
//count video
// if (isGroup && mek.message.videoMessage && from == pvxmano) {
// setCountVideo(sender, from);
// }
//send all sticker message to given group
// if (
// mek.message.stickerMessage &&
// mek.key.fromMe == false &&
// from.endsWith("@g.us")
// ) {
// console.log(mek);
// const mediaSticker = await conn.downloadAndSaveMediaMessage({
// message: mek.message,
// });
// const webpWithMetadataSticker = await WSF.setMetadata(
// "<{PVX}> BOT 🤖",
// "",
// mediaSticker
// );
// //sticker only 1.0 -> "[email protected]"
// await conn.sendMessage(
// "[email protected]",
// webpWithMetadataSticker,
// MessageType.sticker
// );
// console.log("Sticker Sent!");
// }
/* [INFO]
1) quoted == tagged messages
2) when normal text received
mek = {
key: {
remoteJid: "[email protected]",
fromMe: false,
id: "B98FBDD5A762DEA9F4DD733",
},
message: { conversation: "!help" },
messageTimestamp: "1632654425",
participant: "[email protected]",
ephemeralOutOfSync: false,
};
3) type = "conversation" , "imageMessage" , "videoMessage" , "extendedTextMessage"
-> extendedTextMessage are tagged messages
*/
const isGroup = from.endsWith("@g.us");
//if (!isGroup) return;
const groupMetadata = isGroup ? await conn.groupMetadata(from) : "";
const groupName = isGroup ? groupMetadata.subject : "";
let sender = isGroup ? mek.participant : from;
//count message
if (
isGroup &&
groupName.toUpperCase().includes("<{PVX}>") &&
from !== pvxstickeronly1 &&
from != pvxstickeronly2 &&
from != pvxstickeronly3 &&
from != pvxdeals
) {
let user = conn.contacts[sender];
let username = user
? user.notify || user.vname || user.name || sender.split("@")[0]
: sender.split("@")[0];
setCountMember(sender, from, username);
}
//send sticker
if (
isGroup &&
mek.message.stickerMessage &&
groupName.startsWith("<{PVX}>") &&
from !== pvxstickeronly1 &&
from != pvxstickeronly2 &&
from != pvxstickeronly3 &&
from !== mano
) {
// mek.key.fromMe == false &&
// SEND STICKER
const mediaSticker = await conn.downloadAndSaveMediaMessage({
message: mek.message,
});
// "<{PVX}> BOT 🤖"
const webpWithMetadataSticker = await WSF.setMetadata(
"BOT 🤖",
"pvxcommunity.com",
mediaSticker
);
await conn.sendMessage(
pvxstickeronly1,
webpWithMetadataSticker,
MessageType.sticker
);
await conn.sendMessage(
pvxstickeronly2,
webpWithMetadataSticker,
MessageType.sticker
);
console.log(`${countSent} sticker sent!`);
countSent += 1;
}
if (!isCmd) return;
errors = {
admin_error: "❌ I'm not Admin here!",
};
// if (isGroup && groupName.toUpperCase().includes("<{PVX}>")) {
// let user = conn.contacts[sender];
// let username = user
// ? user.notify ||
// user.vname ||
// user.name ||
// sender.split("@")[0]
// : sender.split("@")[0];
// setCountMember(sender, from, username);
// }
// console.log(mek);
if (mek.key.fromMe) sender = botNumberJid;
const groupDesc = isGroup ? groupMetadata.desc : "";
const groupMembers = isGroup ? groupMetadata.participants : "";
const groupAdmins = isGroup ? getGroupAdmins(groupMembers) : "";
const isBotGroupAdmins = groupAdmins.includes(botNumberJid) || false;
const isGroupAdmins = groupAdmins.includes(sender) || false;
const isMedia = type === "imageMessage" || type === "videoMessage"; //image or video
const isTaggedImage =
type === "extendedTextMessage" && content.includes("imageMessage");
const isTaggedVideo =
type === "extendedTextMessage" && content.includes("videoMessage");
const isTaggedSticker =
type === "extendedTextMessage" && content.includes("stickerMessage");
const isTaggedDocument =
type === "extendedTextMessage" && content.includes("documentMessage");
// Display every command info
console.log(
"[COMMAND]",
command,
"[FROM]",
sender.split("@")[0],
"[IN]",
groupName
);
const reply = (message) => {
conn.sendMessage(from, message, MessageType.text, {
quoted: mek,
});
};
const sendText = (message) => {
conn.sendMessage(from, message, MessageType.text);
};
// send every command info to my whatsapp, won't work when i send something for bot
if (myNumber && myNumber + "@s.whatsapp.net" !== sender) {
let count = await countToday();
await conn.sendMessage(
myNumber + "@s.whatsapp.net",
`${count}) [${prefix}${command}] [${groupName}]`,
MessageType.text
);
}
/* -------------------------- CRICKET HELPING FUNCTIONS ------------------------- */
const stopcHelper = () => {
reply("✔️ Stopping Cricket scores for this group !");
console.log("Stopping Cricket scores for " + groupName);
clearInterval(cricSetIntervalGroups[groupName]);
cricStartedGroups[groupName] = false;
};
//return false when stopped in middle. return true when run fully
const startcHelper = async (commandName, isFromSetInterval = false) => {
if (!groupDesc) {
conn.sendMessage(
from,
`❌
- Group description is empty.
- Put match ID in starting of group description.
- Get match ID from cricbuzz today match url.
- example: https://www.cricbuzz.com/live-cricket-scores/37572/mi-vs-kkr-34th-match-indian-premier-league-2021
- so match ID is 37572 !
# If you've put correct match ID in description starting and still facing this error then contact developer by !dev`,
MessageType.text,
{
quoted: mek,
detectLinks: false,
}
);
return false;
}
matchIdGroups[groupName] = groupDesc.slice(0, 5);
if (commandName === "startc" && !isFromSetInterval) {
reply(
"✔️ Starting Cricket scores for matchID: " +
matchIdGroups[groupName] +
" (taken from description)"
);
}
let response = await getCricketScore(
matchIdGroups[groupName],
commandName
);
//response.info have "MO" only when command is startc
if (commandName === "startc" && response.info === "MO") {
sendText(response.message);
reply("✔️ Match over! Stopping Cricket scores for this group !");
console.log("Match over! Stopping Cricket scores for " + groupName);
clearInterval(cricSetIntervalGroups[groupName]);
cricStartedGroups[groupName] = false;
return false;
} else if (commandName === "startc" && response.info === "IO") {
sendText(response.message);
reply(
"✔️ Inning over! Open again live scores later when 2nd inning will start by !startc"
);
stopcHelper();
return false;
} else if (response.info === "ER") {
conn.sendMessage(
from,
`❌
- Group description starting is "${matchIdGroups[groupName]}"
- Put match ID in starting of group description.
- Get match ID from cricbuzz today match url.
- example: https://www.cricbuzz.com/live-cricket-scores/37572/mi-vs-kkr-34th-match-indian-premier-league-2021
- so match ID is 37572 !
# If you've put correct match ID in description starting and still facing this error then contact developer by !dev`,
MessageType.text,
{
quoted: mek,
detectLinks: false,
}
);
return false;
}
sendText(response.message);
return true;
};
// give command name with comma seperated to be blocked for particular group in first line of description like (82132 is matchid for cricket scores)
//82132,score,add,remove
let blockCommandsInDesc = []; //commands to be blocked
if (groupDesc) {
let firstLineDesc = groupDesc.split("\n")[0];
blockCommandsInDesc = firstLineDesc.split(",");
}
if (blockCommandsInDesc.includes(command)) {
reply("❌ Command blocked for this group!");
return;
}
let pvxadminsMem;
try {
let pvxadminsGroup = await conn.groupMetadata(pvxadmin);
pvxadminsMem = pvxadminsGroup.participants.map((mem) => mem.jid);
} catch (err) {
pvxadminsMem = [];
}
/* ------------------------------------ - ----------------------------------- */
/* -------------------------------- COMMANDS -------------------------------- */
/* ------------------------------------ - ----------------------------------- */
switch (command) {
/* ------------------------------- CASE: HELP ------------------------------ */
case "help":
case "h":
const resHelp = await conn.sendMessage(
from,
commandList(prefix),
MessageType.text
);
//delete after 5 min
// setTimeout(async () => {
// await conn.deleteMessage(from, {
// id: resHelp.key.id,
// remoteJid: from,
// fromMe: true,
// });
// }, 1000 * 60 * 5);
break;
/* ------------------------------- CASE: helpr ------------------------------ */
case "helpr":
reply(commandListOwner(prefix));
break;
/* ------------------------------- CASE: countstats ------------------------------ */
case "countstats":
if (myNumber + "@s.whatsapp.net" !== sender) {
reply(`❌ Owner only command!`);
return;
}
let countRes = await getcount();
let countMsg = `COMMAND USED STATS:\n${readMore}`;
countRes.forEach((r) => {
countMsg += `\n${r.to_char} - ${r.times} times`;
});
reply(countMsg);
break;
/* ------------------------------- CASE: blacklist ------------------------------ */
case "blacklist":
let blacklistRes = await getBlacklist();
let blacklistMsg = "Blacklisted Numbers\n";
blacklistRes.forEach((num) => {
blacklistMsg += `\n${num.number}`;
});
reply(blacklistMsg);
break;
/* ------------------------------- CASE: blacklistremove ------------------------------ */
case "blacklistremove":
case "blr":
if (!pvxadminsMem.includes(sender)) {
reply(`❌ PVX admin only command!`);
return;
}
if (!isGroupAdmins) {
reply("❌ Admin command!");
return;
}
let blacklistNumb1 = args[0];
if (!Number(blacklistNumb1)) {
reply(
`❌ Give number to remove from blacklist by ${prefix}blr number!`
);
return;
}
if (blacklistNumb1.startsWith("+")) {
blacklistNumb1 = blacklistNumb1.slice(1);
}
if (
blacklistNumb1.length === 10 &&
!blacklistNumb1.startsWith("91")
) {
blacklistNumb1 = "91" + blacklistNumb1;
}
let blacklistRes1 = await removeBlacklist(blacklistNumb1);
if (blacklistRes1) reply("✔️ Removed from blacklist!");
else reply("❌ Error!");
break;
/* ------------------------------- CASE: blacklistadd ------------------------------ */
case "blacklistadd":
case "bla":
if (!pvxadminsMem.includes(sender)) {
reply(`❌ PVX admin only command!`);
return;
}
if (!isGroupAdmins) {
reply("❌ Admin command!");
return;
}
let blacklistNumb2 = args[0];
if (!Number(blacklistNumb2)) {
reply(`❌ Give number to add in blacklist by ${prefix}bla number!`);
return;
}
if (blacklistNumb2.startsWith("+")) {
blacklistNumb2 = blacklistNumb2.slice(1);
}
if (
blacklistNumb2.length === 10 &&
!blacklistNumb2.startsWith("91")
) {
blacklistNumb2 = "91" + blacklistNumb2;
}
let blacklistRes2 = await addBlacklist(blacklistNumb2);
if (blacklistRes2) reply("✔️ Added to blacklist!");
else reply("❌ Error!");
break;
/* ------------------------------- CASE: warning ------------------------------ */
case "warning":
case "warn":
// if (!pvxadminsMem.includes(sender)) {
// reply(`❌ PVX admin only command!`);
// return;
// }
if (!isGroupAdmins) {
reply("❌ Admin command!");
return;
}
if (!mek.message.extendedTextMessage) {
reply("❌ Tag someone!");
return;
}
try {
let mentioned =
mek.message.extendedTextMessage.contextInfo.mentionedJid;
if (mentioned) {
//when member are mentioned with command
if (mentioned.length === 1) {
let warnCount = await getCountWarning(mentioned[0], from);
let num_split = mentioned[0].split("@s.whatsapp.net")[0];
let warnMsg = `@${num_split} ,You have been warned. Warning status (${
warnCount + 1
}/3). Don't repeat this type of behaviour again or you'll be banned from the group!`;
conn.sendMessage(from, warnMsg, MessageType.extendedText, {