# Copyright (C) 2019-2025 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 re import asyncio import logging from pyrogram import * from pyrogram.enums import MessageEntityType from pyrogram.errors import ChannelPrivate 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"^unwarn_(\d+)$")) async def unwarn_button(client, callback_query): user_id = int(callback_query.match.group(1)) chat_id = callback_query.message.chat.id from_user = callback_query.from_user try: member = await client.get_chat_member(chat_id, from_user.id) if member.status.value not in ("administrator", "creator"): 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 await db.warns.delete_one({"chat_id": chat_id, "user_id": user_id}) await callback_query.answer(f"✅ Peringatan untuk {user_id} telah dihapus.", show_alert=True) @bot.on_callback_query(filters.regex(r"^warn_(\d+)$")) async def warn_button(client, callback_query): user_id = int(callback_query.match.group(1)) chat_id = callback_query.message.chat.id from_user = callback_query.from_user try: member = await client.get_chat_member(chat_id, from_user.id) if member.status.value not in ("administrator", "creator"): 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, reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Unban", callback_data=f"unban_{user_id}" ) ] ] ) ) await callback_query.message.reply_text( f"🚫 User {user_id} telah dihapus setelah 3 kali peringatan." ) 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+)$")) async def unban_button(client, callback_query): user_id = int(callback_query.match.group(1)) chat_id = callback_query.message.chat.id from_user = callback_query.from_user try: member = await client.get_chat_member(chat_id, from_user.id) if member.status.value not in ("administrator", "creator"): 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 {user_id} telah dihapus dari larangan." ) except Exception as e: await callback_query.message.reply_text(f"Gagal menghapus larangan: {e}") @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( -1002407639480, "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 if check_anti_word_by_ryzenth(message.text): logging.info(f"check_anti_word_by_ryzenth: Blocked message from {message.from_user.first_name} in {message.chat.title}") return await message.delete() @bot.on_message( filters.group & ~filters.command(["delmodbot", "addmodbot", "delmoduser", "addmoduser", "start"]) & ~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 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): 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}) 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 ) if warn_count >= 3: await client.ban_chat_member( message.chat.id, message.from_user.id, reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Unban", callback_data=f"unban_{message.from_user.id}" ) ] ] ) ) await message.reply_text( f"🚫 User {message.from_user.id} telah dihapus setelah 3 kali peringatan." ) await db.warns.delete_one({"chat_id": message.chat.id, "user_id": message.from_user.id}) else: await db.warns.insert_one({"chat_id": message.chat.id, "user_id": message.from_user.id, "count": 1}) await message.reply_text( f"⚠️ Peringatan pertama untuk {message.from_user.id}.", reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Unwarn", callback_data=f"unwarn_{message.from_user.id}" ) ] ] ) ) 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}") warn = await db.warns.find_one({"chat_id": message.chat.id, "user_id": message.from_user.id}) 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 ) if warn_count >= 3: await client.ban_chat_member( message.chat.id, message.from_user.id, reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Unban", callback_data=f"unban_{message.from_user.id}" ) ] ] ) ) await message.reply_text( f"🚫 User {message.from_user.id} telah dihapus setelah 3 kali peringatan." ) await db.warns.delete_one({"chat_id": message.chat.id, "user_id": message.from_user.id}) else: await db.warns.insert_one({"chat_id": message.chat.id, "user_id": message.from_user.id, "count": 1}) await message.reply_text( f"⚠️ Peringatan pertama untuk {message.from_user.id}.", reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( "Unwarn", callback_data=f"unwarn_{message.from_user.id}" ) ] ] ) ) await message.delete() except AttributeError: pass if check_anti_word_by_ryzenth(message.text): logging.info(f"check_anti_word_by_ryzenth: Blocked message from {message.from_user.first_name} in {message.chat.title}") 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 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())