-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpycon-main.py
919 lines (701 loc) · 25.1 KB
/
pycon-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
from pyrogram import Client, emoji, filters, enums
from pyrogram.types import (
CallbackQuery,
Chat,
ChatPermissions,
InlineKeyboardMarkup,
InlineKeyboardButton,
Message,
)
import asyncio
from datetime import datetime, timedelta
from random import sample, shuffle
app = Client("pycontzbot")
########## CUSTOM FILTER TO IDENTIFY ADMINS ##########
async def check_admin_filter(_, client: Client, message: Message):
user = await client.get_chat_member(
chat_id=message.chat.id, user_id=message.from_user.id
)
return bool(
user.status == enums.ChatMemberStatus.OWNER
or user.status == enums.ChatMemberStatus.ADMINISTRATOR
)
check_admin = filters.create(check_admin_filter)
########## CAPTCHA AND WELCOME MESSAGE ##########
CAPTCHA_EMOJIS = [
"SKULL",
"ALARM_CLOCK",
"WATERMELON",
"SAFETY_PIN",
"ROLL_OF_PAPER",
"SPOON",
"CUSTARD",
"SNAIL",
"BEER_MUG",
"COFFIN",
"BIRTHDAY_CAKE",
"LOCKED",
"MICROSCOPE",
"TROPHY",
"BOMB",
"LOBSTER",
"PIZZA",
"HAMBURGER",
"GOAT",
"ROSE",
"BANANA",
"BASEBALL",
"CAMERA",
"DOG",
"MAGNET",
"RAINBOW",
"TOMATO",
"SNOWMAN",
"BONE",
]
MENTION = "[{}](tg://user?id={})"
MESSAGE = (
"Welcome {}! Please select the emojis you see below. You are allowed 3 mistakes."
)
@app.on_message(filters.new_chat_members)
async def welcome(client, message):
global captcha
await message.delete()
user_id = ",".join([str(u.id) for u in message.new_chat_members])
user_id = int(user_id)
await client.restrict_chat_member(message.chat.id, user_id, ChatPermissions())
new_members = [MENTION.format(i.first_name, i.id) for i in message.new_chat_members]
message_text = MESSAGE.format(", ".join(new_members))
list_of_emojis = [e for e in sample(CAPTCHA_EMOJIS, 9)]
list_of_emojis = [emoji.__getattribute__(e) for e in list_of_emojis]
captcha = [e for e in sample(list_of_emojis, 3)]
captcha_text = " ".join(captcha)
message_to_reply = await message.reply(
f"{message_text}\n\n\n{captcha_text}",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
list_of_emojis[0],
callback_data=f"{list_of_emojis[0]}.captcha",
),
InlineKeyboardButton(
list_of_emojis[1],
callback_data=f"{list_of_emojis[1]}.captcha",
),
InlineKeyboardButton(
list_of_emojis[2],
callback_data=f"{list_of_emojis[2]}.captcha",
),
],
[
InlineKeyboardButton(
list_of_emojis[3],
callback_data=f"{list_of_emojis[3]}.captcha",
),
InlineKeyboardButton(
list_of_emojis[4],
callback_data=f"{list_of_emojis[4]}.captcha",
),
InlineKeyboardButton(
list_of_emojis[5],
callback_data=f"{list_of_emojis[5]}.captcha",
),
],
[
InlineKeyboardButton(
list_of_emojis[6],
callback_data=f"{list_of_emojis[6]}.captcha",
),
InlineKeyboardButton(
list_of_emojis[7],
callback_data=f"{list_of_emojis[7]}.captcha",
),
InlineKeyboardButton(
list_of_emojis[8],
callback_data=f"{list_of_emojis[8]}.captcha",
),
],
]
),
)
captcha_checker = set() # will confirm our captcha
number_of_tries = 0 # kick user if it reaches 3
@app.on_callback_query(filters.regex(r"captcha"))
async def captcha_function(client: Client, query):
global captcha_checker, number_of_tries
replier = query.from_user.id # one who answered the captcha
target = query.message.entities[0].user.id # target of the captcha
emoji_response = query.data.split(".")[0]
if replier != target:
await query.answer("This message is not for you!", show_alert=True)
return
if emoji_response in captcha:
captcha_checker.add(emoji_response)
await query.answer(text="Correct!", cache_time=1)
if len(captcha_checker) == len(captcha):
new_welcome_message = await query.edit_message_text(
f"Welcome to Pycon Tanzania [{query.from_user.first_name}](tg://user?id={target}).\n\nPlease Follow the Rules of the Groupchat. Click **`Help`** below for more information.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Help",
callback_data=f"helpmenu",
),
]
]
),
)
await client.restrict_chat_member(
query.message.chat.id,
target,
ChatPermissions(
can_send_messages=True,
can_send_media_messages=True,
can_send_other_messages=True,
can_add_web_page_previews=True,
can_send_polls=True,
can_change_info=True,
can_invite_users=True,
can_pin_messages=True,
),
)
captcha_checker = set()
number_of_tries = 0
elif number_of_tries == 2:
await query.answer("You have been banned for 60 seconds", show_alert=True)
await asyncio.sleep(5)
kicker = await client.ban_chat_member(
query.message.chat.id,
target,
datetime.now() + timedelta(seconds=60), # Kick user from chat for a minute
)
await kicker.delete()
await query.message.delete()
captcha_checker = set()
number_of_tries = 0
elif emoji_response not in captcha:
await query.answer(text="Wrong!", cache_time=1)
number_of_tries += 1
@app.on_message(filters.left_chat_member)
async def member_left_group(client, message):
await message.delete()
########## HELP COMMAND ##########
@app.on_message(
filters.command(commands="help", prefixes=["/", "#", "!"], case_sensitive=False)
)
@app.on_callback_query(filters.regex(r"helpmenu"))
async def help_menu_function(client, message):
to_respond = "reply" if type(message) == Message else "edit_message_text"
if to_respond == "edit_message_text":
await message.answer()
if to_respond == "reply":
await message.delete()
await getattr(message, to_respond)(
text="Welcome To Pycon Tanzania",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Rules",
callback_data="rules.helpresponse",
),
InlineKeyboardButton(
"About",
callback_data="about.helpresponse",
),
],
[
InlineKeyboardButton(
"Events",
callback_data="events.helpresponse",
),
InlineKeyboardButton(
"Announcements",
callback_data="announcementsmenu",
),
],
[
InlineKeyboardButton(
"Resources",
callback_data="resources.helpresponse",
),
InlineKeyboardButton(
"Administrator",
callback_data="adminmenu",
),
],
]
),
)
RESOURCES = """
**Here are some good resources to learn Python:**
• [Official Tutorial](https://docs.python.org/3/tutorial/index.html) - Book
• [Dive Into Python 3](https://www.diveinto.org/python3/table-of-contents.html) - Book
• [Hitchhiker's Guide!](https://docs.python-guide.org) - Book
• [Learn Python](https://www.learnpython.org/) - Interactive
• [Project Python](http://projectpython.net) - Interactive
• [Python Video Tutorials](https://www.youtube.com/playlist?list=PL-osiE80TeTt2d9bfVyTiXJA-UTHn6WwU) - Video
• [MIT OpenCourseWare](http://ocw.mit.edu/6-0001F16) - Course
• @PythonRes - Channel
"""
RULES = """
**Rules of the Group:**
• All conversations must be in English or Kiswahili
• Business advertisements without proper authorization will lead to a ban
• Any Forex, Crypto, Trading and related content will lead to a ban
• Disrespect will not be tolerated in the group chat
"""
HELP_SWITCHER = {
"rules": RULES,
"about": "A Community of Professionals, Entrepreneurs, Scientists & Students Collaborating to Innovate & Advance Python Language Usage. Contact [email protected] or visit our website: https://pycon.or.tz",
"events": "Our next Pycon Meeting will be in Zanzibar on Dec 2022. Stay tuned for updates",
"announcements": "There are no announcements at the moment",
"resources": RESOURCES,
}
@app.on_callback_query(filters.regex(r"helpresponse"))
async def help_menu_response(client: Client, query: CallbackQuery):
queried = query.data.split(".")[0]
await query.answer()
await query.edit_message_text(
text=HELP_SWITCHER[queried],
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Back To Menu",
callback_data=f"helpmenu",
),
]
]
),
)
@app.on_callback_query(filters.regex(r"adminmenu"))
async def admin_help_function(client: Client, query: CallbackQuery):
queried = query.data.split(".")[0]
await query.answer()
await query.edit_message_text(
text="Here are the Administrative Commands:",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Mute",
callback_data="mute.adminresponse",
),
InlineKeyboardButton(
"Ban",
callback_data="ban.adminresponse",
),
],
[
InlineKeyboardButton(
"Delete",
callback_data="delete.adminresponse",
),
InlineKeyboardButton(
"Promote",
callback_data="promote.adminresponse",
),
],
[
InlineKeyboardButton(
"Back To Menu",
callback_data=f"helpmenu",
),
],
]
),
)
ADMIN_HELP_SWITCHER = {
"mute": "Respond to a chat with **`/mute`** to mute the sender",
"ban": "Respond to a chat with **`/ban`** to ban the sender",
"delete": "Respond to a chat with **`/delete`** to delete the message",
"promote": "Respond to a chat with **`/promote`** to give the sender admin privileges",
}
@app.on_callback_query(filters.regex(r"adminresponse"))
async def admin_response_function(client: Client, query: CallbackQuery):
queried = query.data.split(".")[0]
await query.answer()
await query.edit_message_text(
text=ADMIN_HELP_SWITCHER[queried],
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Back",
callback_data="adminmenu",
),
InlineKeyboardButton(
"Help Menu",
callback_data="helpmenu",
),
]
]
),
)
############ ANNOUNCEMENTS ##################
@app.on_callback_query(filters.regex(r"announcementsmenu"))
async def announcements_menu_function(client: Client, query: CallbackQuery):
await query.answer()
await query.edit_message_text(
text="PyCon Tanzania Starts on 5th December",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Topics",
callback_data="topics",
),
InlineKeyboardButton(
"Speakers",
callback_data="speakers",
),
],
[
InlineKeyboardButton(
"Events",
callback_data="events",
),
InlineKeyboardButton(
"Back To Menu",
callback_data=f"helpmenu",
),
],
]
),
)
AllTopics = """
*AI Transformers and Self-Attention*
```by Isack Odero```
*Analysing the Development of Cervical Cancer Using ML*
```by Eng. Saida Nyasasi```
*Explainability for Natural Language Processing*
```by Antony Mipawa```
*Fun Simple Python Programs*
```by Monalisa Mbilinyi```
*Geospatial Data Analysis Using Python*
```by Khairiya Masoud```
*NLP for African Languages and Building Chatbots with Sarufi*
```by Antony Mipawa and Kalebu Gwalugano```
*Network Analysis Made Simple Using NetworkX*
```by Mridul Seth```
*Poultry Disease Diagnosis with Deep Learning*
```by Dr. Dina Machuve```
*Predicting Fake News Using GCN*
```by Zephania Reuben```
*Programming Embedded IoT with Python*
```by Mahir Nasor```
*Python Language Foundation*
```by Abubakar Omar and Joan Henry```
*Python Web Development with Django*
```by Lugano Ngulwa```
*Species Determination of Malaria Vectors Using AI*
```by Issa Mshani```
*WebScrapping of Consumer Prices*
```by Alban Manishimwe```
*WebScrapping with Beautiful Soup*
```by Nathaniel Mwaipopo```
*Why is Data Science Necessary, Why Now?*
```by Hassan Kibirige```
"""
@app.on_callback_query(filters.regex(r"topics"))
async def topics(client: Client, query: CallbackQuery):
await query.answer()
await query.edit_message_text(
text=f"The following will be discussed:\n\n{AllTopics}",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Back",
callback_data="announcementsmenu",
),
InlineKeyboardButton(
"Back To Menu",
callback_data=f"helpmenu",
),
],
]
),
)
AllSpeakers = """
*Abubakar Omar*
```Python Teacher```
*Alban Manishimwe*
```Uganda Bureau of Statistics```
*Antony Mipawa*
```Software Developer Neurotech```
*Dr. Dina Machuve*
```Co-Founder DevData Analytics```
*Eng. Saida Nyasasi*
```ED & Researcher iSuite```
*Hassan Kibirige*
```Author of Plotnine Python Library```
*Isack Odero*
```Founder NileAGI```
*Issa Mshani*
```Research Scientist Ifakara Health Institute```
*Joan Henry*
```Software Developer```
*Kalebu Gwalugano*
```Founder Neurotech```
*Khairiya Masoud*
```State University of Zanzibar```
*Lugano Ngulwa*
```Software Developer```
*Mahir Nasor*
```Z TechHub Zanzibar```
*Monalisa Mbilinyi*
```Python Software Developer```
*Mridul Seth*
```Python Software Developer```
*Nathaniel Mwaipopo*
```Python Software Developer```
*Zephania Reuben*
"""
@app.on_callback_query(filters.regex(r"speakers"))
async def speakers(client: Client, query: CallbackQuery):
await query.answer()
await query.edit_message_text(
text=f"The following will be the our event speakers:\n\n{AllSpeakers}",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Back",
callback_data="announcementsmenu",
),
InlineKeyboardButton(
"Back To Menu",
callback_data=f"helpmenu",
),
],
]
),
)
AllEvents = """
5th | December | 2022
09:00-09:30: Opening Keynotes
09:30-10:30: Loren Crary
10:30-10:45: Break
10:45-11:15: Foundations of Python Bootcamp
11:15-11:45: Foundations of Python Bootcamp
11:45-13:15: Lunch
13:15-13:45: Django Web Development
13:45-14:15: Django Web Development
14:15-14:30: Break
14:30-15:00: Network Analysis Made Simple Using NetworkX
15:00-15:30: Network Analysis Made Simple Using NetworkX
15:30-15:45: Break
15:45-16:15: Hackathon - NLP for African Languages Building Chatbots with Sarufi
16:15-16:45: Hackathon - NLP for African Languages Building Chatbots with Sarufi
16:45-17:00: PyCon Social Event
6th | December | 2022
09:00-09:30: Hackathon - NLP for African Languages Building Chatbots with Sarufi
09:30-10:30: Tigo Hackathon
10:30-10:45: Break
10:45-11:15: Hackathon - NLP for African Languages Building Chatbots with Sarufi
11:15-11:45: Tigo Hackathon
11:45-13:15: Lunch
13:15-13:45: Hackathon - NLP for African Languages Building Chatbots with Sarufi
13:45-14:15: Tigo Hackathon
14:15-14:30: Break
14:30-15:00: Hackathon - NLP for African Languages Building Chatbots with Sarufi
15:00-15:30: Tigo Hackathon
15:30-15:45: Break
15:45-16:15: Hackathon - NLP for African Languages Building Chatbots with Sarufi
16:15-16:45: Hackathon Birds of Feather (BOF)
16:45-17:00: PyCon Social Event
7th | December | 2022
09:00-09:30: Why is Data Science Necessary, Why Now?
09:30-10:30: Geospatial Data Analysis Using Python
10:30-10:45: Break
10:45-11:15: Species Determination of Malaria Vectors Using AI
11:15-11:45: Python Development Tigo
11:45-13:15: Lunch
13:15-13:45: Analysing the Development of Cervical Cancer Using ML
13:45-14:15: Explainability for Natural Language Processing
14:15-14:30: Break
14:30-15:00: Predicting Fake News Using GCN
15:00-15:30: Poultry Disease Diagnosis with Deep Learning
15:30-15:45: Break
15:45-16:15: AI Transformers and Self-Attention
16:15-16:45: Panel Discussion on DS/ML/AI
16:45-17:00: PyCon Social Event
8th | December | 2022
09:00-09:30: Fun Simple Python Programs
09:30-10:30: Python Development Tigo
10:30-10:45: Break
10:45-11:15: Programming Embedded IoT with Python
11:15-11:45: Python Web Development with Django
11:45-13:15: Lunch
13:15-13:45: WebScrapping of Consumer Prices
13:45-14:15: Testing Smart Contracts with Pytest & Brownie
14:15-14:30: Break
14:30-15:00: WebScrapping with Beautiful Soup
15:00-15:30: Lightening Talks Pyladies
15:30-15:45: Break
15:45-16:15: Lightening Talks Pyladies
16:15-16:45: Business Analysis with AI. Inspiring Women in AI. Teaching Python To Learn Python.
16:45-17:00: Closing Keynote, DG ICT Commission
"""
@app.on_callback_query(filters.regex(r"events"))
async def events(client: Client, query: CallbackQuery):
await query.answer()
await query.edit_message_text(
text=f"Here's the events timetable:\n\n{AllEvents}",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Back",
callback_data="announcementsmenu",
),
InlineKeyboardButton(
"Back To Menu",
callback_data=f"helpmenu",
),
],
]
),
)
########## MUTE COMMAND ##########
@app.on_message(
filters.command(commands="mute", prefixes=["!", "/", "#"]) & check_admin
)
async def mute(client: Client, message: Message):
if not message.reply_to_message:
return
user = await client.get_chat_member(
chat_id=message.chat.id, user_id=message.reply_to_message.from_user.id
)
if (
user.status == enums.ChatMemberStatus.OWNER
or user.status == enums.ChatMemberStatus.ADMINISTRATOR
):
message_to_reply = await message.reply(text="Cannot Mute Admins")
await asyncio.sleep(5)
await message_to_reply.delete()
await message.delete()
return
await message.reply_to_message.delete()
await client.restrict_chat_member(
message.chat.id,
message.reply_to_message.from_user.id,
ChatPermissions(),
datetime.now() + timedelta(hours=6),
)
await message.reply(
text=f"[{message.reply_to_message.from_user.first_name}](tg://user?id={message.reply_to_message.from_user.id}) has been muted for 6 hours.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Unmute", f"unmute.{message.reply_to_message.from_user.id}"
)
]
]
),
)
@app.on_callback_query(filters.regex(r"unmute"))
async def unmute(client: Client, query: CallbackQuery):
to_be_unmuted = query.data.split(".")[1]
text = query.message.text
user = await client.get_chat_member(
chat_id=query.message.chat.id, user_id=query.from_user.id
)
if not (
user.status == enums.ChatMemberStatus.OWNER
or user.status == enums.ChatMemberStatus.ADMINISTRATOR
):
await query.answer("Only admins can perform this action", show_alert=True)
return
await client.restrict_chat_member(
query.message.chat.id,
to_be_unmuted,
ChatPermissions(
can_send_messages=True,
can_send_media_messages=True,
can_send_other_messages=True,
can_add_web_page_previews=True,
can_send_polls=True,
can_change_info=True,
can_invite_users=True,
can_pin_messages=True,
),
)
await query.edit_message_text(f"~~{text.markdown}~~\n\nYou have been Unmuted")
######## BAN COMMAND ########
@app.on_message(filters.command(commands="ban", prefixes=["!", "/", "#"]) & check_admin)
async def ban(client: Client, message: Message):
if not message.reply_to_message:
return
user = await client.get_chat_member(
chat_id=message.chat.id, user_id=message.reply_to_message.from_user.id
)
if (
user.status == enums.ChatMemberStatus.OWNER
or user.status == enums.ChatMemberStatus.ADMINISTRATOR
):
message_to_reply = await message.reply(text="Cannot Ban Admins")
await asyncio.sleep(5)
await message_to_reply.delete()
await message.delete()
return
await client.ban_chat_member(message.chat.id, message.reply_to_message.from_user.id)
await message.reply_to_message.delete()
await message.reply(
text=f"[{message.reply_to_message.from_user.first_name}](tg://user?id={message.reply_to_message.from_user.id}) has been permanently banned.",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"Unban", f"unban.{message.reply_to_message.from_user.id}"
)
]
]
),
)
@app.on_callback_query(filters.regex(r"unban"))
async def unban(client: Client, query: CallbackQuery):
to_be_unbanned = query.data.split(".")[1]
text = query.message.text
user = await client.get_chat_member(
chat_id=query.message.chat.id, user_id=query.from_user.id
)
if not (
user.status == enums.ChatMemberStatus.OWNER
or user.status == enums.ChatMemberStatus.ADMINISTRATOR
):
await query.answer("Only admins can perform this action", show_alert=True)
return
await client.unban_chat_member(query.message.chat.id, to_be_unbanned)
await query.edit_message_text(f"~~{text.markdown}~~\n\nYou have been Unbanned")
########## PROMOTE ADMIN ##########
@app.on_message(
filters.command(commands="promote", prefixes=["!", "/", "#"]) & check_admin
)
async def promote(client: Client, message: Message):
to_be_promoted = message.reply_to_message.from_user.id
chat_id = message.chat.id
await client.promote_chat_member(chat_id, to_be_promoted)
message_to_reply = await message.reply(
f"Promoted [{message.reply_to_message.from_user.first_name}](tg://user?id={to_be_promoted})"
)
await asyncio.sleep(30)
await message_to_reply.delete()
await message.delete()
########## DELETE MESSAGES ##########
@app.on_message(
filters.command(commands="delete", prefixes=["!", "/", "#"]) & check_admin
)
async def delete_a_message(client: Client, message: Message):
if not message.reply_to_message:
await message.delete()
return
await message.delete()
await message.reply_to_message.delete()
app.run()