import asyncio
import re
import ast
import math
import random
lock = asyncio.Lock()

from pyrogram.errors.exceptions.bad_request_400 import MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty
from Script import script
import pyrogram
from database.connections_mdb import active_connection, all_connections, delete_connection, if_active, make_active, \
    make_inactive
from info import ADMINS, AUTH_CHANNEL, AUTH_USERS, SUPPORT_CHAT_ID, SUPPORT_CHAT, CUSTOM_FILE_CAPTION, PICS, AUTH_GROUPS, P_TTI_SHOW_OFF, NOR_IMG, LOG_CHANNEL, SPELL_IMG, MAX_B_TN, IMDB, \
    SINGLE_BUTTON, SPELL_CHECK_REPLY, IMDB_TEMPLATE, NO_RESULTS_MSG
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, InputMediaPhoto
from pyrogram import Client, filters, enums
from pyrogram.errors import FloodWait, UserIsBlocked, MessageNotModified, PeerIdInvalid
from utils import get_size, is_subscribed, get_poster, search_gagala, temp, get_settings, save_group_settings, send_all
from database.users_chats_db import db
from database.ia_filterdb import Media, get_file_details, get_search_results, get_bad_files
from database.filters_mdb import (
    del_all,
    find_filter,
    get_filters,
)
from database.gfilters_mdb import (
    find_gfilter,
    get_gfilters,
    del_allg
)
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)

BUTTONS = {}
SPELL_CHECK = {}


@Client.on_message(filters.group & filters.text & filters.incoming)
async def give_filter(client, message):
    if message.chat.id != SUPPORT_CHAT_ID:
        glob = await global_filters(client, message)
        if glob == False:
            manual = await manual_filters(client, message)
            if manual == False:
                settings = await get_settings(message.chat.id)
                try:
                    if settings['auto_ffilter']:
                        await auto_filter(client, message)
                except KeyError:
                    grpid = await active_connection(str(message.from_user.id))
                    await save_group_settings(grpid, 'auto_ffilter', True)
                    settings = await get_settings(message.chat.id)
                    if settings['auto_ffilter']:
                        await auto_filter(client, message)
    else: #a better logic to avoid repeated lines of code in auto_filter function
        search = message.text
        temp_files, temp_offset, total_results = await get_search_results(chat_id=message.chat.id, query=search.lower(), offset=0, filter=True)
        if total_results == 0:
            return
        else:
            return await message.reply_text(f"<b>ğŸ‘‹ ğ�–§ğ�–¾ğ�—’ {message.from_user.mention} \nğŸ“� {str(total_results)} ğ�–±ğ�–¾ğ�—Œğ�—�ğ�—…ğ�—�ğ�—Œ ğ�–ºğ�—‹ğ�–¾ ğ�–¿ğ�—ˆğ�—�ğ�—‡ğ�–½ ğ�–¿ğ�—ˆğ�—‹ ğ�—’ğ�—ˆğ�—�ğ�—‹ ğ�—Šğ�—�ğ�–¾ğ�—‹ğ�—’ {search}.\n\nKindly ask movies and series here â¬‡\n@blaster_arena & @blaster_movies</b>")

@Client.on_message(filters.private & filters.text & filters.incoming)
async def pv_filter(client, message):
    kd = await global_filters(client, message)
    if kd == False:
        await auto_filter(client, message)

@Client.on_callback_query(filters.regex(r"^next"))
async def next_page(bot, query):
    ident, req, key, offset = query.data.split("_")
    if int(req) not in [query.from_user.id, 0]:
        return await query.answer(script.ALRT_TXT.format(query.from_user.first_name), show_alert=True)
    try:
        offset = int(offset)
    except:
        offset = 0
    search = BUTTONS.get(key)
    if not search:
        await query.answer(script.OLD_ALRT_TXT.format(query.from_user.first_name),show_alert=True)
        return

    files, n_offset, total = await get_search_results(query.message.chat.id, search, offset=offset, filter=True)
    try:
        n_offset = int(n_offset)
    except:
        n_offset = 0

    if not files:
        return
    settings = await get_settings(query.message.chat.id)
    pre = 'filep' if settings['file_secure'] else 'file'
    temp.FILES_IDS[key] = files
    if settings['button']:
        btn = [
            [
                InlineKeyboardButton(
                   text=f"ğŸ”–{get_size(file.file_size)}ğŸ”®{file.file_name}", callback_data=f'{pre}#{file.file_id}'
                ),
            ]
            for file in files
        ]
    else:
        btn = [
            [
                InlineKeyboardButton(
                    text=f"{file.file_name}", callback_data=f'{pre}#{file.file_id}'
                ),
                InlineKeyboardButton(
                    text=f"{get_size(file.file_size)}",
                    callback_data=f'{pre}#{file.file_id}',
                ),
            ]
            for file in files
        ]
    try:
        if settings['auto_delete']:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ]
            )

        else:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ]
            )
                
    except KeyError:
        grpid = await active_connection(str(query.message.from_user.id))
        await save_group_settings(grpid, 'auto_delete', True)
        settings = await get_settings(query.message.chat.id)
        if settings['auto_delete']:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ]
            )

        else:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ]
            )
    try:
        settings = await get_settings(query.message.chat.id)
        if settings['max_btn']:
            if 0 < offset <= 10:
                off_set = 0
            elif offset == 0:
                off_set = None
            else:
                off_set = offset - 10
            if n_offset == 0:
                btn.append(
                    [InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"), InlineKeyboardButton(f"{math.ceil(int(offset)/10)+1} / {math.ceil(total/10)}", callback_data="pages")]
                )
            elif off_set is None:
                btn.append([InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(f"{math.ceil(int(offset)/10)+1} / {math.ceil(total/10)}", callback_data="pages"), InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")])
            else:
                btn.append(
                    [
                        InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"),
                        InlineKeyboardButton(f"{math.ceil(int(offset)/10)+1} / {math.ceil(total/10)}", callback_data="pages"),
                        InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")
                    ],
                )
        else:
            if 0 < offset <= int(MAX_B_TN):
                off_set = 0
            elif offset == 0:
                off_set = None
            else:
                off_set = offset - int(MAX_B_TN)
            if n_offset == 0:
                btn.append(
                    [InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"), InlineKeyboardButton(f"{math.ceil(int(offset)/int(MAX_B_TN))+1} / {math.ceil(total/int(MAX_B_TN))}", callback_data="pages")]
                )
            elif off_set is None:
                btn.append([InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(f"{math.ceil(int(offset)/int(MAX_B_TN))+1} / {math.ceil(total/int(MAX_B_TN))}", callback_data="pages"), InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")])
            else:
                btn.append(
                    [
                        InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"),
                        InlineKeyboardButton(f"{math.ceil(int(offset)/int(MAX_B_TN))+1} / {math.ceil(total/int(MAX_B_TN))}", callback_data="pages"),
                        InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")
                    ],
                )
    except KeyError:
        await save_group_settings(query.message.chat.id, 'max_btn', False)
        settings = await get_settings(query.message.chat.id)
        if settings['max_btn']:
            if 0 < offset <= 10:
                off_set = 0
            elif offset == 0:
                off_set = None
            else:
                off_set = offset - 10
            if n_offset == 0:
                btn.append(
                    [InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"), InlineKeyboardButton(f"{math.ceil(int(offset)/10)+1} / {math.ceil(total/10)}", callback_data="pages")]
                )
            elif off_set is None:
                btn.append([InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(f"{math.ceil(int(offset)/10)+1} / {math.ceil(total/10)}", callback_data="pages"), InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")])
            else:
                btn.append(
                    [
                        InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"),
                        InlineKeyboardButton(f"{math.ceil(int(offset)/10)+1} / {math.ceil(total/10)}", callback_data="pages"),
                        InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")
                    ],
                )
        else:
            if 0 < offset <= int(MAX_B_TN):
                off_set = 0
            elif offset == 0:
                off_set = None
            else:
                off_set = offset - int(MAX_B_TN)
            if n_offset == 0:
                btn.append(
                    [InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"), InlineKeyboardButton(f"{math.ceil(int(offset)/int(MAX_B_TN))+1} / {math.ceil(total/int(MAX_B_TN))}", callback_data="pages")]
                )
            elif off_set is None:
                btn.append([InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(f"{math.ceil(int(offset)/int(MAX_B_TN))+1} / {math.ceil(total/int(MAX_B_TN))}", callback_data="pages"), InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")])
            else:
                btn.append(
                    [
                        InlineKeyboardButton("â—€ï¸� ğ�–¡ğ�– ğ�–¢ğ�–ª", callback_data=f"next_{req}_{key}_{off_set}"),
                        InlineKeyboardButton(f"{math.ceil(int(offset)/int(MAX_B_TN))+1} / {math.ceil(total/int(MAX_B_TN))}", callback_data="pages"),
                        InlineKeyboardButton("ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�", callback_data=f"next_{req}_{key}_{n_offset}")
                    ],
                )
    btn.insert(0, [
        InlineKeyboardButton(f'ğŸ�¬ {search} ğŸ�¬', 'rkbtn')
    ])
    btn.insert(2, [
        InlineKeyboardButton("ğŸ“¤ ğ�–²ğ�–¾ğ�—‡ğ�–½ ğ�– ğ�—…ğ�—… ğ�–¥ğ�—‚ğ�—…ğ�–¾ğ�—Œ ğŸ“¤", callback_data=f"send_all#{req}#{key}#{pre}")
    ])
    try:
        await query.edit_message_reply_markup(
            reply_markup=InlineKeyboardMarkup(btn)
        )
    except MessageNotModified:
        pass
    await query.answer()


@Client.on_callback_query(filters.regex(r"^spol"))
async def advantage_spoll_choker(bot, query):
    _, user, movie_, key = query.data.split('#')
    movies = temp.SPELL_CHECK.get(key)
    if not movies:
        return await query.answer(script.OLD_ALRT_TXT.format(query.from_user.first_name), show_alert=True)
    if int(user) != 0 and query.from_user.id != int(user):
        return await query.answer(script.ALRT_TXT.format(query.from_user.first_name), show_alert=True)
    if movie_ == "close_spellcheck":
        return await query.message.delete()
    movie = movies[(int(movie_))]
    await query.answer(script.TOP_ALRT_MSG)
    gl = await global_filters(bot, query.message, text=movie)
    if gl == False:
        k = await manual_filters(bot, query.message, text=movie)
        if k == False:
            files, offset, total_results = await get_search_results(query.message.chat.id, movie, offset=0, filter=True)
            if files:
                k = (movie, files, offset, total_results)
                await auto_filter(bot, query, k)
            else:
                reqstr1 = query.from_user.id if query.from_user else 0
                reqstr = await bot.get_users(reqstr1)
                if NO_RESULTS_MSG:
                    await bot.send_message(chat_id=LOG_CHANNEL, text=(script.NORSLTS.format(reqstr.id, reqstr.mention, movie)))
                k = await query.message.edit(script.MVE_NT_FND)
                await asyncio.sleep(10)
                await k.delete()


@Client.on_callback_query()
async def cb_handler(client: Client, query: CallbackQuery):
    if query.data == "close_data":
        await query.message.delete()
    elif query.data == "gfiltersdeleteallconfirm":
        await del_allg(query.message, 'gfilters')
        await query.answer("Done !")
        return
    elif query.data == "gfiltersdeleteallcancel": 
        await query.message.reply_to_message.delete()
        await query.message.delete()
        await query.answer("Process Cancelled !")
        return
    elif query.data == "delallconfirm":
        userid = query.from_user.id
        chat_type = query.message.chat.type

        if chat_type == enums.ChatType.PRIVATE:
            grpid = await active_connection(str(userid))
            if grpid is not None:
                grp_id = grpid
                try:
                    chat = await client.get_chat(grpid)
                    title = chat.title
                except:
                    await query.message.edit_text("Make sure I'm present in your group!!", quote=True)
                    return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')
            else:
                await query.message.edit_text(
                    "I'm not connected to any groups!\nCheck /connections or connect to any groups",
                    quote=True
                )
                return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')

        elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
            grp_id = query.message.chat.id
            title = query.message.chat.title

        else:
            return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')

        st = await client.get_chat_member(grp_id, userid)
        if (st.status == enums.ChatMemberStatus.OWNER) or (str(userid) in ADMINS):
            await del_all(query.message, grp_id, title)
        else:
            await query.answer("You need to be Group Owner or an Auth User to do that!", show_alert=True)
    elif query.data == "delallcancel":
        userid = query.from_user.id
        chat_type = query.message.chat.type

        if chat_type == enums.ChatType.PRIVATE:
            await query.message.reply_to_message.delete()
            await query.message.delete()

        elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]:
            grp_id = query.message.chat.id
            st = await client.get_chat_member(grp_id, userid)
            if (st.status == enums.ChatMemberStatus.OWNER) or (str(userid) in ADMINS):
                await query.message.delete()
                try:
                    await query.message.reply_to_message.delete()
                except:
                    pass
            else:
                await query.answer("That's not for you!!", show_alert=True)
    elif "groupcb" in query.data:
        await query.answer()

        group_id = query.data.split(":")[1]

        act = query.data.split(":")[2]
        hr = await client.get_chat(int(group_id))
        title = hr.title
        user_id = query.from_user.id

        if act == "":
            stat = "CONNECT"
            cb = "connectcb"
        else:
            stat = "DISCONNECT"
            cb = "disconnect"

        keyboard = InlineKeyboardMarkup([
            [InlineKeyboardButton(f"{stat}", callback_data=f"{cb}:{group_id}"),
             InlineKeyboardButton("DELETE", callback_data=f"deletecb:{group_id}")],
            [InlineKeyboardButton("BACK", callback_data="backcb")]
        ])

        await query.message.edit_text(
            f"Group Name : **{title}**\nGroup ID : `{group_id}`",
            reply_markup=keyboard,
            parse_mode=enums.ParseMode.MARKDOWN
        )
        return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')
    elif "connectcb" in query.data:
        await query.answer()

        group_id = query.data.split(":")[1]

        hr = await client.get_chat(int(group_id))

        title = hr.title

        user_id = query.from_user.id

        mkact = await make_active(str(user_id), str(group_id))

        if mkact:
            await query.message.edit_text(
                f"Connected to **{title}**",
                parse_mode=enums.ParseMode.MARKDOWN
            )
        else:
            await query.message.edit_text('Disconnected from', parse_mode=enums.ParseMode.MARKDOWN)
        return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')
    elif "disconnect" in query.data:
        await query.answer()

        group_id = query.data.split(":")[1]

        hr = await client.get_chat(int(group_id))

        title = hr.title
        user_id = query.from_user.id

        mkinact = await make_inactive(str(user_id))

        if mkinact:
            await query.message.edit_text(
                f"Disconnected from **{title}**",
                parse_mode=enums.ParseMode.MARKDOWN
            )
        else:
            await query.message.edit_text(
                f"Some error occurred!!",
                parse_mode=enums.ParseMode.MARKDOWN
            )
        return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')
    elif "deletecb" in query.data:
        await query.answer()

        user_id = query.from_user.id
        group_id = query.data.split(":")[1]

        delcon = await delete_connection(str(user_id), str(group_id))

        if delcon:
            await query.message.edit_text(
                "Successfully deleted connection"
            )
        else:
            await query.message.edit_text(
                f"Some error occurred!!",
                parse_mode=enums.ParseMode.MARKDOWN
            )
        return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')
    elif query.data == "backcb":
        await query.answer()

        userid = query.from_user.id

        groupids = await all_connections(str(userid))
        if groupids is None:
            await query.message.edit_text(
                "There are no active connections!! Connect to some groups first.",
            )
            return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')
        buttons = []
        for groupid in groupids:
            try:
                ttl = await client.get_chat(int(groupid))
                title = ttl.title
                active = await if_active(str(userid), str(groupid))
                act = " - ACTIVE" if active else ""
                buttons.append(
                    [
                        InlineKeyboardButton(
                            text=f"{title}{act}", callback_data=f"groupcb:{groupid}:{act}"
                        )
                    ]
                )
            except:
                pass
        if buttons:
            await query.message.edit_text(
                "Your connected group details ;\n\n",
                reply_markup=InlineKeyboardMarkup(buttons)
            )
    elif "gfilteralert" in query.data:
        grp_id = query.message.chat.id
        i = query.data.split(":")[1]
        keyword = query.data.split(":")[2]
        reply_text, btn, alerts, fileid = await find_gfilter('gfilters', keyword)
        if alerts is not None:
            alerts = ast.literal_eval(alerts)
            alert = alerts[int(i)]
            alert = alert.replace("\\n", "\n").replace("\\t", "\t")
            await query.answer(alert, show_alert=True)
    elif "alertmessage" in query.data:
        grp_id = query.message.chat.id
        i = query.data.split(":")[1]
        keyword = query.data.split(":")[2]
        reply_text, btn, alerts, fileid = await find_filter(grp_id, keyword)
        if alerts is not None:
            alerts = ast.literal_eval(alerts)
            alert = alerts[int(i)]
            alert = alert.replace("\\n", "\n").replace("\\t", "\t")
            await query.answer(alert, show_alert=True)
    if query.data.startswith("file"):
        clicked = query.from_user.id
        try:
            typed = query.message.reply_to_message.from_user.id
        except:
            typed = query.from_user.id
        ident, file_id = query.data.split("#")
        files_ = await get_file_details(file_id)
        if not files_:
            return await query.answer('No such file exist.')
        files = files_[0]
        title = files.file_name
        size = get_size(files.file_size)
        f_caption = files.caption
        settings = await get_settings(query.message.chat.id)
        if CUSTOM_FILE_CAPTION:
            try:
                f_caption = CUSTOM_FILE_CAPTION.format(file_name='' if title is None else title,
                                                       file_size='' if size is None else size,
                                                       file_caption='' if f_caption is None else f_caption)
            except Exception as e:
                logger.exception(e)
            f_caption = f_caption
        if f_caption is None:
            f_caption = f"{files.file_name}"

        try:
            if AUTH_CHANNEL and not await is_subscribed(client, query):
                if clicked == typed:
                    await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
                    return
                else:
                    await query.answer(f"ğ�–§ğ�–¾ğ�—’ {query.from_user.first_name}, ğ�–³ğ�—�ğ�—‚ğ�—Œ ğ�—‚ğ�—Œ ğ�—‡ğ�—ˆğ�—� ğ�—’ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� !", show_alert=True)
            elif settings['botpm']:
                if clicked == typed:
                    await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
                    return
                else:
                    await query.answer(f"ğ�–§ğ�–¾ğ�—’ {query.from_user.first_name}, ğ�–³ğ�—�ğ�—‚ğ�—Œ ğ�—‚ğ�—Œ ğ�—‡ğ�—ˆğ�—� ğ�—’ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� !", show_alert=True)
            else:
                if clicked == typed:
                    await client.send_cached_media(
                        chat_id=query.from_user.id,
                        file_id=file_id,
                        caption=f_caption,
                        protect_content=True if ident == "filep" else False,
                        reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton('âš”ï¸� ğ�–¯ğ�–¨ğ�–±ğ�–® ğ�–´ğ�–¯ğ�–£ğ�– ğ�–³ğ�–¤ğ�–² âš”ï¸�', url="https://t.me/piroxbots") ] ] ))
                else:
                    await query.answer(f"ğ�–§ğ�–¾ğ�—’ {query.from_user.first_name}, ğ�–³ğ�—�ğ�—‚ğ�—Œ ğ�—‚ğ�—Œ ğ�—‡ğ�—ˆğ�—� ğ�—’ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� !", show_alert=True)
                await query.answer('ğ�–¢ğ�—�ğ�–¾ğ�–¼ğ�—„ ğ�–¯ğ�–¬, ğ�–¨ ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�–¾ğ�—‡ğ�—� ğ�–¿ğ�—‚ğ�—…ğ�–¾ğ�—Œ ğ�—‚ğ�—‡ ğ�–¯ğ�–¬', show_alert=True)
        except UserIsBlocked:
            await query.answer('ğ�–´ğ�—‡ğ�–»ğ�—…ğ�—ˆğ�–¼ğ�—„ ğ�—�ğ�—�ğ�–¾ ğ�–»ğ�—ˆğ�—� ğ�—†ğ�–ºğ�—‡ğ�—� !', show_alert=True)
        except PeerIdInvalid:
            await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
        except Exception as e:
            await query.answer(url=f"https://t.me/{temp.U_NAME}?start={ident}_{file_id}")
    elif query.data.startswith("checksub"):
        if AUTH_CHANNEL and not await is_subscribed(client, query):
            await query.answer("ğ�–¨ ğ�–«ğ�—‚ğ�—„ğ�–¾ ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�–²ğ�—†ğ�–ºğ�—‹ğ�—�ğ�—‡ğ�–¾ğ�—Œğ�—Œ, ğ�–¡ğ�—�ğ�—� ğ�–£ğ�—ˆğ�—‡'ğ�—� ğ�–¡ğ�–¾ ğ�–®ğ�—�ğ�–¾ğ�—‹ğ�—Œğ�—†ğ�–ºğ�—‹ğ�—� ğŸ˜’ \nğ�–©ğ�—ˆğ�—‚ğ�—‡ ğ�–´ğ�—‰ğ�–½ğ�–ºğ�—�ğ�–¾ ğ�–¢ğ�—�ğ�–ºğ�—‡ğ�—‡ğ�–¾ğ�—… ğ�–¿ğ�—‚ğ�—‹ğ�—Œğ�—� ;)", show_alert=True)
            return
        ident, file_id = query.data.split("#")
        files_ = await get_file_details(file_id)
        if not files_:
            return await query.answer('No such file exist.')
        files = files_[0]
        title = files.file_name
        size = get_size(files.file_size)
        f_caption = files.caption
        if CUSTOM_FILE_CAPTION:
            try:
                f_caption = CUSTOM_FILE_CAPTION.format(file_name='' if title is None else title,
                                                       file_size='' if size is None else size,
                                                       file_caption='' if f_caption is None else f_caption)
            except Exception as e:
                logger.exception(e)
                f_caption = f_caption
        if f_caption is None:
            f_caption = f"{title}"
        await query.answer()
        await client.send_cached_media(
            chat_id=query.from_user.id,
            file_id=file_id,
            caption=f_caption,
            protect_content=True if ident == 'checksubp' else False,
            reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton('âš”ï¸� ğ�–¯ğ�–¨ğ�–±ğ�–® ğ�–´ğ�–¯ğ�–£ğ�– ğ�–³ğ�–¤ğ�–² âš”ï¸�', url="https://t.me/piroxbots") ] ] ))
    elif query.data == "pages":
        await query.answer()

    elif query.data.startswith("send_all"):
        _, req, key, pre = query.data.split("#")
        if int(req) not in [query.from_user.id, 0]:
            return await query.answer(script.ALRT_TXT.format(query.from_user.first_name), show_alert=True)
        
        await query.answer(url=f"https://t.me/{temp.U_NAME}?start=all_{key}_{pre}")
        

    elif query.data.startswith("killfilesdq"):
        ident, keyword = query.data.split("#")
        await query.message.edit_text(f"<b>Fetching Files for your query {keyword} on DB... Please wait...</b>")
        files, total = await get_bad_files(keyword)
        await query.message.edit_text(f"<b>Found {total} files for your query {keyword} !\n\nFile deletion process will start in 5 seconds !</b>")
        await asyncio.sleep(5)
        deleted = 0
        async with lock:
            try:
                for file in files:
                    file_ids = file.file_id
                    file_name = file.file_name
                    result = await Media.collection.delete_one({
                        '_id': file_ids,
                    })
                    if result.deleted_count:
                        logger.info(f'File Found for your query {keyword}! Successfully deleted {file_name} from database.')
                    deleted += 1
                    if deleted % 20 == 0:
                        await query.message.edit_text(f"<b>Process started for deleting files from DB. Successfully deleted {str(deleted)} files from DB for your query {keyword} !\n\nPlease wait...</b>")
            except Exception as e:
                logger.exception(e)
                await query.message.edit_text(f'Error: {e}')
            else:
                await query.message.edit_text(f"<b>Process Completed for file deletion !\n\nSuccessfully deleted {str(deleted)} files from database for your query {keyword}.</b>")

    elif query.data.startswith("opnsetgrp"):
        ident, grp_id = query.data.split("#")
        userid = query.from_user.id if query.from_user else None
        st = await client.get_chat_member(grp_id, userid)
        if (
                st.status != enums.ChatMemberStatus.ADMINISTRATOR
                and st.status != enums.ChatMemberStatus.OWNER
                and str(userid) not in ADMINS
        ):
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)
            return
        title = query.message.chat.title
        settings = await get_settings(grp_id)
        if settings is not None:
            buttons = [
                [
                    InlineKeyboardButton('ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡',
                                         callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}'),
                    InlineKeyboardButton('ğ�–²ğ�—‚ğ�—‡ğ�—€ğ�—…ğ�–¾ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡' if settings["button"] else 'ğ�–£ğ�—ˆğ�—�ğ�–»ğ�—…ğ�–¾',
                                         callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¥ğ�—‚ğ�—…ğ�–¾ ğ�–²ğ�–¾ğ�—‡ğ�–½ ğ�–¬ğ�—ˆğ�–½ğ�–¾', callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}'),
                    InlineKeyboardButton('ğ�–¬ğ�–ºğ�—‡ğ�—�ğ�–ºğ�—… ğ�–²ğ�—�ğ�–ºğ�—‹ğ�—�' if settings["botpm"] else 'ğ�– ğ�—�ğ�—�ğ�—ˆ ğ�–²ğ�–¾ğ�—‡ğ�–½',
                                         callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¯ğ�—‹ğ�—ˆğ�—�ğ�–¾ğ�–¼ğ�—� ğ�–¢ğ�—ˆğ�—‡ğ�—�ğ�–¾ğ�—‡ğ�—�',
                                         callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["file_secure"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¨ğ�–¬ğ�–£ğ�–»', callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["imdb"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–²ğ�—‰ğ�–¾ğ�—…ğ�—… ğ�–¢ğ�—�ğ�–¾ğ�–¼ğ�—„',
                                         callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["spell_check"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¶ğ�–¾ğ�—…ğ�–¼ğ�—ˆğ�—†ğ�–¾ ğ�–¬ğ�–¾ğ�—Œğ�—Œğ�–ºğ�—€ğ�–¾', callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["welcome"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�– ğ�—�ğ�—�ğ�—ˆ ğ�–£ğ�–¾ğ�—…ğ�–¾ğ�—�ğ�–¾',
                                         callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{str(grp_id)}'),
                    InlineKeyboardButton('5 ğ�–¬ğ�—‚ğ�—‡' if settings["auto_delete"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�– ğ�—�ğ�—�ğ�—ˆ-ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹',
                                         callback_data=f'setgs#auto_ffilter#{settings["auto_ffilter"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["auto_ffilter"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#auto_ffilter#{settings["auto_ffilter"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¬ğ�–ºğ�—‘ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡ğ�—Œ',
                                         callback_data=f'setgs#max_btn#{settings["max_btn"]}#{str(grp_id)}'),
                    InlineKeyboardButton('10' if settings["max_btn"] else f'{MAX_B_TN}',
                                         callback_data=f'setgs#max_btn#{settings["max_btn"]}#{str(grp_id)}')
                ]
            ]
            reply_markup = InlineKeyboardMarkup(buttons)
            await query.message.edit_text(
                text=f"<b>ğ�–¢ğ�—�ğ�–ºğ�—‡ğ�—€ğ�–¾ ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�–²ğ�–¾ğ�—�ğ�—�ğ�—‚ğ�—‡ğ�—€ğ�—Œ ğ�–¥ğ�—ˆğ�—‹ {title} ğ�– ğ�—Œ ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�–¶ğ�—‚ğ�—Œğ�—�</b>",
                disable_web_page_preview=True,
                parse_mode=enums.ParseMode.HTML
            )
            await query.message.edit_reply_markup(reply_markup)
        
    elif query.data.startswith("opnsetpm"):
        ident, grp_id = query.data.split("#")
        userid = query.from_user.id if query.from_user else None
        st = await client.get_chat_member(grp_id, userid)
        if (
                st.status != enums.ChatMemberStatus.ADMINISTRATOR
                and st.status != enums.ChatMemberStatus.OWNER
                and str(userid) not in ADMINS
        ):
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)
            return
        title = query.message.chat.title
        settings = await get_settings(grp_id)
        btn2 = [[
                 InlineKeyboardButton("â�¡ ğ�–®ğ�—‰ğ�–¾ğ�—‡ ğ�—‚ğ�—‡ ğ�–¯ğ�–¬ â�¡", url=f"t.me/{temp.U_NAME}")
               ]]
        reply_markup = InlineKeyboardMarkup(btn2)
        await query.message.edit_text(f"<b>ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—Œğ�–¾ğ�—�ğ�—�ğ�—‚ğ�—‡ğ�—€ğ�—Œ ğ�—†ğ�–¾ğ�—‡ğ�—� ğ�–¿ğ�—ˆğ�—‹ {title} ğ�—�ğ�–ºğ�—Œ ğ�–»ğ�–¾ğ�–¾ğ�—‡ ğ�—Œğ�–¾ğ�—‡ğ�—� ğ�—�ğ�—ˆ ğ�—’ğ�—ˆğ�—�ğ�—‹ ğ�–¯ğ�–¬</b>")
        await query.message.edit_reply_markup(reply_markup)
        if settings is not None:
            buttons = [
                [
                    InlineKeyboardButton('ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡',
                                         callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}'),
                    InlineKeyboardButton('ğ�–²ğ�—‚ğ�—‡ğ�—€ğ�—…ğ�–¾ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡' if settings["button"] else 'ğ�–£ğ�—ˆğ�—�ğ�–»ğ�—…ğ�–¾',
                                         callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¥ğ�—‚ğ�—…ğ�–¾ ğ�–²ğ�–¾ğ�—‡ğ�–½ ğ�–¬ğ�—ˆğ�–½ğ�–¾', callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}'),
                    InlineKeyboardButton('ğ�–¬ğ�–ºğ�—‡ğ�—�ğ�–ºğ�—… ğ�–²ğ�—�ğ�–ºğ�—‹ğ�—�' if settings["botpm"] else 'ğ�– ğ�—�ğ�—�ğ�—ˆ ğ�–²ğ�–¾ğ�—‡ğ�–½',
                                         callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¯ğ�—‹ğ�—ˆğ�—�ğ�–¾ğ�–¼ğ�—� ğ�–¢ğ�—ˆğ�—‡ğ�—�ğ�–¾ğ�—‡ğ�—�',
                                         callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["file_secure"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¨ğ�–¬ğ�–£ğ�–»', callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["imdb"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–²ğ�—‰ğ�–¾ğ�—…ğ�—… ğ�–¢ğ�—�ğ�–¾ğ�–¼ğ�—„',
                                         callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["spell_check"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¶ğ�–¾ğ�—…ğ�–¼ğ�—ˆğ�—†ğ�–¾ ğ�–¬ğ�–¾ğ�—Œğ�—Œğ�–ºğ�—€ğ�–¾', callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["welcome"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�– ğ�—�ğ�—�ğ�—ˆ ğ�–£ğ�–¾ğ�—…ğ�–¾ğ�—�ğ�–¾',
                                         callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{str(grp_id)}'),
                    InlineKeyboardButton('5 ğ�–¬ğ�—‚ğ�—‡' if settings["auto_delete"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�– ğ�—�ğ�—�ğ�—ˆ-ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹',
                                         callback_data=f'setgs#auto_ffilter#{settings["auto_ffilter"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["auto_ffilter"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#auto_ffilter#{settings["auto_ffilter"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¬ğ�–ºğ�—‘ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡ğ�—Œ',
                                         callback_data=f'setgs#max_btn#{settings["max_btn"]}#{str(grp_id)}'),
                    InlineKeyboardButton('10' if settings["max_btn"] else f'{MAX_B_TN}',
                                         callback_data=f'setgs#max_btn#{settings["max_btn"]}#{str(grp_id)}')
                ]
            ]
            reply_markup = InlineKeyboardMarkup(buttons)
            await client.send_message(
                chat_id=userid,
                text=f"<b>ğ�–¢ğ�—�ğ�–ºğ�—‡ğ�—€ğ�–¾ ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�–²ğ�–¾ğ�—�ğ�—�ğ�—‚ğ�—‡ğ�—€ğ�—Œ ğ�–¥ğ�—ˆğ�—‹ {title} ğ�– ğ�—Œ ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�–¶ğ�—‚ğ�—Œğ�—�</b>",
                reply_markup=reply_markup,
                disable_web_page_preview=True,
                parse_mode=enums.ParseMode.HTML,
                reply_to_message_id=query.message.id
            )

    elif query.data.startswith("show_option"):
        ident, from_user = query.data.split("#")
        btn = [[
                InlineKeyboardButton("âš  ğ�–´ğ�—‡ğ�–ºğ�—�ğ�–ºğ�—‚ğ�–ºğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ âš ", callback_data=f"unavailable#{from_user}"),
                InlineKeyboardButton("âœ… ğ�–´ğ�—‰ğ�—…ğ�—ˆğ�–ºğ�–½ğ�–¾ğ�–½ âœ…", callback_data=f"uploaded#{from_user}")
             ],[
                InlineKeyboardButton("ğŸ”° ğ�– ğ�—…ğ�—‹ğ�–¾ğ�–ºğ�–½ğ�—’ ğ�– ğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ ğŸ”°", callback_data=f"already_available#{from_user}")
              ]]
        btn2 = [[
                 InlineKeyboardButton("â�• ğ�–µğ�—‚ğ�–¾ğ�—� ğ�–²ğ�—�ğ�–ºğ�—�ğ�—�ğ�—Œ â�•", url=f"{query.message.link}")
               ]]
        if query.from_user.id in ADMINS:
            user = await client.get_users(from_user)
            reply_markup = InlineKeyboardMarkup(btn)
            await query.message.edit_reply_markup(reply_markup)
            await query.answer("ğ�–§ğ�–¾ğ�—‹ğ�–¾ ğ�–ºğ�—‹ğ�–¾ ğ�—�ğ�—�ğ�–¾ ğ�—ˆğ�—‰ğ�—�ğ�—‚ğ�—ˆğ�—‡ğ�—Œ")
        else:
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�—�ğ�–¿ğ�–¿ğ�—‚ğ�–¼ğ�—‚ğ�–¾ğ�—‡ğ�—� ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)
        
    elif query.data.startswith("unavailable"):
        ident, from_user = query.data.split("#")
        btn = [[
                InlineKeyboardButton("âš  ğ�–´ğ�—‡ğ�–ºğ�—�ğ�–ºğ�—‚ğ�–ºğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ âš ", callback_data=f"unalert#{from_user}")
              ]]
        btn2 = [[
                 InlineKeyboardButton("â�• ğ�–µğ�—‚ğ�–¾ğ�—� ğ�–²ğ�—�ğ�–ºğ�—�ğ�—�ğ�—Œ â�•", url=f"{query.message.link}")
               ]]
        if query.from_user.id in ADMINS:
            user = await client.get_users(from_user)
            reply_markup = InlineKeyboardMarkup(btn)
            content = query.message.text
            await query.message.edit_text(f"<b><strike>{content}</strike></b>")
            await query.message.edit_reply_markup(reply_markup)
            await query.answer("ğ�–²ğ�–¾ğ�—� ğ�—�ğ�—ˆ ğ�–´ğ�—‡ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾")
            try:
                await client.send_message(chat_id=int(from_user), text=f"<b>ğ�–§ğ�–¾ğ�—’ {user.mention}, ğ�–²ğ�—ˆğ�—‹ğ�—‹ğ�—’ ğ�—’ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—‚ğ�—Œ ğ�—�ğ�—‡ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾. ğ�–²ğ�—ˆ ğ�—†ğ�—ˆğ�–½ğ�–¾ğ�—‹ğ�–ºğ�—�ğ�—ˆğ�—‹ğ�—Œ ğ�–¼ğ�–ºğ�—‡'ğ�—� ğ�–ºğ�–½ğ�–½ ğ�—‚ğ�—� !</b>", reply_markup=InlineKeyboardMarkup(btn2))
            except UserIsBlocked:
                await client.send_message(chat_id=int(SUPPORT_CHAT_ID), text=f"<b>ğ�–§ğ�–¾ğ�—’ {user.mention}, ğ�–²ğ�—ˆğ�—‹ğ�—‹ğ�—’ ğ�—’ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—‚ğ�—Œ ğ�—�ğ�—‡ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾. ğ�–²ğ�—ˆ ğ�—†ğ�—ˆğ�–½ğ�–¾ğ�—‹ğ�–ºğ�—�ğ�—ˆğ�—‹ğ�—Œ ğ�–¼ğ�–ºğ�—‡'ğ�—� ğ�–ºğ�–½ğ�–½ ğ�—‚ğ�—� !\n\nğŸ“� ğ�–­ğ�—ˆğ�—�ğ�–¾: ğ�–³ğ�—�ğ�—‚ğ�—Œ ğ�—†ğ�–¾ğ�—Œğ�—Œğ�–ºğ�—€ğ�–¾ ğ�—‚ğ�—Œ ğ�—Œğ�–¾ğ�—‡ğ�—� ğ�—‚ğ�—‡ ğ�–¦ğ�—‹ğ�—ˆğ�—�ğ�—‰ ğ�–»ğ�–¾ğ�–¼ğ�–ºğ�—�ğ�—Œğ�–¾ ğ�—’ğ�—ˆğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�–¡ğ�—…ğ�—ˆğ�–¼ğ�—„ğ�–¾ğ�–½ ğ�—�ğ�—�ğ�–¾ ğ�–¡ğ�—ˆğ�—� ! ğ�–´ğ�—‡ğ�–»ğ�—…ğ�—ˆğ�–¼ğ�—„ ğ�—�ğ�—�ğ�–¾ ğ�–¡ğ�—ˆğ�—� !</b>", reply_markup=InlineKeyboardMarkup(btn2))
        else:
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�—�ğ�–¿ğ�–¿ğ�—‚ğ�–¼ğ�—‚ğ�–¾ğ�—‡ğ�—� ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)

    elif query.data.startswith("uploaded"):
        ident, from_user = query.data.split("#")
        btn = [[
                InlineKeyboardButton("âœ… ğ�–´ğ�—‰ğ�—…ğ�—ˆğ�–ºğ�–½ğ�–¾ğ�–½ âœ…", callback_data=f"upalert#{from_user}")
              ]]
        btn2 = [[
                 InlineKeyboardButton("â�• ğ�–µğ�—‚ğ�–¾ğ�—� ğ�–²ğ�—�ğ�–ºğ�—�ğ�—�ğ�—Œ â�•", url=f"{query.message.link}")
               ]]
        if query.from_user.id in ADMINS:
            user = await client.get_users(from_user)
            reply_markup = InlineKeyboardMarkup(btn)
            content = query.message.text
            await query.message.edit_text(f"<b><strike>{content}</strike></b>")
            await query.message.edit_reply_markup(reply_markup)
            await query.answer("ğ�–²ğ�–¾ğ�—� ğ�—�ğ�—ˆ ğ�–´ğ�—‰ğ�—…ğ�—ˆğ�–ºğ�–½ğ�–¾ğ�–½")
            try:
                await client.send_message(chat_id=int(from_user), text=f"<b>ğ�–§ğ�–¾ğ�—’ {user.mention}, ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—�ğ�–ºğ�—Œ ğ�–»ğ�–¾ğ�–¾ğ�—‡ ğ�—�ğ�—‰ğ�—…ğ�—ˆğ�–ºğ�–½ğ�–¾ğ�–½ ğ�–»ğ�—’ ğ�—†ğ�—ˆğ�–½ğ�–¾ğ�—‹ğ�–ºğ�—�ğ�—ˆğ�—‹. ğ�–ªğ�—‚ğ�—‡ğ�–½ğ�—…ğ�—’ ğ�—Œğ�–¾ğ�–ºğ�—‹ğ�–¼ğ�—� ğ�–ºğ�—€ğ�–ºğ�—‚ğ�—‡ @blaster_arena & @blaster_movies !</b>", reply_markup=InlineKeyboardMarkup(btn2))
            except UserIsBlocked:
                await client.send_message(chat_id=int(SUPPORT_CHAT_ID), text=f"<b>ğ�–§ğ�–¾ğ�—’ {user.mention}, ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—�ğ�–ºğ�—Œ ğ�–»ğ�–¾ğ�–¾ğ�—‡ ğ�—�ğ�—‰ğ�—…ğ�—ˆğ�–ºğ�–½ğ�–¾ğ�–½ ğ�–»ğ�—’ ğ�—†ğ�—ˆğ�–½ğ�–¾ğ�—‹ğ�–ºğ�—�ğ�—ˆğ�—‹. ğ�–ªğ�—‚ğ�—‡ğ�–½ğ�—…ğ�—’ ğ�—Œğ�–¾ğ�–ºğ�—‹ğ�–¼ğ�—� ğ�–ºğ�—€ğ�–ºğ�—‚ğ�—‡ @blaster_arena & @blaster_movies !\n\nğŸ“� ğ�–­ğ�—ˆğ�—�ğ�–¾: ğ�–³ğ�—�ğ�—‚ğ�—Œ ğ�—†ğ�–¾ğ�—Œğ�—Œğ�–ºğ�—€ğ�–¾ ğ�—‚ğ�—Œ ğ�—Œğ�–¾ğ�—‡ğ�—� ğ�—‚ğ�—‡ ğ�–¦ğ�—‹ğ�—ˆğ�—�ğ�—‰ ğ�–»ğ�–¾ğ�–¼ğ�–ºğ�—�ğ�—Œğ�–¾ ğ�—’ğ�—ˆğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�–¡ğ�—…ğ�—ˆğ�–¼ğ�—„ğ�–¾ğ�–½ ğ�—�ğ�—�ğ�–¾ ğ�–¡ğ�—ˆğ�—� ! ğ�–´ğ�—‡ğ�–»ğ�—…ğ�—ˆğ�–¼ğ�—„ ğ�—�ğ�—�ğ�–¾ ğ�–¡ğ�—ˆğ�—� !</b>", reply_markup=InlineKeyboardMarkup(btn2))
        else:
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�—�ğ�–¿ğ�–¿ğ�—‚ğ�–¼ğ�—‚ğ�–¾ğ�—‡ğ�—� ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)

    elif query.data.startswith("already_available"):
        ident, from_user = query.data.split("#")
        btn = [[
                InlineKeyboardButton("ğŸ”° ğ�– ğ�—…ğ�—‹ğ�–¾ğ�–ºğ�–½ğ�—’ ğ�– ğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ ğŸ”°", callback_data=f"alalert#{from_user}")
              ]]
        btn2 = [[
                 InlineKeyboardButton("â�• ğ�–µğ�—‚ğ�–¾ğ�—� ğ�–²ğ�—�ğ�–ºğ�—�ğ�—�ğ�—Œ â�•", url=f"{query.message.link}")
               ]]
        if query.from_user.id in ADMINS:
            user = await client.get_users(from_user)
            reply_markup = InlineKeyboardMarkup(btn)
            content = query.message.text
            await query.message.edit_text(f"<b><strike>{content}</strike></b>")
            await query.message.edit_reply_markup(reply_markup)
            await query.answer("ğ�–²ğ�–¾ğ�—� ğ�—�ğ�—ˆ ğ�–ºğ�—…ğ�—‹ğ�–¾ğ�–ºğ�–½ğ�—’ ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ !")
            try:
                await client.send_message(chat_id=int(from_user), text=f"<b>ğ�–§ğ�–¾ğ�—’ {user.mention}, ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—‚ğ�—Œ ğ�–ºğ�—…ğ�—‹ğ�–¾ğ�–ºğ�–½ğ�—’ ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ ğ�—ˆğ�—‡ ğ�–¡ğ�—ˆğ�—�. ğ�–ªğ�—‚ğ�—‡ğ�–½ğ�—…ğ�—’ ğ�—Œğ�–¾ğ�–ºğ�—‹ğ�–¼ğ�—� ğ�–ºğ�—€ğ�–ºğ�—‚ğ�—‡ @blaster_arena & @blaster_movies !</b>", reply_markup=InlineKeyboardMarkup(btn2))
            except UserIsBlocked:
                await client.send_message(chat_id=int(SUPPORT_CHAT_ID), text=f"<b>ğ�–§ğ�–¾ğ�—’ {user.mention}, ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—‚ğ�—Œ ğ�–ºğ�—…ğ�—‹ğ�–¾ğ�–ºğ�–½ğ�—’ ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ ğ�—ˆğ�—‡ ğ�–¡ğ�—ˆğ�—�. ğ�–ªğ�—‚ğ�—‡ğ�–½ğ�—…ğ�—’ ğ�—Œğ�–¾ğ�–ºğ�—‹ğ�–¼ğ�—� ğ�–ºğ�—€ğ�–ºğ�—‚ğ�—‡ @blaster_arena & @blaster_movies !\n\nğŸ“� ğ�–­ğ�—ˆğ�—�ğ�–¾: ğ�–³ğ�—�ğ�—‚ğ�—Œ ğ�—†ğ�–¾ğ�—Œğ�—Œğ�–ºğ�—€ğ�–¾ ğ�—‚ğ�—Œ ğ�—Œğ�–¾ğ�—‡ğ�—� ğ�—‚ğ�—‡ ğ�–¦ğ�—‹ğ�—ˆğ�—�ğ�—‰ ğ�–»ğ�–¾ğ�–¼ğ�–ºğ�—�ğ�—Œğ�–¾ ğ�—’ğ�—ˆğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�–¡ğ�—…ğ�—ˆğ�–¼ğ�—„ğ�–¾ğ�–½ ğ�—�ğ�—�ğ�–¾ ğ�–¡ğ�—ˆğ�—� ! ğ�–´ğ�—‡ğ�–»ğ�—…ğ�—ˆğ�–¼ğ�—„ ğ�—�ğ�—�ğ�–¾ ğ�–¡ğ�—ˆğ�—� !</b>", reply_markup=InlineKeyboardMarkup(btn2))
        else:
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�—�ğ�–¿ğ�–¿ğ�—‚ğ�–¼ğ�—‚ğ�–¾ğ�—‡ğ�—� ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)

    elif query.data.startswith("alalert"):
        ident, from_user = query.data.split("#")
        if int(query.from_user.id) == int(from_user):
            user = await client.get_users(from_user)
            await query.answer(f"ğ�–§ğ�–¾ğ�—’ {user.first_name}, ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—‚ğ�—Œ ğ�–ºğ�—…ğ�—‹ğ�–¾ğ�–ºğ�–½ğ�—’ ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ !", show_alert=True)
        else:
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�—�ğ�–¿ğ�–¿ğ�—‚ğ�–¼ğ�—‚ğ�–¾ğ�—‡ğ�—� ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)

    elif query.data.startswith("upalert"):
        ident, from_user = query.data.split("#")
        if int(query.from_user.id) == int(from_user):
            user = await client.get_users(from_user)
            await query.answer(f"ğ�–§ğ�–¾ğ�—’ {user.first_name}, ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—‚ğ�—Œ ğ�—�ğ�—‰ğ�—…ğ�—ˆğ�–ºğ�–½ğ�–¾ğ�–½ !", show_alert=True)
        else:
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�—�ğ�–¿ğ�–¿ğ�—‚ğ�–¼ğ�—‚ğ�–¾ğ�—‡ğ�—� ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)
        
    elif query.data.startswith("unalert"):
        ident, from_user = query.data.split("#")
        if int(query.from_user.id) == int(from_user):
            user = await client.get_users(from_user)
            await query.answer(f"ğ�–§ğ�–¾ğ�—’ {user.first_name}, ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�—‹ğ�–¾ğ�—Šğ�—�ğ�–¾ğ�—Œğ�—� ğ�—‚ğ�—Œ ğ�–ºğ�—…ğ�—‹ğ�–¾ğ�–ºğ�–½ğ�—’ ğ�—�ğ�—‡ğ�–ºğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ !", show_alert=True)
        else:
            await query.answer("ğ�–¸ğ�—ˆğ�—� ğ�–½ğ�—ˆğ�—‡'ğ�—� ğ�—�ğ�–ºğ�—�ğ�–¾ ğ�—Œğ�—�ğ�–¿ğ�–¿ğ�—‚ğ�–¼ğ�—‚ğ�–¾ğ�—‡ğ�—� ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—�ğ�—Œ ğ�—�ğ�—ˆ ğ�–½ğ�—ˆ ğ�—�ğ�—�ğ�—‚ğ�—Œ !", show_alert=True)

    elif query.data == 'rkbtn':
        await query.answer("ğ�–§ğ�–¾ğ�—’ ğ�–¡ğ�—‹ğ�—ˆ ğŸ˜�\n\nğŸ�¯ ğ�–¢ğ�—…ğ�—‚ğ�–¼ğ�—„ ğ�–®ğ�—‡ ğ�–³ğ�—�ğ�–¾ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡ ğ�–»ğ�–¾ğ�—…ğ�—ˆğ�—� ğ�–³ğ�—�ğ�–¾ ğ�–¥ğ�—‚ğ�—…ğ�–¾ğ�—Œ ğ�–¸ğ�—ˆğ�—� ğ�–¶ğ�–ºğ�—‡ğ�—� ğ�– ğ�—‡ğ�–½ ğ�–²ğ�—�ğ�–ºğ�—‹ğ�—� ğ�–³ğ�—�ğ�–¾ ğ�–¡ğ�—ˆğ�—� â¬‡ï¸�", True)

    elif query.data == 'info':
        await query.answer("ğ�—¥ğ�—²ğ�—¾ğ�˜‚ğ�—²ğ�˜€ğ�˜�ğ�˜€ ğ�—™ğ�—¼ğ�—¿ğ�—ºğ�—®ğ�˜�ğ�˜€\n\nâ€¢ ğ�–²ğ�—ˆğ�—…ğ�—ˆ 2017\nâ€¢ ğ�–£ğ�—�ğ�—ˆğ�—ˆğ�—† 3 ğ�–§ğ�—‚ğ�—‡ğ�–½ğ�—‚\nâ€¢ ğ�–ªğ�—�ğ�—‹ğ�—�ğ�—‰ ğ�–ªğ�–ºğ�—‡ğ�—‡ğ�–ºğ�–½ğ�–º\nâ€¢ ğ�–£ğ�–ºğ�—‹ğ�—„ ğ�—Œ01\nâ€¢ ğ�–²ğ�—�ğ�–¾ ğ�–§ğ�—�ğ�—…ğ�—„ 720ğ�—‰\nâ€¢ ğ�–¥ğ�—‹ğ�—‚ğ�–¾ğ�—‡ğ�–½ğ�—Œ ğ�—Œ03 1080ğ�—‰\n\nâ€¼ï¸�ğ�——ğ�—¼ğ�—»ğ�˜� ğ�—®ğ�—±ğ�—± ğ�˜„ğ�—¼ğ�—¿ğ�—±ğ�˜€ & ğ�˜€ğ�˜†ğ�—ºğ�—¯ğ�—¼ğ�—¹ğ�˜€  , . - ğ�—¹ğ�—¶ğ�—¸ğ�—² send link movie series ğ�—²ğ�˜�ğ�—°â€¼ï¸�", True)
    
    elif query.data == 'tips':
        await query.answer("ğ�–³ğ�—�ğ�—‚ğ�—Œ ğ�–¬ğ�–¾ğ�—Œğ�—Œğ�–ºğ�—€ğ�–¾ ğ�–¶ğ�—‚ğ�—…ğ�—… ğ�–¡ğ�–¾ ğ�–£ğ�–¾ğ�—…ğ�–¾ğ�—�ğ�–¾ğ�–½ ğ�– ğ�–¿ğ�—�ğ�–¾ğ�—‹ 5 ğ�–¬ğ�—‚ğ�—‡ğ�—�ğ�—�ğ�–¾ğ�—Œ ğ�—�ğ�—ˆ ğ�–¯ğ�—‹ğ�–¾ğ�—�ğ�–¾ğ�—‡ğ�—� ğ�–¢ğ�—ˆğ�—‰ğ�—’ğ�—‹ğ�—‚ğ�—€ğ�—�ğ�—� !\n\nğ�–³ğ�—�ğ�–ºğ�—‡ğ�—„ ğ�–¸ğ�—ˆğ�—� ğ�–¥ğ�—ˆğ�—‹ ğ�–´ğ�—Œğ�—‚ğ�—‡ğ�—€ ğ�–¬ğ�–¾ ğŸ˜Š\n\n\nğ�–¯ğ�—ˆğ�—�ğ�–¾ğ�—‹ğ�–¾ğ�–½ ğ�–¡ğ�—’ ğ�–¯ğ�–¨ğ�–±ğ�–®", True)

    elif query.data == "start":
        buttons = [[
                    InlineKeyboardButton('â�• ğ�– ğ�–½ğ�–½ ğ�–¬ğ�–¾ ğ�–³ğ�—ˆ ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�–¦ğ�—‹ğ�—ˆğ�—�ğ�—‰ â�•', url=f"http://t.me/{temp.U_NAME}?startgroup=true")
                ],[
                    InlineKeyboardButton('ğŸ›¡ ğ�–®ğ�—�ğ�—‡ğ�–¾ğ�—‹', callback_data="owner_info"),
                    InlineKeyboardButton('ğŸ§© ğ�–²ğ�—�ğ�—‰ğ�—‰ğ�—ˆğ�—‹ğ�—� ğ�–¦ğ�—‹ğ�—ˆğ�—�ğ�—‰', url=f"https://t.me/{SUPPORT_CHAT}")
                ],[
                    InlineKeyboardButton('â„¹ï¸� ğ�–§ğ�–¾ğ�—…ğ�—‰', callback_data='help'),
                    InlineKeyboardButton('ğŸ˜Š ğ�– ğ�–»ğ�—ˆğ�—�ğ�—�', callback_data='about'),
                ],[
                    InlineKeyboardButton('ğŸ”� ğ�–¨ğ�—‡ğ�—…ğ�—‚ğ�—‡ğ�–¾ ğ�–²ğ�–¾ğ�–ºğ�—‹ğ�–¼ğ�—�', switch_inline_query_current_chat='')
                  ]]
        
        reply_markup = InlineKeyboardMarkup(buttons)
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        await query.message.edit_text(
            text=script.START_TXT.format(query.from_user.mention, temp.U_NAME, temp.B_NAME),
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
        await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')

    elif query.data == "filters":
        buttons = [[
            InlineKeyboardButton('âœ� ğ�–¬ğ�–ºğ�—‡ğ�—�ğ�–ºğ�—… ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹', callback_data='manuelfilter'),
            InlineKeyboardButton('ğŸ“Š ğ�– ğ�—�ğ�—�ğ�—ˆ ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹', callback_data='autofilter')
        ],[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='help'),
            InlineKeyboardButton('ğŸ“ˆ ğ�–¦ğ�—…ğ�—ˆğ�–»ğ�–ºğ�—… ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹', callback_data='global_filters')
        ]]
        
        reply_markup = InlineKeyboardMarkup(buttons)
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        await query.message.edit_text(
            text=script.ALL_FILTERS.format(query.from_user.mention),
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )

    elif query.data == "global_filters":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='filters')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.GFILTER_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    
    elif query.data == "help":
        buttons = [[
            InlineKeyboardButton('ğŸ’¼ ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹ğ�—Œ ğ�–¬ğ�—ˆğ�–½ğ�–¾', callback_data='filters'),
            InlineKeyboardButton('ğŸ—‚ ğ�–¥ğ�—‚ğ�—…ğ�–¾ ğ�–²ğ�—�ğ�—ˆğ�—‹ğ�–¾', callback_data='store_file')
        ], [
            InlineKeyboardButton('ğŸ“Ÿ ğ�–¢ğ�—ˆğ�—‡ğ�—‡ğ�–¾ğ�–¼ğ�—�ğ�—‚ğ�—ˆğ�—‡ğ�—Œ', callback_data='coct'),
            InlineKeyboardButton('âš™ ğ�–¤ğ�—‘ğ�—�ğ�—‹ğ�–º ğ�–¬ğ�—ˆğ�–½ğ�–¾ğ�—Œ', callback_data='extra')
        ], [
            InlineKeyboardButton('ğŸ�˜ ğ�–§ğ�—ˆğ�—†ğ�–¾', callback_data='start'),
            InlineKeyboardButton('â™»ï¸� Status', callback_data='stats')
        ]]
        
        reply_markup = InlineKeyboardMarkup(buttons)
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        await query.message.edit_text(
            text=script.HELP_TXT.format(query.from_user.mention),
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "about":
        buttons = [[
            InlineKeyboardButton('ğŸ§¬ ğ�–²ğ�—�ğ�—‰ğ�—‰ğ�—ˆğ�—‹ğ�—� ğ�–¦ğ�—‹ğ�—ˆğ�—�ğ�—‰', url=f"https://t.me/{SUPPORT_CHAT}"),
            InlineKeyboardButton('ğŸ“� ğ�–²ğ�—ˆğ�—�ğ�—‹ğ�–¼ğ�–¾ ğ�–¢ğ�—ˆğ�–½ğ�–¾', callback_data='source')
        ],[
            InlineKeyboardButton('ğŸ�˜ ğ�–§ğ�—ˆğ�—†ğ�–¾', callback_data='start'),
            InlineKeyboardButton('â�Œ ğ�–¢ğ�—…ğ�—ˆğ�—Œğ�–¾', callback_data='close_data')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.ABOUT_TXT.format(temp.B_NAME),
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "source":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='about')
        ]]
        reply_markup = InlineKeyboardMarkup(buttons)
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        await query.message.edit_text(
            text=script.SOURCE_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "manuelfilter":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='filters'),
            InlineKeyboardButton('â�º ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡ğ�—Œ', callback_data='button')
        ]]
        reply_markup = InlineKeyboardMarkup(buttons)
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        await query.message.edit_text(
            text=script.MANUELFILTER_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "button":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='manuelfilter')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.BUTTON_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "autofilter":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='filters')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.AUTOFILTER_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "coct":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='help')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.CONNECTION_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "extra":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='help'),
            InlineKeyboardButton('âš  ğ�– ğ�–½ğ�—†ğ�—‚ğ�—‡', callback_data='admin')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.EXTRAMOD_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    
    elif query.data == "store_file":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='help')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.FILE_STORE_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    
    elif query.data == "admin":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='extra')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        await query.message.edit_text(
            text=script.ADMIN_TXT,
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "stats":
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='help'),
            InlineKeyboardButton('â™»ï¸� ğ�–±ğ�–¾ğ�–¿ğ�—‹ğ�–¾ğ�—Œğ�—�', callback_data='rfrsh')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        total = await Media.count_documents()
        users = await db.total_users_count()
        chats = await db.total_chat_count()
        monsize = await db.get_db_size()
        free = 536870912 - monsize
        monsize = get_size(monsize)
        free = get_size(free)
        await query.message.edit_text(
            text=script.STATUS_TXT.format(total, users, chats, monsize, free),
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "rfrsh":
        await query.answer("Fetching MongoDb DataBase...")
        buttons = [[
            InlineKeyboardButton('ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„', callback_data='help'),
            InlineKeyboardButton('â™»ï¸� ğ�–±ğ�–¾ğ�–¿ğ�—‹ğ�–¾ğ�—Œğ�—�', callback_data='rfrsh')
        ]]
        await client.edit_message_media(
            query.message.chat.id, 
            query.message.id, 
            InputMediaPhoto(random.choice(PICS))
        )
        reply_markup = InlineKeyboardMarkup(buttons)
        total = await Media.count_documents()
        users = await db.total_users_count()
        chats = await db.total_chat_count()
        monsize = await db.get_db_size()
        free = 536870912 - monsize
        monsize = get_size(monsize)
        free = get_size(free)
        await query.message.edit_text(
            text=script.STATUS_TXT.format(total, users, chats, monsize, free),
            reply_markup=reply_markup,
            parse_mode=enums.ParseMode.HTML
        )
    elif query.data == "owner_info":
            btn = [[
                    InlineKeyboardButton("ğŸ‘©â€�ğŸ¦¯ ğ�–¡ğ�–ºğ�–¼ğ�—„", callback_data="start"),
                    InlineKeyboardButton("ğŸ“� ğ�–¢ğ�—ˆğ�—‡ğ�—�ğ�–ºğ�–¼ğ�—�", url=f"t.me/rithesh_rkrm_17")
                  ]]
            await client.edit_message_media(
                query.message.chat.id, 
                query.message.id, 
                InputMediaPhoto(random.choice(PICS))
            )
            reply_markup = InlineKeyboardMarkup(btn)
            await query.message.edit_text(
                text=(script.OWNER_INFO),
                reply_markup=reply_markup,
                parse_mode=enums.ParseMode.HTML
            )

    elif query.data.startswith("setgs"):
        ident, set_type, status, grp_id = query.data.split("#")
        grpid = await active_connection(str(query.from_user.id))

        if str(grp_id) != str(grpid):
            await query.message.edit("Your Active Connection Has Been Changed. Go To /settings.")
            return await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')

        if status == "True":
            await save_group_settings(grpid, set_type, False)
        else:
            await save_group_settings(grpid, set_type, True)

        settings = await get_settings(grpid)

        if settings is not None:
            buttons = [
                [
                    InlineKeyboardButton('ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡',
                                         callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}'),
                    InlineKeyboardButton('ğ�–²ğ�—‚ğ�—‡ğ�—€ğ�—…ğ�–¾ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡' if settings["button"] else 'ğ�–£ğ�—ˆğ�—�ğ�–»ğ�—…ğ�–¾',
                                         callback_data=f'setgs#button#{settings["button"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¥ğ�—‚ğ�—…ğ�–¾ ğ�–²ğ�–¾ğ�—‡ğ�–½ ğ�–¬ğ�—ˆğ�–½ğ�–¾', callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}'),
                    InlineKeyboardButton('ğ�–¬ğ�–ºğ�—‡ğ�—�ğ�–ºğ�—… ğ�–²ğ�—�ğ�–ºğ�—‹ğ�—�' if settings["botpm"] else 'ğ�– ğ�—�ğ�—�ğ�—ˆ ğ�–²ğ�–¾ğ�—‡ğ�–½',
                                         callback_data=f'setgs#botpm#{settings["botpm"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¯ğ�—‹ğ�—ˆğ�—�ğ�–¾ğ�–¼ğ�—� ğ�–¢ğ�—ˆğ�—‡ğ�—�ğ�–¾ğ�—‡ğ�—�',
                                         callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["file_secure"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#file_secure#{settings["file_secure"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¨ğ�–¬ğ�–£ğ�–»', callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["imdb"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#imdb#{settings["imdb"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–²ğ�—‰ğ�–¾ğ�—…ğ�—… ğ�–¢ğ�—�ğ�–¾ğ�–¼ğ�—„',
                                         callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["spell_check"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#spell_check#{settings["spell_check"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¶ğ�–¾ğ�—…ğ�–¼ğ�—ˆğ�—†ğ�–¾ ğ�–¬ğ�–¾ğ�—Œğ�—Œğ�–ºğ�—€ğ�–¾', callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["welcome"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#welcome#{settings["welcome"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�– ğ�—�ğ�—�ğ�—ˆ ğ�–£ğ�–¾ğ�—…ğ�–¾ğ�—�ğ�–¾',
                                         callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{str(grp_id)}'),
                    InlineKeyboardButton('5 ğ�–¬ğ�—‚ğ�—‡' if settings["auto_delete"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#auto_delete#{settings["auto_delete"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�– ğ�—�ğ�—�ğ�—ˆ-ğ�–¥ğ�—‚ğ�—…ğ�—�ğ�–¾ğ�—‹',
                                         callback_data=f'setgs#auto_ffilter#{settings["auto_ffilter"]}#{str(grp_id)}'),
                    InlineKeyboardButton('âœ… ğ�–®ğ�—‡' if settings["auto_ffilter"] else 'â�Œ ğ�–®ğ�–¿ğ�–¿',
                                         callback_data=f'setgs#auto_ffilter#{settings["auto_ffilter"]}#{str(grp_id)}')
                ],
                [
                    InlineKeyboardButton('ğ�–¬ğ�–ºğ�—‘ ğ�–¡ğ�—�ğ�—�ğ�—�ğ�—ˆğ�—‡ğ�—Œ',
                                         callback_data=f'setgs#max_btn#{settings["max_btn"]}#{str(grp_id)}'),
                    InlineKeyboardButton('10' if settings["max_btn"] else f'{MAX_B_TN}',
                                         callback_data=f'setgs#max_btn#{settings["max_btn"]}#{str(grp_id)}')
                ]
            ]
            reply_markup = InlineKeyboardMarkup(buttons)
            await query.message.edit_reply_markup(reply_markup)
    await query.answer('ğ�–¯ğ�—‚ğ�—‹ğ�–ºğ�–¼ğ�—’ ğ�—‚ğ�—Œ ğ�–¢ğ�—‹ğ�—‚ğ�—†ğ�–¾ !')

    
async def auto_filter(client, msg, spoll=False):
    reqstr1 = msg.from_user.id if msg.from_user else 0
    reqstr = await client.get_users(reqstr1)
    if not spoll:
        message = msg
        settings = await get_settings(message.chat.id)
        if message.text.startswith("/"): return  # ignore commands
        if re.findall("((^\/|^,|^!|^\.|^[\U0001F600-\U000E007F]).*)", message.text):
            return
        if len(message.text) < 100:
            search = message.text
            files, offset, total_results = await get_search_results(message.chat.id ,search.lower(), offset=0, filter=True)
            if not files:
                if settings["spell_check"]:
                    return await advantage_spell_chok(client, msg)
                else:
                    if NO_RESULTS_MSG:
                        await client.send_message(chat_id=LOG_CHANNEL, text=(script.NORSLTS.format(reqstr.id, reqstr.mention, search)))
                    return
        else:
            return
    else:
        message = msg.message.reply_to_message  # msg will be callback query
        search, files, offset, total_results = spoll
        settings = await get_settings(msg.message.chat.id)
        
    key = f"{message.chat.id}-{message.id}"
    temp.FILES_IDS[key] = files
    pre = 'filep' if settings['file_secure'] else 'file'
    req = message.from_user.id if message.from_user else 0
    BUTTONS[key] = search
    
    if settings["button"]:
        btn = [
            [
                InlineKeyboardButton(
                    text=f"ğŸ”–{get_size(file.file_size)}ğŸ”®{file.file_name}", callback_data=f'{pre}#{file.file_id}'
                ),
            ]
            for file in files
        ]
    else:
        btn = [
            [
                InlineKeyboardButton(
                    text=f"{file.file_name}",
                    callback_data=f'{pre}#{file.file_id}',
                ),
                InlineKeyboardButton(
                    text=f"{get_size(file.file_size)}",
                    callback_data=f'{pre}#{file.file_id}',
                ),
            ]
            for file in files
        ]

    try:
        if settings['auto_delete']:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ]
            )

        else:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ]
            )
                
    except KeyError:
        grpid = await active_connection(str(message.from_user.id))
        await save_group_settings(grpid, 'auto_delete', True)
        settings = await get_settings(message.chat.id)
        if settings['auto_delete']:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ]
            )

        else:
            btn.insert(0, 
            [
                InlineKeyboardButton(f'ğŸ˜‡ Info', 'tips'),
                InlineKeyboardButton(f'ğŸ“� ğ�–³ğ�—‚ğ�—‰ğ�—Œ', 'info')
            ])
            
                      
    btn.insert(0, [
        InlineKeyboardButton(f'ğŸ�¬ {search} ğŸ�¬', 'rkbtn')
    ])
    btn.insert(2, [
        InlineKeyboardButton("ğŸ“¤ ğ�–²ğ�–¾ğ�—‡ğ�–½ ğ�– ğ�—…ğ�—… ğ�–¥ğ�—‚ğ�—…ğ�–¾ğ�—Œ ğŸ“¤", callback_data=f"send_all#{req}#{key}#{pre}")
    ])
    
    if offset != "":
        try:
            settings = await get_settings(message.chat.id)
            if settings['max_btn']:
                btn.append(
                    [InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(text=f"1/{math.ceil(int(total_results)/10)}",callback_data="pages"), InlineKeyboardButton(text="ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�",callback_data=f"next_{req}_{key}_{offset}")]
                )
            else:
                btn.append(
                    [InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(text=f"1/{math.ceil(int(total_results)/int(MAX_B_TN))}",callback_data="pages"), InlineKeyboardButton(text="ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�",callback_data=f"next_{req}_{key}_{offset}")]
                )
        except KeyError:
            await save_group_settings(message.chat.id, 'max_btn', False)
            settings = await get_settings(message.chat.id)
            if settings['max_btn']:
                btn.append(
                    [InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(text=f"1/{math.ceil(int(total_results)/10)}",callback_data="pages"), InlineKeyboardButton(text="ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�",callback_data=f"next_{req}_{key}_{offset}")]
                )
            else:
                btn.append(
                    [InlineKeyboardButton("ğŸ“ƒ", callback_data="pages"), InlineKeyboardButton(text=f"1/{math.ceil(int(total_results)/int(MAX_B_TN))}",callback_data="pages"), InlineKeyboardButton(text="ğ�–­ğ�–¤ğ�–·ğ�–³ â–¶ï¸�",callback_data=f"next_{req}_{key}_{offset}")]
                )
    else:
        btn.append(
            [InlineKeyboardButton(text="â�Œ ğ�–­ğ�—ˆ ğ�–¬ğ�—ˆğ�—‹ğ�–¾ ğ�–¯ğ�–ºğ�—€ğ�–¾ğ�—Œ ğ�– ğ�—�ğ�–ºğ�—‚ğ�—…ğ�–ºğ�–»ğ�—…ğ�–¾ ! â�Œ",callback_data="pages")]
        )
    imdb = await get_poster(search, file=(files[0]).file_name) if settings["imdb"] else None
    TEMPLATE = settings['template']
    if imdb:
        cap = TEMPLATE.format(
            query=search,
            title=imdb['title'],
            votes=imdb['votes'],
            aka=imdb["aka"],
            seasons=imdb["seasons"],
            box_office=imdb['box_office'],
            localized_title=imdb['localized_title'],
            kind=imdb['kind'],
            imdb_id=imdb["imdb_id"],
            cast=imdb["cast"],
            runtime=imdb["runtime"],
            countries=imdb["countries"],
            certificates=imdb["certificates"],
            languages=imdb["languages"],
            director=imdb["director"],
            writer=imdb["writer"],
            producer=imdb["producer"],
            composer=imdb["composer"],
            cinematographer=imdb["cinematographer"],
            music_team=imdb["music_team"],
            distributors=imdb["distributors"],
            release_date=imdb['release_date'],
            year=imdb['year'],
            genres=imdb['genres'],
            poster=imdb['poster'],
            plot=imdb['plot'],
            rating=imdb['rating'],
            url=imdb['url'],
            **locals()
        )
    else:
        cap = f"<b>ğŸ‘‹ ğ�–§ğ�–¾ğ�—’ {message.from_user.mention}\nğŸ“� ğ�–¸ğ�—ˆğ�—�ğ�—‹ ğ�–¥ğ�—‚ğ�—…ğ�–¾ğ�—Œ ğ�– ğ�—‹ğ�–¾ ğ�–±ğ�–¾ğ�–ºğ�–½ğ�—’\n\nâ™¨ï¸� ğ�–¯ğ�—ˆğ�—�ğ�–¾ğ�—‹ğ�–¾ğ�–½ ğ�–¡ğ�—’ @piroxbots</b>"
    if imdb and imdb.get('poster'):
        try:
            hehe = await message.reply_photo(photo=imdb.get('poster'), caption=cap[:1024], reply_markup=InlineKeyboardMarkup(btn))
            try:
                if settings['auto_delete']:
                    await asyncio.sleep(600)
                    await hehe.delete()
                    await message.delete()
            except KeyError:
                grpid = await active_connection(str(message.from_user.id))
                await save_group_settings(grpid, 'auto_delete', True)
                settings = await get_settings(message.chat.id)
                if settings['auto_delete']:
                    await asyncio.sleep(600)
                    await hehe.delete()
                    await message.delete()
        except (MediaEmpty, PhotoInvalidDimensions, WebpageMediaEmpty):
            pic = imdb.get('poster')
            poster = pic.replace('.jpg', "._V1_UX360.jpg")
            hmm = await message.reply_photo(photo=poster, caption=cap[:1024], reply_markup=InlineKeyboardMarkup(btn))
            try:
                if settings['auto_delete']:
                    await asyncio.sleep(600)
                    await hmm.delete()
                    await message.delete()
            except KeyError:
                grpid = await active_connection(str(message.from_user.id))
                await save_group_settings(grpid, 'auto_delete', True)
                settings = await get_settings(message.chat.id)
                if settings['auto_delete']:
                    await asyncio.sleep(600)
                    await hmm.delete()
                    await message.delete()
        except Exception as e:
            logger.exception(e)
            fek = await message.reply_photo(photo=NOR_IMG, caption=cap, reply_markup=InlineKeyboardMarkup(btn))
            try:
                if settings['auto_delete']:
                    await asyncio.sleep(600)
                    await fek.delete()
                    await message.delete()
            except KeyError:
                grpid = await active_connection(str(message.from_user.id))
                await save_group_settings(grpid, 'auto_delete', True)
                settings = await get_settings(message.chat.id)
                if settings['auto_delete']:
                    await asyncio.sleep(600)
                    await fek.delete()
                    await message.delete()
    else:
        fuk = await message.reply_photo(photo=NOR_IMG, caption=cap, reply_markup=InlineKeyboardMarkup(btn))
        try:
            if settings['auto_delete']:
                await asyncio.sleep(600)
                await fuk.delete()
                await message.delete()
        except KeyError:
            grpid = await active_connection(str(message.from_user.id))
            await save_group_settings(grpid, 'auto_delete', True)
            settings = await get_settings(message.chat.id)
            if settings['auto_delete']:
                await asyncio.sleep(600)
                await fuk.delete()
                await message.delete()
    if spoll:
        await msg.message.delete()

async def advantage_spell_chok(client, msg):
    mv_id = msg.id
    mv_rqst = msg.text
    reqstr1 = msg.from_user.id if msg.from_user else 0
    reqstr = await client.get_users(reqstr1)
    settings = await get_settings(msg.chat.id)
    query = re.sub(
        r"\b(pl(i|e)*?(s|z+|ease|se|ese|(e+)s(e)?)|((send|snd|giv(e)?|gib)(\sme)?)|movie(s)?|new|latest|br((o|u)h?)*|^h(e|a)?(l)*(o)*|mal(ayalam)?|t(h)?amil|file|that|find|und(o)*|kit(t(i|y)?)?o(w)?|thar(u)?(o)*w?|kittum(o)*|aya(k)*(um(o)*)?|full\smovie|any(one)|with\ssubtitle(s)?)",
        "", msg.text, flags=re.IGNORECASE)  # plis contribute some common words
    query = query.strip() + " movie"
    try:
        movies = await get_poster(mv_rqst, bulk=True)
    except Exception as e:
        logger.exception(e)
        reqst_gle = mv_rqst.replace(" ", "+")
        button = [[
                   InlineKeyboardButton("ğŸ”� ğ�–¦ğ�—ˆğ�—ˆğ�—€ğ�—…ğ�–¾", url=f"https://www.google.com/search?q={reqst_gle}")
        ]]
        if NO_RESULTS_MSG:
            await client.send_message(chat_id=LOG_CHANNEL, text=(script.NORSLTS.format(reqstr.id, reqstr.mention, mv_rqst)))
        k = await msg.reply_photo(
            photo=SPELL_IMG, 
            caption=script.I_CUDNT.format(mv_rqst),
            reply_markup=InlineKeyboardMarkup(button)
        )
        await asyncio.sleep(30)
        await k.delete()
        return
    movielist = []
    if not movies:
        reqst_gle = mv_rqst.replace(" ", "+")
        button = [[
                   InlineKeyboardButton("ğŸ”� ğ�–¦ğ�—ˆğ�—ˆğ�—€ğ�—…ğ�–¾", url=f"https://www.google.com/search?q={reqst_gle}")
        ]]
        if NO_RESULTS_MSG:
            await client.send_message(chat_id=LOG_CHANNEL, text=(script.NORSLTS.format(reqstr.id, reqstr.mention, mv_rqst)))
        k = await msg.reply_photo(
            photo=SPELL_IMG, 
            caption=script.I_CUDNT.format(mv_rqst),
            reply_markup=InlineKeyboardMarkup(button)
        )
        await asyncio.sleep(30)
        await k.delete()
        return
    movielist += [movie.get('title') for movie in movies]
    movielist += [f"{movie.get('title')} {movie.get('year')}" for movie in movies]
    key=f"{msg.chat.id}-{msg.id}"
    temp.SPELL_CHECK[key] = movielist
    btn = [
        [
            InlineKeyboardButton(
                text=movie_name.strip(),
                callback_data=f"spol#{reqstr1}#{k}#{key}",
            )
        ]
        for k, movie_name in enumerate(movielist)
    ]
    btn.append([InlineKeyboardButton(text="Close", callback_data=f'spol#{reqstr1}#close_spellcheck#{key}')])
    spell_check_del = await msg.reply_photo(
        photo=(SPELL_IMG),
        caption=(script.CUDNT_FND.format(mv_rqst)),
        reply_markup=InlineKeyboardMarkup(btn)
    )
    try:
        if settings['auto_delete']:
            await asyncio.sleep(600)
            await spell_check_del.delete()
    except KeyError:
            grpid = await active_connection(str(message.from_user.id))
            await save_group_settings(grpid, 'auto_delete', True)
            settings = await get_settings(message.chat.id)
            if settings['auto_delete']:
                await asyncio.sleep(600)
                await spell_check_del.delete()


async def manual_filters(client, message, text=False):
    settings = await get_settings(message.chat.id)
    group_id = message.chat.id
    name = text or message.text
    reply_id = message.reply_to_message.id if message.reply_to_message else message.id
    keywords = await get_filters(group_id)
    for keyword in reversed(sorted(keywords, key=len)):
        pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])"
        if re.search(pattern, name, flags=re.IGNORECASE):
            reply_text, btn, alert, fileid = await find_filter(group_id, keyword)

            if reply_text:
                reply_text = reply_text.replace("\\n", "\n").replace("\\t", "\t")

            if btn is not None:
                try:
                    if fileid == "None":
                        if btn == "[]":
                            piroxrk = await client.send_message(
                                group_id, 
                                reply_text, 
                                disable_web_page_preview=True,
                                protect_content=True if settings["file_secure"] else False,
                                reply_to_message_id=reply_id
                            )
                            try:
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message)
                                    try:
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                else:
                                    try:
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                            except KeyError:
                                grpid = await active_connection(str(message.from_user.id))
                                await save_group_settings(grpid, 'auto_ffilter', True)
                                settings = await get_settings(message.chat.id)
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message)

                        else:
                            button = eval(btn)
                            piroxrk = await client.send_message(
                                group_id,
                                reply_text,
                                disable_web_page_preview=True,
                                reply_markup=InlineKeyboardMarkup(button),
                                protect_content=True if settings["file_secure"] else False,
                                reply_to_message_id=reply_id
                            )
                            try:
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message)
                                    try:
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                else:
                                    try:
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                            except KeyError:
                                grpid = await active_connection(str(message.from_user.id))
                                await save_group_settings(grpid, 'auto_ffilter', True)
                                settings = await get_settings(message.chat.id)
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message)

                    elif btn == "[]":
                        piroxrk = await client.send_cached_media(
                            group_id,
                            fileid,
                            caption=reply_text or "",
                            protect_content=True if settings["file_secure"] else False,
                            reply_to_message_id=reply_id
                        )
                        try:
                            if settings['auto_ffilter']:
                                await auto_filter(client, message)
                                try:
                                    if settings['auto_delete']:
                                        await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_delete', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_delete']:
                                        await piroxrk.delete()
                            else:
                                try:
                                    if settings['auto_delete']:
                                        await asyncio.sleep(600)
                                        await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_delete', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_delete']:
                                        await asyncio.sleep(600)
                                        await piroxrk.delete()
                        except KeyError:
                            grpid = await active_connection(str(message.from_user.id))
                            await save_group_settings(grpid, 'auto_ffilter', True)
                            settings = await get_settings(message.chat.id)
                            if settings['auto_ffilter']:
                                await auto_filter(client, message)

                    else:
                        button = eval(btn)
                        piroxrk = await message.reply_cached_media(
                            fileid,
                            caption=reply_text or "",
                            reply_markup=InlineKeyboardMarkup(button),
                            reply_to_message_id=reply_id
                        )
                        try:
                            if settings['auto_ffilter']:
                                await auto_filter(client, message)
                                try:
                                    if settings['auto_delete']:
                                        await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_delete', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_delete']:
                                        await piroxrk.delete()
                            else:
                                try:
                                    if settings['auto_delete']:
                                        await asyncio.sleep(600)
                                        await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_delete', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_delete']:
                                        await asyncio.sleep(600)
                                        await piroxrk.delete()
                        except KeyError:
                            grpid = await active_connection(str(message.from_user.id))
                            await save_group_settings(grpid, 'auto_ffilter', True)
                            settings = await get_settings(message.chat.id)
                            if settings['auto_ffilter']:
                                await auto_filter(client, message)

                except Exception as e:
                    logger.exception(e)
                break
    else:
        return False

async def global_filters(client, message, text=False):
    settings = await get_settings(message.chat.id)
    group_id = message.chat.id
    name = text or message.text
    reply_id = message.reply_to_message.id if message.reply_to_message else message.id
    keywords = await get_gfilters('gfilters')
    for keyword in reversed(sorted(keywords, key=len)):
        pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])"
        if re.search(pattern, name, flags=re.IGNORECASE):
            reply_text, btn, alert, fileid = await find_gfilter('gfilters', keyword)

            if reply_text:
                reply_text = reply_text.replace("\\n", "\n").replace("\\t", "\t")

            if btn is not None:
                try:
                    if fileid == "None":
                        if btn == "[]":
                            piroxrk = await client.send_message(
                                group_id, 
                                reply_text, 
                                disable_web_page_preview=True,
                                reply_to_message_id=reply_id
                            )
                            manual = await manual_filters(client, message)
                            if manual == False:
                                settings = await get_settings(message.chat.id)
                                try:
                                    if settings['auto_ffilter']:
                                        await auto_filter(client, message)
                                        try:
                                            if settings['auto_delete']:
                                                await piroxrk.delete()
                                        except KeyError:
                                            grpid = await active_connection(str(message.from_user.id))
                                            await save_group_settings(grpid, 'auto_delete', True)
                                            settings = await get_settings(message.chat.id)
                                            if settings['auto_delete']:
                                                await piroxrk.delete()
                                    else:
                                        try:
                                            if settings['auto_delete']:
                                                await asyncio.sleep(600)
                                                await piroxrk.delete()
                                        except KeyError:
                                            grpid = await active_connection(str(message.from_user.id))
                                            await save_group_settings(grpid, 'auto_delete', True)
                                            settings = await get_settings(message.chat.id)
                                            if settings['auto_delete']:
                                                await asyncio.sleep(600)
                                                await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_ffilter', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_ffilter']:
                                        await auto_filter(client, message) 
                            else:
                                try:
                                    if settings['auto_delete']:
                                        await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_delete', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_delete']:
                                        await piroxrk.delete()
                            
                        else:
                            button = eval(btn)
                            piroxrk = await client.send_message(
                                group_id,
                                reply_text,
                                disable_web_page_preview=True,
                                reply_markup=InlineKeyboardMarkup(button),
                                reply_to_message_id=reply_id
                            )
                            manual = await manual_filters(client, message)
                            if manual == False:
                                settings = await get_settings(message.chat.id)
                                try:
                                    if settings['auto_ffilter']:
                                        await auto_filter(client, message)
                                        try:
                                            if settings['auto_delete']:
                                                await piroxrk.delete()
                                        except KeyError:
                                            grpid = await active_connection(str(message.from_user.id))
                                            await save_group_settings(grpid, 'auto_delete', True)
                                            settings = await get_settings(message.chat.id)
                                            if settings['auto_delete']:
                                                await piroxrk.delete()
                                    else:
                                        try:
                                            if settings['auto_delete']:
                                                await asyncio.sleep(600)
                                                await piroxrk.delete()
                                        except KeyError:
                                            grpid = await active_connection(str(message.from_user.id))
                                            await save_group_settings(grpid, 'auto_delete', True)
                                            settings = await get_settings(message.chat.id)
                                            if settings['auto_delete']:
                                                await asyncio.sleep(600)
                                                await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_ffilter', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_ffilter']:
                                        await auto_filter(client, message) 
                            else:
                                try:
                                    if settings['auto_delete']:
                                        await piroxrk.delete()
                                except KeyError:
                                    grpid = await active_connection(str(message.from_user.id))
                                    await save_group_settings(grpid, 'auto_delete', True)
                                    settings = await get_settings(message.chat.id)
                                    if settings['auto_delete']:
                                        await piroxrk.delete()

                    elif btn == "[]":
                        piroxrk = await client.send_cached_media(
                            group_id,
                            fileid,
                            caption=reply_text or "",
                            reply_to_message_id=reply_id
                        )
                        manual = await manual_filters(client, message)
                        if manual == False:
                            settings = await get_settings(message.chat.id)
                            try:
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message)
                                    try:
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                else:
                                    try:
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                            except KeyError:
                                grpid = await active_connection(str(message.from_user.id))
                                await save_group_settings(grpid, 'auto_ffilter', True)
                                settings = await get_settings(message.chat.id)
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message) 
                        else:
                            try:
                                if settings['auto_delete']:
                                    await piroxrk.delete()
                            except KeyError:
                                grpid = await active_connection(str(message.from_user.id))
                                await save_group_settings(grpid, 'auto_delete', True)
                                settings = await get_settings(message.chat.id)
                                if settings['auto_delete']:
                                    await piroxrk.delete()

                    else:
                        button = eval(btn)
                        piroxrk = await message.reply_cached_media(
                            fileid,
                            caption=reply_text or "",
                            reply_markup=InlineKeyboardMarkup(button),
                            reply_to_message_id=reply_id
                        )
                        manual = await manual_filters(client, message)
                        if manual == False:
                            settings = await get_settings(message.chat.id)
                            try:
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message)
                                    try:
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await piroxrk.delete()
                                else:
                                    try:
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                                    except KeyError:
                                        grpid = await active_connection(str(message.from_user.id))
                                        await save_group_settings(grpid, 'auto_delete', True)
                                        settings = await get_settings(message.chat.id)
                                        if settings['auto_delete']:
                                            await asyncio.sleep(600)
                                            await piroxrk.delete()
                            except KeyError:
                                grpid = await active_connection(str(message.from_user.id))
                                await save_group_settings(grpid, 'auto_ffilter', True)
                                settings = await get_settings(message.chat.id)
                                if settings['auto_ffilter']:
                                    await auto_filter(client, message) 
                        else:
                            try:
                                if settings['auto_delete']:
                                    await piroxrk.delete()
                            except KeyError:
                                grpid = await active_connection(str(message.from_user.id))
                                await save_group_settings(grpid, 'auto_delete', True)
                                settings = await get_settings(message.chat.id)
                                if settings['auto_delete']:
                                    await piroxrk.delete()

                except Exception as e:
                    logger.exception(e)
                break
    else:
        return False
