-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
1365 lines (1141 loc) · 54.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
from telegram import *
from telegram.ext import *
import fnmatch
import os
import shutil
import logging
import constants as keys
import responses as r
import random
import urllib.request as urllib
from fontpreview import *
from pyunpack import Archive
from py7zr import unpack_7zarchive
from fontTools import ttLib
import requests
import re
import zipfile
from time import *
member_count_alert = 1000
magifonts_id = keys.gid
font_ext = ("ttf", "otf")
zip_ext= ("zip","7z","rar")
todof = "file_17.ttf"
file_responses = ["This your OP font by your OP group", "You are the best!!", "You are OP", "Keep it up, i am waiting for more...","Here you go!", "Thanks for being one of us","Check this out!!", "Take this...","I hope you like it!", "Done!!","Compiled...","Finished!"]
FONT, BOLD, ITALICS = range(3)
PREVIEW = 1
bot = Bot(keys.API_KEY)
admins = [1441717868, 783535757]
def getFilename_fromURL(url):
cd = requests.get(url, allow_redirects=True).headers.get('content-disposition')
if not cd:
return None
fname = re.findall('filename=(.+)', cd)
if len(fname) == 0:
return None
return fname[0]
def member_join(update, context):
for member in update.message.new_chat_members:
member_count = int(bot.get_chat_members_count(update.message.chat_id))
if member_count%member_count_alert == 0:
message = update.message.reply_text(f"{member.full_name} is the "+str(member_count)+"th to join the group!!\nWhoo!! "+str(member_count)+" members!")
try:
bot.pin_chat_message(update.message.chat_id, message.message_id)
except:
update.message.reply_text("I can't even pin a message.. dang!")
def preview_command(update,context):
clearcache()
if update.message.reply_to_message:
msg = bot.send_message(update.message.chat_id, "Gimme a minute")
#keyboard = [
#[
# InlineKeyboardButton("OMF (Recommended)", callback_data='OMF'),
# InlineKeyboardButton("MFFM", callback_data='MFFM'),
#]
#]
#reply_markup = InlineKeyboardMarkup(keyboard)
#context.user_data["file_request"] = update.message.reply_to_message
#context.user_data["preview_message"] = update.message
preview(update,context,update.message.reply_to_message)
bot.deleteMessage(update.message.chat_id, msg.message_id)
#bot.send_message(update.message.chat_id, "Ignore any missing glyphs or broken characters.\nThose will be replaced by Roboto font when flashing the module...")
else:
update.message.reply_text("Reply to a valid font file...")
def preview(update,context,doc):
os.chdir(orig_dir)
if doc.document.file_name.split(".")[-1].lower() in font_ext:
os.chdir("preview")
doc.document.get_file().download(custom_path=remove_ext(doc.document.file_name)+".ttf")
pic = previewfont(None, remove_ext(doc.document.file_name)+".ttf")
os.chdir(orig_dir)
os.chdir("preview")
bot.send_photo(update.message.chat_id, open("preview.png", "rb"))
elif doc.document.file_name.split(".")[-1].lower() in zip_ext:
os.chdir("preview")
doc.document.get_file().download(custom_path="preview_zip."+doc.document.file_name.split(".")[-1].lower())
print("gonna extract")
create_dir("preview_zip")
extract("preview_zip."+doc.document.file_name.split(".")[-1].lower(),"preview_zip/")
ffiles = []
ffiles = list(find("*.otf", "preview_zip"))
regular_font = ""
if len(ffiles)<1:
ffiles = list(find("*.ttf", "preview_zip"))
regular_font = find_font(ffiles,"Regular", remove_ext(doc.document.file_name))
bold_font = find_font(ffiles,"Bold")
light_font = find_font(ffiles,"Light")
italic_font = find_font(ffiles,"Italic")
print(regular_font)
if regular_font:
#regular_font = ffiles[i]
os.chdir(orig_dir)
pic = previewfont(None, regular_font, bold_font, light_font, italic_font)
os.chdir(orig_dir)
os.chdir("preview")
bot.send_photo(update.message.chat_id, open("preview.png", "rb"))
os.chdir(orig_dir)
#break
else:
update.message.reply_text("Send valid font file/zip wen?")
def start_command(update, context):
update.message.reply_text("I'm alive bRUH!...")
def help_command(update,context):
update.message.reply_text("Search for it on Google, duh. Tag @TheSc1enceGuy for some very important questions...")
def ccache_command(update,context):
clearcache()
update.message.reply_text("Done")
def about_command(update,context):
#update.message.reply_text("Memebers count: "+str(bot.get_chat_members_count(update.message.chat_id)))
update.message.reply_text("This bot will convert any sent font (.ttf or .otf) or web downloaded zip file to a magisk flashable zip... enjoy!")
def maker_command(update,context):
update.message.reply_text("@TheSc1enceGuy(akshit singh) has made this bot...")
def owner_command(update,context):
update.message.reply_text("@TheSc1enceGuy(akshit singh) is my father... and he is the owner too lel ;)")
def handle_message(update,context):
if hasattr(update.message, "text"):
text = str(update.message.text).lower()
if r.sample_responses(text) not in (""):
update.message.reply_text(r.sample_responses(text))
def error(update,context):
print(f"Update {update} caused error {context.error}")
error = str(context.error).lower()
try:
chat_id = update.message.chat_id
except:
chat_id = magifonts_id
if error == "timed out":
bot.send_message(chat_id,"Request Timed Out. Pls try again...")
return
elif error == "broken file":
bot.send_message(chat_id,"File is broken LoL xD.\nSorry, I feel sad for you...")
return
elif error == str("Message can't be deleted").lower():
print("I cant delete a message either lol")
else:
bot.send_message(chat_id,"An Error Occured...")
#OMF update function
def updateomf(update, context):
if update.message.from_user.id in admins:
try:
print("updating OMF")
os.chdir(orig_dir)
shutil.rmtree("OMF_old")
if os.path.isdir('OMF_reverted'):
shutil.rmtree("OMF_reverted")
os.rename("OMF", "OMF_old")
urllib.urlretrieve("https://gitlab.com/nongthaihoang/omftemplate/-/archive/master/omftemplate-master.zip", "OMF.zip")
# os.mkdir("OMF")
extract("OMF.zip", os.getcwd())
os.rename("omftemplate-master", "OMF")
print(os.listdir())
update.message.reply_text("Updated OMF successfully")
except:
update.message.reply_text("An error occured, which might have caused some messups. so better check that out asap...")
os.chdir(orig_dir)
initialize()
fix_update()
else:
update.message.reply_text("Only my owner can execute this cmd")
#OMF revert function
def revertomf(update, context):
if update.message.from_user.id in admins:
print("reverting OMF")
os.chdir(orig_dir)
if os.path.isdir('OMD_reverted') or os.path.isdir('OMF_old'):
try:
if os.path.isdir('OMF_reverted'):
os.rename('OMF', 'OMF_old')
os.rename('OMF_reverted', "OMF")
else:
os.chdir(orig_dir)
os.rename("OMF", "OMF_reverted")
os.rename("OMF_old", "OMF")
update.message.reply_text("Revert successful!")
except:
update.message.reply_text("An error occured, that too during Reverting,,. so better check that out asap!")
os.chdir(orig_dir)
else:
update.message.reply_text("Nothing to revert sir!")
initialize()
else:
update.message.reply_text("Only my owner can execute this cmd")
def main():
# Create the Updater and pass it your bot's token.
updater = Updater(keys.API_KEY)
# Get the dispatcher to register handlers
dispatcher = updater.dispatcher
try:
print("updating OMF")
os.chdir(orig_dir)
shutil.rmtree("OMF_old")
if os.path.isdir('OMF_reverted'):
shutil.rmtree("OMF_reverted")
os.rename("OMF", "OMF_old")
urllib.urlretrieve("https://gitlab.com/nongthaihoang/omftemplate/-/archive/master/omftemplate-master.zip", "OMF.zip")
# os.mkdir("OMF")
extract("OMF.zip", os.getcwd())
os.rename("omftemplate-master", "OMF")
print(os.listdir())
print("Updated OMF successfully!")
except:
print("error_occured while updating")
os.chdir(orig_dir)
initialize()
fix_update()
dispatcher.add_handler(CommandHandler("preview",preview_command))
dispatcher.add_handler(CommandHandler("start", start_command))
dispatcher.add_handler(CommandHandler("help",help_command))
dispatcher.add_handler(CommandHandler("ccache",ccache_command))
dispatcher.add_handler(CommandHandler("creator",maker_command))
dispatcher.add_handler(CommandHandler("owner",owner_command))
dispatcher.add_handler(CommandHandler("about",about_command))
dispatcher.add_handler(CommandHandler("module",module_command))
dispatcher.add_handler(CommandHandler("ffiles",ffiles_command))
dispatcher.add_handler(CommandHandler("delete",delete_command))
dispatcher.add_handler(CallbackQueryHandler(button, pattern="^OMF||MFFM||advanced_module||cancel_module$"))
dispatcher.add_handler(CommandHandler("faketrigger",member_join))
dispatcher.add_handler(CommandHandler("extractfont",extract_font))
#OMF update and backup
dispatcher.add_handler(CommandHandler("updateomf",updateomf))
dispatcher.add_handler(CommandHandler("revertomf",revertomf))
dispatcher.add_handler(MessageHandler(Filters.text, handle_message))
dispatcher.add_error_handler(error)
add_group_handle = MessageHandler(Filters.status_update.new_chat_members, member_join)
dispatcher.add_handler(add_group_handle)
adv_handler = ConversationHandler(
entry_points=[CommandHandler("advanced",advanced_main)],
states={
TEMPLATE: [CallbackQueryHandler(template, pattern='^template$')],
METRICS: [CallbackQueryHandler(metrics, pattern='^metrics$')],
ASCENT: [CallbackQueryHandler(ascent, pattern='^ascent_advanced$')],
DESCENT: [CallbackQueryHandler(descent, pattern='^descent_advanced$')],
LINEGAP: [CallbackQueryHandler(linegap, pattern='^linegap_advanced$')],
EM: [CallbackQueryHandler(em, pattern='^em_advanced$')],
ASCENT_R: [MessageHandler(Filters.text, ascent_received)],
DESCENT_R: [MessageHandler(Filters.text, descent_received)],
LINEGAP_R: [MessageHandler(Filters.text, linegap_received)],
EM_R: [MessageHandler(Filters.text, em_received)],
},
fallbacks=[CallbackQueryHandler(button, pattern='^cancel_advanced$')],
)
# Add ConversationHandler to dispatcher that will be used for handling updates
#dispatcher.add_handler(adv_handler)
# Start the Bot
updater.start_polling(drop_pending_updates=True)
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
def extract(file, location):
create_dir(location)
if file.split(".")[-1] == "7z":
shutil.unpack_archive(file, location)
else:
Archive(file).extractall(location)
def capscheck(x):
lower_tfontsall = list(map(lambda x : x.split(".")[0].lower(), tfontsall.copy()))
if x in lower_tfontsall:
return list(map(lambda x : x.split(".")[0], tfontsall.copy()))[lower_tfontsall.index(x)]
def delete_command(update, context):
if update.message.reply_to_message.document:
if update.message.reply_to_message.document.file_name.split(".")[-1] in zip_ext:
clearcache()
doc = update.message.reply_to_message.document
os.chdir(orig_dir)
os.chdir("ziptodo")
doc.get_file().download(custom_path=doc.file_name)
create_dir("to_delete")
extract(doc.file_name,"to_delete/")
ffiles = find("*.ttf", "to_delete")
find("*.otf","to_delete") if not ffiles else ffiles
for attr in context.args:
if attr in list(map(lambda x : name_from_dir(x), ffiles)):
os.remove(find(attr, "to_delete")[0])
else:
to_del = capscheck(attr)
font = find_font(ffiles, to_del, remove_ext(doc.file_name))
if font:
os.remove(font)
else:
update.message.reply_text("Couldn't find that...")
return
print("makin archive")
shutil.make_archive(remove_ext(doc.file_name)+"_mod","zip","to_delete/")
bot.send_document(magifonts_id, open(remove_ext(doc.file_name)+"_mod.zip", "rb"))
return
else:
update.message.reply_text("Are you sure that that is a zip file?\nYou might wana get your eyes tested...")
else:
update.message.reply_text("Reply to a zip...")
def module_command(update,context):
if update.message.reply_to_message:
if int(update.message.reply_to_message.document.file_size) <= 20000000:
print(int(update.message.reply_to_message.document.file_size))
keyboard = [
[
InlineKeyboardButton("OMF (Recommended)", callback_data='OMF'),
InlineKeyboardButton("MFFM", callback_data='MFFM'),
],
#[InlineKeyboardButton("Advanced", callback_data='advanced')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
context.user_data["file_request"] = update.message.reply_to_message
context.user_data["module_message"] = update.message
update.message.reply_text('What Type of Module?', reply_markup=reply_markup)
msgarray = []
if "/module " in update.message.text:
msgarray = list(map(lambda x: x.replace('\"', ""), update.message.text.replace("/module ", "").split(" ")))
filename=None
#print("filename: ",msgarray)
if len(msgarray) >= 1:
filename = msgarray[0]
#ttfdownload(update,update.message.reply_to_message,filename)
#bot.delete_message(update.message.chat_id,msg.message_id)
else:
update.message.reply_text("File is too big sar...")
else:
update.message.reply_text("Reply to a font file/zip bro.")
TEMPLATE, METRICS, ASCENT, DESCENT, LINEGAP, EM, ASCENT_R, DESCENT_R, LINEGAP_R, EM_R = range(10)
def ascent_received(update, context):
print("ascent_r")
bot.delete_message(update.message.chat_id, update.message.message_id)
context.user_data["advanced"]["metrics_msg"].edit_message_text("Ascent has been saved too: ", update.message.text)
return METRICS
def descent_received(update, context):
print("descent_r")
bot.delete_message(update.message.chat_id, update.message.message_id)
context.user_data["advanced"]["metrics_msg"].edit_message_text("Descent has been saved too: ", update.message.text)
return METRICS
def linegap_received(update, context):
print("linegap_r")
bot.delete_message(update.message.chat_id, update.message.message_id)
context.user_data["advanced"]["metrics_msg"].edit_message_text("LineGap has been saved too: ", update.message.text)
return METRICS
def em_received(update, context):
print("em_r")
bot.delete_message(update.message.chat_id, update.message.message_id)
context.user_data["advanced"]["metrics_msg"].edit_message_text("UPM has been saved too: ", update.message.text)
return METRICS
def button(update, context):
query = update.callback_query
def module():
query = update.callback_query
query.answer()
if query.data in ("OMF","MFFM"):
query.edit_message_text(text=f"Processing: {query.data}")
print(context.user_data.get("file_request", "File Request Not found..."))
file = context.user_data.get("file_request", "File Request Not found...")
usermsg = context.user_data["module_message"]
msgarray = []
if "/module " in usermsg.text:
msgarray = list(map(lambda x: x.replace('\"', ""), usermsg.text.replace("/module ", "").split(" ")))
filename=None
#print("filename: ",msgarray)
if len(msgarray) >= 1:
filename = msgarray[0]
if query.data == "OMF":
ttfdownload("OMF", usermsg,file, filename, keys.omf_dir, keys.omffonts_dir, keys.omf_r, keys.omf_b, keys.omf_i, keys.omf_all, keys.omf_single)
if query.data == "MFFM":
ttfdownload("MFFM", usermsg,file, filename, keys.mffm_dir, keys.mffmfonts_dir, keys.mffm_r, keys.mffm_b, keys.mffm_i, keys.mffm_all, keys.mffm_single)
bot.deleteMessage(query.message.chat_id, query.message.message_id)
bot.deleteMessage(usermsg.chat_id, usermsg.message_id)
def compile_advanced():
print("")
if query.data == "template":
template()
if query.data == "advanced":
main()
if query.data == "metrics":
metrics()
if query.data == "MFFM_advanced":
context.user_data["advanced"]["template"] = "MFFM"
metrics()
if query.data == "OMF_advanced":
context.user_data["advanced"]["template"] = "OMF"
metrics()
if query.data == "ascent_advanced":
ascent()
if query.data == "descent_advanced":
descent()
if query.data == "linegap_advanced":
linegap()
if query.data == "em_advanced":
em()
if "advanced" in context.user_data:
print(context.user_data["advanced"])
#if query.data == "metrics":
# metrics()
def cancel():
query.answer()
query.edit_message_text(text="Request Cancelled...")
return
def proceed():
if query.data == "OMF" or query.data == "MFFM":
module()
if query.data == "advanced_module":
advanced()
if query.data == "cancel_module":
cancel()
if query.data in ("template", "metrics","advanced","MFFM_advanced","OMF_advanced","ascent_advanced","descent_advanced","linegap_advanced","em_advanced"):
query.answer()
advanced()
return
userMessage = None
if update.callback_query.message.reply_to_message:
if update.callback_query.message.reply_to_message.from_user.username == update.effective_user.username:
userMessage = update.callback_query.message.reply_to_message
proceed()
else:
return
else:
proceed()
return
tfonts = ["Regular.ttf"]
tfontsr = ["Regular.ttf","Light.ttf","Thin.ttf"]
tfontsb = [ "Medium.ttf","Black.ttf","Bold.ttf"]
tfontsi = ["BlackItalic.ttf","BoldItalic.ttf","MediumItalic.ttf","Italic.ttf","LightItalic.ttf","ThinItalic.ttf"]#todof= file...
tfontsall = ["Regular.ttf","Light.ttf","Thin.ttf","Medium.ttf","Black.ttf","Bold.ttf","BlackItalic.ttf","BoldItalic.ttf","MediumItalic.ttf","Italic.ttf","LightItalic.ttf","ThinItalic.ttf"]
#os.chdir("C:/Users/rsran/Downloads/akshit ka fonts")
def advanced(update,context):
print("advanced: ",query.data)
keyboard = [
[InlineKeyboardButton("Advanced", callback_data='advanced')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
context.user_data["file_request"] = update.message.reply_to_message
context.user_data["module_message"] = update.message
update.message.reply_text('What Type of Module?', reply_markup=reply_markup)
query = None
def advanced_main(update,context):
query = update.callback_query
print("advanced_main")
context.user_data["advanced"] = {}
keyboard = [
[
InlineKeyboardButton("Template", callback_data='template'),
InlineKeyboardButton("Metrics", callback_data='metrics'),
],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
update.message.reply_text('Choose Template: ', reply_markup=reply_markup)
def template(update,context):
query = update.callback_query
print("template")
keyboard = [
[
InlineKeyboardButton("OMF", callback_data='OMF_advanced'),
InlineKeyboardButton("MFFM", callback_data='MFFM_advanced'),
],
[InlineKeyboardButton("Back", callback_data='advanced')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
query.edit_message_text('Choose Template: ', reply_markup=reply_markup)
return METRICS
def metrics(update,context):
query = update.callback_query
keyboard = [
[
InlineKeyboardButton("Ascent", callback_data='ascent_advanced'),
InlineKeyboardButton("Descent", callback_data='descent_advanced'),
InlineKeyboardButton("LineGap", callback_data='linegap_advanced'),
InlineKeyboardButton("unitsPerEm", callback_data='em_advanced')
],
[InlineKeyboardButton("Back", callback_data='advanced')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
query.edit_message_text('Choose Template: ', reply_markup=reply_markup)
print("metrics")
#compile_advanced()
return
def ascent(update,context):
query = update.callback_query
keyboard = [
[InlineKeyboardButton("Back", callback_data='metrics')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
print(context.user_data)
reply_markup = InlineKeyboardMarkup(keyboard)
query.edit_message_text('Options: ', reply_markup=reply_markup)
context.user_data["advanced"]["metrics_msg"] = bot.send_message(query.message.chat_id, "Reply to this message by sending ascent in numbers.\nex. 1900"+(("\n@"+userMessage.from_user.username) if userMessage else ""), reply_markup=ForceReply(selective = True if userMessage else False))
return ASCENT_R
def descent(update,context):
query = update.callback_query
keyboard = [
[InlineKeyboardButton("Back", callback_data='metrics')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
query.edit_message_text('Options: ', reply_markup=reply_markup)
context.user_data["advanced"]["metrics_msg"] = bot.send_message(query.message.chat_id,"Reply to this message by sending descent in numbers.\nex. -500"+(("\n@"+userMessage.from_user.username) if userMessage else ""), reply_markup=ForceReply(selective = True if userMessage else False))
return DESCENT_R
def linegap(update,context):
query = update.callback_query
keyboard = [
[InlineKeyboardButton("Back", callback_data='metrics')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
query.edit_message_text('Options: ', reply_markup=reply_markup)
context.user_data["advanced"]["metrics_msg"] = bot.send_message(query.message.chat_id,"Reply to this message by sending linegap in numbers.\nex. 0"+(("\n@"+userMessage.from_user.username) if userMessage else ""), reply_markup=ForceReply(selective = True if userMessage else False))
return LINEGAP_R
def em(update,context):
query = update.callback_query
keyboard = [
[InlineKeyboardButton("Back", callback_data='metrics')],
[InlineKeyboardButton("Cancel", callback_data='cancel_module')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
query.edit_message_text('Options: ', reply_markup=reply_markup)
context.user_data["advanced"]["metrics_msg"] = bot.send_message(query.message.chat_id,"Reply to this message by sending unitsPerEm in numbers.\nex. 2048"+(("\n@"+userMessage.from_user.username) if userMessage else ""), reply_markup=ForceReply(selective = True if userMessage else False))
return EM_R
def modulify(template_type, templatedir, fontdir, zipname = None, fonts = ["Regular.ttf"]):
print("modulify me hu")
if not zipname:
zipname=remove_ext(todof)
zipname = zipname.replace("[Magifonts]","")+"[Magifonts]"
os.chdir(orig_dir)
os.chdir(fontdir)
processfonts([["", "../../todo/"+todof]])
for i in range(0,len(fonts)):
shutil.copyfile(src="../../todo/"+todof , dst=fonts[i])
print("copied files")
#print(os.getcwd())
os.chdir(orig_dir)
os.chdir(templatedir)
edit_module_prop(remove_ext(todof), templatedir, template_type)
os.chdir(orig_dir)
shutil.make_archive("magiFont/"+zipname, 'zip', templatedir)
print("archive ready")
return zipname
def modulifybi(fname,zipname=False):
print(["moodulify bi reached",fname])
if not zipname:
zipname=fname.split(".")[0]
os.chdir(orig_dir)
fnameb = fname+"-bold.ttf"
fnamei = fname+"-italics.ttf"
todocontents = []
for dirs,file,name in walklevel("todo"):
todocontents = name
if fnameb not in todocontents:
fnameb = fname
if fnamei not in todocontents:
fnamei = fname
os.chdir(keys.fonts_dir)
for i in range(0,len(tfontsr)):
shutil.copyfile(src="../../todo/"+fname , dst=tfontsr[i])
for i in range(0,len(tfontsb)):
shutil.copyfile(src="../../todo/"+fnameb , dst=tfontsb[i])
for i in range(0,len(tfontsi)):
shutil.copyfile(src="../../todo/"+fnamei , dst=tfontsi[i])
print(4)
#print(os.getcwd())
os.chdir(orig_dir)
os.chdir(keys.template_dir)
edit_module_prop(remove_ext(fname))
os.chdir(orig_dir)
#print(zipname)
shutil.make_archive("magiFont/"+zipname, 'zip', keys.template_dir)
return zipname
#print(5)
def edit_module_prop(fname, templatedir, template_type = "OMF"):
os.chdir(orig_dir)
os.chdir(templatedir)
os.rename('module.prop','module.txt')
if template_type == "OMF":
prop_list = ["id=Magifonts_omf_font_module\n","name="+fname+"\n","Moduleversion=v2021.05.23\n""versionCode=2021052301\n","author=nongthaihoang @GitLab; MFFM; @TheSc1enceGuy\n","description=OMF Advanced font installer for Android. Module prepared by @magifont_bot. Join @MFFMDisc / @Magifonts_Support for more.\n"]
else:
prop_list = ["id=Magifonts_mffm_font_module\n","name="+fname+"\n","Moduleversion=v2021.05.23\n""versionCode=2021052301\n","author=MFFM; @TheSc1enceGuy\n","description=MFFM Advanced font installer for Android. Module prepared by @magifont_bot. Join @MFFMDisc / @Magifonts_Support for more.\n"]
my_file = open("module.txt", "w")
my_file.write("".join(prop_list))
my_file.close()
os.rename('module.txt','module.prop')
os.chdir(orig_dir)
def remove_ext(filewext):
file = filewext.split(".").copy()
file.pop(-1)
strfile = ""
for i in file:
strfile+=str(i)
return strfile
def extract_font(update,context):
if update.message.reply_to_message.document:
if update.message.reply_to_message.document.file_name.split(".")[-1] in zip_ext:
clearcache()
doc = update.message.reply_to_message
os.chdir(orig_dir)
os.chdir("ffiles")
doc.document.get_file().download(custom_path="ffiles."+doc.document.file_name.split(".")[-1].lower())
extract("ffiles."+doc.document.file_name.split(".")[-1].lower(), "fonts")
ffiles = find("*.ttf", "fonts")
if not ffiles:
ffiles = find("*.otf", "fonts")
if not ffiles:
update.message.reply_text("It has no Fonts in .ttf ot .otf format! xD")
else:
ffiles_str=""
#ffiles = list(map(lambda x : name_from_dir(x), ffiles))
for i in ffiles:
if ffiles:
bot.send_document(update.message.chat_id, open(i,"rb"), caption=shortName(ttLib.TTFont(i))[0])
#ffiles_str += "\n"+i
else:
ffiles = i
#update.message.reply_text(ffiles_str)
else:
update.message.reply_text("Reply to a .zip wen?")
else:
update.message.reply_text("Reply to a .zip file sar...")
def ffiles_command(update,context):
if update.message.reply_to_message.document:
if update.message.reply_to_message.document.file_name.split(".")[-1] in zip_ext:
clearcache()
doc = update.message.reply_to_message
os.chdir(orig_dir)
os.chdir("ffiles")
doc.document.get_file().download(custom_path="ffiles."+doc.document.file_name.split(".")[-1].lower())
extract("ffiles."+doc.document.file_name.split(".")[-1].lower(), "fonts")
ffiles = find("*.ttf", "fonts")
print(ffiles)
print(os.getcwd())
if not ffiles:
ffiles = find("*.otf", "fonts")
if not ffiles:
update.message.reply_text("It has no Fonts in .ttf ot .otf format! xD")
else:
ffiles_str=""
ffiles = list(map(lambda x : name_from_dir(x), ffiles))
for i in ffiles:
if ffiles:
ffiles_str += "\n"+i
else:
ffiles = i
update.message.reply_text(ffiles_str)
else:
update.message.reply_text("Reply to a .zip wen?")
else:
update.message.reply_text("Reply to a .zip file sar...")
def ttfdownload(template_type, docmsg, doc, zipname, templatedir, fontdir, fontsr = tfontsr, fontsb = tfontsb, fontsi = tfontsi, fontsall = tfontsall, single_file = tfonts):
if not zipname:
zipname = remove_ext(doc.document.file_name).replace("[Magifonts]","")
print(doc)
os.chdir(orig_dir)
clearcache()
try:
print("ttf download requested by @"+docmsg.from_user.username)
except:
print("ttf download requested")
if doc.document.file_name.split(".")[-1].lower() in font_ext:
print(os.getcwd())
os.chdir("todo")
doc.document.get_file().download(custom_path=doc.document.file_name)
global todof
for dirs,file,name in walklevel(os.getcwd()):
print("DIRECTORY LOCATION ABHI KI:")
print(os.getcwd())
todof=name[-1]
print(name)
if todof.split(".")[-1].lower() in font_ext:
os.chdir("../")
to_send = modulify(template_type, templatedir, fontdir, zipname, single_file)
os.chdir(orig_dir)
os.chdir("magiFont")
print("sending...")
flashable_in = "Magisk / TWRP (Read Instructions)" if (template_type.lower()=="omf") else "Magisk"
bot.send_document(magifonts_id, open(to_send+".zip",'rb'),caption=random.choice(file_responses)+"\nFont Name: "+zipname+"\nTemplate used: "+template_type+"\nFlashable in: "+flashable_in+"\nTime: "+strftime("%a, %d %b %Y", gmtime()))
try:
bot.send_message(magifonts_id,"Here you go! - @"+docmsg.from_user.username)
except:
bot.send_message(magifonts_id,"Here you go!")
if not str(doc.chat_id) == str(magifonts_id):
doc.reply_text("Your file has been posted in @magifonts_support")
# doc.reply_text("Checkout #submit-sample\nThanks for being a part of the awesome community!!")
os.chdir("../")
else:
doc.reply_text("invalid file type!")
os.chdir("../")
elif doc.document.file_name.split(".")[-1].lower() in zip_ext:
os.chdir("ziptodo")
doc.document.get_file().download(custom_path=doc.document.file_name)
print("file downloaded!")
extract(doc.document.file_name, remove_ext(doc.document.file_name))
print("file unzipped: ",remove_ext(doc.document.file_name))
ffiles = find("*.ttf",remove_ext(doc.document.file_name))
print(0)
origflist = deforigflist( keys.omf_all if template_type.lower() == "omf" else keys.mffm_all)
flist = origflist.copy()
if not ffiles:
print("otf")
ffiles = find("*.otf",remove_ext(doc.document.file_name))
if not ffiles:
doc.reply_text("This zip has no .ttf or .otf file... :(")
return
#print("files: ",ffiles[0])
if len(ffiles) == 1:
shutil.copyfile(ffiles[0], os.path.join("../",fontdir,"Regular.ttf"))
flist[flist.index(["Regular",False])][1] = ffiles[0]
else:
for j in range(len(fontsall)):
#print("filename..")
x = find_font(ffiles, remove_ext(fontsall[j]),remove_ext(doc.document.file_name), "filename")
if x:
if [remove_ext(name_from_dir(fontsall[j])),False] in flist:
flist[flist.index([remove_ext(name_from_dir(fontsall[j])),False])][1] = x
#print("\n\n gonna fallback \n\n")
for j in range(len(fontsall)):
if [remove_ext(name_from_dir(fontsall[j])),False] in flist:
#print("fallback")
x = find_font(ffiles, remove_ext(fontsall[j]),remove_ext(doc.document.file_name), "fontname")
if x:
#print("fallback: ",x, " for ", remove_ext(fontsall[j]))
#print("applied")
flist[flist.index([remove_ext(name_from_dir(fontsall[j])),False])][1] = x
if not template_type.lower() == "omf":
for i in range(len(ffiles)):
#for j in range(len(fontsall)):
deffonts = definefonts(flist)
if not remove_ext(fontsall[j]) in deffonts:
nearest = nearest_weight2(flist,remove_ext(fontsall[j]), deffonts)
if nearest:
x = find_font(ffiles, nearest,remove_ext(doc.document.file_name))
if x:
flist[flist.index([remove_ext(fontsall[j]),False])][1] = x
else:
x = find_font(ffiles, "Regular",remove_ext(doc.document.file_name))
if x:
flist[flist.index([remove_ext(fontsall[j]),False])][1] = x
paste_to_template(flist,"ziptodo",fontdir)
edit_module_prop(zipname,templatedir)
os.chdir("ziptodo")
processfonts(flist)
os.chdir(orig_dir)
print("magiFont/"+remove_ext(doc.document.file_name)+".zip")
shutil.make_archive("magiFont/"+zipname+"[Magifonts]", "zip",templatedir)
if os.stat("magiFont/"+zipname+"[Magifonts]"+".zip").st_size <= 20000000:
bot.send_document(magifonts_id, open("magiFont/"+zipname+"[Magifonts]"+".zip",'rb'),caption=random.choice(file_responses)+"\nFont Name: "+zipname+"\nTemplate used: "+template_type+"\nFlashable in: "+"Magisk"+"\nTime: "+strftime("%a, %d %b %Y", gmtime()))
try:
bot.send_message(magifonts_id,"Here you go! - @"+docmsg.from_user.username)
except:
bot.send_message(magifonts_id,"Here you go!")
if not (docmsg.chat_id == magifonts_id):
bot.send_message(docmsg.chat_id,"The file has been posted to @magifonts_support")
else:
bot.send_message(docmsg.chat_id,"The file is too big to send.\nTelegram has a limit of max 20mb for bots to send files...")
os.chdir("../")
else:
os.chdir("../")
doc.reply_text("Sar, sorry but I can't make this to a module. Pls gib font(ttf or otf) file/zip :(")
#os.chdir("../magiTemplate/system/fonts")
#for i in range(0,len(tfontsr)):
# shutil.copyfile(src="../../../todo/"+fname , dst=tfontsr[i])
origflist = []
def get_key(dictioary, attr):
for keys,values in dictionary.items():
if attr == keys:
return values
return False
def processfonts(fontslist, em = None, ascent = None, descent = None, linegap = None):
em = em if em else None
ascent = ascent if ascent else 1900
descent = descent if descent else -500
linegap = linegap if linegap else 0
fonts = []
defined = []
for i in fontslist:
if i[1] and i[1] not in defined:
defined.append(i[1])
print("Processing fonts...\n", defined,"\n\n")
fonts = fontslist#[find_font(defined, "Regular"), find_font(defined, "Italic")]
for i in range(len(defined)):
em = em if em else None
ascent = ascent if ascent else 1900
descent = descent if descent else -500
linegap = linegap if linegap else 0
if defined[i]:
tt = ttLib.TTFont(defined[i])
#if tt["head"].unitsPerEm >= 2040:
# tt["hhea"].ascent = 1800
#else:
# tt["hhea"].ascent = 900
if not em:
ascent = int((ascent*tt["head"].unitsPerEm)/2048)
descent = int((descent*tt["head"].unitsPerEm)/2048)
tt["hhea"].ascent = ascent
tt["OS/2"].sTypoAscender = ascent
tt["hhea"].descent = descent
tt["OS/2"].sTypoDescender = descent
tt["head"].unitsPerEm = em if em else tt["head"].unitsPerEm
if em:
tt["hhea"].ascent = ascent
tt["OS/2"].sTypoAscender = ascent
else:
if int(tt["head"].unitsPerEm) == 2048:
tt["hhea"].ascent = 1900
tt["OS/2"].sTypoAscender = 1900
if int(tt["head"].unitsPerEm) == 1000:
tt["hhea"].ascent = 900
tt["OS/2"].sTypoAscender = 900
tt["hhea"].lineGap = linegap
tt["OS/2"].sTypoLineGap = linegap
if em:
tt["hhea"].descent = descent
tt["OS/2"].sTypoDescender = descent
else:
if int(tt["head"].unitsPerEm) == 2048:
tt["hhea"].descent = -500
tt["OS/2"].sTypoDescender = -500
if int(tt["head"].unitsPerEm) == 1000:
tt["hhea"].descent = -270
tt["OS/2"].sTypoDescender = -270
#tt.saveXML("lesse")
print("fixed: ", name_from_dir(defined[i]), tt["hhea"].ascent, tt["hhea"].descent, tt["hhea"].lineGap, tt["head"].unitsPerEm)
tt.save(defined[i])
def paste_to_template(flist,src,dst):
os.chdir(orig_dir)
for i in range(len(flist)):
if flist[i][1]:
if os.path.exists(src+"/"+flist[i][1]):
shutil.copyfile(src+"/"+flist[i][1], dst+"/"+flist[i][0]+".ttf")
def modulify2(flist,src,dst,definedfonts,filedst):
os.chdir(orig_dir)
if "Regular" in definedfonts:
if len(definedfonts) == 1:
shutil.copyfile(src+"/"+flist[2][1], dst+"/Regular.ttf")
else:
for i in range(len(flist)):
if flist[i][1]:
shutil.copyfile(src+"/"+flist[i][1], dst+"/"+flist[i][0]+".ttf")
for i in range(len(flist)):
if not flist[i][1]:
shutil.copyfile(src+"/"+return_font(flist,"Regular"), dst+"/"+flist[i][0]+".ttf")
edit_module_prop(remove_ext(filedst.split("/")[-1]))