File size: 94,793 Bytes
deef7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9279357
 
 
 
 
 
 
 
 
 
 
 
 
 
deef7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9279357
 
 
 
deef7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9279357
 
 
 
deef7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9279357
 
 
 
deef7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
// Import necessary modules
const express = require('express');
const { sinhalaSub } = require("mrnima-moviedl");

const FormData = require('form-data');

const { catbox } = require('./catbox'); // Import the Catbox uploader


const { exec } = require("child_process");


const yts = require('yt-search'); // 
// Initialize Express app for HTTP server
const app = express();
const PORT = process.env.PORT || 3000;

// Basic HTML response for health check
app.get('/', (req, res) => {
  res.send(`
    <html>
      <head>
        <title>Bot Status</title>
      </head>
      <body style="text-align: center; margin-top: 50px; font-family: Arial, sans-serif;">
        <h1 style="color: green;">โœ… Connected to Telegram</h1>
        <p>Your bot is up and running!</p>
      </body>
    </html>
  `);
});

// Start the HTTP server
app.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${PORT}`);
});


//
const TelegramBot = 
require('node-telegram-bot-api');
const axios = require('axios');
const fs = require('fs');
const apiKey = '7398508893:AAFqoZK_n0FNZ5I9_5L4BpyDSh3YvatZ3B8'; 
// Replace 'YOUR_TELEGRAM_BOT_TOKEN' with your bot token
const bot = new TelegramBot('7398508893:AAFE6xOytstrMZ0PpRa3ieH6SLBy9TR9vq4', { polling: true });

// Set up a list for tracking muted users
const mutedUsers = new Set();

// Anti-link feature variable
let antiLinkActive = false;

// Check if user is admin
const isAdmin = async (chatId, userId) => {
    try {
        const member = await bot.getChatMember(chatId, userId);
        return member.status === 'administrator' || member.status === 'creator';
    } catch (error) {
        return false;
    }
};





// /tiktok command
bot.onText(/\/(tiktok|tt|ttmedia)(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const text = match[2]; // Extract the TikTok link from the command

    if (!text) {
        // If no TikTok link is provided, send a usage guide
        return bot.sendMessage(chatId, "โŒ Please provide a TikTok link.\nExample: `/tiktok https://www.tiktok.com/@username/video/1234567890`");
    }

    bot.sendMessage(chatId, "๐Ÿ”„ Fetching your TikTok media... Please wait.");

    try {
        // Fetch TikTok media using the external API
        const response = await axios.get(`https://api.paxsenix.biz.id/dl/tiktok?url=${encodeURIComponent(text)}`);
        const data = response.data;

        if (data && data.downloadsUrl) {
            // Send the video
            await bot.sendVideo(chatId, data.downloadsUrl.video);

            // Send the audio
            await bot.sendAudio(chatId, data.downloadsUrl.music);
        } else {
            bot.sendMessage(chatId, "โŒ Unable to fetch TikTok media. Please check the link and try again.");
        }
    } catch (error) {
        console.error("Error during TikTok download command:");
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request. Please try again later.");
    }
});


bot.onText(/\/couplepp/, async (msg) => {
    const chatId = msg.chat.id;

    try {
        // Inform the user that the bot is fetching the pictures
        await bot.sendMessage(chatId, "๐Ÿ” *Fetching couple profile pictures...*", { parse_mode: "Markdown" });

        // Fetch the data from the API
        const apiUrl = "https://api.maskser.me/api/randomgambar/couplepp";
        const response = await axios.get(apiUrl);

        if (response.data.status) {
            const { male, female } = response.data.result;

            // Send the male picture
            await bot.sendPhoto(chatId, male, {
                caption: "๐Ÿ‘ฆ *Male Picture*",
                parse_mode: "Markdown"
            });

            // Send the female picture
            await bot.sendPhoto(chatId, female, {
                caption: "๐Ÿ‘ง *Female Picture*",
                parse_mode: "Markdown"
            });
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch couple pictures. Please try again later.");
        }
    } catch (error) {
        console.error("Error fetching couple pictures:");
        bot.sendMessage(chatId, "โŒ An error occurred while fetching couple pictures. Please try again.");
    }
});


// Handle /gpt command
bot.onText(/\/gpt (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const query = match[1]?.trim();

  if (!query) {
    return bot.sendMessage(chatId, "โŒ Please provide a prompt after the /gpt command.\nExample: `/gpt What is AI?`", {
      parse_mode: "Markdown",
    });
  }

  try {
    // Show typing indicator
    await bot.sendChatAction(chatId, "typing");

    // Make a request to the new GPT API
    const apiUrl = `https://api.paxsenix.biz.id/ai/gpt4?text=${encodeURIComponent(query)}`;
    const { data } = await axios.get(apiUrl);

    

    // Check the API response
    if (!data.ok || !data.message) {
      return bot.sendMessage(chatId, `โŒ GPT API Error: Unable to fetch a response. Please try again later.`);
    }

    // Send the GPT response to the user
    await bot.sendMessage(chatId, `${data.message}`, { parse_mode: "Markdown" });
  } catch (error) {
    console.error("Error fetching GPT response:");
    await bot.sendMessage(chatId, "โŒ An error occurred while fetching the GPT response. Please try again later.");
  }
});


bot.onText(/\/url/, async (msg) => {
    const chatId = msg.chat.id;

    // Check if the message is a reply to an image or video
    const fileId = msg.reply_to_message?.photo?.[msg.reply_to_message.photo.length - 1]?.file_id ||
                   msg.reply_to_message?.video?.file_id;

    if (!fileId) {
        return bot.sendMessage(chatId, "โ— *Reply to an image or video with /url to get a public link.*", { parse_mode: "Markdown" });
    }

    try {
        // React to indicate processing
        const processingMsg = await bot.sendMessage(chatId, "โณ *Uploading your file...*", { parse_mode: "Markdown" });

        // Download the file locally
        const filePath = await bot.downloadFile(fileId, "./downloads");

        // Upload the file to Catbox
        const uploadResponse = await catbox(filePath);

        // Check and send the result
        if (uploadResponse.url) {
            await bot.sendMessage(chatId, `โœ… *Upload Successful!*\n\n๐Ÿ”— *URL:*\n${uploadResponse.url}\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`, { parse_mode: "Markdown" });
        } else {
            await bot.sendMessage(chatId, "โŒ *Upload Failed. Please try again.*", { parse_mode: "Markdown" });
        }

        // Clean up the downloaded file
        fs.unlinkSync(filePath);
        await bot.deleteMessage(chatId, processingMsg.message_id);
    } catch (error) {
        console.error("Error in /url command:");
        bot.sendMessage(chatId, `โŒ *An error occurred`, { parse_mode: "Markdown" });
    }
});



bot.onText(/\/remini/, async (msg) => {
    const chatId = msg.chat.id;

    // Check if the message is a reply to an image
    const fileId = msg.reply_to_message?.photo?.[msg.reply_to_message.photo.length - 1]?.file_id;

    if (!fileId) {
        return bot.sendMessage(chatId, "โ— *Reply to an image with /remini to enhance it.*", { parse_mode: "Markdown" });
    }

    try {
        // React to indicate processing
        const processingMsg = await bot.sendMessage(chatId, "โณ *Enhancing your image...*", { parse_mode: "Markdown" });

        // Download the image locally
        const filePath = await bot.downloadFile(fileId, "./downloads");

        // Upload the image to Catbox
        const uploadResponse = await catbox(filePath);

        if (!uploadResponse.url) {
            fs.unlinkSync(filePath); // Clean up the downloaded file
            return bot.sendMessage(chatId, "โŒ *Upload Failed. Please try again.*", { parse_mode: "Markdown" });
        }

        const imageUrl = uploadResponse.url; // Get the uploaded image URL

        // Call the Remini API with the uploaded image URL
        const enhancedImageUrl = `https://bk9.fun/tools/enhance?url=${encodeURIComponent(imageUrl)}`;

        // Send the enhanced image back to the user
        await bot.sendPhoto(chatId, enhancedImageUrl, {
            caption: `โœ… *Successfully Enhanced Your Image!*\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
            parse_mode: "Markdown",
        });

        // Clean up the downloaded file
        fs.unlinkSync(filePath);
        await bot.deleteMessage(chatId, processingMsg.message_id);
    } catch (error) {
        console.error("Error in /remini command:");
        bot.sendMessage(chatId, `โŒ *An error occurred`, { parse_mode: "Markdown" });
    }
});





bot.onText(/\/video (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const query = match[1]?.trim();

    if (!query) {
        return bot.sendMessage(chatId, "โ— *Usage*: `/video <search term>`", { parse_mode: 'Markdown' });
    }

    try {
        const searchMsg = await bot.sendMessage(chatId, "๐Ÿ” *Searching for your video...*", { parse_mode: "Markdown" });

        // Step 1: Search for the video
        const search = await yts(query);
        const video = search.all[0]; // Take the first result
        if (!video) {
            return bot.sendMessage(chatId, "โŒ Video not found!");
        }

        // Step 2: Fetch video download link from the API
        const apiUrl = `https://apis.davidcyriltech.my.id/download/ytmp4`;
        const response = await axios.get(apiUrl, { params: { url: video.url } });
        const { success, result } = response.data;

        if (success && result) {
            const { title, download_url } = result;
            const filePath = `./temp/${title.replace(/[^\w\s]/gi, '')}.mp4`;

            // Step 3: Download video locally
            const writer = fs.createWriteStream(filePath);
            const videoStream = await axios({
                url: download_url,
                method: 'GET',
                responseType: 'stream'
            });

            videoStream.data.pipe(writer);

            await new Promise((resolve, reject) => {
                writer.on('finish', resolve);
                writer.on('error', reject);
            });

await bot.sendVideo(chatId, download_url, {
    caption: `๐ŸŽฌ *Here is your video:*\n๐ŸŽฅ *${title}*\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
    parse_mode: "Markdown"
});
            // Step 5: Delete the file after sending
            fs.unlinkSync(filePath);
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch the video. Please try again.");
        }

        await bot.deleteMessage(chatId, searchMsg.message_id);
    } catch (err) {
        console.error("Error in /video command:", err);
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request.");
    }
});

// /play command
bot.onText(/\/play(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const inputText = match[1];

    if (!inputText) {
        return bot.sendMessage(chatId, "โŒ Please provide the song name.\nExample: `/play Faded by Alan Walker`");
    }

    try {
        // Notify user that the bot is searching
        await bot.sendMessage(chatId, "๐Ÿ” Searching for your song...");

        // Perform a YouTube search
        const search = await yts(inputText);
        const video = search.all[0];

        if (!video) {
            return bot.sendMessage(chatId, "โŒ Sorry, I couldn't find the song. Try another keyword.");
        }

        // Fetch the song download link using the new API
        const apiUrl = `https://apis.davidcyriltech.my.id/download/ytmp3?url=${encodeURIComponent(video.url)}`;
        const response = await axios.get(apiUrl);
        const { success, result } = response.data;

        if (success && result) {
            const { title, thumbnail, download_url } = result;
            const filename = `./${video.title.replace(/[^a-zA-Z0-9]/g, "_")}.mp3`;

            // Send song details with thumbnail
            await bot.sendPhoto(chatId, thumbnail, {
                caption: `๐ŸŽถ *Music Player* ๐ŸŽถ\n\n` +
                    `๐ŸŽต *Title:* ${video.title}\n` +
                    `๐Ÿ”— [Watch on YouTube](${video.url})\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
                parse_mode: "Markdown",
            });

            // Download the audio file
            const writer = fs.createWriteStream(filename);
            const { data } = await axios({
                url: download_url,
                method: "GET",
                responseType: "stream",
            });

            data.pipe(writer);

            await new Promise((resolve, reject) => {
                writer.on("finish", resolve);
                writer.on("error", reject);
            });

            // Send the locally saved audio file
            await bot.sendAudio(chatId, filename, {
                caption: `๐ŸŽง *Here's your song:*\n๐ŸŽต *Title:* ${video.title}\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
                parse_mode: "Markdown",
            });

            // Delete the file after sending
            fs.unlink(filename, (err) => {
                if (err) console.error("Error deleting file:", err);
            });
        } else {
            bot.sendMessage(chatId, "โŒ Unable to download the song. Please try again later.");
        }
    } catch (error) {
        console.error("Error during /play command:", error);
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request. Please try again later.");
    }
});
bot.onText(/\/ytmp3 (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const youtubeLink = match[1]?.trim();

    if (!youtubeLink) {
        return bot.sendMessage(chatId, "โ— *Usage*: `/ytmp3 <YouTube link>`\nExample: `/ytmp3 https://youtube.com/watch?v=iI34LYmJ1Fs`", { parse_mode: 'Markdown' });
    }

    try {
        const loadingMsg = await bot.sendMessage(chatId, "๐Ÿ” *Processing your audio...*", { parse_mode: "Markdown" });

        // Fetch audio download link
        const apiUrl = `https://apis.davidcyriltech.my.id/download/ytmp3`;
        const response = await axios.get(apiUrl, { params: { url: youtubeLink } });
        const { success, result } = response.data;

        if (success && result) {
            const { title, download_url } = result;
            const filename = `./temp/${Date.now()}.mp3`;

            // Download the audio locally
            const audioResponse = await axios({
                url: download_url,
                method: "GET",
                responseType: "stream",
            });

            const writer = fs.createWriteStream(filename);
            audioResponse.data.pipe(writer);

            writer.on("finish", async () => {
                await bot.sendAudio(chatId, download_url, {
    caption: `๐ŸŽง *${title}*\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
    parse_mode: "Markdown"
});

                fs.unlinkSync(filename); // Delete after sending
            });
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch the audio. Please check the link and try again.");
        }

        await bot.deleteMessage(chatId, loadingMsg.message_id);
    } catch (err) {
        console.error("Error in /ytmp3 command:", err);
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request.");
    }
});

let chatbotActive = {}; // Stores active chatbot users
let conversationIds = {}; // Stores conversation ID for each user

bot.onText(/\/gitclone (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const repoUrl = match[1]?.trim();

    if (!repoUrl) {
        return bot.sendMessage(chatId, "โ— *Usage*: `/gitclone <GitHub Repo URL>`\nExample: `/gitclone https://github.com/DeeCeeXxx2/Queen_Anita-V3`", { parse_mode: 'Markdown' });
    }

    if (!repoUrl.includes("github.com")) {
        return bot.sendMessage(chatId, "โŒ *Invalid GitHub link! Please provide a valid URL.*");
    }

    try {
        let regex = /(?:https|git)(?::\/\/|@)github\.com[\/:]([^\/:]+)\/(.+)/i;
        let [, user, repo] = repoUrl.match(regex) || [];
        repo = repo.replace(/.git$/, "");
        let zipUrl = `https://api.github.com/repos/${user}/${repo}/zipball`;

        // Fetch file name from GitHub API
        let response = await fetch(zipUrl, { method: "HEAD" });
        let filename = response.headers.get("content-disposition").match(/attachment; filename=(.*)/)[1];

        await bot.sendDocument(chatId, zipUrl, {
            caption: `๐Ÿ“ฆ *Repository:* ${repo}\n๐Ÿ”— *Download Link:* [Click Here](${zipUrl})\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
            parse_mode: "Markdown",
            fileName: filename + ".zip",
            mimetype: "application/zip"
        });
    } catch (err) {
        console.error("Error in /gitclone command:", err);
        bot.sendMessage(chatId, "โŒ *An error occurred while fetching the repository. Please try again later.*");
    }
});

bot.onText(/\/chatbot$/, async (msg) => {
    const chatId = msg.chat.id;

    await bot.sendMessage(
        chatId,
        "โ— *Invalid Command!*\n\nUse:\nโœ… `/chatbot on` - To activate AI chat\nโŒ `/chatbot off` - To deactivate AI chat",
        { parse_mode: "Markdown" }
    );
});






bot.onText(/\/mediafire (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const mediafireUrl = match[1]?.trim();

    if (!mediafireUrl) {
        return bot.sendMessage(chatId, "โ— *Usage*: `/mediafire <MediaFire Link>`\nExample: `/mediafire https://www.mediafire.com/file/n6tgcrktbnov1oy/Queen_Anita-V4.zip/file`", { parse_mode: 'Markdown' });
    }

    try {
        const loadingMsg = await bot.sendMessage(chatId, "๐Ÿ“ฅ *Fetching file details...*", { parse_mode: "Markdown" });

        const apiUrl = `https://apis.davidcyriltech.my.id/mediafire?url=${encodeURIComponent(mediafireUrl)}`;
        const response = await axios.get(apiUrl);
        const { success, result } = response.data;

        if (success && result) {
            const { fileName, downloadLink } = result;
            const filePath = path.join(__dirname, "temp", fileName.replace(/[^\w\s]/gi, "_"));

            // Step 1: Download the file locally
            const writer = fs.createWriteStream(filePath);
            const fileResponse = await axios({
                url: downloadLink,
                method: "GET",
                responseType: "stream",
            });

            fileResponse.data.pipe(writer);

            await new Promise((resolve, reject) => {
                writer.on("finish", resolve);
                writer.on("error", reject);
            });

            // Step 2: Send the file
            await bot.sendDocument(chatId, filePath, {
                caption: `๐Ÿ“ฆ *File Name:* ${fileName}\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
                parse_mode: "Markdown",
            });

            // Step 3: Delete the file after sending
            fs.unlinkSync(filePath);
        } else {
            bot.sendMessage(chatId, "โŒ *Failed to fetch file details! Please check the MediaFire URL and try again.*");
        }

        await bot.deleteMessage(chatId, loadingMsg.message_id);
    } catch (error) {
        console.error("Error in /mediafire command:", error);
        bot.sendMessage(chatId, "โŒ *An error occurred while processing your request. Please try again later.*");
    }
});

bot.onText(/\/ss (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const websiteUrl = match[1]?.trim();

    if (!websiteUrl) {
        return bot.sendMessage(chatId, "โ— *Usage*: `/ssweb <Website URL>`\nExample: `/ssweb https://example.com`", { parse_mode: 'Markdown' });
    }

    try {
        const loadingMsg = await bot.sendMessage(chatId, "๐Ÿ“ธ *Capturing screenshot...*", { parse_mode: "Markdown" });

        const apiUrl = `https://apis.davidcyriltech.my.id/ssweb?url=${encodeURIComponent(websiteUrl)}`;
        await bot.sendPhoto(chatId, apiUrl, {
            caption: `๐Ÿ–ผ๏ธ *Screenshot of:* ${websiteUrl}`,
            parse_mode: "Markdown"
        });

        await bot.deleteMessage(chatId, loadingMsg.message_id);
    } catch (error) {
        console.error("Error in /ssweb command:", error);
        bot.sendMessage(chatId, "โŒ *Failed to capture the screenshot. Please try again later.*");
    }
});

bot.onText(/\/ytmp4 (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const youtubeLink = match[1]?.trim();

    if (!youtubeLink) {
        return bot.sendMessage(chatId, "โ— *Usage*: `/ytmp4 <YouTube link>`\nExample: `/ytmp4 https://youtube.com/watch?v=iI34LYmJ1Fs`", { parse_mode: 'Markdown' });
    }

    try {
        const loadingMsg = await bot.sendMessage(chatId, "๐Ÿ” *Processing your video...*", { parse_mode: "Markdown" });

        // Fetch video download link
        const apiUrl = `https://apis.davidcyriltech.my.id/download/ytmp4`;
        const response = await axios.get(apiUrl, { params: { url: youtubeLink } });
        const { success, result } = response.data;

        if (success && result) {
            const { title, download_url } = result;
            const filename = `./temp/${Date.now()}.mp4`;

            // Download the video locally
            const videoResponse = await axios({
                url: download_url,
                method: "GET",
                responseType: "stream",
            });

            const writer = fs.createWriteStream(filename);
            videoResponse.data.pipe(writer);

            writer.on("finish", async () => {
                await bot.sendVideo(chatId, download_url, {
    caption: `๐ŸŽฌ *${title}*\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
    parse_mode: "Markdown"
});

                fs.unlinkSync(filename); // Delete after sending
            });
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch the video. Please check the link and try again.");
        }

        await bot.deleteMessage(chatId, loadingMsg.message_id);
    } catch (err) {
        console.error("Error in /ytmp4 command:", err);
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request.");
    }
});


    const path = require("path");
    

    
    // Utility: Validate and fetch direct PixelDrain link
    async function getDirectPixelDrainLink(fileUrl) {
      try {
        const response = await axios.get(fileUrl, { maxRedirects: 0, validateStatus: (status) => status < 400 });
        return response.headers.location || fileUrl; // Return direct link
      } catch (error) {
        console.error("Error validating PixelDrain link:");
        throw new Error("Invalid or inaccessible PixelDrain link.");
      }
    }
    
    // Utility: Download file from PixelDrain and save it locally
    async function downloadFile(fileUrl, downloadPath) {
      try {
        const response = await axios({
          url: fileUrl,
          method: "GET",
          responseType: "stream",
        });
    
        const writer = fs.createWriteStream(downloadPath);
        response.data.pipe(writer);
    
        return new Promise((resolve, reject) => {
          writer.on("finish", () => {
            console.log(`File downloaded to: ${downloadPath}`);
            resolve();
          });
          writer.on("error", (err) => {
            console.error("Download error:");
        reject(err);
      });
    });
  } catch (error) {
    console.error("Error downloading file:", );
    throw new Error("Failed to download file.");
  }
}

// Utility: Stream file directly to Telegram
async function streamFileToTelegram(chatId, filePath, caption) {
  try {
    await bot.sendDocument(chatId, filePath, { caption: caption });
    console.log("File streamed successfully to Telegram.");
  } catch (error) {
    console.error("Error streaming file:");
    throw new Error("Failed to stream file to Telegram.");
  }
}

bot.onText(/\/bible (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const chapterInput = match[1]?.trim();

    if (!chapterInput) {
        return bot.sendMessage(
            chatId,
            "โ— *Usage*: `/bible <chapter and verse>`\nExample: `/bible john 3:16`",
            { parse_mode: "Markdown" }
        );
    }

    const BASE_URL = "https://bible-api.com";

    try {
        // Fetch the chapter data from the Bible API
        const response = await axios.get(`${BASE_URL}/${encodeURIComponent(chapterInput)}`);
        if (!response.data) {
            throw new Error("Failed to fetch the Bible chapter. Please check the input and try again.");
        }

        const chapterData = response.data;

        // Format the Bible chapter message
        const bibleChapter = `
๐Ÿ“– *The Holy Bible*\n
๐Ÿ“œ *Chapter:* ${chapterData.reference}\n
๐Ÿ“š *Translation:* ${chapterData.translation_name}\n
๐Ÿ“– *Number of Verses:* ${chapterData.verses.length}\n
๐Ÿ”ฎ *Chapter Content:*\n${chapterData.text}
        `;

        // Send the formatted message with an image
        await bot.sendPhoto(chatId, "./atomic.jpg", {
            caption: bibleChapter,
            parse_mode: "Markdown",
        });
    } catch (error) {
        console.error("Error in /bible command:");
        bot.sendMessage(chatId, `โŒ Error: `);
    }
});


bot.onText(/\/text2image (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const prompt = match[1]; // Extract the prompt from the command

    // Check if the user provided a prompt
    if (!prompt) {
        return bot.sendMessage(chatId, "โŒ *Please provide a prompt!* \n\nUsage: `/magicstudio <prompt>`", { parse_mode: "Markdown" });
    }

    try {
        // Inform the user the process has started
        await bot.sendMessage(chatId, "โœจ *Generating image... Please wait!*", { parse_mode: "Markdown" });

        // API URL to generate the image
        const apiUrl = `https://bk9.fun/ai/magicstudio?prompt=${encodeURIComponent(prompt)}`;

        // Fetch the generated image from the API
        const response = await axios.get(apiUrl, { responseType: "stream" });

        // Send the image back to the user
        await bot.sendPhoto(chatId, response.data, {
            caption: `๐Ÿ–ผ๏ธ *Here's your generated image for:* \`${prompt}\`\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
            parse_mode: "Markdown"
        });

    } catch (error) {
        console.error("Error generating image:");
        bot.sendMessage(chatId, "โŒ *Failed to generate the image. Please try again later!*", { parse_mode: "Markdown" });
    }
});
// /apk command
bot.onText(/\/apk (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const packageName = match[1]?.trim();

  if (!packageName) {
    return bot.sendMessage(chatId, "โ— *Usage*: `/apk <package_name>`\nExample: `/apk com.whatsapp`", { parse_mode: "Markdown" });
  }

  try {
    // Step 1: Fetch APK details from the API
    const apiUrl = `https://bk9.fun/download/apk?id=${encodeURIComponent(packageName)}`;
    const response = await axios.get(apiUrl);
    const { status, BK9 } = response.data;

    if (!status || !BK9) {
      return bot.sendMessage(chatId, "โŒ APK details not found. Please check the package name and try again.");
    }

    // Step 2: Prepare APK details message
    const apkDetails = `๐Ÿ“ฑ *APK Details*\n\n` +
      `*Name:* ${BK9.name}\n` +
      `*Last Updated:* ${BK9.lastup}\n` +
      `*Package:* \`${BK9.package}\`\n\n` +
      `\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`;

    const downloadLink = BK9.dllink;

    // Step 3: Create Inline Keyboard Button for download link
    const inlineKeyboard = [
      [
        {
          text: "๐Ÿ“ฅ Download APK",
          url: downloadLink,
        },
      ],
    ];

    const options = {
      reply_markup: {
        inline_keyboard: inlineKeyboard,
      },
      parse_mode: "Markdown",
    };

    // Step 4: Send APK details with the download button
    await bot.sendPhoto(chatId, BK9.icon, {
      caption: apkDetails,
      ...options,
    });
  } catch (error) {
    console.error("Error fetching APK details:");
    await bot.sendMessage(chatId, "โŒ An error occurred while fetching APK details. Please try again.");
  }
});


// /movie command
bot.onText(/\/movie (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const query = match[1]?.trim();

  if (!query) {
    return bot.sendMessage(chatId, "โŒ *Please provide a search query!*\nExample: `/movie Deadpool`", { parse_mode: "Markdown" });
  }

  try {
    // Step 1: Search SinhalaSub for movies
    const sinhala = await sinhalaSub();
    const results = await sinhala.search(query);
    const movies = results.result.slice(0, 10); // Limit results to 10

    if (!movies.length) {
      return bot.sendMessage(chatId, `โŒ No results found for: *${query}*`, { parse_mode: "Markdown" });
    }

    // Step 2: Create Inline Keyboard Buttons for movies
    const inlineKeyboard = movies.map((movie, index) => [
      {
        text: `${index + 1}. ${movie.title}`,
        callback_data: `movie_${index}`, // Unique identifier for each movie
      },
    ]);

    const options = {
      reply_markup: {
        inline_keyboard: inlineKeyboard,
      },
      parse_mode: "Markdown",
    };

    await bot.sendMessage(chatId, `๐Ÿ“ฝ๏ธ *Search Results for:* \`${query}\`\n\nSelect a movie from the list:`, options);

    // Step 3: Handle movie selection
    bot.on("callback_query", async (callbackQuery) => {
      const { data, message } = callbackQuery;

      // Check if the callback is for this movie selection
      if (data.startsWith("movie_")) {
        const selectedIndex = parseInt(data.split("_")[1], 10);
        const selectedMovie = movies[selectedIndex];
        const apiUrl = `https://api-site-2.vercel.app/api/sinhalasub/movie?url=${encodeURIComponent(selectedMovie.link)}`;

        try {
          // Step 4: Fetch download links
          const { data: movieData } = await axios.get(apiUrl);
          const movieDetails = movieData.result;
          const downloadLinks = movieDetails.dl_links || [];

          if (!downloadLinks.length) {
            return bot.sendMessage(chatId, "โŒ No PixelDrain links found for this movie.");
          }

          // Step 5: Create Inline Keyboard Buttons for direct download links
          const qualityKeyboard = downloadLinks.map((link) => {
            const pixelDrainId = link.link.split("/").pop(); // Extract the file ID
            const directDownloadLink = `https://pixeldrain.com/api/file/${pixelDrainId}?download`; // Use /download endpoint
            return [
              {
                text: `${link.quality} - ${link.size}`,
                url: directDownloadLink, // Direct download link
              },
            ];
          });

          const qualityOptions = {
            reply_markup: {
              inline_keyboard: qualityKeyboard,
            },
            parse_mode: "Markdown",
          };

          await bot.sendMessage(
            chatId,
            `๐ŸŽฅ *Available Qualities for:* \`${movieDetails.title}\`\n\nSelect a quality to download directly:\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
            qualityOptions
          );

          // Acknowledge the callback to avoid timeout errors
          bot.answerCallbackQuery(callbackQuery.id);
        } catch (error) {
          console.error("Error fetching movie details:");
          await bot.sendMessage(chatId, "โŒ Failed to fetch movie details. Please try again.");
        }
      }
    });
  } catch (error) {
    console.error("Error executing /movie command:");
    await bot.sendMessage(chatId, "โŒ An error occurred while processing your request.");
  }
});




bot.onText(/\/shazam/, async (msg) => {
    const chatId = msg.chat.id;

    // Ensure the command is a reply to an audio or video message
    const fileId = msg.reply_to_message?.audio?.file_id || msg.reply_to_message?.video?.file_id;
    if (!fileId) {
        return bot.sendMessage(chatId, "โŒ Please reply to an audio or video file with /shazam to identify it.");
    }

    try {
        // Notify the user that the bot is processing the file
        const processingMsg = await bot.sendMessage(chatId, "๐ŸŽต Identifying the audio... Please wait!");

        // Download the file locally
        const filePath = await bot.downloadFile(fileId, "./downloads");

        // Upload the file to Catbox
        const uploadResponse = await catbox(filePath);
        if (!uploadResponse.url) {
            throw new Error("Failed to upload the file for analysis.");
        }

        // Call Shazam API
        const shazamApiUrl = `https://api.paxsenix.biz.id/tools/shazam?url=${encodeURIComponent(uploadResponse.url)}`;
        const shazamResponse = await axios.get(shazamApiUrl);
        const shazamResult = shazamResponse.data;

        // Handle Shazam API response
        if (shazamResult?.ok && shazamResult?.track) {
            const { title, artist, url } = shazamResult.track;
            const resultMessage = `๐ŸŽถ *Audio Identified:*\n\n` +
                `๐ŸŽต *Title:* ${title}\n` +
                `๐ŸŽค *Artist:* ${artist}\n` +
                `[๐Ÿ”— Listen on Shazam](${url})\n\n` +
                `*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`;

            await bot.sendMessage(chatId, resultMessage, { parse_mode: "Markdown" });
        } else {
            bot.sendMessage(chatId, "โŒ Unable to identify the audio. Please try again with a different file.");
        }

        // Cleanup local file
        fs.unlinkSync(filePath);
        await bot.deleteMessage(chatId, processingMsg.message_id);
    } catch (error) {
        console.error("Error in /shazam command:");
        bot.sendMessage(chatId, "โš ๏ธ An error occurred while processing your request. Please try again later.");
    }
});


bot.onText(/\/(image|img)(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const query = match[2]; // Extract the search query from the command

    if (!query) {
        return bot.sendMessage(
            chatId,
            "โŒ Please provide a search query.\n\n*Usage:* `/image <query>`\n*Example:* `/image cats`",
            { parse_mode: "Markdown" }
        );
    }

    bot.sendMessage(chatId, "๐Ÿ” Searching for images... Please wait.");

    try {
        // Call the Bing Image Search API
        const apiResponse = await axios.get(`https://api.siputzx.my.id/api/s/bimg`, {
            params: { query: query }
        });

        if (apiResponse.status === 200 && apiResponse.data.status) {
            const images = apiResponse.data.data;

            if (!images || images.length === 0) {
                return bot.sendMessage(chatId, `โŒ No images found for "${query}". Please try another query.`);
            }

            // Limit to max 5 images
            const maxImages = Math.min(images.length, 5);
            for (let i = 0; i < maxImages; i++) {
                await bot.sendPhoto(chatId, images[i], {
                    caption: `๐Ÿ”Ž *Image Search Result:*\n\n๐Ÿ“„ *Query:* "${query}"\n๐Ÿ“ท *Image ${i + 1}/${maxImages}*\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
                    parse_mode: "Markdown"
                });
            }
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch images. Please try again later.");
        }
    } catch (error) {
        console.error("Error in /imagesearch command:");
        bot.sendMessage(
            chatId,
            `โš ๏ธ An error occurred:\n\n*Message:*`,
            { parse_mode: "Markdown" }
        );
    }
});

bot.onText(/\/(spotifysearch)(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const query = match[2]; // Extract the search query from the command

    if (!query) {
        return bot.sendMessage(
            chatId,
            "โŒ Please provide a search query.\n\n*Usage:* `/spotifysearch <query>`\n*Example:* `/spotifysearch Spectre`",
            { parse_mode: "Markdown" }
        );
    }

    bot.sendMessage(chatId, "๐Ÿ” Searching for tracks on Spotify... Please wait.");

    try {
        // Call the Spotify Search API
        const apiResponse = await axios.get(`https://api.giftedtech.my.id/api/search/spotifysearch`, {
            params: { apikey: "gifted-md", query: query }
        });

        if (apiResponse.status === 200 && apiResponse.data.success) {
            const tracks = apiResponse.data.results;

            if (!tracks || tracks.length === 0) {
                return bot.sendMessage(chatId, `โŒ No tracks found for "${query}". Please try another query.`);
            }

            // Limit to max 5 tracks
            const maxTracks = Math.min(tracks.length, 5);
            let message = `๐ŸŽง *Spotify Search Results:*\n\n`;
            tracks.slice(0, maxTracks).forEach((track, index) => {
                message += `๐ŸŽต *${index + 1}. ${track.title}*\n` +
                           `๐Ÿ‘ค *Artist:* ${track.artist}\n` +
                           `โฑ๏ธ *Duration:* ${track.duration}\n` +
                           `๐Ÿ”— [Listen on Spotify](${track.url})\n\n`;
            });

            bot.sendMessage(chatId, message, { parse_mode: "Markdown" });
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch tracks. Please try again later.");
        }
    } catch (error) {
        console.error("Error in /spotifysearch command:");
        bot.sendMessage(
            chatId,
            `โš ๏ธ An error occurred:\n\n*Message:*`,
            { parse_mode: "Markdown" }
        );
    }
});


bot.onText(/\/(spotify-download|spotdl)(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const spotifyUrl = match[2]; // Extract the Spotify track URL from the command

    if (!spotifyUrl) {
        return bot.sendMessage(
            chatId,
            "โŒ Please provide a Spotify track URL.\n\n*Usage:* `/spotify-download <Spotify URL>`\n*Example:* `/spotify-download https://open.spotify.com/track/2DGa7iaidT5s0qnINlwMjJ`",
            { parse_mode: "Markdown" }
        );
    }

    bot.sendMessage(chatId, "๐Ÿ”„ Fetching your Spotify track... Please wait.");

    try {
        // Call the Spotify Download API
        const apiResponse = await axios.get(`https://api.giftedtech.my.id/api/download/spotifydl`, {
            params: { apikey: "gifted-md", url: spotifyUrl }
        });

        if (apiResponse.status === 200 && apiResponse.data.success) {
            const track = apiResponse.data.result;

            const caption = `๐ŸŽต *Spotify Track Downloaded:*\n\n` +
                            `๐Ÿ”น *Title:* ${track.title}\n` +
                            `โฑ๏ธ *Duration:* ${track.duration}\n` +
                            `๐ŸŽง *Quality:* ${track.quality}`;

            // Send the audio file to the user
            await bot.sendAudio(chatId, track.download_url, {
                caption: caption,
                parse_mode: "Markdown",
                thumb: track.thumbnail, // Optional: Thumbnail as album art
            });
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch track details. Please check the Spotify URL and try again.");
        }
    } catch (error) {
        console.error("Error in /spotify-download command:");
        bot.sendMessage(
            chatId,
            `โš ๏ธ An error occurred:\n\n*Message:*`,
            { parse_mode: "Markdown" }
        );
    }
});


bot.onText(/\/(song)(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const query = match[2]; // Extract the search query from the command

    if (!query) {
        return bot.sendMessage(
            chatId,
            "โŒ Please provide a search query.\n\n*Usage:* `/song <song title>`\n*Example:* `/song faded`",
            { parse_mode: "Markdown" }
        );
    }

    bot.sendMessage(chatId, "๐Ÿ” Searching for songs on Spotify... Please wait.");

    try {
        // Call the Spotify Search API
        const searchResponse = await axios.get(`https://api.giftedtech.my.id/api/search/spotifysearch`, {
            params: { apikey: "gifted", query: query }
        });

        if (searchResponse.status === 200 && searchResponse.data.success && searchResponse.data.results.length > 0) {
            const results = searchResponse.data.results;

            // Create inline keyboard buttons for the search results
            const buttons = results.slice(0, 10).map((item) => [
                { text: `${item.title} - ${item.artist}`, callback_data: `song_${item.id}` }
            ]);

            bot.sendMessage(chatId, "๐ŸŽถ Select a song to download:", {
                reply_markup: {
                    inline_keyboard: buttons
                }
            });
        } else {
            bot.sendMessage(chatId, "โŒ No songs found. Please try a different query.");
        }
    } catch (error) {
        console.error("Error in /song command:");
        bot.sendMessage(chatId, `โš ๏ธ An error occurred:\n\n*Message:*`, { parse_mode: "Markdown" });
    }
});

// Handle button clicks for song selection
bot.on("callback_query", async (callbackQuery) => {
    const chatId = callbackQuery.message.chat.id;
    const data = callbackQuery.data;

    if (data.startsWith("song_")) {
        const trackId = data.split("_")[1];

        bot.sendMessage(chatId, "๐Ÿ”„ Downloading your song... Please wait.");

        try {
            // Call the Spotify Download API
            const downloadResponse = await axios.get(`https://api.giftedtech.my.id/api/download/spotifydl`, {
                params: { apikey: "gifted", url: `https://open.spotify.com/track/${trackId}` }
            });

            if (downloadResponse.status === 200 && downloadResponse.data.success) {
                const track = downloadResponse.data.result;

                // Send the audio file
                await bot.sendAudio(chatId, track.download_url, {
                    caption: `๐Ÿ”น *Title:* ${track.title}\n` +
                             `โฑ๏ธ *Duration:* ${track.duration}\n` +
                             `๐ŸŽง *Quality:* ${track.quality}\n\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
                    parse_mode: "Markdown",
                    thumb: track.thumbnail // Optional: Thumbnail as album art
                });
            } else {
                bot.sendMessage(chatId, "โŒ Failed to download the song. Please try again.");
            }
        } catch (error) {
            console.error("Error during song download:");
            bot.sendMessage(chatId, `โš ๏ธ An error occurred:\n\n*Message:*`, { parse_mode: "Markdown" });
        }
    }
});

// /facebook command
bot.onText(/\/(facebook|fb|fbdl|fbdownload)(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const text = match[2]; // Extract the Facebook video link from the command

    // Guide if no link is provided
    if (!text) {
        return bot.sendMessage(chatId, "โŒ Please provide a Facebook video link.\nExample: `/fb https://www.facebook.com/reel/1256751708994400?mibextid=rS40aB7S9Ucbxw6v`");
    }

    // Notify user of processing
    bot.sendMessage(chatId, "๐Ÿ”„ Fetching your Facebook video... Please wait.");

    try {
        // Fetch video data using the new API
        const apiResponse = await axios.get('https://bk9.fun/download/fb', {
            params: { url: text },
        });

        const responseData = apiResponse.data;

        // Check if the API response is valid
        if (responseData.status && responseData.BK9) {
            const videoData = responseData.BK9;
            const hdLink = videoData.hd || videoData.sd; // Use HD link if available, fallback to SD
            const videoTitle = videoData.title || "Facebook Video";

            // Send the video file directly
            await bot.sendVideo(chatId, hdLink, {
                caption: `แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ`,
                parse_mode: 'Markdown',
            });
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch the video. Please check the link and try again.");
        }
    } catch (error) {
        console.error("Error in Facebook Downloader:");
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request. Please try again later.");
    }
});


// Temporary storage for mapping callback data to URLs
const twitterDownloadLinks = new Map();

bot.onText(/\/twitter (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const twitterUrl = match[1]?.trim();

    // Validate input
    if (!twitterUrl || !twitterUrl.startsWith("http")) {
        return bot.sendMessage(chatId, "โŒ Please provide a valid Twitter link.\nExample: `/twitter https://x.com/elonmusk/status/1870904082564555012`");
    }

    // Notify user of processing
    bot.sendMessage(chatId, "๐Ÿ”„ Fetching Twitter media... Please wait.");

    try {
        // Fetch data from the API
        const apiUrl = `https://api.paxsenix.biz.id/dl/twitter?url=${encodeURIComponent(twitterUrl)}`;
        const response = await axios.get(apiUrl);
        const data = response.data;

        // Check if API returned valid data
        if (!data.ok) {
            return bot.sendMessage(chatId, "โŒ Failed to fetch Twitter media. Please check the link and try again.");
        }

        // Generate unique identifiers for the buttons
        const uniqueIdHD = `HD_${Date.now()}`;
        const uniqueIdSD = `SD_${Date.now()}`;
        const uniqueIdAudio = `Audio_${Date.now()}`;

        // Store URLs in the mapping
        if (data.HD) twitterDownloadLinks.set(uniqueIdHD, data.HD);
        if (data.SD) twitterDownloadLinks.set(uniqueIdSD, data.SD);
        if (data.audio) twitterDownloadLinks.set(uniqueIdAudio, data.audio);

        // Inline keyboard for video quality selection
        const inlineKeyboard = [];
        if (data.HD) inlineKeyboard.push([{ text: "HD Video", callback_data: uniqueIdHD }]);
        if (data.SD) inlineKeyboard.push([{ text: "SD Video", callback_data: uniqueIdSD }]);
        if (data.audio) inlineKeyboard.push([{ text: "Audio Only", callback_data: uniqueIdAudio }]);

        // Send preview with inline buttons
        await bot.sendPhoto(chatId, data.thumb, {
            caption: `๐ŸŒŸ *ATOMIC TWITTER DOWNLOADER!*\n\n๐ŸŽ‰ *แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*\n\nSelect the desired quality below:`,
            parse_mode: "Markdown",
            reply_markup: {
                inline_keyboard: inlineKeyboard,
            },
        });
    } catch (error) {
        console.error("Error in Twitter Downloader:");
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request. Please try again later.");
    }
});

// Handle callback queries for Twitter downloads
bot.on("callback_query", async (callbackQuery) => {
    const chatId = callbackQuery.message.chat.id;
    const data = callbackQuery.data;

    // Check if the callback data exists in the mapping
    const url = twitterDownloadLinks.get(data);
    if (url) {
        // Notify user that the download is in progress
        await bot.sendMessage(chatId, "๐Ÿ“ฅ Downloading your media...");

        try {
            // Determine the type based on the callback data
            if (data.startsWith("HD") || data.startsWith("SD")) {
                await bot.sendVideo(chatId, url, { caption: `๐ŸŽฌแด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ` });
            } else if (data.startsWith("Audio")) {
                await bot.sendAudio(chatId, url, { caption: "๐ŸŽต แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ!" });
            }

            // Remove the mapping after successful download
            twitterDownloadLinks.delete(data);
        } catch (error) {
            console.error(`Error sending media:`);
            await bot.sendMessage(chatId, "โŒ Failed to send the requested media. Please try again later.");
        }
    } else {
        bot.sendMessage(chatId, "");
    }

    // Acknowledge the callback query to avoid timeout
    bot.answerCallbackQuery(callbackQuery.id);
});

// /instagram command
bot.onText(/\/(instagram|ig|igvideo|igimage|igdownload|instadl)(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const text = match[2]; // Extract the Instagram URL from the command

    // Guide if no link is provided
    if (!text || !text.startsWith('http')) {
        return bot.sendMessage(chatId, "โŒ Please provide a valid Instagram link.\nExample: `/instagram https://www.instagram.com/reel/DDgvfkAuBMI/`");
    }

    // Notify user of processing
    bot.sendMessage(chatId, "๐Ÿ”„ Fetching your Instagram media... Please wait.");

    try {
        // Fetch Instagram media data using the API
        const apiResponse = await axios.get('https://api.paxsenix.biz.id/dl/ig', {
            params: { url: text },
        });

        const responseData = apiResponse.data;

        // Check if the API response is valid
        if (responseData.ok && responseData.url && responseData.url.length > 0) {
            const media = responseData.url[0]; // Assume the first item is the main media
            const mediaUrl = media.url;
            const mediaType = media.type || "video"; // Default to video

            if (mediaType === "video") {
                // Send the video
                await bot.sendVideo(chatId, mediaUrl, {
                    caption: `*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
                    parse_mode: "Markdown",
                });
            } else {
                // Send the image
                await bot.sendPhoto(chatId, mediaUrl, {
                    caption: `*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
                    parse_mode: "Markdown",
                });
            }
        } else {
            bot.sendMessage(chatId, "โŒ Failed to fetch media. Please check the link and try again.");
        }
    } catch (error) {
        console.error("Error in Instagram Downloader:");
        bot.sendMessage(chatId, "โŒ An error occurred while processing your request. Please try again later.");
    }
});
// Anti-link command
// Anti-link toggle commands (Admins only)
bot.onText(/\/antilink (on|off)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const userId = msg.from.id;
    const action = match[1];

    // Check if the user is an admin
    if (await isAdmin(chatId, userId)) {
        if (action === 'on') {
            antiLinkActive = true;
            bot.sendMessage(chatId, "Anti-link is now activated!");
        } else if (action === 'off') {
            antiLinkActive = false;
            bot.sendMessage(chatId, "Anti-link is now deactivated!");
        }
    } else {
        bot.sendMessage(chatId, "You don't have permission to use this command.");
    }
});


bot.onText(/\/xvideodownload (.+)?/, async (msg, match) => {
  const chatId = msg.chat.id;
  const input = match[1]?.trim(); // Get the user-provided URL (if any)

  // Check for the last stored video URL or input
  const url = input || (global.db?.data?.users?.[msg.from.id]?.lastVideoUrl);
  if (!url) {
    return bot.sendMessage(chatId, "โŒ *No video URL found!*\nPlease provide a valid video link or use `/videosearch` first.", {
      parse_mode: "Markdown",
    });
  }

  try {
    // Step 1: Call the video download API
    const apiUrl = `https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(url)}`;
    const response = await axios.get(apiUrl);
    const result = response.data;

    // Step 2: Check if the API returned a valid response
    if (result.status === 200 && result.data?.url) {
      const videoStreamUrl = result.data.url;

      // Step 3: Download the video content
      const videoResponse = await axios({
        url: videoStreamUrl,
        method: 'GET',
        responseType: 'stream',
      });

      // Step 4: Send the video to the user
      const videoInfo = result.data;
      const body = `๐ŸŽฅ *Video Details:*\n\n` +
                   `๐Ÿ”ค *Title:* ${videoInfo.title}\n` +
                   `๐Ÿ‘€ *Views:* ${videoInfo.views}\n` +
                   `๐Ÿ‘ *Likes:* ${videoInfo.like_count}\n` +
                   `๐Ÿ‘Ž *Dislikes:* ${videoInfo.dislike_count}\n` +
                   `โญ *Votes:* ${videoInfo.vote}\n` +
                   `๐Ÿ”— *Source:* [Watch Original Video](${url})\n\n` +
                   `*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœโ„ข*`;

      await bot.sendMessage(chatId, body, { parse_mode: "Markdown" });

      bot.sendVideo(chatId, videoResponse.data, {
        caption: `*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
        parse_mode: "Markdown",
      });
    } else {
      bot.sendMessage(chatId, "โŒ Failed to fetch the video. Please try again later.");
    }
  } catch (error) {
    console.error("Video Download Error:");
    bot.sendMessage(chatId, "โŒ An error occurred while downloading the video. Please try again.");
  }
});

bot.onText(/\/videodownload (.+)?/, async (msg, match) => {
  const chatId = msg.chat.id;
  const input = match[1]?.trim(); // Get the user-provided URL (if any)

  // Check for the last stored video URL or input
  const url = input || (global.db?.data?.users?.[msg.from.id]?.lastVideoUrl);
  if (!url) {
    return bot.sendMessage(chatId, "โŒ *No video URL found!*\nPlease provide a valid video link or use `/xvideosearch` first.", {
      parse_mode: "Markdown",
    });
  }

  try {
    // Step 1: Call the video download API
    const apiUrl = `https://api.agatz.xyz/api/xvideodown?url=${encodeURIComponent(url)}`;
    const response = await axios.get(apiUrl);
    const result = response.data;

    // Step 2: Check if the API returned a valid response
    if (result.status === 200 && result.data?.url) {
      const videoInfo = result.data;
      const videoUrl = videoInfo.url;

      // Step 3: Prepare the video details for the user
      const body = `๐ŸŽฅ *Video Details:*\n\n` +
                   `๐Ÿ”ค *Title:* ${videoInfo.title}\n` +
                   `๐Ÿ‘€ *Views:* ${videoInfo.views}\n` +
                   `๐Ÿ‘ *Likes:* ${videoInfo.like_count}\n` +
                   `๐Ÿ‘Ž *Dislikes:* ${videoInfo.dislike_count}\n` +
                   `โญ *Votes:* ${videoInfo.vote}\n` +
                   `๐Ÿ”— *URL:* [Watch Original Video](${url})\n\n` +
                   `*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`;

      // Step 4: Send the video thumbnail and downloadable video to the user
      await bot.sendPhoto(chatId, videoInfo.thumb, {
        caption: body,
        parse_mode: "Markdown",
      });

      await bot.sendVideo(chatId, videoUrl, {
        caption: `*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
        parse_mode: "Markdown",
      });
    } else {
      bot.sendMessage(chatId, "โŒ Failed to fetch the video. Please try again later.");
    }
  } catch (error) {
    console.error("Video Download Error:");
    bot.sendMessage(chatId, "โŒ An error occurred while downloading the video. Please try again.");
  }
});





const { randomUUID } = require("crypto");

// /text2speech command
bot.onText(/\/text2speech (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const input = match[1].trim();

  if (!input) {
    return bot.sendMessage(chatId, "โŒ *Please provide text to convert to speech!*\nExample: `/text2speech Hello world | en`", {
      parse_mode: "Markdown",
    });
  }

  try {
    // Split input into text and optional language code
    const [text, lang] = input.split("|").map((item) => item.trim());
    const language = lang || "en"; // Default to 'en' if no language provided

    if (!text) {
      return bot.sendMessage(chatId, "โŒ *Please provide valid text for the speech conversion.*", {
        parse_mode: "Markdown",
      });
    }

    const encodedText = encodeURIComponent(text);
    const apiUrl = `https://bk9.fun/tools/tts?q=${encodedText}&lang=${language}`;

    // Step 1: Fetch the audio file
    const response = await axios({
      method: "GET",
      url: apiUrl,
      responseType: "stream",
    });

    // Generate a random filename for the audio
    const fileName = `${randomUUID()}.mp3`;
    const filePath = `./${fileName}`;

    // Step 2: Save the audio stream to a file
    const writer = fs.createWriteStream(filePath);
    response.data.pipe(writer);

    writer.on("finish", async () => {
      try {
        // Step 3: Send the audio file to the user
        await bot.sendAudio(chatId, filePath, {
          caption: `๐ŸŽ™๏ธ *Text-to-Speech Result*\n๐ŸŒ *Language:* ${language.toUpperCase()}`,
          parse_mode: "Markdown",
        });

        // Cleanup: Delete the temporary file
        fs.unlinkSync(filePath);
        console.log(`Temporary file ${fileName} deleted successfully.`);
      } catch (sendError) {
        console.error("Error sending TTS file:");
        bot.sendMessage(chatId, "โŒ Failed to send the generated audio file.");
        if (fs.existsSync(filePath)) fs.unlinkSync(filePath); // Ensure cleanup
      }
    });

    writer.on("error", (error) => {
      console.error("Error saving TTS file:");
      bot.sendMessage(chatId, "โŒ Failed to generate or send the audio.");
    });
  } catch (error) {
    console.error("TTS Error:");
    bot.sendMessage(chatId, "โŒ An error occurred while generating speech. Please try again.");
  }
});




// /dog command
bot.onText(/\/dog/, async (msg) => {
    const chatId = msg.chat.id;

    try {
        const response = await axios.get('https://dog.ceo/api/breeds/image/random');
        const dogUrl = response.data.message;
        bot.sendPhoto(chatId, dogUrl);
    } catch (error) {
        bot.sendMessage(chatId, 'Could not fetch a dog picture at the moment. Please try again later.');
    }
});





// Function to get currency conversion rate from ExchangeRate-API
async function getCurrencyConversion(amount, fromCurrency, toCurrency) {
  try {
    // Request currency conversion data from ExchangeRate-API
    const response = await axios.get(`https://v6.exchangerate-api.com/v6/${apiKey}/latest/${fromCurrency}`);

    const rates = response.data.conversion_rates;
    const conversionRate = rates[toCurrency];

    if (conversionRate) {
      const convertedAmount = (amount * conversionRate).toFixed(2);
      return `${amount} ${fromCurrency} = ${convertedAmount} ${toCurrency}`;
    } else {
      return `Sorry, I couldn't find the conversion rate for ${toCurrency}.`;
    }
  } catch (error) {
    console.error('Error fetching currency conversion:');
    return 'Oops! Something went wrong. Please try again later.';
  }
}

// Command handler for /currency
bot.onText(/\/currency (\d+\.?\d*) (\w+) to (\w+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const amount = parseFloat(match[1]);
  const fromCurrency = match[2].toUpperCase();
  const toCurrency = match[3].toUpperCase();

  // Validate the amount
  if (isNaN(amount) || amount <= 0) {
    bot.sendMessage(chatId, 'Please provide a valid amount to convert. Example: /currency 100 USD to EUR');
    return;
  }

  const conversionResult = await getCurrencyConversion(amount, fromCurrency, toCurrency);
  bot.sendMessage(chatId, conversionResult);
});





// Flag to indicate when an admin has issued /setgrouppic
let awaitingGroupPic = new Map();

// /setgrouppic command (admins only)
bot.onText(/\/setgrouppic/, async (msg) => {
    const chatId = msg.chat.id;
    const userId = msg.from.id;

    if (msg.chat.type !== 'group' && msg.chat.type !== 'supergroup') {
        bot.sendMessage(chatId, 'This command can only be used in group chats.');
        return;
    }

    // Check if the user is an admin
    if (await isAdmin(chatId, userId)) {
        bot.sendMessage(chatId, 'Please send the new group picture as a photo.');
        awaitingGroupPic.set(chatId, userId); // Track the admin who issued the command
    } else {
        bot.sendMessage(chatId, "You don't have permission to use this command.");
    }
});

// Handle photo uploads for /setgrouppic
bot.on('photo', async (msg) => {
    const chatId = msg.chat.id;
    const userId = msg.from.id;

    // Check if we are awaiting a photo from an admin
    if (awaitingGroupPic.get(chatId) === userId) {
        const photoId = msg.photo[msg.photo.length - 1].file_id;

        try {
            const file = await bot.getFile(photoId);
            const downloadPath = await bot.downloadFile(photoId, './');

            await bot.setChatPhoto(chatId, fs.createReadStream(downloadPath));
            bot.sendMessage(chatId, 'Group picture updated successfully!');

            // Clean up
            fs.unlinkSync(downloadPath);
            awaitingGroupPic.delete(chatId); // Remove the flag after setting the picture
        } catch (error) {
            console.error('Error:');
            bot.sendMessage(chatId, 'Failed to update group picture. Make sure I have the required permissions.');
        }
    }
});

// Kick command
bot.onText(/\/kick/, async (msg) => {
    const chatId = msg.chat.id;

    if (msg.reply_to_message) {
        const userId = msg.reply_to_message.from.id; // User to kick must be mentioned in reply
        const requesterId = msg.from.id; // ID of the person issuing the command

        if (await isAdmin(chatId, requesterId)) {
            try {
                await bot.kickChatMember(chatId, userId);
                bot.sendMessage(chatId, "User has been kicked.");
                // Optionally, unban the user immediately to allow them to rejoin if necessary
                setTimeout(() => {
                    bot.unbanChatMember(chatId, userId);
                }, 1000);
            } catch (err) {
                console.error("Failed to kick user:");
                bot.sendMessage(chatId, "Failed to kick user. Ensure I have appropriate permissions.");
            }
        } else {
            bot.sendMessage(chatId, "You don't have permission to use this command.");
        }
    } else {
        bot.sendMessage(chatId, "Please reply to a user's message to kick them.");
    }
});

// Mute command
// Mute command
bot.onText(/\/mute/, async (msg) => {
    const chatId = msg.chat.id;
    const requesterId = msg.from.id;

    // Check if the user issuing the command is an admin
    if (await isAdmin(chatId, requesterId)) {
        if (msg.reply_to_message) {
            const userId = msg.reply_to_message.from.id; // User to mute must be mentioned in reply
            mutedUsers.add(userId);
            bot.sendMessage(chatId, `User has been muted.`);
        } else {
            bot.sendMessage(chatId, "Please reply to a user's message to mute them.");
        }
    } else {
        bot.sendMessage(chatId, "You don't have permission to use this command.");
    }
});

// Function to get anime details from Jikan API
async function getAnimeInfo(animeName) {
  try {
    const response = await axios.get(`https://api.jikan.moe/v4/anime?q=${animeName}&limit=1`);
    const anime = response.data.data[0];
    if (anime) {
      const title = anime.title;
      const synopsis = anime.synopsis;
      const rating = anime.rating;
      const imageUrl = anime.images.jpg.image_url;
      const url = anime.url;

      return {
        info: `*${title}*\n\n${synopsis}\n\n*Rating:* ${rating}\n\n[More Info](${url})`,
        imageUrl: imageUrl,
      };
    } else {
      return { info: 'No anime found with that name.', imageUrl: null };
    }
  } catch (error) {
    console.error('Error fetching anime info:');
    return { info: 'Oops! Something went wrong.', imageUrl: null };
  }
}

// Command handler for /anime
bot.onText(/\/anime (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const animeName = match[1];

  const { info, imageUrl } = await getAnimeInfo(animeName);

  // Send the information as a message
  bot.sendMessage(chatId, info, { parse_mode: 'Markdown' });

  // If an image URL is available, send the image
  if (imageUrl) {
    bot.sendPhoto(chatId, imageUrl);
  }
});



// Unmute command
bot.onText(/\/unmute/, (msg) => {
    const chatId = msg.chat.id;
    if (msg.reply_to_message) {
        const userId = msg.reply_to_message.from.id; // User to unmute must be mentioned in reply
        mutedUsers.delete(userId);
        bot.sendMessage(chatId, `User has been unmuted.`);
    } else {
        bot.sendMessage(chatId, "Please reply to a user's message to unmute them.");
    }
});

// Promote command
bot.onText(/\/promote/, async (msg) => {
    const chatId = msg.chat.id;
    if (msg.reply_to_message) {
        const userId = msg.reply_to_message.from.id; // User to promote must be mentioned in reply
        if (await isAdmin(chatId, msg.from.id)) {
            try {
                await bot.promoteChatMember(chatId, userId, {
                    can_change_info: true,
                    can_post_messages: true,
                    can_edit_messages: true,
                    can_delete_messages: true,
                    can_invite_users: true,
                    can_restrict_members: true,
                    can_pin_messages: true,
                    can_promote_members: true
                });
                bot.sendMessage(chatId, "User has been promoted to admin.");
            } catch (err) {
                bot.sendMessage(chatId, "Failed to promote user.");
            }
        } else {
            bot.sendMessage(chatId, "You don't have permission to use this command.");
        }
    } else {
        bot.sendMessage(chatId, "Please reply to a user's message to promote them.");
    }
});

// Demote command
bot.onText(/\/demote/, async (msg) => {
    const chatId = msg.chat.id;
    if (msg.reply_to_message) {
        const userId = msg.reply_to_message.from.id; // User to demote must be mentioned in reply
        if (await isAdmin(chatId, msg.from.id)) {
            try {
                await bot.promoteChatMember(chatId, userId, {
                    can_change_info: false,
                    can_post_messages: false,
                    can_edit_messages: false,
                    can_delete_messages: false,
                    can_invite_users: false,
                    can_restrict_members: false,
                    can_pin_messages: false,
                    can_promote_members: false
                });
                bot.sendMessage(chatId, "User has been demoted.");
            } catch (err) {
                bot.sendMessage(chatId, "Failed to demote user.");
            }
        } else {
            bot.sendMessage(chatId, "You don't have permission to use this command.");
        }
    } else {
        bot.sendMessage(chatId, "Please reply to a user's message to demote them.");
    }
});

// Set name command
bot.onText(/\/setname (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const newName = match[1];
    if (await isAdmin(chatId, msg.from.id)) {
        try {
            await bot.setChatTitle(chatId, newName);
            bot.sendMessage(chatId, `Group name has been changed to "${newName}".`);
        } catch (err) {
            bot.sendMessage(chatId, "Failed to change group name.");
        }
    } else {
        bot.sendMessage(chatId, "You don't have permission to use this command.");
    }
});

// /meme command
bot.onText(/\/meme/, async (msg) => {
    const chatId = msg.chat.id;

    try {
        const response = await axios.get('https://meme-api.herokuapp.com/gimme');
        const memeUrl = response.data.url;
        bot.sendPhoto(chatId, memeUrl);
    } catch (error) {
        bot.sendMessage(chatId, 'Could not retrieve a meme at the moment. Please try again later.');
    }
});

// /joke command
bot.onText(/\/joke/, async (msg) => {
    const chatId = msg.chat.id;
    try {
        const response = await axios.get('https://official-joke-api.appspot.com/random_joke');
        const joke = `${response.data.setup} - ${response.data.punchline}`;
        bot.sendMessage(chatId, joke);
    } catch (error) {
        bot.sendMessage(chatId, 'Failed to fetch a joke. Please try again later.');
    }
});




// /text2pdf command
bot.onText(/\/text2pdf (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const inputText = match[1].trim();

  if (!inputText) {
    return bot.sendMessage(
      chatId,
      "โŒ *Please provide the text to convert into a PDF!*\nExample: `/text2pdf Hello, this is a test.`",
      { parse_mode: "Markdown" }
    );
  }

  try {
    // Encode the text to be sent in the URL
    const encodedText = encodeURIComponent(inputText);
    const pdfUrl = `https://bk9.fun/tools/pdf?q=${encodedText}`;

    // Step 1: Fetch the PDF file
    const response = await axios({
      method: "GET",
      url: pdfUrl,
      responseType: "stream",
    });

    // Generate a random file name for the PDF
    const fileName = `document_${Date.now()}.pdf`;
    const filePath = `./${fileName}`;

    // Step 2: Save the PDF stream to a file
    const writer = require("fs").createWriteStream(filePath);
    response.data.pipe(writer);

    writer.on("finish", async () => {
      // Step 3: Send the PDF file to the user
      await bot.sendDocument(chatId, filePath, {
        caption: `โœ… Your PDF file has been generated successfully!\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
        parse_mode: "Markdown",
      });

      // Cleanup: Delete the temporary file
      require("fs").unlinkSync(filePath);
      console.log(`Temporary file ${fileName} deleted successfully.`);
    });

    writer.on("error", (error) => {
      console.error("Error saving PDF file:");
      bot.sendMessage(chatId, "โŒ Failed to generate or send the PDF file.");
    });
  } catch (error) {
    console.error("PDF Generation Error:");
    bot.sendMessage(chatId, "โŒ An error occurred while generating the PDF. Please try again.");
  }
});


bot.onText(/\/xvideosearch (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const query = match[1].trim();

  if (!query) {
    return bot.sendMessage(chatId, "โŒ *Please provide a search query!*\nExample: `/xvideosearch step sister`", {
      parse_mode: "Markdown",
    });
  }

  try {
    // Step 1: Call the video search API
    const apiUrl = `https://api.agatz.xyz/api/xvideo?message=${encodeURIComponent(query)}`;
    const response = await axios.get(apiUrl);
    const result = response.data;

    // Step 2: Check if results exist
    if (result.status === 200 && result.data.length > 0) {
      const videoInfo = result.data[0]; // Get the first video result

      // Step 3: Prepare the message body
      const body = `๐ŸŽฅ *Video Search Result:*\n\n` +
                   `๐Ÿ”ค *Title:* ${videoInfo.title}\n` +
                   `โฑ๏ธ *Duration:* ${videoInfo.duration}\n\nแด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ`;

      // Step 4: Add an inline keyboard button with the video link
      const options = {
        parse_mode: "Markdown",
        reply_markup: {
          inline_keyboard: [
            [
              {
                text: "๐Ÿ”— Watch Video",
                url: videoInfo.url,
              },
            ],
          ],
        },
      };

      // Step 5: Send the video thumbnail and details to the user with the button
      await bot.sendPhoto(chatId, videoInfo.thumb, {
        caption: body,
        ...options,
      });
    } else {
      bot.sendMessage(chatId, "โŒ No results found. Please try a different query.");
    }
  } catch (error) {
    console.error("Video Search Error:");
    bot.sendMessage(chatId, "โŒ An error occurred while fetching the search results. Please try again.");
  }
});

// Tag all command
bot.onText(/\/tagall/, async (msg) => {
    const chatId = msg.chat.id;
    if (await isAdmin(chatId, msg.from.id)) {
        const members = await bot.getChatAdministrators(chatId);
        const memberMentions = members.map(member => {
            return member.user.username ? `@${member.user.username}` : member.user.first_name;
        }).join(', ');
        
        bot.sendMessage(chatId, `Tagging all members:\n${memberMentions}`);
    } else {
        bot.sendMessage(chatId, "You don't have permission to use this command.");
    }
});

// Define the /Aza command
bot.onText(/\/support/, (msg) => {
    const chatId = msg.chat.id;
    const response = "9066528353 OPAY ๐Ÿ‡ณ๐Ÿ‡ฌ\nPlease support Developer.";

    // Send the message
    bot.sendMessage(chatId, response);
});

// Define the /owner command
bot.onText(/\/owner/, (msg) => {
    const chatId = msg.chat.id;
    const response = "@deecee_x";

    // Send the message
    bot.sendMessage(chatId, response);
});

// /setdescription command
bot.onText(/\/setdescription (.+)/, (msg, match) => {
  const chatId = msg.chat.id;
  const description = match[1];

  if (msg.chat.type !== 'group' && msg.chat.type !== 'supergroup') {
    bot.sendMessage(chatId, 'This command can only be used in group chats.');
    return;
  }

  // Check if the user is an admin
  bot.getChatMember(chatId, msg.from.id).then(member => {
    if (member.status === 'administrator' || member.status === 'creator') {
      bot.setChatDescription(chatId, description)
        .then(() => {
          bot.sendMessage(chatId, 'Group description updated successfully!');
        })
        .catch((error) => {
          console.error('Error:');
          bot.sendMessage(chatId, 'Failed to update group description. Make sure I have the required permissions.');
        });
    } else {
      bot.sendMessage(chatId, 'Only group admins can use this command.');
    }
  }).catch(error => {
    console.error('Error fetching chat member:');
    bot.sendMessage(chatId, 'An error occurred while verifying your admin status.');
  });
});

// Get link command
bot.onText(/\/getlink/, async (msg) => {
    const chatId = msg.chat.id;
    if (await isAdmin(chatId, msg.from.id)) {
        try {
            const link = await bot.exportChatInviteLink(chatId);
            bot.sendMessage(chatId, `Here is your invite link: ${link}`);
        } catch (err) {
            bot.sendMessage(chatId, "Failed to get the invite link.");
        }
    } else {
        bot.sendMessage(chatId, "You don't have permission to use this command.");
    }
});

// Welcome and goodbye messages
bot.on('new_chat_members', (msg) => {
    const chatId = msg.chat.id;
    msg.new_chat_members.forEach(user => {
        bot.sendMessage(chatId, `Welcome ${user.first_name} to the group!`);
    });
});

bot.on('left_chat_member', (msg) => {
    const chatId = msg.chat.id;
    const user = msg.left_chat_member;
    bot.sendMessage(chatId, `${user.first_name} has left the group.`);
});

// Anti-link functionality
bot.on('message', (msg) => {
    const chatId = msg.chat.id;

    // Check if anti-link is active
    if (antiLinkActive && msg.entities) {
        msg.entities.forEach(entity => {
            if (entity.type === "url") {
                bot.deleteMessage(chatId, msg.message_id)
                    .then(() => {
                        bot.sendMessage(chatId, "Links are not allowed in this group.");
                    })
                    .catch(err => {
                        console.error("Failed to delete message:");
                    });
            }
        });
    }

    // Mute functionality
    if (mutedUsers.has(msg.from.id)) {
        bot.deleteMessage(chatId, msg.message_id)
            .catch(err => {
                console.error("Failed to delete muted user message:");
            });
    }
});






bot.onText(/\/txt2image (.+)/, async (msg, match) => {
    const chatId = msg.chat.id;
    const prompt = match[1]; // Extract the prompt from the command

    // Check if the user provided a prompt
    if (!prompt) {
        return bot.sendMessage(chatId, "โŒ *Please provide a prompt!* \n\nUsage: `/magicstudio <prompt>`", { parse_mode: "Markdown" });
    }

    try {
        // Inform the user the process has started
        await bot.sendMessage(chatId, "โœจ *Generating image... Please wait!*", { parse_mode: "Markdown" });

        // API URL to generate the image
        const apiUrl = `https://bk9.fun/ai/magicstudio?prompt=${encodeURIComponent(prompt)}`;

        // Fetch the generated image from the API
        const response = await axios.get(apiUrl, { responseType: "stream" });

        // Send the image back to the user
        await bot.sendPhoto(chatId, response.data, {
            caption: `๐Ÿ–ผ๏ธ *Here's your generated image for:* \`${prompt}\`\n\nแด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ`,
            parse_mode: "Markdown"
        });

    } catch (error) {
        console.error("Error generating image:");
        bot.sendMessage(chatId, "โŒ *Failed to generate the image. Please try again later!*", { parse_mode: "Markdown" });
    }
});






bot.onText(/\/flux(?: (.+))?/, async (msg, match) => {
    const chatId = msg.chat.id;
    const prompt = match[1]; // Extract the user's prompt from the command

    if (!prompt) {
        // If no prompt is provided, send a usage guide
        return bot.sendMessage(chatId, "โŒ Please provide a prompt to generate an image.\n\nExample: `/flux cat`", { parse_mode: "Markdown" });
    }

    bot.sendMessage(chatId, "๐Ÿ”„ Generating your image... Please wait.");

    try {
        // Call the Flux API to generate the image
        const apiUrl = `https://apis.davidcyriltech.my.id/flux?prompt=${encodeURIComponent(prompt)}`;
        
        // Send the generated image to the user
        await bot.sendPhoto(chatId, apiUrl, {
            caption: `โœจ *Flux Image Generated*\n\n๐Ÿ”น *Prompt:* ${prompt}\n*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*`,
            parse_mode: "Markdown",
        });
    } catch (error) {
        console.error("Error during /flux command:");
        bot.sendMessage(chatId, "โŒ An error occurred while generating the image. Please try again later.");
    }
});


const { shannzCdn } = require("./uploader"); // Import new uploader module

bot.on("message", async (msg) => {
  const chatId = msg.chat.id;
  const text = msg.text?.trim().toLowerCase();

  if (text === "remini" && msg.reply_to_message?.photo) {
    try {
      await bot.sendMessage(chatId, "โณ Processing your image...");

      // Step 1: Download Image from Telegram
      const fileId = msg.reply_to_message.photo[msg.reply_to_message.photo.length - 1].file_id;
      const file = await bot.getFile(fileId);
      const fileUrl = `https://api.telegram.org/file/bot${process.env.BOT_TOKEN}/${file.file_path}`;
      const localFilePath = path.join(__dirname, "downloads", `${fileId}.jpg`);

      const writer = fs.createWriteStream(localFilePath);
      const imageResponse = await axios({ url: fileUrl, method: "GET", responseType: "stream" });
      imageResponse.data.pipe(writer);

      await new Promise((resolve, reject) => {
        writer.on("finish", resolve);
        writer.on("error", reject);
      });

      // Step 2: Upload Image to Shannz CDN
      const uploadResponse = await shannzCdn(localFilePath);
      console.log("Shannz CDN Response:", uploadResponse);

      if (!uploadResponse || !uploadResponse.url) {
        fs.unlinkSync(localFilePath);
        return bot.sendMessage(chatId, "โŒ Failed to upload the image. Please try again.");
      }

      const imageUrl = uploadResponse.url;
      console.log("Uploaded Image URL:", imageUrl);

      // Step 3: Send Image to Remini API
      const enhanceUrl = `https://bk9.fun/tools/enhance?url=${encodeURIComponent(imageUrl)}`;
      console.log("Enhancement API URL:", enhanceUrl);

      // Step 4: Send Enhanced Image to User
      await bot.sendPhoto(chatId, enhanceUrl, {
        caption: "โœจ *Image Enhanced Successfully!*",
        parse_mode: "Markdown",
      });

      fs.unlinkSync(localFilePath); // Cleanup
    } catch (error) {
      console.error("Error enhancing image:");
      bot.sendMessage(chatId, `โŒ Error`);
    }
  }
});
// Handle /delete Command
bot.onText(/\/delete/, async (msg) => {
  const chatId = msg.chat.id;

  if (msg.reply_to_message) {
    try {
      await bot.deleteMessage(chatId, msg.reply_to_message.message_id);
      await bot.deleteMessage(chatId, msg.message_id);
    } catch (error) {
      bot.sendMessage(chatId, "โŒ Unable to delete the message. Check my permissions.");
    }
  } else {
    bot.sendMessage(chatId, "โŒ Please reply to a message to delete it.");
  }
});
// Delete Message Command
bot.onText(/\/delete/, async (msg) => {
  const chatId = msg.chat.id;

  if (msg.reply_to_message) {
    const messageId = msg.reply_to_message.message_id;

    try {
      // Delete the replied message
      await bot.deleteMessage(chatId, messageId);
      // Optionally delete the command message
      await bot.deleteMessage(chatId, msg.message_id);

      // Confirmation message
      await bot.sendMessage(chatId, "โœ… Message deleted successfully.", { reply_to_message_id: msg.message_id });
    } catch (error) {
      console.error("Delete message error:");
      bot.sendMessage(
        chatId,
        "โŒ Failed to delete the message. Ensure I have the necessary permissions.",
        { reply_to_message_id: msg.message_id }
      );
    }
  } else {
    bot.sendMessage(chatId, "โŒ Please reply to the message you want to delete.", { reply_to_message_id: msg.message_id });
  }
});

// Start the bot
bot.onText(/\/help/, (msg) => {
    const chatId = msg.chat.id;
    bot.sendMessage(chatId, "Hi I Am Atomic! Use /start for available commands.");
});

// Store the start time when the bot starts
const startTime = Date.now();

// Command to get bot runtime
bot.onText(/\/runtime/, (msg) => {
    const chatId = msg.chat.id;
  
    // Calculate runtime
    const uptimeMs = Date.now() - startTime;
    const uptimeSeconds = Math.floor(uptimeMs / 1000);
    const hours = Math.floor(uptimeSeconds / 3600);
    const minutes = Math.floor((uptimeSeconds % 3600) / 60);
    const seconds = uptimeSeconds % 60;

    // Send back the bot runtime
    bot.sendMessage(chatId, `The bot has been running for ${hours} hours, ${minutes} minutes, and ${seconds} seconds.`);
});

// /ping command
bot.onText(/\/ping/, (msg) => {
  const chatId = msg.chat.id;
  const start = Date.now(); // Record the start time

  bot.sendMessage(chatId, 'Pong!').then(() => {
    const end = Date.now(); // Record the end time
    const ping = end - start; // Calculate the difference in milliseconds
    bot.sendMessage(chatId, `Response time: ${ping} ms`);
  });
});

// Unified /start command
bot.onText(/\/start/, (msg) => {
    const chatId = msg.chat.id;

    // First page: Download Commands
    const helpMessageDownload = `
*๐Ÿ”ฅ ATOMIC BOT MENU ๐Ÿ”ฅ*

โฌ‡๏ธ *Download Commands*:
- ๐ŸŽถ /play <song name>: Download and play music from YouTube.
- ๐ŸŽถ /song <song name>: Download and play music from Spotify.
- ๐ŸŽฅ /tiktok <link>: Download TikTok videos.
- ๐Ÿ“ธ /instagram <link>: Download Instagram media.
- ๐Ÿ“˜ /fb <link>: Download Facebook videos.
- ๐ŸŽฅ /video <song name>: Download Music Videos.
- ๐ŸŽถ /ytmp3 <link>: Download Music Videos.
- ๐ŸŽฅ /ytmp4 <link>: Download and play music.
- ๐Ÿ“ฆ /mediafire <link>: Downloads MediaFire Files
- ๐Ÿ“ฆ /apk <app name>: Downloads Apk.
- ๐Ÿ“ฆ /gitclone <llnk>: Downloads files from github
- ๐ŸŽฌ /movie <movie name>: Downloads movies.
- ๐ŸŽฌ /twitter <link>: Downloads twitter videos.
`;

    bot.sendMessage(chatId, helpMessageDownload, {
        parse_mode: 'Markdown',
        reply_markup: {
            inline_keyboard: [
                [{ text: "โžก๏ธ NEXT", callback_data: "help_next_1" }]
            ]
        }
    });
});

// Handle button clicks for pagination
bot.on('callback_query', (query) => {
    const chatId = query.message.chat.id;

    // First "NEXT" button (from Download Menu to Admin Commands)
    if (query.data === "help_next_1") {
        const helpMessageAdmin = `๐Ÿค– *AI Commands*:
- ๐Ÿค– /chatbot <on / off>: Interact with ai models without using any prefix
- ๐Ÿค– /gpt <query>: Get an AI-powered response.
- ๐Ÿ”Š /text2speech <text>: Convert text to speech.
- ๐Ÿช„ /text2image <prompt>: Generates Any Ai Image of your choice.
- ๐Ÿช„ /flux <prompt>: Generates Any Realistic Ai Images.
`;

        bot.editMessageText(helpMessageAdmin, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_0" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_2" }
                    ]
                ]
            }
        });
    }

    // Second "NEXT" button (from Admin Commands to AI Menu)
    if (query.data === "help_next_2") {
        const helpMessageAI = `
๐Ÿ› ๏ธ *Admin Commands*:
- ๐Ÿ‘ฎโ€โ™‚๏ธ /kick: Kick a user (reply to their message).
- ๐Ÿค /mute: Mute a user (reply to their message).
- ๐Ÿ”“ /unmute: Unmute a user (reply to their message).
- ๐Ÿ“ˆ /promote: Promote a user to admin (reply to their message).
- ๐Ÿ“‰ /demote: Demote an admin (reply to their message).
- ๐Ÿ“ /setname <new name>: Change the group name.
- ๐Ÿ”— /getlink: Get the group invite link.
- ๐Ÿšซ /antilink: Toggle anti-link feature.
- ๐Ÿ–ผ๏ธ /setgrouppic: Change the group picture.
- โœ๏ธ /setdescription <text>: Update group description.
`;

        bot.editMessageText(helpMessageAI, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_1" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_3" }
                    ]
                ]
            }
        });
    }

    // Third "NEXT" button (from AI Menu to Tools Menu)
    if (query.data === "help_next_3") {
        const helpMessageTools = `
๐Ÿ”ง *Special Menu*:
- ๐Ÿฅต /xvideosearch: <query> searches for adult videos 
- ๐Ÿ‘™ /xvideodownload: <link> downloads adult videos 
`;

        bot.editMessageText(helpMessageTools, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_2" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_4" }
                    ]
                ]
            }
        });
    }
    
        // Third "NEXT" button (from AI Menu to Tools Menu)
    if (query.data === "help_next_4") {
        const helpMessageTools = `
๐Ÿ”ง *Tools Menu*:
- ๐Ÿ“„ /txt2pdf: Convert text to PDF. (coming soon)
- ๐Ÿ–‡๏ธ /url: Coverts Video, Photo, any file to url
- ๐Ÿ“ธ /ss: screenshots a website 
- ๐Ÿ˜ /remini: Enhances any low quality image 
- ๐Ÿฅฐ /couplepp: sends couples pics
- ๐Ÿ–ผ๏ธ /image: searchs for images on the internet 
- ๐ŸŽ™๏ธ /shazam: identifies any music on a video or audio file
`;

        bot.editMessageText(helpMessageTools, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_3" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_5" }
                    ]
                ]
            }
        });
    }

    // Fourth "NEXT" button (from Tools Menu to Utility Commands)
    if (query.data === "help_next_5") {
        const helpMessageUtility = `
๐Ÿ“Š *Utility Commands*:
- โณ /runtime: Check the bot's uptime.
- ๐Ÿ“ /ping: Check bot's response time.
- ๐Ÿ’ธ /currency <amount> <from> to <to>: Convert currencies (e.g., /currency 100 USD to EUR).
- ๐Ÿ—‘๏ธ /delete: Delete a specific message (reply to it).
`;

        bot.editMessageText(helpMessageUtility, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_4" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_6" }
                    ]
                ]
            }
        });
    }

    // Fifth "NEXT" button (from Utility Commands to Other Commands)
    if (query.data === "help_next_6") {
        const helpMessageOther = `
๐Ÿ™‹โ€โ™‚๏ธ *Other Commands*:
- ๐Ÿ‘‘ /owner: Show the owner details.
- ๐Ÿค /support: Support the developer.
- ๐Ÿ“ข /tagall: Tag all group members.
- ๐Ÿš€ /start: Welcome message and introduction.
- โ“ /help: Show this help menu.

*แด˜แดแดกแด‡ส€แด‡แด… ส™ส แด…แด€แด ษชแด… แด„สส€ษชสŸ แด›แด‡แด„สœ*
`;

        bot.editMessageText(helpMessageOther, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_5" }
                    ]
                ]
            }
        });
    }

    // Handle "BACK" buttons
    if (query.data === "help_back_0") {
        bot.editMessageText(helpMessageDownload, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [{ text: "โžก๏ธ NEXT", callback_data: "help_next_1" }]
                ]
            }
        });
    }

    if (query.data === "help_back_1") {
        const helpMessageAdmin = `
๐Ÿ› ๏ธ *Admin Commands*:
- ๐Ÿ‘ฎโ€โ™‚๏ธ /kick: Kick a user (reply to their message).
- ๐Ÿค /mute: Mute a user (reply to their message).
- ๐Ÿ”“ /unmute: Unmute a user (reply to their message).
- ๐Ÿ“ˆ /promote: Promote a user to admin (reply to their message).
- ๐Ÿ“‰ /demote: Demote an admin (reply to their message).
- ๐Ÿ“ /setname <new name>: Change the group name.
- ๐Ÿ”— /getlink: Get the group invite link.
- ๐Ÿšซ /antilink: Toggle anti-link feature.
- ๐Ÿ–ผ๏ธ /setgrouppic: Change the group picture.
- โœ๏ธ /setdescription <text>: Update group description.
`;

        bot.editMessageText(helpMessageAdmin, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_0" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_2" }
                    ]
                ]
            }
        });
    }

    if (query.data === "help_back_2") {
        const helpMessageAI = `
๐Ÿค– *AI Commands*:
- ๐Ÿค– /gpt <query>: Answers any question.
- ๐Ÿ”Š /text2speech <text>: Convert text to speech. (coming soon)
- ๐Ÿ”Š /text2speech <text>: Convert text to speech.
- ๐Ÿช„ /text2image <prompt>: Generates Any Ai Image of your choice.
- ๐Ÿช„ /flux <prompt>: Generates Any Realistic Ai Images.
`;

        bot.editMessageText(helpMessageAI, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_1" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_3" }
                    ]
                ]
            }
        });
    }

    if (query.data === "help_back_3") {
        const helpMessageTools = `
๐Ÿ”ง *Special Menu*:
- ๐Ÿฅต /xvideosearch: <query> searches for adult videos 
- ๐Ÿ‘™ /xvideodownload: <link> downloads adult videos
`;

        bot.editMessageText(helpMessageTools, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_2" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_4" }
                    ]
                ]
            }
        });
    }
    

    if (query.data === "help_back_3") {
        const helpMessageTools = `
๐Ÿ”ง *Tools Menu*:
- ๐Ÿ“„ /txt2pdf: Convert text to PDF.
- ๐Ÿ–‡๏ธ /url: Coverts Video, Photo, any file to url
- ๐Ÿ˜ /remini: Enhances any low quality image 
- ๐Ÿ–ผ๏ธ /image: searchs for images on the internet 
- ๐ŸŽ™๏ธ /shazam: identifies any music on a video or audio file
`;

        bot.editMessageText(helpMessageTools, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_2" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_4" }
                    ]
                ]
            }
        });
    }

    if (query.data === "help_back_4") {
        const helpMessageUtility = `
๐Ÿ“Š *Utility Commands*:
- โณ /runtime: Check the bot's uptime.
- ๐Ÿ“ /ping: Check bot's response time.
- ๐Ÿ’ธ /currency <amount> <from> to <to>: Convert currencies (e.g., /currency 100 USD to EUR).
- ๐Ÿ—‘๏ธ /delete: Delete a specific message (reply to it).
`;

        bot.editMessageText(helpMessageUtility, {
            chat_id: chatId,
            message_id: query.message.message_id,
            parse_mode: 'Markdown',
            reply_markup: {
                inline_keyboard: [
                    [
                        { text: "โฌ…๏ธ BACK", callback_data: "help_back_3" },
                        { text: "โžก๏ธ NEXT", callback_data: "help_next_5" }
                    ]
                ]
            }
        });
    }
});