from app import app from pyrogram import filters from pyrogram.types import ReplyKeyboardMarkup, Message from pyrogram.client import Client from modules.utils import locale, logWrite from modules.database import col_users, col_spoilers from modules import custom_filters from bson.objectid import ObjectId from bson.errors import InvalidId @app.on_message( custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) & ~custom_filters.banned ) async def cmd_start(app: Client, msg: Message): user = col_users.find_one({"user": msg.from_user.id}) if user is None: col_users.insert_one( { "user": msg.from_user.id, "link": None, "label": "", "tg_name": msg.from_user.first_name, "tg_phone": msg.from_user.phone_number, "tg_locale": msg.from_user.language_code, "tg_username": msg.from_user.username, } ) logWrite(f"User {msg.from_user.id} started bot interaction") await msg.reply_text( locale("start", "message", locale=msg.from_user), reply_markup=ReplyKeyboardMarkup( locale("welcome", "keyboard", locale=msg.from_user), resize_keyboard=True, ), ) if len(msg.command) > 1: try: spoiler = col_spoilers.find_one({"_id": ObjectId(msg.command[1])}) if spoiler["photo"] is not None: await msg.reply_cached_media( spoiler["photo"], caption=spoiler["caption"] ) if spoiler["video"] is not None: await msg.reply_cached_media( spoiler["video"], caption=spoiler["caption"] ) if spoiler["audio"] is not None: await msg.reply_cached_media( spoiler["audio"], caption=spoiler["caption"] ) if spoiler["animation"] is not None: await msg.reply_cached_media( spoiler["animation"], caption=spoiler["caption"] ) if spoiler["document"] is not None: await msg.reply_cached_media( spoiler["document"], caption=spoiler["caption"] ) if spoiler["text"] is not None: await msg.reply_text(spoiler["text"]) except InvalidId: await msg.reply_text(f"Got an invalid ID {msg.command[1]}")