-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
main.py
1438 lines (1113 loc) · 59.9 KB
/
main.py
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
import pyrogram
from pyrogram import Client
from pyrogram import filters
from pyrogram import enums
from pyrogram.types import InlineKeyboardMarkup,InlineKeyboardButton
import os
import shutil
import subprocess
import threading
import time
from buttons import *
import aifunctions
import helperfunctions
import mediainfo
import guess
import tormag
import progconv
import others
import tictactoe
# env
bot_token = os.environ.get("TOKEN", "")
api_hash = os.environ.get("HASH", "")
api_id = os.environ.get("ID", "")
# bot
app = Client("my_bot",api_id=api_id, api_hash=api_hash,bot_token=bot_token)
MESGS = {}
# msgs functions
def saveMsg(msg, msg_type):
MESGS[msg.from_user.id] = [msg, msg_type]
def getSavedMsg(msg):
return MESGS.get(msg.from_user.id, [None, None])
def removeSavedMsg(msg):
del MESGS[msg.from_user.id]
# main function to follow
def follow(message,inputt,new,old,oldmessage):
output = helperfunctions.updtname(inputt,new)
# ffmpeg videos audios
if (output.upper().endswith(VIDAUD) or new == "gif") and inputt.upper().endswith(VIDAUD):
print("It is VID/AUD option")
file,msg = down(message)
srclink = helperfunctions.videoinfo(file)
cmd = helperfunctions.ffmpegcommand(file,output,new)
if msg != None:
app.edit_message_text(message.chat.id, msg.id, '__Converting__')
os.system(cmd)
os.remove(file)
conlink = helperfunctions.videoinfo(output)
if os.path.exists(output) and os.path.getsize(output) > 0:
caption=f'**Source File** : __{srclink}__\n\n**Converted File** : __{conlink}__'
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
up(message,output,msg,capt=caption)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
# images
elif output.upper().endswith(IMG) and inputt.upper().endswith(IMG):
print("It is IMG option")
file = app.download_media(message)
srclink = helperfunctions.imageinfo(file)
cmd = helperfunctions.magickcommand(file,output,new)
os.system(cmd)
conlink = helperfunctions.imageinfo(output)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id,document=output, force_document=True, caption=f'**Source File** : __{srclink}\n\n**Converted File** : __{conlink}__', reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
if new == "ocr":
cmd = helperfunctions.tesrctcommand(file,message.id)
os.system(cmd)
with open(f"{message.id}.txt","r") as ocr:
text = ocr.read()
os.remove(f"{message.id}.txt")
if text != "":
app.send_message(message.chat.id, text, reply_to_message_id=message.id)
if new == "ico":
slist = ["256", "128", "96", "64", "48", "32", "16"]
for ele in slist:
toutput = helperfunctions.updtname(inputt,f"{ele}.png")
os.remove(toutput)
os.remove(file)
# stickers
elif output.upper().endswith(IMG) and inputt.upper().endswith("TGS"):
if new == "webp" or new == "gif" or new == "png":
print("It is Animated Sticker option")
file = app.download_media(message)
srclink = helperfunctions.imageinfo(file)
os.system(f'./tgsconverter "{file}" "{new}"')
os.remove(file)
output = helperfunctions.updtname(file,new)
conlink = helperfunctions.imageinfo(output)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id,document=output, force_document=True, caption=f'**Source File** : __{srclink}\n\n**Converted File** : __{conlink}__', reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
else:
app.send_message(message.chat.id,"__Only Availble Conversions for Animated Stickers are **GIF, PNG** and **WEBP**__", reply_to_message_id=message.id)
# ebooks
elif output.upper().endswith(EB) and inputt.upper().endswith(EB):
print("It is Ebook option")
file = app.download_media(message)
cmd = helperfunctions.calibrecommand(file,output)
os.system(cmd)
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id, document=output, force_document=True, reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
# libreoffice documents
elif (output.upper().endswith(LBW) and inputt.upper().endswith(LBW)) or (output.upper().endswith(LBI) and inputt.upper().endswith(LBI)) or (output.upper().endswith(LBC) and inputt.upper().endswith(LBC)):
print("It is LibreOffice option")
file = app.download_media(message)
cmd = helperfunctions.libreofficecommand(file,new)
# os.system(cmd)
subprocess.run([cmd],env={"HOME": "."},)
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id,document=output, force_document=True, reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
# fonts
elif output.upper().endswith(FF) and inputt.upper().endswith(FF):
print("It is FontForge option")
file = app.download_media(message)
cmd = helperfunctions.fontforgecommand(file,output,message)
os.system(cmd)
os.remove(f"{message.id}-convert.pe")
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id,document=output, force_document=True, reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
# subtitles
elif output.upper().endswith(SUB) and inputt.upper().endswith(SUB):
if not ((old.upper() in ["TTML", "SCC", "SRT"]) and (new.upper() in ["TTML","SRT", "VTT"])):
app.send_message(message.chat.id,f"__**{old.upper()}** to **{new.upper()}** is not Supported.\n\n**Supported Formats**\n**Inputs**: TTML, SCC & SRT\n**Outputs**: TTML, SRT & VTT__", reply_to_message_id=message.id)
else:
print("It is Subtitles option")
file = app.download_media(message)
cmd = helperfunctions.subtitlescommand(file,output)
os.system(cmd)
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id,document=output, force_document=True, reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
# programs
elif output.upper().endswith(PRO) and inputt.upper().endswith(PRO):
flag = 0
if ((old.upper() == "C") and (new.upper() == "GO")):
flag = 1
elif ((old.upper() == "PY") and (new.upper() in ['CPP','RS','JL','KT','NIM','DART','GO'])):
flag = 2
extens = ['CPP','RS','JL','KT','NIM','DART','GO']
langs = ['cpp','rust','julia','kotlin','nim','dart','go']
for i in range(len(langs)):
if new.upper() == extens[i]:
lang = langs[i]
elif ((old.upper() == "JAVA") and (new.upper() in ["JS","TS"])):
flag = 3
lang = new.upper()
if not flag:
app.send_message(message.chat.id,f"__**{old.upper()}** to **{new.upper()}** is not Supported.\n\
\n**Supported Formats:**\nC -> GO\nPY -> CPP, RS, JL, KT, NIM, DART & GO\nJAVA -> JS & TS__", reply_to_message_id=message.id)
else:
print("It is Programs option")
file = app.download_media(message)
if flag == 1:
output = progconv.c2Go(file)
elif flag == 2:
output = progconv.py2Many(file,lang)
elif flag == 3:
with open(file,"r") as jfile:
javacode = jfile.read()
info = progconv.java2JSandTS(javacode,lang)
if info[0] == 1:
with open(output,"w") as pfile:
pfile.write(info[1])
else:
errormessage = ""
for ele in info[1]:
errormessage = errormessage + ele + "\n"
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id,document=output, force_document=True, reply_to_message_id=message.id)
else:
if flag != 3:
errormessage = "Error while Conversion"
app.send_message(message.chat.id,f"__{errormessage}__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
# 3D files
elif output.upper().endswith(T3D) and inputt.upper().endswith(T3D):
if (old.upper() == "WRL"):
app.send_message(message.chat.id,f"__**{old.upper()}** is Export Only, cannot be used to Convert from__", reply_to_message_id=message.id)
else:
print("It is 3D files option")
file = app.download_media(message)
cmd = helperfunctions.ctm3dcommand(file,output)
os.system(cmd)
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
app.send_document(message.chat.id,document=output, force_document=True, reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__Error while Conversion__", reply_to_message_id=message.id)
if os.path.exists(output):
os.remove(output)
# or else
else:
app.send_message(message.chat.id,"__Choose a Valid Extension, don't Type it__", reply_to_message_id=message.id)
# deleting message
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
# negative to positive
def negetivetopostive(message,oldmessage):
file = app.download_media(message)
output = file.split("/")[-1]
try:
print("using c41lab")
os.system(f'./c41lab.py "{file}" "{output}"')
app.send_document(message.chat.id,document=output, force_document=True,caption="used tool -> **c41lab**", reply_to_message_id=message.id)
os.remove(output)
except: pass
try:
print("using simple tool")
aifunctions.positiver(file,output)
app.send_document(message.chat.id,document=output, force_document=True,caption="used tool -> **openCV**", reply_to_message_id=message.id)
os.remove(output)
except: pass
try:
print("using negfix8")
os.system(f'./negfix8 "{file}" "{output}"')
app.send_document(message.chat.id,document=output, force_document=True,caption="used tool -> **negfix8**", reply_to_message_id=message.id)
os.remove(output)
except: pass
os.remove(file)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
# color image
def colorizeimage(message,oldmessage):
file = app.download_media(message)
output = file.split("/")[-1]
try:
aifunctions.deoldify(file,output)
app.send_document(message.chat.id,document=output, force_document=True,caption="used tool -> **Deoldify**", reply_to_message_id=message.id)
os.remove(output)
except: pass
try:
aifunctions.colorize_image(output,file)
app.send_document(message.chat.id,document=output, force_document=True,caption="used tool -> **Local Model**", reply_to_message_id=message.id)
os.remove(output)
except: pass
os.remove(file)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
# dalle
def genrateimages(message,prompt,msg):
# dalle mini
filelist = aifunctions.dallemini(prompt)
app.send_message(message.chat.id,"**DALLE MINI**", reply_to_message_id=message.id)
for ele in filelist:
app.send_document(message.chat.id,document=ele,force_document=True)
os.remove(ele)
os.rmdir(prompt)
# satbility ai
filelist = aifunctions.stabilityAI(prompt)
app.send_message(message.chat.id,"**STABLE DIFFUSION**", reply_to_message_id=message.id)
for ele in filelist:
app.send_document(message.chat.id,document=ele,force_document=True)
os.remove(ele)
# delete msg
app.delete_messages(message.chat.id,message_ids=msg.id)
# riffusion
def genratemusic(message,prompt,msg):
musicfile, thumbfile = aifunctions.riffusion(prompt)
app.send_audio(message.chat.id, musicfile, duration=10, performer="Riffusion", title=prompt, thumb=thumbfile, reply_to_message_id=message.id)
os.remove(musicfile)
os.remove(thumbfile)
app.delete_messages(message.chat.id,message_ids=msg.id)
# cog video
def genratevideos(message,prompt):
hash, queuepos = aifunctions.cogvideo(prompt,AutoCall=False)
msg = app.send_message(message.chat.id,f"**Prompt received and Request is sent. Expected waiting time is {(queuepos+1)*3} mins**", reply_to_message_id=message.id)
file = aifunctions.cogvideostatus(hash,prompt)
app.send_video(message.chat.id, video=file, reply_to_message_id=message.id) #,caption=f"COGVIDEO : {prompt}")
os.remove(file)
app.delete_messages(message.chat.id,message_ids=msg.id)
# delete msg
def dltmsg(umsg,rmsg,sec=15):
time.sleep(sec)
app.delete_messages(umsg.chat.id,message_ids=[umsg.id,rmsg.id])
# read file
def readf(message,oldmessage):
file = app.download_media(message)
try:
with open(file,"r", encoding="utf-8") as rf:
txt = rf.read()
n = 4096
split = [txt[i:i+n] for i in range(0, len(txt), n)]
if len(split) > 10:
app.send_message(message.chat.id, "__File Contents is too Long__", reply_to_message_id=message.id)
return
for ele in split:
app.send_message(message.chat.id, ele, disable_web_page_preview=True, reply_to_message_id=message.id)
time.sleep(3)
except Exception as e:
app.send_message(message.chat.id, f"__Error in Reading File : {e}__", reply_to_message_id=message.id)
os.remove(file)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
# send video
def sendvideo(message,oldmessage):
file, msg = down(message)
thumb,duration,width,height = mediainfo.allinfo(file)
up(message, file, msg, video=True, capt=f'**{file.split("/")[-1]}**' ,thumb=thumb, duration=duration, height=height, widht=width)
app.delete_messages(message.chat.id, message_ids=oldmessage.id)
os.remove(file)
# send document
def senddoc(message,oldmessage):
file, msg = down(message)
up(message, file, msg)
app.delete_messages(message.chat.id, message_ids=oldmessage.id)
os.remove(file)
# send photo
def sendphoto(message,oldmessage):
file = app.download_media(message)
app.send_photo(message.chat.id, photo=file, reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
os.remove(file)
# extract file
def extract(message,oldm):
file, msg = down(message)
cmd,foldername,infofile = helperfunctions.zipcommand(file,message)
if msg != None:
app.edit_message_text(message.chat.id, msg.id, '__Extracting__')
os.system(cmd)
os.remove(file)
with open(infofile, 'r') as f:
lines = f.read()
last = lines.split("Everything is Ok\n\n")[-1].replace(" ","")
os.remove(infofile)
if os.path.exists(foldername):
dir_list = helperfunctions.absoluteFilePaths(foldername)
if len(dir_list) > 30:
if msg != None:
app.delete_messages(message.chat.id,message_ids=msg.id)
app.send_message(message.chat.id, f"__Number of files is **{len(dir_list)}** which is more than the limit of **30**__", reply_to_message_id=message.id)
else:
for ele in dir_list:
if os.path.getsize(ele) > 0:
up(message, ele, msg, multi=True)
os.remove(ele)
else:
app.send_message(message.chat.id, f'**{ele.split("/")[-1]}** __is Skipped because it is 0 bytes__', reply_to_message_id=message.id)
if msg != None:
app.delete_messages(message.chat.id,message_ids=msg.id)
app.send_message(message.chat.id, f'__{last}__', reply_to_message_id=message.id)
shutil.rmtree(foldername)
else:
app.send_message(message.chat.id, "**Unable to Extract**", reply_to_message_id=message.id)
app.delete_messages(message.chat.id, message_ids=oldm.id)
# getting magnet
def getmag(message,oldm):
file = app.download_media(message)
maglink = tormag.getMagnet(file)
app.send_message(message.chat.id, f'__{maglink}__', reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldm.id)
os.remove(file)
# getting tor file
def gettorfile(message,oldm):
file = tormag.getTorFile(message.text)
app.send_document(message.chat.id, file, reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldm.id)
os.remove(file)
# compiling
def compile(message,oldm):
ext = message.document.file_name.split(".")[-1]
# jar compilation
if ext.upper() == "JAR":
file = app.download_media(message)
cmd,folder,files = helperfunctions.warpcommand(file,message)
os.system(cmd)
if not os.path.exists(folder):
cmd,folder,files = helperfunctions.warpcommand(file,message,True)
os.system(cmd)
os.remove(file)
if os.path.exists(folder):
app.send_chat_action(message.chat.id, enums.ChatAction.UPLOAD_DOCUMENT)
for ele in files:
if os.path.exists(ele) and os.path.getsize(ele) > 0:
app.send_document(message.chat.id,document=ele, force_document=True, reply_to_message_id=message.id)
os.remove(ele)
shutil.rmtree(folder)
else:
app.send_message(message.chat.id,"__Error while Compiling__", reply_to_message_id=message.id)
# c and c++ compilation
elif ext.upper() in ['C','CPP']:
file = app.download_media(message)
cmd,output = helperfunctions.gppcommand(file)
os.system(cmd)
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_document(message.chat.id,document=output, caption="__Linux Executable__", force_document=True, reply_to_message_id=message.id)
os.remove(output)
else:
app.send_message(message.chat.id,"__Error while Compiling__", reply_to_message_id=message.id)
# python compile
elif ext.upper() == "PY":
file = app.download_media(message)
cmd, output, ofold, tfold, temp = helperfunctions.pyinstallcommand(message,file)
os.system(cmd)
os.remove(file)
if os.path.exists(output) and os.path.getsize(output) > 0:
app.send_document(message.chat.id,document=output, caption="__Linux Executable__", force_document=True, reply_to_message_id=message.id)
os.remove(output)
else:
app.send_message(message.chat.id,"__Error while Compiling__", reply_to_message_id=message.id)
if os.path.exists(temp):
os.remove(temp)
if os.path.exists(ofold):
shutil.rmtree(ofold)
if os.path.exists(tfold):
shutil.rmtree(tfold)
# not supported yet
else:
app.send_message(message.chat.id,"__At this time Compilation only supports from JAR, PY, C and CPP Files__", reply_to_message_id=message.id)
# delete message
app.delete_messages(message.chat.id,message_ids=oldm.id)
# running a program
def runpro(message,oldm):
ext = message.document.file_name.split(".")[-1]
# python run
if ext.upper() == "PY":
file = app.download_media(message)
code = open(file,"r",encoding="utf-8").read()
os.remove(file)
info = others.pyrun(code)
app.send_message(message.chat.id, info, reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldm.id)
# not supported yet
else:
app.send_message(message.chat.id,"__At this time Running only supports from PY Files__", reply_to_message_id=message.id)
# bg remove
def bgremove(message,oldm):
file = app.download_media(message)
ofile = aifunctions.bg_remove(file)
os.remove(file)
app.send_document(message.chat.id, ofile, reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldm.id)
os.remove(ofile)
# scanning
def scan(message,oldm):
file = app.download_media(message)
info = helperfunctions.scanner(file)
app.send_message(message.chat.id,f"__{info}__", reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldm.id)
os.remove(file)
# make file
def makefile(message,mtext,oldmessage):
text = mtext.split("\n")
if len(text) == 1:
app.send_message(message.chat.id, "__Make-File takes First line of your Text as Filename and File content will start from Second line__", reply_to_message_id=message.id)
return
firstline = text[0]
firstline = "".join( x for x in firstline if (x.isalnum() or x in "._-@ "))
text.remove(text[0])
mtext = ""
for ele in text:
mtext = mtext + f"{ele}\n"
with open(firstline,"w") as file:
file.write(mtext)
if os.path.exists(firstline) and os.path.getsize(firstline) > 0:
app.send_document(message.chat.id, document=firstline, reply_to_message_id=message.id)
else:
app.send_message(message.chat.id, "__Error while making file__", reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
os.remove(firstline)
# transcript speech to text
def transcript(message,oldmessage):
file = app.download_media(message)
inputt = file.split("/")[-1]
output = helperfunctions.updtname(inputt,"wav")
temp = helperfunctions.updtname(inputt,"txt")
if file.endswith("wav"):
aifunctions.splitfn(file,message,temp)
else:
cmd = helperfunctions.ffmpegcommand(file,output,"wav")
os.system(cmd)
aifunctions.splitfn(output,message,temp)
os.remove(output)
if os.path.getsize(temp) > 0:
app.send_document(message.chat.id, document=temp,caption="**Google Engine**", reply_to_message_id=message.id)
os.remove(temp)
data = aifunctions.whisper(file)
if data is not None:
with open(temp,"w") as wfile:
wfile.write(data)
if os.path.getsize(temp) > 0:
app.send_document(message.chat.id, document=temp,caption="**OpenAI Engine** __(whisper)__", reply_to_message_id=message.id)
os.remove(temp)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
os.remove(file)
# text to 3d
def textTo3d(prompt,message,msg):
htmlfile = aifunctions.pointE(prompt)
app.send_document(message.chat.id, htmlfile, reply_to_message_id=message.id)
app.delete_messages(message.chat.id, message_ids=msg.id)
os.remove(htmlfile)
# text to speech
def speak(message,oldmessage):
file = app.download_media(message)
inputt = file.split("/")[-1]
output = helperfunctions.updtname(inputt,"mp3")
aifunctions.texttospeech(file,output)
os.remove(file)
app.send_document(message.chat.id, document=output, reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
os.remove(output)
# upscaling
def increaseres(message,oldmessage):
file = app.download_media(message)
inputt = file.split("/")[-1]
try:
aifunctions.upscale(file,inputt)
os.remove(file)
app.send_document(message.chat.id, document=inputt, reply_to_message_id=message.id)
except Exception as e:
app.send_message(message.chat.id, f"__Error : {e}__", reply_to_message_id=message.id)
app.delete_messages(message.chat.id,message_ids=oldmessage.id)
os.remove(inputt)
# renaming
def rname(message,newname,oldm):
app.delete_messages(message.chat.id,message_ids=message.id+1)
file, msg = down(message)
os.rename(file,newname)
up(message, newname, msg)
app.delete_messages(message.chat.id,message_ids=oldm.id)
os.remove(newname)
# save restricted
def saverec(message):
if "https://t.me/c/" in message.text:
app.send_message(message.chat.id, "**Send me only Public Channel Links**", reply_to_message_id=message.id)
return
datas = message.text.split("/")
msgid = int(datas[-1])
username = datas[-2]
msg = app.get_messages(username,msgid)
app.copy_message(message.chat.id, msg.chat.id, msg.id)
# AI chat
def handleAIChat(message):
hash = str(message.chat.id)
if hash[0] == "-": hash = str(hash)[1:]
app.send_chat_action(message.chat.id, enums.ChatAction.TYPING)
reply = aifunctions.chatWithAI(message.text, hash)
if reply != None: app.send_message(message.chat.id, reply, reply_to_message_id=message.id)
else: app.send_chat_action(message.chat.id, enums.ChatAction.CANCEL)
# bloom
def handelbloom(para,message,msg):
ans = aifunctions.bloom(para)
if ans is not None: app.send_message(message.chat.id, f'__{ans}__', reply_to_message_id=message.id)
app.delete_messages(message.chat.id, message_ids=msg.id)
# others
def other(message):
# time date
if message.text in ["time","Time",'date','Date']:
app.send_message(message.chat.id, others.timeanddate(), reply_to_message_id=message.id)
# b64 decode
elif message.text[:5] == "b64d ":
try:
app.send_message(message.chat.id, f'__{others.b64d(message.text[5:])}__', reply_to_message_id=message.id)
except:
app.send_message(message.chat.id, "__Invalid__", reply_to_message_id=message.id)
# b64 encode
elif message.text[:5] == "b64e ":
try:
app.send_message(message.chat.id, f'__{others.b64e(message.text[5:])}__', reply_to_message_id=message.id)
except:
app.send_message(message.chat.id, "__Invalid__", reply_to_message_id=message.id)
# maths
elif not message.text.isalnum():
info = others.maths(message.text)
if info != None:
app.send_message(message.chat.id, info, reply_to_message_id=message.id)
else:
handleAIChat(message)
# AI chat
else:
handleAIChat(message)
# download with progress
def down(message):
try:
size = int(message.document.file_size)
except:
try:
size = int(message.video.file_size)
except:
size = 1
if size > 25000000:
msg = app.send_message(message.chat.id, '__Downloading__', reply_to_message_id=message.id)
dosta = threading.Thread(target=lambda:downstatus(f'{message.id}downstatus.txt',msg),daemon=True)
dosta.start()
else:
msg = None
file = app.download_media(message,progress=dprogress, progress_args=[message])
os.remove(f'{message.id}downstatus.txt')
return file,msg
# uploading with progress
def up(message, file, msg, video=False, capt="", thumb=None, duration=0, widht=0, height=0, multi=False):
if msg != None:
try:
app.edit_message_text(message.chat.id, msg.id, '__Uploading__')
except:
pass
if os.path.getsize(file) > 25000000:
upsta = threading.Thread(target=lambda:upstatus(f'{message.id}upstatus.txt',msg),daemon=True)
upsta.start()
if not video:
app.send_document(message.chat.id, document=file, caption=capt, force_document=True ,reply_to_message_id=message.id, progress=uprogress, progress_args=[message])
else:
app.send_video(message.chat.id, video=file, caption=capt, thumb=thumb, duration=duration, width=widht, height=height, reply_to_message_id=message.id, progress=uprogress, progress_args=[message])
if thumb != None:
os.remove(thumb)
if os.path.exists(f'{message.id}upstatus.txt'):
os.remove(f'{message.id}upstatus.txt')
if msg != None and not multi:
app.delete_messages(message.chat.id,message_ids=msg.id)
# up progress
def uprogress(current, total, message):
with open(f'{message.id}upstatus.txt',"w") as fileup:
fileup.write(f"{current * 100 / total:.1f}%")
# down progress
def dprogress(current, total, message):
with open(f'{message.id}downstatus.txt',"w") as fileup:
fileup.write(f"{current * 100 / total:.1f}%")
# upload status
def upstatus(statusfile,message):
while True:
if os.path.exists(statusfile):
break
time.sleep(5)
while os.path.exists(statusfile):
with open(statusfile,"r") as upread:
txt = upread.read()
#if "%" not in txt:
#txt = "0.0%"
try:
app.edit_message_text(message.chat.id, message.id, f"__Uploaded__ : **{txt}**")
#if txt == "100.0%":
#break
time.sleep(10)
except:
time.sleep(5)
# download status
def downstatus(statusfile,message):
while True:
if os.path.exists(statusfile):
break
time.sleep(5)
while os.path.exists(statusfile):
with open(statusfile,"r") as upread:
txt = upread.read()
#if "%" not in txt:
#txt = "0.0%"
try:
app.edit_message_text(message.chat.id, message.id, f"__Downloaded__ : **{txt}**")
#if txt == "100.0%":
#break
time.sleep(10)
except:
time.sleep(5)
# app messages
@app.on_message(filters.command(['start']))
def start(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
app.send_message(message.chat.id, f"Welcome {message.from_user.mention}\nSend a **File** first and then you can choose **Extension**\n\n__want to know more about me ?\nuse /help - to get List of Commands\nuse /detail - to get List of Supported Extensions\n\nI also have Special AI features including ChatBot, you don't believe me? ask me anything__", reply_to_message_id=message.id)
# detail
@app.on_message(filters.command(['detail']))
def start(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
oldm = app.send_message(message.chat.id, START_TEXT, reply_to_message_id=message.id)
dm = threading.Thread(target=lambda:dltmsg(message,oldm,30),daemon=True)
dm.start()
# help
@app.on_message(filters.command(['help']))
def help(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
oldm = app.send_message(message.chat.id,
"__Available Commands__\n\n**/start - To Check Availabe Conversions\n/help - Help Message\n/detail - Supported Extensions\n/imagegen - Text to Image\n/musicgen - Text to Music\n/3dgen - Text to 3D\n/bloom - AI Article Writter\n/cancel - To Cancel\n/rename - To Rename File\n/read - To Read File\n/make - To Make File\n/guess - Bot will Guess\n/tictactoe - To Play Tic Tac Toe\n/source - Github Source Code\n**", reply_to_message_id=message.id)
dm = threading.Thread(target=lambda:dltmsg(message,oldm),daemon=True)
dm.start()
#source
@app.on_message(filters.command(['source']))
def source(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
oldm = app.send_message(message.chat.id, "**__GITHUB__ - https://github.com/bipinkrish/File-Converter-Bot**", disable_web_page_preview=True, reply_to_message_id=message.id)
dm = threading.Thread(target=lambda:dltmsg(message,oldm),daemon=True)
dm.start()
# rename
@app.on_message(filters.command(['rename']))
def rename(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
try:
newname = message.text.split("/rename ")[1]
except:
app.send_message(message.chat.id, "__Usage: **/rename new-file-name**\n(with extension)__", reply_to_message_id=message.id)
return
nmessage, msg_type = getSavedMsg(message)
if nmessage:
oldm = app.send_message(message.chat.id, "__**Renaming**__", reply_markup=ReplyKeyboardRemove(), reply_to_message_id=nmessage.id)
rn = threading.Thread(target=lambda:rname(nmessage,newname,oldm),daemon=True)
rn.start()
removeSavedMsg(message)
else:
app.send_message(message.chat.id, "__You need to send me a File first__", reply_to_message_id=message.id)
# cancel
@app.on_message(filters.command(['cancel']))
def cancel(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
nmessage, msg_type = getSavedMsg(message)
if nmessage:
removeSavedMsg(message)
app.delete_messages(message.chat.id,message_ids=nmessage.id+1)
app.send_message(message.chat.id,"__Your job was **Canceled**__",reply_markup=ReplyKeyboardRemove(), reply_to_message_id=message.id)
else:
app.send_message(message.chat.id,"__No job to Cancel__", reply_to_message_id=message.id)
# imagen command
@app.on_message(filters.command(["imagegen"]))
def getpompt(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
# getting prompt from the text
try:
prompt = message.text.split("/imagegen ")[1]
except:
app.send_message(message.chat.id,'__Send Prompt with Command,\nUsage :__ **/imagegen dog with funny hat**', reply_to_message_id=message.id)
return
# threding
msg = app.send_message(message.chat.id,"__Prompt received and Request is sent. Waiting time is 1-2 mins__", reply_to_message_id=message.id)
ai = threading.Thread(target=lambda:genrateimages(message,prompt,msg),daemon=True)
ai.start()
# music gen
@app.on_message(filters.command(["musicgen"]))
def getpompt(client: pyrogram.client.Client, message: pyrogram.types.messages_and_media.message.Message):
# getting prompt from the text
try:
prompt = message.text.split("/musicgen ")[1]
except:
app.send_message(message.chat.id,'__Send Prompt with Command,\nUsage :__ **/musicgen a slow, emotional piano ballad in the key of C Major with a tempo of 60 BPM and a time signature of 4/4.**', reply_to_message_id=message.id)
return
# threding
msg = app.send_message(message.chat.id,"__Prompt received and Request is sent. Waiting time is 1 minute__", reply_to_message_id=message.id)
mai = threading.Thread(target=lambda:genratemusic(message,prompt,msg),daemon=True)