-
Notifications
You must be signed in to change notification settings - Fork 0
/
AminoBot.py
1334 lines (1064 loc) · 49.4 KB
/
AminoBot.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 sys
import os
import txt2pdf
from gtts import gTTS, lang
from json import dumps, load
from time import sleep
from string import punctuation
from random import choice, randint
from pathlib import Path
from threading import Thread
from contextlib import suppress
from unicodedata import normalize
from pdf2image import convert_from_path
from youtube_dl import YoutubeDL
from amino.client import Client
from amino.sub_client import SubClient
# Big optimisation thanks to SempreLEGIT#1378 ♥
path_lock = 'utilities/locked_commands'
path_welcome = 'utilities/welcome_message'
path_banned_words = 'utilities/banned_words'
path_picture = 'pictures'
path_sound = 'sound'
path_download = 'download'
for i in ("utilities", path_welcome, path_banned_words, path_picture, path_sound, path_download, path_lock):
Path(i).mkdir(exist_ok=True)
class BotAmino:
def __init__(self, client, community, inv: str = None):
self.client = client
self.prefix = "!"
self.lvl_min = 0
self.marche = True
if isinstance(community, int):
self.community_id = community
self.community = self.client.get_community_info(comId=self.community_id)
self.community_amino_id = self.community.aminoId
else:
self.community_amino_id = community
self.informations = self.client.get_from_code(f"http://aminoapps.com/c/{community}")
self.community_id = self.informations.json["extensions"]["community"]["ndcId"]
self.community = self.client.get_community_info(comId=self.community_id)
self.community_name = self.community.name
try:
self.community_leader_agent_id = self.community.json["agent"]["uid"]
except Exception:
self.community_leader_agent_id = "-"
try:
self.community_staff_list = self.community.json["communityHeadList"]
except Exception:
self.community_staff_list = ""
if self.community_staff_list:
self.community_leaders = [elem["uid"] for elem in self.community_staff_list if elem["role"] in (100, 102)]
self.community_curators = [elem["uid"] for elem in self.community_staff_list if elem["role"] == 101]
self.community_staff = [elem["uid"] for elem in self.community_staff_list]
if not Path(f'{path_welcome}/{self.community_amino_id}.txt').exists():
self.create_welcome_files()
if not Path(f'{path_banned_words}/{self.community_amino_id}.json').exists():
self.create_banned_files()
if not Path(f'{path_lock}/{self.community_amino_id}.json').exists():
self.create_lock_files()
self.subclient = SubClient(comId=self.community_id, profile=client.profile)
self.banned_words = self.banned_words()
self.message_bvn = self.get_welcome_message()
self.locked_command = self.get_locked_command()
self.subclient.activity_status("on")
user_list = self.subclient.get_all_users(start=0, size=25, type="recent")
self.all_users = user_list.json['userProfileCount']
def create_welcome_files(self):
with open(f'{path_welcome}/{self.community_amino_id}.txt', 'w', encoding='utf8'):
pass
def create_banned_files(self):
with open(f'{path_banned_words}/{self.community_amino_id}.json', 'w', encoding='utf8') as file_:
file_.write('[]')
def create_lock_files(self):
with open(f'{path_lock}/{self.community_amino_id}.json', 'w', encoding='utf8') as file_:
file_.write('[]')
def is_in_staff(self, uid):
return uid in self.community_staff
def is_leader(self, uid):
return uid in self.community_leaders
def is_curator(self, uid):
return uid in self.community_curators
def is_agent(self, uid):
return uid == self.community_leader_agent_id
def accept_role(self, rid: str = None, cid: str = None):
with suppress(Exception):
self.subclient.accept_host(cid)
return True
try:
self.subclient.promotion(noticeId=rid)
return True
except Exception:
return False
def get_staff(self, community):
if isinstance(community, int):
with suppress(Exception):
community = self.client.get_community_info(com_id=community)
else:
try:
informations = self.client.get_from_code(f"http://aminoapps.com/c/{community}")
except Exception:
return False
community_id = informations.json["extensions"]["community"]["ndcId"]
community = self.client.get_community_info(comId=community_id)
try:
community_staff_list = community.json["communityHeadList"]
community_staff = [elem["uid"] for elem in community_staff_list]
except Exception:
community_staff_list = ""
else:
return community_staff
def get_user_id(self, user_name):
size = self.all_users
st = 0
while size > 100:
users = self.subclient.get_all_users(start=st, size=100)
for user in users.json['userProfileList']:
if user_name == user['nickname'] or user_name == user['uid']:
return (user["nickname"], user['uid'])
for user in users.json['userProfileList']:
if user_name.lower() in user['nickname'].lower():
return (user["nickname"], user['uid'])
size -= 100
st += 100
users = self.subclient.get_all_users(start=0, size=size)
for user in users.json['userProfileList']:
if user_name.lower() == user['nickname'].lower() or user_name == user['uid']:
return (user["nickname"], user['uid'])
for user in users.json['userProfileList']:
if user_name.lower() in user['nickname'].lower():
return (user["nickname"], user['uid'])
return False
def ask_all_members(self, message, lvl: int):
size = self.all_users
st = 0
while size > 100:
users = self.subclient.get_all_users(start=st, size=100)
user_lvl_list = [user['uid'] for user in users.json['userProfileList'] if user['level'] <= lvl]
self.subclient.start_chat(userId=user_lvl_list, message=message)
size -= 100
st += 100
users = self.subclient.get_all_users(start=0, size=size)
user_lvl_list = [user['uid'] for user in users.json['userProfileList'] if user['level'] <= lvl]
self.subclient.start_chat(userId=user_lvl_list, message=message)
def ask_amino_staff(self, message):
self.subclient.start_chat(userId=self.community_staff, message=message)
def get_chat_id(self, chat: str = None):
with suppress(Exception):
return self.subclient.get_from_code(f"http://aminoapps.com/c/{chat}").objectId
val = self.subclient.get_public_chat_threads()
for title, chat_id in zip(val.title, val.chatId):
if chat == title:
return chat_id
for title, chat_id in zip(val.title, val.chatId):
if chat.lower() in title.lower() or chat == chat_id:
return chat_id
return False
def set_prefix(self, prefix: str):
self.prefix = prefix
def stop_instance(self):
self.marche = False
def set_welcome_message(self, message: str):
with open(f"{path_welcome}/{self.community_amino_id}.txt", "w", encoding="utf8") as file_:
file_.write(message)
self.message_bvn = message
def get_welcome_message(self):
with open(f"{path_welcome}/{self.community_amino_id}.txt", "r", encoding="utf8") as file_:
return file_.read()
def add_locked_command(self, list_: list):
self.locked_command.extend(list_)
with open(f"{path_lock}/{self.community_amino_id}.json", "w", encoding="utf8") as file_:
file_.write(dumps(self.locked_command, sort_keys=False, indent=4))
def remove_locked_command(self, list_: list):
for elem in list_:
if elem in self.locked_command:
self.locked_command.remove(elem)
with open(f"{path_lock}/{self.community_amino_id}.json", "w", encoding="utf8") as file_:
file_.write(dumps(self.locked_command, sort_keys=False, indent=4))
def get_locked_command(self):
with open(f"{path_lock}/{self.community_amino_id}.json", "r", encoding="utf8") as file_:
return load(file_)
def banned_words(self):
with open(f"{path_banned_words}/{self.community_amino_id}.json", "r", encoding="utf8") as file_:
return [elem.lower() for elem in load(file_)]
def add_banned_words(self, list_: list):
self.banned_words.extend(list_)
with open(f"{path_banned_words}/{self.community_amino_id}.json", "w", encoding="utf8") as file_:
file_.write(dumps(self.banned_words, sort_keys=False, indent=4))
def remove_banned_words(self, list_: list):
for elem in list_:
if elem in self.banned_words:
self.banned_words.remove(elem)
with open(f"{path_banned_words}/{self.community_amino_id}.json", "w", encoding="utf8") as file_:
file_.write(dumps(self.banned_words, sort_keys=False, indent=4))
def leave_community(self):
self.client.leave_community(comId=self.community_id)
self.marche = False
for elem in self.subclient.get_public_chat_threads().chatId:
with suppress(Exception):
self.subclient.leave_chat(elem)
def check_new_member(self):
new_list = self.subclient.get_all_users()
new_member = [elem["uid"] for elem in new_list.json["userProfileList"]]
for elem in new_member:
try:
val = self.subclient.get_wall_comments(userId=elem, sorting='newest').commentId
except Exception:
val = True
if not val:
with suppress(Exception):
self.subclient.comment(message=self.message_bvn, userId=elem)
self.all_users += 1
def get_member_level(self, uid):
return self.subclient.get_user_info(userId=uid).level
def is_level_good(self, uid):
return self.subclient.get_user_info(userId=uid).level > self.lvl_min
def get_member_titles(self, uid):
try:
return self.subclient.get_user_info(userId=uid).customTitles
except Exception:
return False
def get_member_info(self, uid):
return self.subclient.get_user_info(userId=uid)
def get_message_level(self, level: int):
return f"You need the level {level} to do this command"
def delete_message(self, chatId: str, messageId: str, reason: str = "Clear", asStaff: bool = False):
self.subclient.delete_message(chatId, messageId, asStaff, reason)
def send_message(self, chatId: str = None, message: str = "None", messageType: str = None, file: str = None, fileType: str = None, replyTo: str = None, mentionUserIds: str = None):
self.subclient.send_message(chatId=chatId, message=message, file=file, fileType=fileType, replyTo=replyTo, messageType=messageType, mentionUserIds=mentionUserIds)
def join_chat(self, chat: str, chatId: str = None):
chat = chat.replace("http:aminoapps.com/p/", "")
if not chat:
with suppress(Exception):
self.subclient.join_chat(chatId)
return ""
with suppress(Exception):
chati = self.subclient.get_from_code(f"http://aminoapps.com/c/{chat}").objectId
self.subclient.join_chat(chati)
return chat
chats = self.subclient.get_public_chat_threads()
for title, chat_id in zip(chats.title, chats.chatId):
if chat == title:
self.subclient.join_chat(chat_id)
return title
chats = self.subclient.get_public_chat_threads()
for title, chat_id in zip(chats.title, chats.chatId):
if chat.lower() in title.lower() or chat == chat_id:
self.subclient.join_chat(chat_id)
return title
return False
def get_chats(self):
return self.subclient.get_public_chat_threads()
def join_all_chat(self):
for elem in self.subclient.get_public_chat_threads().chatId:
with suppress(Exception):
self.subclient.join_chat(elem)
def leave_chat(self, chat: str):
self.subclient.leave_chat(chat)
def leave_all_chats(self):
for elem in self.subclient.get_public_chat_threads().chatId:
with suppress(Exception):
self.subclient.leave_chat(elem)
def follow_user(self, uid):
self.subclient.follow(userId=[uid])
def unfollow_user(self, uid):
self.subclient.unfollow(userId=uid)
def add_title(self, uid, title: str, color: str = "#999999"):
member = self.get_member_titles(uid)
tlist = []
clist = []
with suppress(Exception):
tlist = [elem['title'] for elem in member]
clist = [elem['color'] for elem in member]
tlist.append(title)
clist.append(color)
with suppress(Exception):
self.subclient.edit_titles(uid, tlist, clist)
return True
def remove_title(self, uid, title: str):
member = self.get_member_titles(uid)
tlist = []
clist = []
for elem in member:
tlist.append(elem["title"])
clist.append(elem["color"])
if title in tlist:
nb = tlist.index(title)
tlist.pop(nb)
clist.pop(nb)
self.subclient.edit_titles(uid, tlist, clist)
return True
def passive(self):
i = 59
o = 0
activities = ["!cookie for cookies", "Hello everyone!", "!help for help"]
while self.marche:
if i >= 60:
if self.message_bvn:
self.check_new_member()
with suppress(Exception):
self.subclient.activity_status('on')
self.subclient.edit_profile(content=activities[o])
i = 0
o += 1
if o > len(activities)-1:
o = 0
i += 1
sleep(1)
def run(self):
Thread(target=self.passive).start()
def is_it_bot(uid):
return uid == botId
def is_it_me(uid):
return uid in ('2137891f-82b5-4811-ac74-308d7a46345b', 'fa1f3678-df94-4445-8ec4-902651140841',
'f198e2f4-603c-481a-ab74-efd0f688f666')
def is_it_admin(uid):
return uid in perms_list
def join_community(comId: str = None, inv: str = None):
with suppress(Exception):
client.join_community(comId=comId, invitationId=inv)
return 1
if inv:
with suppress(Exception):
client.request_join_community(comId=comId, message='Cookie for everyone!!')
return 2
def join_amino(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
invit = None
if taille_commu >= 20 and not (is_it_me(authorId) or is_it_admin(authorId)):
subClient.send_message(chatId, "The bot has joined too many communities!")
return
staff = subClient.get_staff(message)
if not staff:
subClient.send_message(chatId, "Wrong amino ID!")
return
if authorId not in staff and not is_it_me(authorId):
subClient.send_message(chatId, "You need to be in the community's staff!")
return
try:
test = message.strip().split()
amino_c = test[0]
invit = test[1]
invit = invit.replace("http://aminoapps.com/invite/", "")
except Exception:
amino_c = message
invit = None
try:
val = subClient.client.get_from_code(f"http://aminoapps.com/c/{amino_c}")
comId = val.json["extensions"]["community"]["ndcId"]
except Exception:
val = ""
isJoined = val.json["extensions"]["isCurrentUserJoined"]
if not isJoined:
join_community(comId, invit)
val = client.get_from_code(f"http://aminoapps.com/c/{amino_c}")
isJoined = val.json["extensions"]["isCurrentUserJoined"]
if isJoined:
communaute[comId] = BotAmino(client=client, community=message)
communaute[comId].run()
subClient.send_message(chatId, "Joined!")
return
subClient.send_message(chatId, "Waiting for join!")
return
else:
subClient.send_message(chatId, "Allready joined!")
return
subClient.send_message(chatId, "Waiting for join!")
def title(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(botId):
color = None
try:
elem = message.strip().split("color=")
message, color = elem[0], elem[1].strip()
if not color.startswith("#"):
color = "#"+color
val = subClient.add_title(authorId, message, color)
except Exception:
val = subClient.add_title(authorId, message)
if val:
subClient.send_message(chatId, f"The titles of {author} has changed")
else:
subClient.send_message(chatId, subClient.get_message_level(subClient.lvl_min))
def cookie(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
subClient.send_message(chatId, f"Here is a cookie for {author} 🍪")
def ramen(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
subClient.send_message(chatId, f"Here are some ramen for {author} 🍜")
def dice(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if not message:
subClient.send_message(chatId, f"🎲 -{randint(1, 20)},(1-20)- 🎲")
return
with suppress(Exception):
pt = message.split('d')
val = ''
cpt = 0
if int(pt[0]) > 20:
pt[0] = 20
if int(pt[1]) > 1000000:
pt[1] = 1000000
for _ in range(int(pt[0])):
ppt = randint(1, int(pt[1]))
cpt += ppt
val += str(ppt)+" "
print(f'🎲 -{cpt},[ {val}](1-{pt[1]})- 🎲')
subClient.send_message(chatId, f'🎲 -{cpt},[ {val}](1-{pt[1]})- 🎲')
def join(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
val = subClient.join_chat(message, chatId)
if val or val == "":
subClient.send_message(chatId, f"Chat {val} joined".strip())
else:
subClient.send_message(chatId, "No chat joined")
def join_all(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(authorId) or is_it_me(authorId):
if subClient.join_all_chat():
subClient.send_message(chatId, "All chat joined")
def leave_all(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(authorId) or is_it_me(authorId) or is_it_admin(authorId):
subClient.send_message(chatId, "Leaving all chat...")
subClient.leave_all_chats()
def leave(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if message and (is_it_me(authorId) or is_it_admin(authorId)):
chat_ide = subClient.get_chat_id(message)
if chat_ide:
chatId = chat_ide
subClient.leave_chat(chatId)
def clear(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if (subClient.is_in_staff(authorId) or is_it_me(authorId) or is_it_admin(authorId)) and subClient.is_in_staff(botId):
size = 1
msg = ""
val = ""
subClient.delete_message(chatId, messageId, asStaff=True)
if "chat=" in message and is_it_me(authorId):
chat_name = message.rsplit("chat=", 1).pop()
chat_ide = subClient.get_chat_id(chat_name)
if chat_ide:
chatId = chat_ide
message = " ".join(message.strip().split()[:-1])
with suppress(Exception):
size = int(message.strip().split(' ').pop())
msg = ' '.join(message.strip().split(' ')[:-1])
if size > 50 and not is_it_me(authorId):
size = 50
if msg:
try:
val = subClient.get_user_id(msg)
except Exception:
val = ""
messages = subClient.subclient.get_chat_messages(chatId=chatId, size=size)
for message, authorId in zip(messages.messageId, messages.author.userId):
if not val:
subClient.delete_message(chatId, message, asStaff=True)
elif authorId == val[1]:
subClient.delete_message(chatId, message, asStaff=True)
def spam(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
try:
size = int(message.strip().split().pop())
msg = " ".join(message.strip().split()[:-1])
except ValueError:
size = 1
msg = message
if size > 10 and not (is_it_me(authorId) or is_it_admin(authorId)):
size = 10
for _ in range(size):
with suppress(Exception):
subClient.send_message(chatId, msg)
def mention(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if "chat=" in message and is_it_me(authorId):
chat_name = message.rsplit("chat=", 1).pop()
chat_ide = subClient.get_chat_id(chat_name)
if chat_ide:
chatId = chat_ide
message = " ".join(message.strip().split()[:-1])
try:
size = int(message.strip().split().pop())
message = " ".join(message.strip().split()[:-1])
except ValueError:
size = 1
val = subClient.get_user_id(message)
if not val:
subClient.send_message(chatId=chatId, message="Username not found")
return
if size > 5 and not (is_it_me(authorId) or is_it_admin(authorId)):
size = 5
if val:
for _ in range(size):
with suppress(Exception):
subClient.send_message(chatId=chatId, message=f"@{val[0]}", mentionUserIds=[val[1]])
def mentionall(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(authorId) or is_it_me(authorId) or is_it_admin(authorId):
if message and is_it_me(authorId):
chat_ide = subClient.get_chat_id(message)
if chat_ide:
chatId = chat_ide
message = " ".join(message.strip().split()[:-1])
try:
size = int(message.strip().split().pop())
message = " ".join(message.strip().split()[:-1])
except ValueError:
size = 1
if size > 5 and not (is_it_me(authorId) or is_it_admin(authorId)):
size = 5
mention = [userId for userId in subClient.subclient.get_chat_users(chatId=chatId).userId]
test = "".join(["" for user in subClient.subclient.get_chat_users(chatId=chatId).userId])
for _ in range(size):
with suppress(Exception):
subClient.send_message(chatId=chatId, message=f"@everyone{test}", mentionUserIds=mention)
def msg(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
value = 0
size = 1
ment = None
with suppress(Exception):
subClient.delete_message(chatId, messageId, asStaff=True)
if "chat=" in message and is_it_me(authorId):
chat_name = message.rsplit("chat=", 1).pop()
chat_ide = subClient.get_chat_id(chat_name)
if chat_ide:
chatId = chat_ide
message = " ".join(message.strip().split()[:-1])
try:
size = int(message.split().pop())
message = " ".join(message.strip().split()[:-1])
except ValueError:
size = 0
try:
value = int(message.split().pop())
message = " ".join(message.strip().split()[:-1])
except ValueError:
value = size
size = 1
if not message and value == 1:
message = f"@{author}"
ment = authorId
if size > 10 and not (is_it_me(authorId) or is_it_admin(authorId)):
size = 10
for _ in range(size):
with suppress(Exception):
subClient.send_message(chatId=chatId, message=f"{message}", messageType=value, mentionUserIds=ment)
def add_banned_word(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(authorId) or is_it_me(authorId) or is_it_admin(authorId):
if not message or message in subClient.banned_words:
return
try:
message = message.lower().strip().split()
except Exception:
message = [message.lower().strip()]
subClient.add_banned_words(message)
subClient.send_message(chatId, "Banned word list updated")
def remove_banned_word(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(authorId) or is_it_me(authorId) or is_it_admin(authorId):
if not message:
return
try:
message = message.lower().strip().split()
except Exception:
message = [message.lower().strip()]
subClient.remove_banned_words(message)
subClient.send_message(chatId, "Banned word list updated")
def banned_word_list(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
val = ""
if subClient.banned_words:
for elem in subClient.banned_words:
val += elem+"\n"
else:
val = "No words in the list"
subClient.send_message(chatId, val)
def sw(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(authorId) or is_it_me(authorId) or is_it_admin(authorId):
subClient.set_welcome_message(message)
subClient.send_message(chatId, "Welcome message changed")
def get_chats(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
val = subClient.get_chats()
for title, _ in zip(val.title, val.chatId):
subClient.send_message(chatId, title)
def chat_id(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if is_it_me(authorId) or is_it_admin(authorId):
val = subClient.get_chats()
for title, chat_id in zip(val.title, val.chatId):
if message.lower() in title.lower():
subClient.send_message(chatId, f"{title} | {chat_id}")
def leave_amino(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if subClient.is_in_staff(authorId) or is_it_me(authorId) or is_it_admin(authorId):
subClient.send_message(chatId, "Leaving the amino!")
subClient.leave_community()
del communaute[subClient.community_id]
def prank(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
with suppress(Exception):
subClient.delete_message(chatId, messageId, asStaff=True)
transactionId = "5b3964da-a83d-c4d0-daf3-6e259d10fbc3"
old_chat = None
if message and is_it_me(authorId):
chat_ide = subClient.get_chat_id(message)
if chat_ide:
old_chat = chatId
chatId = chat_ide
for _ in range(10):
subClient.subclient.send_coins(coins=500, chatId=chatId, transactionId=transactionId)
if old_chat:
chatId = old_chat
subClient.send_message(chatId, "Done")
def image(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
val = os.listdir("pictures")
if val:
file = choice(val)
with suppress(Exception):
with open(path_picture+file, 'rb') as fp:
subClient.send_message(chatId, file=fp, fileType="image")
else:
subClient.send_message(chatId, "Error! No file")
def audio(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
val = os.listdir("sound")
if val:
file = choice(val)
with suppress(Exception):
with open(path_sound+file, 'rb') as fp:
subClient.send_message(chatId, file=fp, fileType="audio")
else:
subClient.send_message(chatId, "Error! No file")
def telecharger(url):
music = None
if ("=" in url and "/" in url and " " not in url) or ("/" in url and " " not in url):
if "=" in url and "/" in url:
music = url.rsplit("=", 1)[-1]
elif "/" in url:
music = url.rsplit("/")[-1]
if music in os.listdir(path_sound):
return music
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'extract-audio': True,
'outtmpl': f"{path_download}/{music}.webm",
}
with YoutubeDL(ydl_opts) as ydl:
video_length = ydl.extract_info(url, download=True).get('duration')
ydl.cache.remove()
url = music+".mp3"
return url, video_length
return False, False
def decoupe(musical, temps):
size = 170
with open(musical, "rb") as fichier:
nombre_ligne = len(fichier.readlines())
if temps < 180 or temps > 540:
return False
decoupage = int(size*nombre_ligne / temps)
t = 0
file_list = []
for a in range(0, nombre_ligne, decoupage):
b = a + decoupage
if b >= nombre_ligne:
b = nombre_ligne
with open(musical, "rb") as fichier:
lignes = fichier.readlines()[a:b]
with open(musical.replace(".mp3", "PART"+str(t)+".mp3"), "wb") as mus:
for ligne in lignes:
mus.write(ligne)
file_list.append(musical.replace(".mp3", "PART"+str(t)+".mp3"))
t += 1
return file_list
def convert(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
music, size = telecharger(message)
if music:
music = f"{path_download}/{music}"
val = decoupe(music, size)
if not val:
try:
with open(music, 'rb') as fp:
subClient.send_message(chatId, file=fp, fileType="audio")
except Exception:
subClient.send_message(chatId, "Error! File too heavy (9 min max)")
os.remove(music)
return
os.remove(music)
for elem in val:
with suppress(Exception):
with open(elem, 'rb') as fp:
subClient.send_message(chatId, file=fp, fileType="audio")
os.remove(elem)
return
subClient.send_message(chatId, "Error! Wrong link")
def helper(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if not message:
subClient.send_message(chatId, helpMsg)
elif message == "msg":
subClient.send_message(chatId, help_message)
elif message == "ask":
subClient.send_message(chatId, helpAsk)
else:
subClient.send_message(chatId, "No help is available for this command")
def reboot(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if is_it_me(authorId) or is_it_admin(authorId):
subClient.send_message(chatId, "Restarting Bot")
os.execv(sys.executable, ["None", os.path.basename(sys.argv[0])])
def stop(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if is_it_me(authorId) or is_it_admin(authorId):
subClient.send_message(chatId, "Stopping Bot")
os.execv(sys.executable, ["None", "None"])
def uinfo(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if is_it_me(authorId) or is_it_admin(authorId):
val = ""
val2 = ""
uid = ""
with suppress(Exception):
val = subClient.client.get_user_info(message)
with suppress(Exception):
val2 = subClient.subclient.get_user_info(message)
if not val:
uid = subClient.get_user_id(message)
if uid:
val = subClient.client.get_user_info(uid[1])
val2 = subClient.subclient.get_user_info(uid[1])
print(val, val2)
if not val:
with suppress(Exception):
lin = subClient.client.get_from_code(f"http://aminoapps.com/u/{message}").json["extensions"]["linkInfo"]["objectId"]
val = subClient.client.get_user_info(lin)
with suppress(Exception):
val2 = subClient.subclient.get_user_info(lin)
with suppress(Exception):
with open("elJson.json", "w") as file_:
file_.write(dumps(val.json, sort_keys=False, indent=4))
with suppress(Exception):
with open("elJson2.json", "w") as file_:
file_.write(dumps(val2.json, sort_keys=False, indent=4))
for i in ("elJson.json", "elJson2.json"):
if os.path.getsize(i):
txt2pdf.callPDF(i, "result.pdf")
pages = convert_from_path('result.pdf', 150)
file = 'result.jpg'
for page in pages:
page.save(file, 'JPEG')
with open(file, 'rb') as fp:
subClient.send_message(chatId, file=fp, fileType="image")
os.remove(file)
os.remove("result.pdf")
if not os.path.getsize("elJson.json") and not os.path.getsize("elJson.json"):
subClient.send_message(chatId, "Error!")
def cinfo(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if is_it_me(authorId) or is_it_admin(authorId):
val = ""
with suppress(Exception):
val = subClient.client.get_from_code(f"http://aminoapps.com/c/{message}")
with suppress(Exception):
with open("elJson.json", "w") as file_:
file_.write(dumps(val.json, sort_keys=False, indent=4))
if os.path.getsize("elJson.json"):
txt2pdf.callPDF("elJson.json", "result.pdf")
pages = convert_from_path('result.pdf', 150)
for page in pages:
file = 'result.jpg'
page.save(file, 'JPEG')
with open(file, 'rb') as fp:
subClient.send_message(chatId, file=fp, fileType="image")
os.remove(file)
os.remove("result.pdf")
if not os.path.getsize("elJson.json"):
subClient.send_message(chatId, "Error!")
def sendinfo(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
if (is_it_admin(authorId) or is_it_me(authorId)) and message != "":
arguments = message.strip().split()
for eljson in ('elJson.json', 'elJson2.json'):
if Path(eljson).exists():
arg = arguments.copy()
with open(eljson, 'r') as file:
val = load(file)
try:
memoire = val[arg.pop(0)]
except Exception:
subClient.send_message(chatId, 'Wrong key!')
if arg:
for elem in arg:
try:
memoire = memoire[str(elem)]
except Exception:
subClient.send_message(chatId, 'Wrong key 1!')
subClient.send_message(chatId, memoire)
def get_global(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
val = subClient.get_user_id(message)[1]
if val:
ide = subClient.client.get_user_info(val).aminoId
subClient.send_message(chatId, f"http://aminoapps.com/u/{ide}")
else:
subClient.send_message(chatId, "Error!")
def follow(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
subClient.follow_user(authorId)
subClient.send_message(chatId, "Now following you!")
def unfollow(subClient=None, chatId=None, authorId=None, author=None, message=None, messageId=None):
subClient.unfollow_user(authorId)