File size: 34,759 Bytes
14c0f0d
 
 
 
 
 
 
 
 
351f170
 
 
 
11402c2
86b0fd2
11402c2
 
351f170
11402c2
884243a
f927f65
11402c2
 
 
d8f2fc8
11402c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0987366
 
 
 
 
 
 
 
cb80429
 
 
 
 
 
 
 
 
fa6ba3e
6305f6e
17cc00b
880c36c
6305f6e
 
 
884243a
6305f6e
 
 
 
 
96226f0
 
a748a75
 
 
6305f6e
1ebfe9a
6305f6e
fa6ba3e
6305f6e
1f023fa
880c36c
6305f6e
 
 
884243a
6305f6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96226f0
 
 
 
 
6305f6e
 
 
880c36c
 
 
6305f6e
 
 
 
880c36c
6305f6e
 
 
 
 
 
 
 
 
 
 
fa6ba3e
6305f6e
1f023fa
880c36c
6305f6e
 
 
884243a
6305f6e
 
 
 
 
 
 
 
 
 
 
 
 
 
a748a75
 
 
 
 
076bde9
 
a748a75
076bde9
 
 
 
 
 
 
 
1ebfe9a
399ef44
 
 
 
076bde9
 
 
 
 
1ebfe9a
 
 
 
 
 
076bde9
 
 
399ef44
 
 
a748a75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad1070b
 
a748a75
 
 
 
076bde9
 
 
 
 
 
 
 
 
 
 
399ef44
 
 
1ebfe9a
 
 
 
 
 
076bde9
 
 
 
 
 
 
 
 
399ef44
076bde9
399ef44
ad1070b
96226f0
 
 
 
ad1070b
076bde9
ad1070b
 
076bde9
ad1070b
8c0c5a6
 
 
390705c
8c0c5a6
390705c
 
 
 
 
 
 
8c0c5a6
 
390705c
 
8c0c5a6
390705c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c0c5a6
390705c
 
8c0c5a6
 
11402c2
f74a9e2
11402c2
 
 
 
f74a9e2
11402c2
 
 
 
 
 
 
 
 
 
47a6d31
60762ab
 
 
 
 
 
 
11402c2
bf4e789
f74a9e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11402c2
 
38d3d27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11402c2
 
38e11f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11402c2
38e11f3
 
 
11402c2
 
 
 
0987366
 
 
 
 
 
 
 
 
38d3d27
 
 
 
 
 
 
11402c2
 
cbab1cd
11402c2
cbab1cd
11402c2
cbab1cd
11402c2
cbab1cd
5502e89
 
cbab1cd
 
0987366
cbab1cd
 
 
d80a48b
 
 
 
 
 
11402c2
880c36c
 
 
 
 
 
 
 
d8f2fc8
8717f89
 
880c36c
8717f89
 
 
11402c2
 
 
aeb19ba
 
 
 
 
 
 
 
 
 
 
38d3d27
 
 
 
 
47a6d31
 
cbab1cd
5502e89
 
cbab1cd
 
6304702
5dfce54
 
 
 
cbab1cd
4a40feb
96226f0
4a40feb
 
 
 
 
 
 
fd3080c
 
 
 
 
 
 
 
 
 
 
 
4a40feb
fd3080c
 
 
4a40feb
fd3080c
4a40feb
fd3080c
 
db16a32
4a40feb
 
a748a75
 
4a40feb
 
 
 
880c36c
4a40feb
 
 
 
 
 
db16a32
cbab1cd
d80a48b
 
5dfce54
 
 
 
d80a48b
6305f6e
96226f0
6305f6e
 
 
 
 
 
 
fd3080c
 
 
 
 
 
 
 
 
 
 
 
6305f6e
fd3080c
 
 
6305f6e
fd3080c
6305f6e
fd3080c
 
db16a32
6305f6e
 
a748a75
 
6305f6e
 
 
 
880c36c
6305f6e
 
 
 
 
 
db16a32
d80a48b
 
4a5f08c
 
d8f2fc8
54eaaba
 
d8f2fc8
 
11402c2
 
 
 
 
 
 
 
 
 
 
38d3d27
 
 
 
 
 
 
cbab1cd
11402c2
 
86b0fd2
 
 
 
 
 
 
 
 
 
 
 
 
351f170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9635ed4
351f170
 
 
 
86b0fd2
 
 
 
 
9635ed4
cb80429
 
9635ed4
cb80429
86b0fd2
 
 
351f170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11402c2
 
 
 
 
 
 
 
 
 
 
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
# Copyright (C) 2019-2025 TeamKillerX <https://github.com/TeamKillerX>
#
# This file is part of TeamKillerX project,
# and licensed under GNU Affero General Public License v3.
# See the GNU Affero General Public License for more details.
#
# All rights reserved. See COPYING, AUTHORS.
#

import io
import os
import sys
import traceback
import re
import httpx
import asyncio
import logging

from pyrogram import *
from pyrogram.enums import MessageEntityType, ChatMemberStatus
from pyrogram.errors import ChannelPrivate, ImageProcessFailed
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from config import *
from database import db
from helper_regex import *

logging.basicConfig(
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    level=logging.INFO,
    datefmt="%Y-%m-%d %H:%M:%S",
)
logging.getLogger("pyrogram").setLevel(logging.WARNING)

eval_regex = r"^(\.e(?:val)?|\.exec|\.sh|\.term|\.python|\.ex|\.bash|\.ls)(\s|$)"

bot = Client(
    "antibot",
    api_id=API_ID,
    api_hash=API_HASH,
    bot_token=BOT_TOKEN,
)

def has_code_entity(message):
    if not message.entities:
        return False
    for entity in message.entities:
        if entity.type == MessageEntityType.PRE:
            return True
    return False

@bot.on_callback_query(filters.regex(r"^deletepaste_(\w+)$"))
async def deletepastecb(client, cb):
    paste_id = cb.matches[0].group(1)
    user_id = cb.from_user.id
    if user_id != 6477856957:
        return await cb.answer("❌ Hanya developer", show_alert=True)
    await delete_paste(paste_id)
    await cb.message.edit_text(f"βœ… Paste ID telah dihapus.")

@bot.on_callback_query(filters.regex(r"^unwarn_(\d+)_(-?\d+)$"))
async def unwarn_button(client, callback_query):
    user_id = int(callback_query.matches[0].group(1))
    chat_id = int(callback_query.matches[0].group(2))
    from_user = callback_query.from_user
    try:
        member = await client.get_chat_member(chat_id, from_user.id)
        if member.status not in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
            await callback_query.answer("❌ Hanya admin yang bisa menghapus peringatan!", show_alert=True)
            return
    except Exception:
        await callback_query.answer("⚠️ Gagal memverifikasi status admin.", show_alert=True)
        return
    warn_data = await db.warns.find_one({"chat_id": chat_id, "user_id": user_id})
    if not warn_data:
        await callback_query.answer("⚠️ Tidak ada peringatan untuk user ini.", show_alert=True)
        await callback_query.message.delete()
        return
    await db.warns.delete_one({"chat_id": chat_id, "user_id": user_id})
    await callback_query.message.edit_text(f"βœ… Peringatan untuk <code>[{user_id}]</code> telah dihapus.")

@bot.on_callback_query(filters.regex(r"^warn_(\d+)_(-?\d+)$"))
async def warn_button(client, callback_query):
    user_id = int(callback_query.matches[0].group(1))
    chat_id = int(callback_query.matches[0].group(2))
    from_user = callback_query.from_user
    try:
        member = await client.get_chat_member(chat_id, from_user.id)
        if member.status not in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
            await callback_query.answer("❌ Hanya admin yang bisa memberikan peringatan!", show_alert=True)
            return
    except Exception:
        await callback_query.answer("⚠️ Gagal memverifikasi status admin.", show_alert=True)
        return

    warn_data = await db.warns.find_one({"chat_id": chat_id, "user_id": user_id})
    warn_count = 1

    if warn_data:
        warn_count = warn_data.get("count", 0) + 1
        await db.warns.update_one(
            {"chat_id": chat_id, "user_id": user_id},
            {"$set": {"count": warn_count}},
            upsert=True
        )
    else:
        await db.warns.insert_one({
            "chat_id": chat_id,
            "user_id": user_id,
            "count": warn_count
        })

    if warn_count >= 3:
        try:
            await client.ban_chat_member(chat_id, user_id)
            await callback_query.message.reply_text(
                f"🚫 User <code>{user_id}</code> telah dihapus setelah 3 kali peringatan.",
                reply_markup=InlineKeyboardMarkup(
                    [
                        [
                            InlineKeyboardButton(
                                "Unban", callback_data=f"unban_{user_id}_{chat_id}"
                            )
                        ]
                    ]
                )
            )
            await db.warns.delete_one({"chat_id": chat_id, "user_id": user_id})
        except Exception as e:
            await callback_query.message.reply_text(f"Gagal menghapus user: {e}")
    else:
        await callback_query.answer(f"⚠️ Peringatan ke {warn_count} diberikan.", show_alert=True)

@bot.on_callback_query(filters.regex(r"^unban_(\d+)_(-?\d+)$"))
async def unban_button(client, callback_query):
    user_id = int(callback_query.matches[0].group(1))
    chat_id = int(callback_query.matches[0].group(2))
    from_user = callback_query.from_user
    try:
        member = await client.get_chat_member(chat_id, from_user.id)
        if member.status not in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
            await callback_query.answer("❌ Hanya admin yang bisa menghapus larangan!", show_alert=True)
            return
    except Exception:
        await callback_query.answer("⚠️ Gagal memverifikasi status admin.", show_alert=True)
        return

    try:
        await client.unban_chat_member(chat_id, user_id)
        await callback_query.message.reply_text(
            f"βœ… User <code>{user_id}</code> telah dihapus dari larangan."
        )
    except Exception as e:
        await callback_query.message.reply_text(f"Gagal menghapus larangan: {e}")

@bot.on_message(filters.command("warn") & filters.group)
async def warn(client, message):
    member = await client.get_chat_member(message.chat.id, message.from_user.id)
    if member.status not in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
        return await message.reply_text("❌ Hanya admin yang bisa memberikan peringatan!")
    
    user_id = None

    if message.reply_to_message and message.reply_to_message.from_user:
        user_id = message.reply_to_message.from_user.id
    elif len(message.command) == 2:
        try:
            user_id = int(message.command[1])
        except ValueError:
            return await message.reply_text("GAK ADA USER ID NYA? GIMANA NARIK BOT KE GRUP LU?")
    else:
        return await message.reply_text("❌ Format salah. Balas pesan atau kirim /warn [user_id]")

    if user_id == client.me.id:
        return await message.reply_text("GAK BISA WARN BOT SENDIRI! GIMANA NARIK BOT KE GRUP LU?")
    
    try:
        get_user = await client.get_users(user_id)
    except Exception:
        return await message.reply_text("❌ User tidak ditemukan.")
    
    get_data = await db.antieval.find_one(
        {"bot_id": client.me.id}
    )
    if get_data and user_id in get_data.get("whitelist_user", []):
        return await message.reply_text("GAK BISA WARN USER YANG SUDAH DI WHITELIST! GIMANA NARIK BOT KE GRUP LU?")
    
    member_admin = await client.get_chat_member(message.chat.id, get_user.id)
    if member_admin.status == ChatMemberStatus.BANNED:
        return await message.reply_text("GAK BISA WARN USER YANG SUDAH DI BANNED! GIMANA NARIK BOT KE GRUP LU?")
    if member_admin.status in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
        return await message.reply_text("GAK BISA WARN ADMIN! GIMANA NARIK BOT KE GRUP LU?")

    try:
        warn_data = await db.warns.find_one({"chat_id": message.chat.id, "user_id": user_id})
        warn_count = 1
        if warn_data:
            warn_count = warn_data.get("count", 0) + 1
            await db.warns.update_one(
                {"chat_id": message.chat.id, "user_id": user_id},
                {"$set": {"count": warn_count}},
                upsert=True
            )
        else:
            await db.warns.insert_one({
                "chat_id": message.chat.id,
                "user_id": user_id,
                "count": warn_count
            })
        if warn_count >= 3:
            await client.ban_chat_member(message.chat.id, user_id)
            await message.reply_text(
                f"🚫 User <code>[{user_id}]</code> telah dihapus setelah 3 kali peringatan.",
                reply_markup=InlineKeyboardMarkup(
                    [
                        [
                            InlineKeyboardButton(
                                "Unban", callback_data=f"unban_{user_id}_{message.chat.id}"
                            )
                        ]
                    ]
                )
            )
            await db.warns.delete_one({"chat_id": message.chat.id, "user_id": user_id})
            return
        else:
            await message.reply_text(
                f"⚠️ Peringatan {warn_count}/3 untuk <code>[{user_id}]</code>\n\n"
                f"Alasan: <code>SPAMMER</code>",
                reply_markup=InlineKeyboardMarkup(
                    [
                        [
                            InlineKeyboardButton(
                                "Unwarn", callback_data=f"unwarn_{user_id}_{message.chat.id}"
                            )
                        ]
                    ]
                )
            )
            return
    except Exception as e:
        logging.error(f"Error adding warning: {e}")
        await message.reply_text(
            "GAGAL MEMBERIKAN PERINGATAN! CEK LAGI USER ID NYA!"
        )

@bot.on_message(filters.command("delwarn") & filters.group)
async def delwarn(client, message):
    member = await client.get_chat_member(message.chat.id, message.from_user.id)
    if member.status not in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
        return await message.reply_text("❌ Hanya admin yang bisa menghapus peringatan!")

    user_id = None

    if  message.reply_to_message and message.reply_to_message.from_user:
        user_id = message.reply_to_message.from_user.id
    elif len(message.command) == 2:
        try:
            user_id = int(message.command[1])
        except ValueError:
            return await message.reply_text("❌ USER ID tidak valid.")
    else:
        return await message.reply_text("❌ Format salah. Balas pesan atau kirim /delwarn [user_id]")

    if user_id == client.me.id:
        return await message.reply_text("GAK BISA HAPUS PERINGATAN BOT SENDIRI! GIMANA NARIK BOT KE GRUP LU?")
    
    get_data = await db.antieval.find_one(
        {"bot_id": client.me.id}
    )
    if get_data and user_id in get_data.get("whitelist_user", []):
        return await message.reply_text("GAK BISA HAPUS PERINGATAN USER YANG SUDAH DI WHITELIST! GIMANA NARIK BOT KE GRUP LU?")

    try:
        get_user = await client.get_users(user_id)
    except Exception:
        return await message.reply_text("❌ User tidak ditemukan.")

    member_admin = await client.get_chat_member(message.chat.id, get_user.id)
    if member_admin.status == ChatMemberStatus.BANNED:
        return await message.reply_text("❌ GAK BISA HAPUS PERINGATAN USER YANG SUDAH DI BANNED!")
    if member_admin.status in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
        return await message.reply_text("❌ GAK BISA HAPUS PERINGATAN ADMIN!")

    try:
        warn_data = await db.warns.find_one({"chat_id": message.chat.id, "user_id": user_id})
        if not warn_data:
            return await message.reply_text("⚠️ Tidak ada peringatan untuk user ini.")

        await db.warns.delete_one({"chat_id": message.chat.id, "user_id": user_id})
        await message.reply_text("βœ… Berhasil menghapus semua peringatan.")
    except Exception as e:
        logging.error(f"Error removing all warnings: {e}")
        await message.reply_text("❌ Gagal menghapus peringatan. Cek lagi user ID-nya.")

@bot.on_message(filters.command("bctanti") & filters.user(6477856957))
async def broadcasts(client, message):
    DEVS = [1191668125]
    
    data = await db.antieval.find_one({"bot_id": client.me.id})
    if not data or not data.get("user_id"):
        return await message.reply("Data tidak ditemukan atau kosong.")
    
    if not message.reply_to_message:
        return await message.reply("Silakan balas ke pesan yang ingin disebarkan.")

    msg = message.reply_to_message
    done = 0
    error = 0
    private_users = set()

    for user in data["user_id"]:
        if user in DEVS:
            continue
        try:
            await msg.forward(user)
            done += 1
        except Exception:
            private_users.add(user)
            error += 1

    if private_users:
        await db.antieval.update_one(
            {"bot_id": client.me.id},
            {"$pull": {"user_id": {"$in": list(private_users)}}},
        )

    await message.reply_text(
        f"βœ… Berhasil dikirim ke `{done}` user.\n"
        f"❌ Gagal ke `{error}` user:\n`{list(private_users)}`"
    )

@bot.on_message(filters.command("start") & filters.private)
async def start_command(client, message):
    reply_markup = InlineKeyboardMarkup( # type: ignore
        [
            [
                InlineKeyboardButton( # type: ignore
                    "Add to Your Group", url=f"https://t.me/{client.me.username}?startgroup=true&admin=manage_chat+change_info+post_messages+edit_messages+delete_messages+invite_users+restrict_members+pin_messages+promote_members+manage_video_chats+anonymous=false"
                )
            ]
        ]
    )
    await db.antieval.update_one(
        {"bot_id": client.me.id},
        {"$addToSet": {"user_id": message.from_user.id}},
        upsert=True,
    )
    await client.send_message(
        -1001589752824,
        "Anti Eval Bot (Start) Logs\n\n"
        f"First Name: {message.from_user.mention}\n"
        f"UserID: `{message.from_user.id}`\n"
        f"Username: `{message.from_user.username if message.from_user else None}`\n",
        reply_markup=InlineKeyboardMarkup([[
            InlineKeyboardButton("πŸ‘€ View User", url=f"tg://openmessage?user_id={message.from_user.id}")
        ]])
    )
    await message.reply_text(
        f"""
πŸ‘‹ **Welcome to Anti Eval Guard!**

🚫 Bot ini dibuat khusus untuk **melindungi grup Telegram dari eval code, promosi gelap, dan kata kasar.** Cocok buat komunitas developer, server publik, atau grup pribadi yang ingin bersih dari spam!

πŸ›‘οΈ **FITUR UTAMA:**
β€’ Deteksi & hapus otomatis kode berbahaya (Python, JS, SH, PHP, DLL)
β€’ Blokir teks promosi seperti "jasa hack", "jual akun", dll
β€’ Filter kata kasar, toxic, dan rasis (Indo)
β€’ Inline, forward, bahkan markdown tak bisa lolos
β€’ Support AI powered moderation (v2)

πŸ”₯ **Note:** Pastikan bot jadi **admin** dan punya izin `Delete`, `Ban`, `Restrict` agar fitur bekerja maksimal!

πŸ” Powered by Ryzenth API β€” sistem AI moderasi canggih & cepat.
""",
        reply_markup=reply_markup
    )

@bot.on_message(filters.command("addmoduser") & filters.group)
async def addwhitelist(client, message):
    if message.from_user.id not in [6477856957]:
        return await message.reply_text("LU SIAPA? GAK ADA IZIN GUE!")
    if len(message.command) != 2:
        return await message.reply_text("GAK ADA USER ID NYA? GIMANA NARIK BOT KE GRUP LU?")
    user_id = int(message.command[1])
    try:
        get_user = await db.antieval.find_one(
            {"bot_id": client.me.id}
        )
        if get_user and user_id in get_user.get("whitelist_user", []):
            return await message.reply_text("USER ID NYA SUDAH ADA DI WHITELIST! GIMANA NARIK BOT KE GRUP LU?")

        await db.antieval.update_one(
            {"bot_id": client.me.id},
            {"$addToSet": {"whitelist_user": user_id}},
            upsert=True,
        )
        await message.reply_text(
            "berhasil menambahkan user ke whitelist"
        )
        return
    except Exception as e:
        logging.error(f"Error adding user to whitelist: {e}")
        await message.reply_text(
            "GAGAL MENAMBAHKAN USER KE WHITELIST! CEK LAGI USER ID NYA!"
        )

@bot.on_message(filters.command("delmoduser") & filters.group)
async def delwhitelist(client, message):
    if message.from_user.id not in [6477856957]:
        return await message.reply_text("LU SIAPA? GAK ADA IZIN GUE!")
    if len(message.command) != 2:
        return await message.reply_text("GAK ADA USER ID NYA? GIMANA NARIK BOT KE GRUP LU?")
    user_id = int(message.command[1])
    try:
        get_user = await db.antieval.find_one(
            {"bot_id": client.me.id}
        )
        if not get_user or user_id not in get_user.get("whitelist_user", []):
            return await message.reply_text("GAK ADA USER ID NYA DI WHITELIST! GIMANA NARIK BOT KE GRUP LU?")

        await db.antieval.update_one(
            {"bot_id": client.me.id},
            {"$pull": {"whitelist_user": user_id}},
            upsert=True,
        )
        await message.reply_text(
            "berhasil menghapus user dari whitelist"
        )
        return
    except Exception as e:
        logging.error(f"Error removing user from whitelist: {e}")
        await message.reply_text(
            "GAGAL MENGHAPUS USER DARI WHITELIST! CEK LAGI USER ID NYA!"
        )

@bot.on_message(filters.command("addmodbot") & filters.group)
async def addwhitelistbot(client, message):
    if message.from_user.id not in [6477856957]:
        return await message.reply_text("LU SIAPA? GAK ADA IZIN GUE!")
    if len(message.command) != 2:
        return await message.reply_text("GAK ADA USER ID NYA? GIMANA NARIK BOT KE GRUP LU?")
    user_id = int(message.command[1])
    try:
        get_user = await db.antieval.find_one(
            {"bot_id": client.me.id}
        )
        if get_user and user_id in get_user.get("whitelist_bot", []):
            return await message.reply_text("USER ID NYA SUDAH ADA DI WHITELIST! GIMANA NARIK BOT KE GRUP LU?")

        await db.antieval.update_one(
            {"bot_id": client.me.id},
            {"$addToSet": {"whitelist_bot": user_id}},
            upsert=True,
        )
        await message.reply_text(
            "berhasil menambahkan bot ke whitelist"
        )
        return
    except Exception as e:
        logging.error(f"Error adding bot to whitelist: {e}")
        await message.reply_text(
            "GAGAL MENAMBAHKAN BOT KE WHITELIST! CEK LAGI USER ID NYA!"
        )

@bot.on_message(filters.command("delmodbot") & filters.group)
async def delwhitelistbot(client, message):
    if message.from_user.id not in [6477856957]:
        return await message.reply_text("LU SIAPA? GAK ADA IZIN GUE!")
    if len(message.command) != 2:
        return await message.reply_text("GAK ADA USER ID NYA? GIMANA NARIK BOT KE GRUP LU?")
    user_id = int(message.command[1])
    try:
        get_user = await db.antieval.find_one(
            {"bot_id": client.me.id}
        )
        if not get_user or user_id not in get_user.get("whitelist_bot", []):
            return await message.reply_text("GAK ADA USER ID NYA DI WHITELIST! GIMANA NARIK BOT KE GRUP LU?")

        await db.antieval.update_one(
            {"bot_id": client.me.id},
            {"$pull": {"whitelist_bot": user_id}},
            upsert=True,
        )
        await message.reply_text(
            "berhasil menghapus bot dari whitelist"
        )
        return
    except Exception as e:
        logging.error(f"Error removing bot from whitelist: {e}")
        await message.reply_text(
            "GAGAL MENGHAPUS BOT DARI WHITELIST! CEK LAGI USER ID NYA!"
        )

@bot.on_chat_member_updated(filters.group)
async def group_join(client, message):
    try:
        if message.new_chat_member and message.new_chat_member.user.id == client.me.id:
            if message.chat.id in LEAVE_GROUP_LIST:
                await client.leave_chat(message.chat.id)
                await message.reply_text(
                    "GUA KELUAR DULU YA! LU TARIK BOT KE GRUP DEVELOPER YANG SUDAH DIBLACKLIST! πŸ’₯\n"
                    "GAK MALU APA TARIK BOT TAPI GAK TAU ATURAN?\n"
                    "INI BUKAN BOT PAJANGAN, INI BOT ANTI EVAL! 🚫🧠"
                )
                return
            
            privileges = message.new_chat_member.privileges

            if not privileges or not privileges.can_restrict_members or not privileges.can_delete_messages:
                await client.send_message(
                    message.chat.id,
                    "GUA KELUAR DULU YA! LU NARIK BOT TAPI GAK KASIH IZIN BANNED! πŸ’₯\n"
                    "BIKIN BOT BUAT APA KALO CUMA JADI PAJANGAN?"
                )
                await client.leave_chat(message.chat.id)
                logging.info(f"Left group: {message.chat.title} ({message.chat.id})")
                return

            await db.antieval.update_one(
                {"bot_id": client.me.id},
                {"$addToSet": {"chat_id": message.chat.id}},
                upsert=True,
            )
            logging.info(f"Added to group: {message.chat.title} ({message.chat.id})")
    except ChannelPrivate:
        pass

@bot.on_message(filters.via_bot)
async def block_inline_via_bot(client, message):
    if message.via_bot:
        check = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
        if not check or not check.can_restrict_members or not check.can_delete_messages:
            await message.reply_text(
                "GUA KELUAR DULU YA! LU NARIK BOT TAPI GAK KASIH IZIN BANNED! πŸ’₯\n"
                "BIKIN BOT BUAT APA KALO CUMA JADI PAJANGAN?"
            )
            await client.leave_chat(message.chat.id)
            logging.info(f"Left group: {message.chat.title} ({message.chat.id})")
            return

        get_user_bot = await db.antieval.find_one(
            {"bot_id": client.me.id}
        )
        if get_user_bot and message.via_bot.id in get_user_bot.get("whitelist_bot", []):
            return

        username = message.via_bot.username.lower()
        if any(ok in username for ok in BLOCKED_INLINE_BOTS):
            logging.info(f"Blocked inline via bot message from {message.from_user.first_name} in {message.chat.title}")
            return await message.delete()

        if message.via_bot and "eval" in message.via_bot.username.lower():
            logging.info(f"Blocked inline via bot message from {message.from_user.first_name} in {message.chat.title}")
            return await message.delete()

        if contains_stylish_with_whitelist(message.text):
            logging.info(f"contains_stylish_with_whitelist: Blocked inline message from {message.from_user.first_name} in {message.chat.title}")
            return await message.delete()

        if has_code_entity(message):
            logging.info(f"has_code_entity: Blocked inline message from {message.from_user.first_name} in {message.chat.title}")
            return await message.delete()

        try:
            if is_blocked_markdown_code(message.text.markdown or ""):
                logging.info(f"is_blocked_markdown_code: Blocked message from {message.from_user.first_name} in {message.chat.title}")
                return await message.delete()
        except AttributeError:
            pass

DISABLED_COMMANDS = [  
    "delmodbot",
    "addmodbot",
    "delmoduser",
    "addmoduser",
    "start",
    "delwarn",
]

@bot.on_message(
        filters.group
        & ~filters.command(DISABLED_COMMANDS)
        & ~filters.via_bot, 
        group=-1
    )
async def markdown_code(client, message):
    check = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
    if not check or not check.can_restrict_members or not check.can_delete_messages:
        try:
            await message.reply_text(
                "GUA KELUAR DULU YA! LU NARIK BOT TAPI GAK KASIH IZIN BANNED! πŸ’₯\n"
                "BIKIN BOT BUAT APA KALO CUMA JADI PAJANGAN?"
            )
            await client.leave_chat(message.chat.id)
            logging.info(f"Left group: {message.chat.title} ({message.chat.id})")
            return
        except ChannelPrivate:
            pass

    get_user = await db.antieval.find_one(
        {"bot_id": client.me.id}
    )
    if get_user and message.from_user.id in get_user.get("whitelist_user", []):
        return
    if message.chat.id == -1001589752824:
        return

    if contains_stylish_with_whitelist(message.text):
        logging.info(f"contains_stylish_with_whitelist: Blocked message from {message.from_user.first_name} in {message.chat.title}")
        return await message.delete()

    if has_code_entity(message):
        member_admin = await client.get_chat_member(message.chat.id, message.from_user.id)
        if member_admin.status in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
            return

        logging.info(f"has_code_entity: Blocked message from {message.from_user.first_name} in {message.chat.title}")
        warn = await db.warns.find_one({"chat_id": message.chat.id, "user_id": message.from_user.id})
        warn_count = 1
        if warn:
            warn_count = warn.get("count", 0) + 1
            await db.warns.update_one(
                {"chat_id": message.chat.id, "user_id": message.from_user.id},
                {"$set": {"count": warn_count}},
                upsert=True
            )
        else:
            await db.warns.insert_one({
                "chat_id": message.chat.id,
                "user_id": message.from_user.id,
                "count": warn_count
            })
        if warn_count >= 3:
            await client.ban_chat_member(message.chat.id, message.from_user.id)
            await message.reply_text(
                f"🚫 User <code>[{message.from_user.id}]</code> telah dihapus setelah 3 kali peringatan.",
                reply_markup=InlineKeyboardMarkup(
                    [
                        [
                            InlineKeyboardButton(
                                "Unban", callback_data=f"unban_{message.from_user.id}_{message.chat.id}"
                            )
                        ]
                    ]
                )
            )
            await db.warns.delete_one({"chat_id": message.chat.id, "user_id": message.from_user.id})
            return
        else:
            await message.reply_text(
                f"⚠️ Peringatan {warn_count}/3 untuk <code>[{message.from_user.id}]</code>\n\n"
                f"Alasan: <code>SPAMMER</code>",
                reply_markup=InlineKeyboardMarkup(
                    [
                        [
                            InlineKeyboardButton(
                                "Unwarn", callback_data=f"unwarn_{message.from_user.id}_{message.chat.id}"
                            )
                        ]
                    ]
                )
            )
            await message.delete()
            return

    try:
        if is_blocked_markdown_code(message.text.markdown or ""):
            member_admin = await client.get_chat_member(message.chat.id, message.from_user.id)
            if member_admin.status in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
                return

            logging.info(f"is_blocked_markdown_code: Blocked message from {message.from_user.first_name} in {message.chat.title}")
            warn = await db.warns.find_one({"chat_id": message.chat.id, "user_id": message.from_user.id})
            warn_count = 1
            if warn:
                warn_count = warn.get("count", 0) + 1
                await db.warns.update_one(
                    {"chat_id": message.chat.id, "user_id": message.from_user.id},
                    {"$set": {"count": warn_count}},
                    upsert=True
                )
            else:
                await db.warns.insert_one({
                    "chat_id": message.chat.id,
                    "user_id": message.from_user.id,
                    "count": warn_count
                })
            if warn_count >= 3:
                await client.ban_chat_member(message.chat.id, message.from_user.id)
                await message.reply_text(
                    f"🚫 User <code>[{message.from_user.id}]</code> telah dihapus setelah 3 kali peringatan.",
                    reply_markup=InlineKeyboardMarkup(
                        [
                            [
                                InlineKeyboardButton(
                                    "Unban", callback_data=f"unban_{message.from_user.id}_{message.chat.id}"
                                )
                            ]
                        ]
                    )
                )
                await db.warns.delete_one({"chat_id": message.chat.id, "user_id": message.from_user.id})
                return
            else:
                await message.reply_text(
                    f"⚠️ Peringatan {warn_count}/3 untuk <code>[{message.from_user.id}]</code>\n\n"
                    f"Alasan: <code>SPAMMER</code>",
                    reply_markup=InlineKeyboardMarkup(
                        [
                            [
                                InlineKeyboardButton(
                                    "Unwarn", callback_data=f"unwarn_{message.from_user.id}_{message.chat.id}"
                                )
                            ]
                        ]
                    )
                )
                await message.delete()
                return
    except AttributeError:
        pass
    is_moderator, reason = check_anti_word_by_ryzenth(message.text)
    if is_moderator:
        logging.info(f"check_anti_word_by_ryzenth: Blocked message from {message.from_user.first_name} in {message.chat.title}")
        full_reason = f"[{message.from_user.first_name}](tg://user?id={message.from_user.id})" + reason
        await message.reply_text(full_reason)
        return await message.delete()

@bot.on_message(filters.regex(eval_regex) & filters.group)
async def block_userbot_eval(client, message):
    check = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
    if not check or not check.can_restrict_members or not check.can_delete_messages:
        await message.reply_text(
            "GUA KELUAR DULU YA! LU NARIK BOT TAPI GAK KASIH IZIN BANNED! πŸ’₯\n"
            "BIKIN BOT BUAT APA KALO CUMA JADI PAJANGAN?"
        )
        await client.leave_chat(message.chat.id)
        logging.info(f"Left group: {message.chat.title} ({message.chat.id})")
        return

    get_user = await db.antieval.find_one(
        {"bot_id": client.me.id}
    )
    if get_user and message.from_user.id in get_user.get("whitelist_user", []):
        return

    logging.info(f"Blocked userbot message from {message.from_user.first_name} in {message.chat.title}")
    await message.delete()

async def paste_text(text: str) -> str:
    async with httpx.AsyncClient() as client:
        response = await client.post("https://paste.rs/", content=text)
        if response.status_code in (201, 206):
            return response.text.strip()
        else:
            raise Exception(f"Paste failed: {response.status_code} - {response.text}")

async def delete_paste(paste_id: str) -> bool:
    async with httpx.AsyncClient() as client:
        response = await client.delete(f"https://paste.rs/{paste_id}")
        return response.status_code == 200

@bot.on_message(
    ~filters.scheduled
    & filters.command(["eval", "ev", "e"])
    & filters.user([1191668125, 6477856957])
    & ~filters.forwarded
)
async def evaluation_cmd(client, message):
    status_message = await message.reply("__Processing eval pyrogram...__")
    try:
        cmd = message.text.split(" ", maxsplit=1)[1]
    except IndexError:
        return await status_message.edit("__No evaluate message!__")
    old_stderr = sys.stderr
    old_stdout = sys.stdout
    redirected_output = sys.stdout = io.StringIO()
    redirected_error = sys.stderr = io.StringIO()
    stdout, stderr, exc = None, None, None
    try:
        await aexec(cmd, client, message)
    except ImageProcessFailed: # type: ignore
        return await status_message.edit("Error ImageProcessFailed")
    except Exception:
        exc = traceback.format_exc()

    stdout = redirected_output.getvalue()
    stderr = redirected_error.getvalue()
    sys.stdout = old_stdout
    sys.stderr = old_stderr

    evaluation = ""
    if exc:
        evaluation = exc
    elif stderr:
        evaluation = stderr
    elif stdout:
        evaluation = stdout
    else:
        evaluation = "Success"

    final_output = f"**OUTPUT**:\n<pre language=''>{evaluation.strip()}</pre>"
    if len(final_output) > 4096:
        urls_paste = await paste_text(evaluation.strip())
        with open("eval.txt", "w+", encoding="utf8") as out_file:
            out_file.write(final_output)
        await status_message.reply_document(
            document="eval.txt",
            caption=f"<code>{cmd[: 4096 // 4 - 1]}</code>",
            reply_markup=InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            "Pastebin", url=f"{urls_paste}"
                        ),
                        InlineKeyboardButton(
                            "Delete Pastebin", callback_data=f"deletepaste_{urls_paste.split('/')[3]}"
                        ),
                    ]
                ]
            ),
            disable_notification=True,
        )
        os.remove("eval.txt")
        await status_message.delete()
    else:
        await status_message.edit_text(final_output)

async def aexec(code, client, message):
    exec(
        (
            "async def __aexec(client, message):\n"
            + " import os\n"
            + " from database import db\n"
            + " randydev = message\n"
            + " message = event = randydev\n"
            + " r = reply = message.reply_to_message\n"
            + " chat = message.chat.id\n"
            + " c = client\n"
            + " to_photo = message.reply_photo\n"
            + " to_video = message.reply_video\n"
            + " p = print\n"
        )
        + "".join(f"\n {l}" for l in code.split("\n"))
    )
    return await locals()["__aexec"](client, message)

async def main():
    await db.connect()
    await bot.start()
    me_user = await bot.get_me()
    me_user = me_user.first_name
    logging.info(f"Info Bot: user {me_user} started!")
    await idle()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())