-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
2039 lines (1960 loc) · 66.6 KB
/
app.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
// Supports ES6
const venom = require("venom-bot");
const axios = require("axios");
const musicInfo = require("music-info");
const openai = require("openai-grammaticalcorrection");
require("dotenv").config();
const _ = require("lodash");
const { remind } = require("./functions/reminders");
const { truthOrDare, wouldYouRather } = require("./functions/gamesHandlers");
const {
sendButtons,
sendReply: VsendReply,
} = require("./functions/venomFunctions");
const { sendMenu } = require("./functions/menuHandlers");
const { groupPerms, showAllRoles } = require("./functions/rolesHandlers");
const {
stkToImg,
imgToSticker,
ocr,
sendGifSticker,
} = require("./functions/mediaHandlers");
const {
animeSearch,
animeDetail,
charDetailById,
animeStaffDetails,
searchCharacterDetail,
mangaSearch,
mangaDetailsById,
} = require("./functions/animeHandlers");
const { analyzeText } = require("./functions/tensorflowHandlers");
// Create the client
venom
.create({
session: "session-name", //name of session
multidevice: true, // for version not multidevice use false.(default: true)
})
.then((client) => {
start(client);
})
.catch((error) => {
console.log(error);
console.log("ERROR OCCURED");
});
let RecievedMsgPermission = false;
// Start the client
function start(client) {
// Get reminder data from database
axios.get(`${process.env.FIREBASE_DOMAIN}/reminders.json`).then((res) => {
for (const key in res.data) {
for (const remKey in res.data[key]) {
remind(
client,
res.data[key][remKey].time,
res.data[key][remKey].msg,
key + ".us",
remKey
);
}
}
});
// Get all groups who have mention all role
let mentionAllGrps = [];
axios
.get(`${process.env.FIREBASE_DOMAIN}/grpFlags/mention-all.json`)
.then((res) => {
for (const key in res.data) {
mentionAllGrps.push({ id: key, grpId: res.data[key].grpId });
}
});
// Get all groups who have mention all admin only role
let mentionAllAdminOnlyGrps = [];
axios
.get(`${process.env.FIREBASE_DOMAIN}/grpFlags/mention-all-admin-only.json`)
.then((res) => {
for (const key in res.data) {
mentionAllAdminOnlyGrps.push({ id: key, grpId: res.data[key].grpId });
}
});
// Get all groups who have nsfw roast role
let nsfwRoastGrps = [];
axios
.get(`${process.env.FIREBASE_DOMAIN}/grpFlags/nsfw-roast.json`)
.then((res) => {
for (const key in res.data) {
nsfwRoastGrps.push({ id: key, grpId: res.data[key].grpId });
}
});
// Get all group data which contains the roles opted by members
let grpData = [];
axios.get(`${process.env.FIREBASE_DOMAIN}/grpData.json`).then((res) => {
for (const key in res.data) {
let roleData = [];
for (const roleKey in res.data[key]) {
let members = [];
for (const memberKey in res.data[key][roleKey].members) {
members.push({
id: memberKey,
memberId: res.data[key][roleKey].members[memberKey].memberId,
});
}
roleData.push({
roleId: roleKey,
roleName: res.data[key][roleKey].roleName,
members: members,
});
}
grpData.push({ grpId: key, roles: roleData });
}
});
const pollGrps = [
"Unofficial",
"#3: HASH",
"OT4KU",
"Straw Hat",
"CATS",
"WE",
"Chaman",
"CS Team",
"BDAY",
"pendicul",
"testing",
"Rsp",
];
// variables and constants used in the code
const wikiEndpoint = "https://en.wikipedia.org/w/api.php?";
const mathsEndpoint = "http://api.mathjs.org/v4/?expr=";
let buttonsArray = [];
let params = {},
op1count = 0,
op2count = 0,
totalVotes = 0,
pollActive = false,
pollMsg = "",
op1msg = "",
op2msg = "",
pollVoters = [],
op1percent = 0,
op2percent = 0,
pollerId = "",
pollerName = "",
pollerGrp = "",
selectedGrpIndex;
let poll = [{}],
perm = false;
let grpArray = [],
selectedGrp = [];
// This function executes whenever a message is sent or recieved
client.onAnyMessage((message) => {
// variables and constants required to make the data readable
const data = message.body;
const botQuery = data.split(" ");
botQuery[0] = botQuery[0].toLowerCase();
const queryCutter = botQuery[0] + " ";
const queryWithDesc = data.substring(queryCutter.length).split("\n"); // Get everything written after the command
let query = queryWithDesc[0]; // This is used as the option people type after the command
const queryPart = query.split("-"); // This is used as extra options that people type after the above query
let composeMsg = [],
msgString = "",
list = [],
selectedRoleIndex,
selectedRole,
roleAbsent = false;
const songParams = {
title: queryPart[0],
artist: queryPart[1],
};
let msgObj = {
type: message.quotedMsg ? message.quotedMsg.type : "chat",
};
switch (botQuery[0]) {
//////////////////////////////////////HI BOT//////////////////////////////////////
case ".hi":
case "hibot":
RecievedMsgPermission = true;
console.log("in hi");
sendReply(
message.chatId,
"No need to say hi to me, I am always here, reading every message you send to this guy.😁\nSend 'HelpBot' for commands",
message.id.toString(),
"Error when sending: "
);
break;
////////////////////////////////////CALCULATE//////////////////////////////////////
case ".calc":
RecievedMsgPermission = true;
axios
.get(mathsEndpoint + encodeURIComponent(query) + "&precision=3")
.then((response) => {
sendReply(
message.chatId,
response.data.toString(),
message.id.toString(),
"Error when sending: "
);
})
.catch((error) => {
console.log(error.response.data);
sendReply(
message.chatId,
error.response.data,
message.id.toString(),
"Error when sending: "
);
});
break;
//////////////////////////////////////ROAST///////////////////////////////////////
case ".roast":
case "botroast":
RecievedMsgPermission = true;
let roastPerm = false;
// Check if the group allows nsfw roats or not
nsfwRoastGrps.forEach((grp) => {
if (message.chat.name.search(grp) !== -1 || !message.isGroupMsg) {
roastPerm = true;
}
});
if (!roastPerm) {
composeMsg = [
"This command is not supported here. There are people here who don't like it.\n```THEY AREN'T COOL ENOUGH.```\n\nAsk admins for activating this command in this group\n\nIf you are an admin yourself, then use GroupPerms command for activating this command in this group.",
];
composeMsg.forEach((txt) => {
msgString += txt;
});
sendReply(
message.chatId,
msgString,
message.id.toString(),
"Error while sending roast"
);
break;
}
axios
.get("https://evilinsult.com/generate_insult.php?lang=en&type=json")
.then(function (response) {
// Abusive roasts
if (
response.data.number == "111" ||
response.data.number === "119" ||
response.data.number === "121" ||
response.data.number === "10" ||
response.data.number === "11"
) {
composeMsg = [
"Ooops.. Please try again\nThe roast was too severe",
];
console.log(response.data.insult);
} else {
composeMsg = [
"Roast from Bot\n-------------------------\n",
"Dear ",
query,
", ",
response.data.insult,
];
}
composeMsg.forEach((txt) => {
msgString += txt;
});
// Send the response to the sender
client
.reply(message.chatId, msgString, message.id.toString())
.then(() => {
console.log(
"Sent message: " + msgString + "\n-------------------"
);
})
.catch((erro) => {
console.error("Error when sending the roast: ", erro);
});
})
.catch((error) => {
console.log(error);
});
break;
///////////////////////////////////TAG EVERYONE///////////////////////////////////////
case ".yall":
case ".y'all":
case ".all":
case ".every":
case "@everyone":
case ".everyone":
RecievedMsgPermission = true;
let annoyPerm = false,
isAdmin = false;
query = data.substring(queryCutter.length);
// Check if the group allows annoying mentions or not
message.chat.groupMetadata.participants.forEach((participant) => {
if (participant.isAdmin && participant.id === message.sender.id) {
isAdmin = true;
}
});
console.log(mentionAllAdminOnlyGrps);
console.log(mentionAllGrps);
mentionAllAdminOnlyGrps.forEach((grp) => {
if (message.isGroupMsg && message.chatId === grp.grpId && isAdmin) {
annoyPerm = true;
}
});
mentionAllGrps.forEach((grp) => {
if (message.isGroupMsg && message.chatId === grp.grpId) {
annoyPerm = true;
}
});
if (!annoyPerm) {
message.isGroupMsg
? (msgString =
"People get annoyed by useless mentioning😔\n\nAsk admins for activating this command in this group\n\nIf you are an admin yourself, then use GroupPerms command for activating this command in this group.\n\nFor example:\nGroupPerms")
: (msgString = "This command is not supported in dms😁");
// Send the response to the sender
client
.reply(message.chatId, msgString, message.id.toString())
.then(() => {
console.log(
"Sent message: " + msgString + "\n-------------------"
);
})
.catch((erro) => {
console.error("Error when sending kanji definition: ", erro);
});
} else {
composeMsg = [
"‼```Tagging Everyone on request of``` *",
message.sender.verifiedName
? message.sender.verifiedName
: message.sender.notifyName,
"‼*\n",
query
? "\n----------------------------------------------------\n"
: "",
query ? query : "",
"\n----------------------------------------------------\n",
];
composeMsg.forEach((txt) => (msgString += txt));
client
.getGroupMembersIds(message.chat.groupMetadata.id)
.then((res) => {
let members = [];
res.forEach((member) => {
members.push(member.user.toString());
msgString += `@${member.user.toString()} | `;
});
msgString += `\n_Total members: ${members.length}_`;
client
.sendMentioned(message.chatId, msgString, members)
.then(() => {
console.log(
"Sent message: " + msgString + "\n-------------------"
);
})
.catch((erro) => {
console.log("Error when tagging: ", erro);
});
})
.catch((erro) => {
console.error("Error when tagging: ", erro);
});
}
break;
/////////////////////////////////KANJI DEFINITION/////////////////////////////////
case ".kd":
case "kanjidef":
case "kanjidefine":
RecievedMsgPermission = true;
// Get the response from the api
axios
.get(encodeURI("https://kanjiapi.dev/v1/kanji/" + query))
.then(function (res) {
const kanjiData = res.data;
let meaningString = "",
kunString = "",
onString = "",
i;
for (i = 0; i < kanjiData.meanings.length; i++) {
meaningString += kanjiData.meanings[i] + " | ";
}
for (i = 0; i < kanjiData.kun_readings.length; i++) {
kunString += kanjiData.kun_readings[i] + " | ";
}
for (i = 0; i < kanjiData.on_readings.length; i++) {
onString += kanjiData.on_readings[i] + " | ";
}
// Set the fields to be sent in message
composeMsg = [
" *Kanji* : ",
query,
"\n *Meanings* : ",
meaningString,
"\n *Kunyomi readings* : ",
kunString,
"\n *Onyomi readings* : ",
onString,
];
composeMsg.forEach(function (txt) {
msgString += txt;
});
// Send the response to the sender
client
.reply(message.chatId, msgString, message.id.toString())
.then(() => {
console.log(
"Sent message: " + msgString + "\n-------------------"
);
})
.catch((erro) => {
console.error("Error when sending kanji definition: ", erro);
});
})
.catch((err) => {
// Send not found to sender
client
.reply(
message.chatId,
"Word not found.. Sorry",
message.id.toString()
)
.then(() => {
console.log(err);
})
.catch((erro) => {
console.error("Error when sending error: ", erro);
});
});
break;
////////////////////////////////////DICTIONARY////////////////////////////////////
case ".ed":
case "engdef":
case "englishdefine":
RecievedMsgPermission = true;
buttonsArray = [
{
buttonId: "ed",
buttonText: { displayText: "EnglishDefine Inception" },
type: 1,
},
{ buttonId: "ihelp", buttonText: { displayText: ".ihelp" }, type: 1 },
{ buttonId: "help", buttonText: { displayText: ".help" }, type: 1 },
];
// Get the response from the api
axios
.get("https://api.dictionaryapi.dev/api/v2/entries/en_US/" + query)
.then((response) => {
// Set the fields of the message
response.data[0].meanings.forEach((meaning) => {
composeMsg.push("*", meaning.partOfSpeech, "*\n\n");
meaning.definitions.forEach((def) => {
composeMsg.push(
"*Definition*: ",
def.definition,
"\n*For Example*: ",
def.example ? def.example : "Not Available😕",
"\n\n"
);
});
composeMsg.push(
"\n---------------------------------------------------\n"
);
});
composeMsg.forEach((txt) => {
msgString += txt;
});
// Send the response to the sender
client
.sendButtons(
message.chatId,
msgString,
buttonsArray,
"Click on buttons for other menus and examples"
)
.then(() => {
console.log(
"Sent message: " + msgString + "\n-------------------"
);
})
.catch((erro) => {
console.error("Error when sending: ", erro);
});
})
.catch((err) => {
client
.sendButtons(
message.chatId,
err.response.data.message +
"\n\n" +
err.response.data.resolution,
buttonsArray,
"Click on buttons for other menus and examples"
)
.then(() => {
console.log(err);
})
.catch((erro) => {
console.error("Error when sending error: ", erro);
});
});
break;
/////////////////////////////TALK WITH AI/////////////////////////////////
case ".talk":
RecievedMsgPermission = true;
query = data.substring(queryCutter.length);
openai.APIkey(process.env.OPENAI_API_KEY);
(async () => {
const data = await openai.GetResponse(query);
msgString =
"You are talking with an AI\nIt said:\n-----------------------\n" +
data.choices[0].text;
sendReply(
message.chatId,
msgString,
message.id.toString(),
"Error when sending AI response: "
);
})();
break;
//////////////////////////TRANSLATE AND CORRECT GRAMMAR/////////////////////////////////
case ".gram":
case ".grammar":
case ".tran":
case ".translate":
case ".ayaz":
RecievedMsgPermission = true;
query = data.substring(queryCutter.length);
openai.APIkey(process.env.OPENAI_API_KEY);
(async () => {
const data = await openai.GetError(query);
composeMsg = [
botQuery[0] === ".tran" || botQuery[0] === ".translate"
? "Translation:"
: "Grammar correction:",
"\n--------------------\n",
data.choices[0].text,
" 😌",
];
composeMsg.forEach((txt) => {
msgString += txt;
});
sendReply(
message.chatId,
msgString,
message.id.toString(),
"Error when correcting grammer: "
);
})();
break;
/////////////////////////////////WIKIPEDIA SEARCH/////////////////////////////////
case ".wiki":
RecievedMsgPermission = true;
params = {
origin: "*",
format: "json",
action: "query",
prop: "extracts",
exintro: true,
explaintext: true,
generator: "search",
gsrlimit: 50,
gsrsearch: query,
};
axios
.get(wikiEndpoint, { params })
.then((response) => {
if (response.data.query) {
// If the page is found then query exists
const wikis = Object.values(response.data.query.pages);
// Set the fields to be sent in message
composeMsg = ["Checkout the menu for the page details👇"]; // composeMsg will be used as description of the button options
list = [
{
title: "Search Results👌",
rows: [],
},
];
wikis.forEach((wiki) => {
list[0].rows.push({
title: `WikiPage ${wiki.pageid}`,
description: wiki.title,
});
});
composeMsg.forEach((txt) => {
msgString += txt;
});
sendListMenu(
message.chatId,
`Searched: '${query}'`,
"subTitle",
msgString,
"Results",
list
);
} else {
sendReply(
message.chatId,
"Not found",
message.id.toString(),
"Error when sending Not found: "
);
}
})
.catch((error) => {
console.log(error);
});
break;
//////////////////////////////////WIKIPEDIA PAGE//////////////////////////////////
case ".wp":
case "wikipage":
RecievedMsgPermission = true;
params = {
origin: "*",
format: "json",
action: "query",
prop: "pageimages|extracts",
pithumbsize: 400,
pageids: query,
exintro: true,
explaintext: true,
};
axios
.get(wikiEndpoint, { params })
.then((response) => {
if (response.data.query) {
// If the page is found then query exists
const wiki = Object.values(response.data.query.pages);
// Set the fields to be sent in message
composeMsg = [
"*Image File name* :\n",
wiki[0].pageimage ? wiki[0].pageimage : "_No image found_ ☹",
"\n*Page ID* : ",
wiki[0].pageid,
"\n*Title* : ",
wiki[0].title,
"\n*Info* : ",
wiki[0].extract,
];
composeMsg.forEach((txt) => {
msgString += txt;
});
// Send the response to the sender
if (wiki[0].thumbnail) {
sendImage(
message.chatId,
wiki[0].thumbnail.source,
msgString,
"Error when sending page details: "
);
} else {
sendText(
message.chatId,
msgString,
"Error when sending page details: "
);
}
} else {
sendText(
message.chatId,
`Searched query: ${query}\n_Page Not Found_\nCheck the syntax and page id\nDon't get confused with similar commands\nCheck them by sending *InfoHelp*`,
"Error when sending page not found"
);
}
})
.catch((error) => {
console.log(error);
});
break;
///////////////////////////////////// POLL //////////////////////////////
case ".poll":
RecievedMsgPermission = true;
// Check permission
let pollPerm = false;
pollGrps.forEach((grp) => {
if (message.isGroupMsg && message.chat.name.search(grp) !== -1) {
pollPerm = true;
}
});
if (!pollPerm) {
message.isGroupMsg
? (msgString =
"Maybe the members won't like the spam\n\nAsk admins for activating this command in this group")
: (msgString = "This command is not supported in dms😁");
sendText(message.chatId, msgString, "Error when sending warning: ");
break;
}
// If there is an active poll going on
if (message.chatId !== pollerGrp && pollActive && !message.fromMe) {
msgString =
"There is already a poll going on in another group.\nWait for it to end😅";
sendText(message.chatId, msgString, "Error when sending warning: ");
break;
}
// Someone entered wrong syntax
if (!queryPart[2] && !pollActive) {
msgString =
"Enter the command properly🤦♂️\n\nOr maybe the poll has ended😅";
client
.sendText(message.chatId, msgString)
.then(() => {
console.log(
"Sent message: " + msgString + "\n------------------\n"
);
})
.catch((erro) => {
console.error("Error while ending the poll: ", erro);
});
break;
}
// If someone requested to end the poll
if (
query === "end" &&
(pollerId === message.sender.id || message.fromMe)
) {
composeMsg = [
"```Closed the poll on request of``` *",
message.sender.displayName,
"*\n----------------------------------\n*",
pollMsg,
"*\nResult:",
"\n1. ",
op1msg,
" (",
op1percent,
"%)",
"\n2. ",
op2msg,
" (",
op2percent,
"%)",
"\nTotal votes: ",
totalVotes,
];
composeMsg.forEach((txt) => {
msgString += txt;
});
(op1count = 0), (op2count = 0), (totalVotes = 0);
(pollMsg = ""), (op1msg = ""), (op2msg = "");
(op1percent = 0), (op2percent = 0);
pollActive = false;
pollVoters = [];
client
.sendText(message.chatId, msgString)
.then(() => {
console.log(
"Sent message: " + msgString + "\n------------------\n"
);
})
.catch((erro) => {
console.error("Error while ending the poll: ", erro);
});
break;
} else if (query === "end" && pollerId !== message.sender.id) {
msgString = `Only the creater of the poll (${pollerName}) can end it`;
sendText(message.chatId, msgString, "Error while ending the poll: ");
break;
}
// Voting logic
if (queryPart[0] === "op1") {
if (!pollVoters.includes(message.sender.id)) {
op1count++;
totalVotes++;
pollVoters.push(message.sender.id);
} else {
msgString = `${
message.sender.verifiedName
? message.sender.verifiedName
: message.sender.displayName
}, You have voted already!!`;
sendText(message.chatId, msgString, "Error while sending warning");
break;
}
} else if (queryPart[0] === "op2") {
if (!pollVoters.includes(message.sender.id)) {
op2count++;
totalVotes++;
pollVoters.push(message.sender.id);
} else {
msgString = `${
message.sender.verifiedName
? message.sender.verifiedName
: message.sender.displayName
}, You have voted already!!`;
sendText(message.chatId, msgString, "Error while sending warning");
break;
}
} else if (totalVotes === 0) {
pollMsg = queryPart[0];
op1msg = queryPart[1];
op2msg = queryPart[2];
op1percent = 0;
op2percent = 0;
pollerGrp = message.chatId;
pollerId = message.sender.id;
(pollerName = message.sender.verifiedName
? message.sender.verifiedName
: message.sender.notifyName),
(pollActive = true);
}
if (totalVotes !== 0) {
op1percent = (op1count / totalVotes) * 100;
op2percent = (op2count / totalVotes) * 100;
op1percent = op1percent.toFixed(2);
op2percent = op2percent.toFixed(2);
}
// Sending response
composeMsg = [
"```Started a poll on the request of``` *",
pollerName,
"*\n----------------------------------\n*",
pollMsg,
"*\nOptions:",
"\n1. ",
op1msg,
" (",
op1percent,
"%)",
"\n2. ",
op2msg,
" (",
op2percent,
"%)",
"\nTotal votes: ",
totalVotes,
];
composeMsg.forEach((txt) => {
msgString += txt;
});
buttonsArray = [
{
buttonId: "opt1",
buttonText: { displayText: ".poll op1-" + op1msg },
type: 1,
},
{
buttonId: "opt2",
buttonText: { displayText: ".poll op2-" + op2msg },
type: 1,
},
{
buttonId: "reset",
buttonText: { displayText: ".poll end" },
type: 1,
},
];
sendButtons(
client,
message.chatId,
msgString,
"You can click on the buttons for voting.\nIf buttons are not available- Send '.poll op1' or '.poll op2' to vote or '.poll end' to end the poll.",
buttonsArray,
"Error when sending poll response: "
);
break;
///////////////////////////////////ANIME DETAIL///////////////////////////////////
case ".ad":
case "animedetail":
RecievedMsgPermission = true;
animeSearch(client, message.chatId, query);
break;
///////////////////////////////////MANGA DETAIL///////////////////////////////////
case ".ms":
case "mangasearch":
RecievedMsgPermission = true;
mangaSearch(client, message.chatId, query);
break;
////////////////////////////////////ANIME DETAIL BY ID/////////////////////////////////////
case ".aid":
case "animedetailbyid":
RecievedMsgPermission = true;
animeDetail(client, message.chatId, query);
break;
////////////////////////////////////MANGA DETAIL BY ID/////////////////////////////////////
case "mangadetail":
RecievedMsgPermission = true;
mangaDetailsById(client, message.chatId, query);
break;
/////////////////////////ANIME CHARACTER DETAIL- BY SEARCH////////////////////////
case ".cd":
case "chardetail":
RecievedMsgPermission = true;
searchCharacterDetail(client, message.chatId, query);
break;
////////////////////////////////////MOVIE DETAIL//////////////////////////////////
case ".md":
case "moviedetail":
RecievedMsgPermission = true;
buttonsArray = [
{
buttonId: "md",
buttonText: { displayText: "MovieDetail Inception" },
type: 1,
},
{
buttonId: "ehelp",
buttonText: { displayText: "EntHelp" },
type: 1,
},
{ buttonId: "help", buttonText: { displayText: ".help" }, type: 1 },
];
axios
.get(
"https://www.omdbapi.com/?apikey=" +
process.env.OMDB_API_KEY +
"&t=" +
query
)
.then((response) => {
// Set the fields of the message
composeMsg = [
"*Title* : ",
response.data.Title,
"\n*Type* : ",
response.data.Type,
"\n*Year* : ",
response.data.Year,
"\n*Rated* : ",
response.data.Rated,
"\n*Released* : ",
response.data.Released,
"\n*Run-time* : ",
response.data.Runtime,
"\n*Genre* : ",
response.data.Genre,
"\n*Director* : ",
response.data.Director,
"\n*Writer* : ",
response.data.Writer,
"\n*Actors* : ",
response.data.Actors,
"\n*Language* : ",
response.data.Language,
"\n*Country* : ",
response.data.Country,
"\n*Awards* : ",
response.data.Awards,
"\n*IMDB rating* : ",
response.data.imdbRating,
"\n*Plot* : ",
response.data.Plot,
];
// Convert the array into text string
composeMsg.forEach((txt) => {
msgString += txt;
});
// Send the response to the sender
if (response.data.Response === "True") {
// If the movie was found then send the details and poster
if (response.data.Poster === "N/A") {
// If there is no poster then send only the details
client
.sendButtons(
message.chatId,
msgString,
buttonsArray,
"Chose the buttons for examples and menu"
)
.then(() => {
console.log(
"Sent message: " + msgString + "\n-------------------"
);
})
.catch((erro) => {
console.error("Error when sending: ", erro);
});
} else {
// If there is a poster then send the details with the poster
client
.sendImage(
message.chatId,
response.data.Poster,
null,
msgString
)
.then(() => {
console.log(
"Sent message: " + msgString + "\n-------------------"
);
})
.catch((erro) => {
console.error("Error when sending: ", erro);