from pyrogram import Client, filters, idle, enums from pyrogram.types import Chat, Message, InlineKeyboardButton, InlineKeyboardMarkup, ChatPrivileges, ChatMember from pyrogram.enums.parse_mode import ParseMode from config import * import logging from motor.motor_asyncio import AsyncIOMotorClient client_db = AsyncIOMotorClient(MONGO_URL) db = client_db["antiarabic"] collection = db["users"] FORMAT = "[antirabic] %(message)s" logging.basicConfig( handlers=[logging.FileHandler("log.txt"), logging.StreamHandler()], level=logging.INFO, format=FORMAT, datefmt="[%X]", ) LOGGER = logging.getLogger('[antirabic]') LOGGER.info("antirabic is starting. | Rendy Projects. | Licensed under GPLv3.") LOGGER.info("Not affiliated to other anime.") LOGGER.info("Project maintained by: github.com/TeamkillerX (t.me/RendyProjects)") logging.getLogger("pyrogram").setLevel(logging.INFO) logging.getLogger("pyrogram").setLevel(logging.WARNING) logging.basicConfig(level=logging.INFO) randydev = Client( "Antiarabic", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN ) ANTIARABIC_GROUPS = 12 LOGS_CHANNEL = -1001589752824 async def can_delete(client: Client, bot_id: int) -> bool: member = await client.get_member(bot_id) if member.status in [enums.ChatMemberStatus.ADMINISTRATOR, enums.ChatMemberStatus.OWNER]: return True else: return False def extract_text(message: Message) -> str: return ( message.text or message.caption or (message.sticker.emoji if message.sticker else None) ) anti_text = """ AntiArabicScript module is used to delete messages containing characters from one of the following automatically: • Arabic • Arabic Supplement • Arabic Extended-A • Arabic Presentation Forms-A • Arabic Presentation Forms-B • Rumi Numeral Symbols • Arabic Mathematical Alphabetic Symbol NOTE: AntiArabicScript module doesn't affect messages sent by admins. Admin only: •/antiarabic on/off: turn antiarabic module on/off ( off by default ) Updates Channel: @RendyProjects """ async def set_chat_setting(chat_id, isboolean): await collection.update_one( {"chat_id": chat_id}, {"$set": {"arabic": isboolean}}, upsert=True ) async def chat_antiarabic(chat_id): user_data = await collection.find_one({"chat_id": chat_id}) if user_data: return user_data.get("arabic", False) return False @randydev.on_message(filters.command("start") & filters.private) async def welcome(client: Client, message: Message): keyboard = InlineKeyboardMarkup([[InlineKeyboardButton(text="Add To 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")]]) get_user_check = f"UserID: {message.from_user.id}\nUsername: @{message.from_user.username if message.from_user else None}\nFirst Name: {message.from_user.first_name}" await client.send_message(LOGS_CHANNEL, get_user_check) await message.reply_text(anti_text, reply_markup=keyboard) @randydev.on_message(filters.command("antiarabic")) async def antiarabic_setting(client: Client, message: Message): args = message.text.lower().split()[1:] chat = message.chat get_user_check = f"ChatID: {message.chat.id}\nChatUsername: @{message.chat.username if message.chat else None}\nUserID: {message.from_user.id}\nUsername: @{message.from_user.username if message.from_user else None}\nFirst Name: {message.from_user.first_name}" if chat.type != "private": if args: if args[0] in ("yes", "on", "true"): await set_chat_setting(chat.id, True) await client.send_message(LOGS_CHANNEL, get_user_check) await message.reply_text("Turned on AntiArabic! Messages sent by any non-admin that contain Arabic text will be deleted.") elif args[0] in ("no", "off", "false"): await set_chat_setting(chat.id, False) await client.send_message(LOGS_CHANNEL, get_user_check) await message.reply_text("Turned off AntiArabic! Messages containing Arabic text won't be deleted.") else: reply_text = f"AntiArabic Mode: {'On' if await chat_antiarabic(chat.id) else 'Off'}" await client.send_message(LOGS_CHANNEL, get_user_check) await message.reply_text(reply_text, parse_mode=ParseMode.MARKDOWN) @randydev.on_message(filters.group & ~filters.private, group=ANTIARABIC_GROUPS) async def antiarabic_filter(client: Client, message: Message): chat = message.chat to_match = extract_text(message) user = message.from_user if not await chat_antiarabic(chat.id): return if not user or user.id == 777000: return if not to_match: return me = await client.get_me() for c in to_match: if ('\u0600' <= c <= '\u06FF' or '\u0750' <= c <= '\u077F' or '\u08A0' <= c <= '\u08FF' or '\uFB50' <= c <= '\uFDFF' or '\uFE70' <= c <= '\uFEFF' or '\U00010E60' <= c <= '\U00010E7F' or '\U0001EE00' <= c <= '\U0001EEFF'): if await can_delete(chat, me.id): return await message.delete() randydev.run()