Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
pmpermit.py885 linesDownload Raw Back to plugins
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available -9 10• `{i}a` or `{i}approve`11    Approve someone to PM.12 13• `{i}da` or `{i}disapprove`14    Disapprove someone to PM.15 16• `{i}block`17    Block someone.18 19• `{i}unblock` | `{i}unblock all`20    Unblock someone.21 22• `{i}nologpm`23    Stop logging messages from the user.24 25• `{i}logpm`26    Start logging messages from the user.27 28• `{i}startarchive`29    Archive new PMs.30 31• `{i}stoparchive`32    Don't archive new PMs.33 34• `{i}cleararchive`35    Unarchive all chats.36 37• `{i}listapproved`38   List all approved PMs.39"""40 41import asyncio42import re43from os import remove44 45from pyUltroid.dB import DEVLIST46 47try:48    from tabulate import tabulate49except ImportError:50    tabulate = None51from telethon import events52from telethon.errors import MessageNotModifiedError53from telethon.tl.functions.contacts import (54    BlockRequest,55    GetBlockedRequest,56    UnblockRequest,57)58from telethon.tl.functions.messages import ReportSpamRequest59from telethon.utils import get_display_name, resolve_bot_file_id60 61from pyUltroid.dB.base import KeyManager62 63from . import *64 65# ========================= CONSTANTS =============================66 67COUNT_PM = {}68LASTMSG = {}69WARN_MSGS = {}70U_WARNS = {}71if isinstance(udB.get_key("PMPERMIT"), (int, str)):72    value = [udB.get_key("PMPERMIT")]73    udB.set_key("PMPERMIT", value)74keym = KeyManager("PMPERMIT", cast=list)75Logm = KeyManager("LOGUSERS", cast=list)76PMPIC = udB.get_key("PMPIC")77LOG_CHANNEL = udB.get_key("LOG_CHANNEL")78UND = get_string("pmperm_1")79UNS = get_string("pmperm_2")80NO_REPLY = get_string("pmperm_3")81 82UNAPPROVED_MSG = "**PMSecurity of {ON}!**\n\n{UND}\n\nYou have {warn}/{twarn} warnings!"83if udB.get_key("PM_TEXT"):84    UNAPPROVED_MSG = (85        "**PMSecurity of {ON}!**\n\n"86        + udB.get_key("PM_TEXT")87        + "\n\nYou have {warn}/{twarn} warnings!"88    )89# 190WARNS = udB.get_key("PMWARNS") or 491PMCMDS = [92    f"{HNDLR}a",93    f"{HNDLR}approve",94    f"{HNDLR}da",95    f"{HNDLR}disapprove",96    f"{HNDLR}block",97    f"{HNDLR}unblock",98]99 100_not_approved = {}101_to_delete = {}102 103my_bot = asst.me.username104 105 106def update_pm(userid, message, warns_given):107    try:108        WARN_MSGS.update({userid: message})109    except KeyError:110        pass111    try:112        U_WARNS.update({userid: warns_given})113    except KeyError:114        pass115 116 117async def delete_pm_warn_msgs(chat: int):118    try:119        await _to_delete[chat].delete()120    except KeyError:121        pass122 123 124# =================================================================125 126 127if udB.get_key("PMLOG"):128 129    @ultroid_cmd(130        pattern="logpm$",131    )132    async def _(e):133        if not e.is_private:134            return await e.eor("`Use me in Private.`", time=3)135        if not Logm.contains(e.chat_id):136            return await e.eor("`Wasn't logging msgs from here.`", time=3)137 138        Logm.remove(e.chat_id)139        return await e.eor("`Now I Will log msgs from here.`", time=3)140 141    @ultroid_cmd(142        pattern="nologpm$",143    )144    async def _(e):145        if not e.is_private:146            return await e.eor("`Use me in Private.`", time=3)147        if Logm.contains(e.chat_id):148            return await e.eor("`Wasn't logging msgs from here.`", time=3)149 150        Logm.add(e.chat_id)151        return await e.eor("`Now I Won't log msgs from here.`", time=3)152 153    @ultroid_bot.on(154        events.NewMessage(155            incoming=True,156            func=lambda e: e.is_private,157        ),158    )159    async def permitpm(event):160        user = await event.get_sender()161        if user.bot or user.is_self or user.verified or Logm.contains(user.id):162            return163        await event.forward_to(udB.get_key("PMLOGGROUP") or LOG_CHANNEL)164 165 166if udB.get_key("PMSETTING"):167    if udB.get_key("AUTOAPPROVE"):168 169        @ultroid_bot.on(170            events.NewMessage(171                outgoing=True,172                func=lambda e: e.is_private and e.out and not e.text.startswith(HNDLR),173            ),174        )175        async def autoappr(e):176            miss = await e.get_chat()177            if miss.bot or miss.is_self or miss.verified or miss.id in DEVLIST:178                return179            if keym.contains(miss.id):180                return181            keym.add(miss.id)182            await delete_pm_warn_msgs(miss.id)183            try:184                await ultroid_bot.edit_folder(miss.id, folder=0)185            except BaseException:186                pass187            try:188                await asst.edit_message(189                    LOG_CHANNEL,190                    _not_approved[miss.id],191                    f"#AutoApproved : <b>OutGoing Message.\nUser : {inline_mention(miss, html=True)}</b> [<code>{miss.id}</code>]",192                    parse_mode="html",193                )194            except KeyError:195                await asst.send_message(196                    LOG_CHANNEL,197                    f"#AutoApproved : <b>OutGoing Message.\nUser : {inline_mention(miss, html=True)}</b> [<code>{miss.id}</code>]",198                    parse_mode="html",199                )200            except MessageNotModifiedError:201                pass202 203    @ultroid_bot.on(204        events.NewMessage(205            incoming=True,206            func=lambda e: e.is_private207            and e.sender_id not in DEVLIST208            and not e.out209            and not e.sender.bot210            and not e.sender.is_self211            and not e.sender.verified,212        )213    )214    async def permitpm(event):215        inline_pm = Redis("INLINE_PM") or False216        user = event.sender217        if not keym.contains(user.id) and event.text != UND:218            if Redis("MOVE_ARCHIVE"):219                try:220                    await ultroid_bot.edit_folder(user.id, folder=1)221                except BaseException as er:222                    LOGS.info(er)223            if event.media and not udB.get_key("DISABLE_PMDEL"):224                await event.delete()225            name = user.first_name226            fullname = get_display_name(user)227            username = f"@{user.username}"228            mention = inline_mention(user)229            count = keym.count()230            try:231                wrn = COUNT_PM[user.id] + 1232                await asst.edit_message(233                    udB.get_key("LOG_CHANNEL"),234                    _not_approved[user.id],235                    f"Incoming PM from **{mention}** [`{user.id}`] with **{wrn}/{WARNS}** warning!",236                    buttons=[237                        Button.inline("Approve PM", data=f"approve_{user.id}"),238                        Button.inline("Block PM", data=f"block_{user.id}"),239                    ],240                )241            except KeyError:242                _not_approved[user.id] = await asst.send_message(243                    udB.get_key("LOG_CHANNEL"),244                    f"Incoming PM from **{mention}** [`{user.id}`] with **1/{WARNS}** warning!",245                    buttons=[246                        Button.inline("Approve PM", data=f"approve_{user.id}"),247                        Button.inline("Block PM", data=f"block_{user.id}"),248                    ],249                )250                wrn = 1251            except MessageNotModifiedError:252                wrn = 1253            if user.id in LASTMSG:254                prevmsg = LASTMSG[user.id]255                if event.text != prevmsg:256                    if "PMSecurity" in event.text or "**PMSecurity" in event.text:257                        return258                    await delete_pm_warn_msgs(user.id)259                    message_ = UNAPPROVED_MSG.format(260                        ON=OWNER_NAME,261                        warn=wrn,262                        twarn=WARNS,263                        UND=UND,264                        name=name,265                        fullname=fullname,266                        username=username,267                        count=count,268                        mention=mention,269                    )270                    update_pm(user.id, message_, wrn)271                    if inline_pm:272                        results = await ultroid_bot.inline_query(273                            my_bot, f"ip_{user.id}"274                        )275                        try:276                            _to_delete[user.id] = await results[0].click(277                                user.id, reply_to=event.id, hide_via=True278                            )279                        except Exception as e:280                            LOGS.info(str(e))281                    elif PMPIC:282                        _to_delete[user.id] = await ultroid_bot.send_file(283                            user.id,284                            PMPIC,285                            caption=message_,286                        )287                    else:288                        _to_delete[user.id] = await ultroid_bot.send_message(289                            user.id, message_290                        )291 292                else:293                    await delete_pm_warn_msgs(user.id)294                    message_ = UNAPPROVED_MSG.format(295                        ON=OWNER_NAME,296                        warn=wrn,297                        twarn=WARNS,298                        UND=UND,299                        name=name,300                        fullname=fullname,301                        username=username,302                        count=count,303                        mention=mention,304                    )305                    update_pm(user.id, message_, wrn)306                    if inline_pm:307                        try:308                            results = await ultroid_bot.inline_query(309                                my_bot, f"ip_{user.id}"310                            )311                            _to_delete[user.id] = await results[0].click(312                                user.id, reply_to=event.id, hide_via=True313                            )314                        except Exception as e:315                            LOGS.info(str(e))316                    elif PMPIC:317                        _to_delete[user.id] = await ultroid_bot.send_file(318                            user.id,319                            PMPIC,320                            caption=message_,321                        )322                    else:323                        _to_delete[user.id] = await ultroid_bot.send_message(324                            user.id, message_325                        )326                LASTMSG.update({user.id: event.text})327            else:328                await delete_pm_warn_msgs(user.id)329                message_ = UNAPPROVED_MSG.format(330                    ON=OWNER_NAME,331                    warn=wrn,332                    twarn=WARNS,333                    UND=UND,334                    name=name,335                    fullname=fullname,336                    username=username,337                    count=count,338                    mention=mention,339                )340                update_pm(user.id, message_, wrn)341                if inline_pm:342                    try:343                        results = await ultroid_bot.inline_query(344                            my_bot, f"ip_{user.id}"345                        )346                        _to_delete[user.id] = await results[0].click(347                            user.id, reply_to=event.id, hide_via=True348                        )349                    except Exception as e:350                        LOGS.info(str(e))351                elif PMPIC:352                    _to_delete[user.id] = await ultroid_bot.send_file(353                        user.id,354                        PMPIC,355                        caption=message_,356                    )357                else:358                    _to_delete[user.id] = await ultroid_bot.send_message(359                        user.id, message_360                    )361            LASTMSG.update({user.id: event.text})362            if user.id not in COUNT_PM:363                COUNT_PM.update({user.id: 1})364            else:365                COUNT_PM[user.id] = COUNT_PM[user.id] + 1366            if COUNT_PM[user.id] >= WARNS:367                await delete_pm_warn_msgs(user.id)368                _to_delete[user.id] = await event.respond(UNS)369                try:370                    del COUNT_PM[user.id]371                    del LASTMSG[user.id]372                except KeyError:373                    await asst.send_message(374                        udB.get_key("LOG_CHANNEL"),375                        "PMPermit is messed! Pls restart the bot!!",376                    )377                    return LOGS.info("COUNT_PM is messed.")378                await ultroid_bot(BlockRequest(user.id))379                await ultroid_bot(ReportSpamRequest(peer=user.id))380                await asst.edit_message(381                    udB.get_key("LOG_CHANNEL"),382                    _not_approved[user.id],383                    f"**{mention}** [`{user.id}`] was Blocked for spamming.",384                )385 386    @ultroid_cmd(pattern="(start|stop|clear)archive$", fullsudo=True)387    async def _(e):388        x = e.pattern_match.group(1).strip()389        if x == "start":390            udB.set_key("MOVE_ARCHIVE", "True")391            await e.eor("Now I will move new Unapproved DM's to archive", time=5)392        elif x == "stop":393            udB.set_key("MOVE_ARCHIVE", "False")394            await e.eor("Now I won't move new Unapproved DM's to archive", time=5)395        elif x == "clear":396            try:397                await e.client.edit_folder(unpack=1)398                await e.eor("Unarchived all chats", time=5)399            except Exception as mm:400                await e.eor(str(mm), time=5)401 402    @ultroid_cmd(pattern="(a|approve)(?: |$)", fullsudo=True)403    async def approvepm(apprvpm):404        if apprvpm.reply_to_msg_id:405            user = (await apprvpm.get_reply_message()).sender406        elif apprvpm.is_private:407            user = await apprvpm.get_chat()408        else:409            return await apprvpm.edit(NO_REPLY)410        if user.id in DEVLIST:411            return await eor(412                apprvpm,413                "Lol, He is my Developer\nHe is auto Approved",414            )415        if not keym.contains(user.id):416            keym.add(user.id)417            try:418                await delete_pm_warn_msgs(user.id)419                await apprvpm.client.edit_folder(user.id, folder=0)420            except BaseException:421                pass422            await eod(423                apprvpm,424                f"<b>{inline_mention(user, html=True)}</b> <code>approved to PM!</code>",425                parse_mode="html",426            )427            try:428                await asst.edit_message(429                    udB.get_key("LOG_CHANNEL"),430                    _not_approved[user.id],431                    f"#APPROVED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was approved to PM you!</code>",432                    buttons=[433                        Button.inline("Disapprove PM", data=f"disapprove_{user.id}"),434                        Button.inline("Block", data=f"block_{user.id}"),435                    ],436                    parse_mode="html",437                )438            except KeyError:439                _not_approved[user.id] = await asst.send_message(440                    udB.get_key("LOG_CHANNEL"),441                    f"#APPROVED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was approved to PM you!</code>",442                    buttons=[443                        Button.inline("Disapprove PM", data=f"disapprove_{user.id}"),444                        Button.inline("Block", data=f"block_{user.id}"),445                    ],446                    parse_mode="html",447                )448            except MessageNotModifiedError:449                pass450        else:451            await apprvpm.eor("`User may already be approved.`", time=5)452 453    @ultroid_cmd(pattern="(da|disapprove)(?: |$)", fullsudo=True)454    async def disapprovepm(e):455        if e.reply_to_msg_id:456            user = (await e.get_reply_message()).sender457        elif e.is_private:458            user = await e.get_chat()459        else:460            return await e.edit(NO_REPLY)461        if user.id in DEVLIST:462            return await eor(463                e,464                "`Lol, He is my Developer\nHe Can't Be DisApproved.`",465            )466        if keym.contains(user.id):467            keym.remove(user.id)468            await eod(469                e,470                f"<b>{inline_mention(user, html=True)}</b> <code>Disapproved to PM!</code>",471                parse_mode="html",472            )473            try:474                await asst.edit_message(475                    udB.get_key("LOG_CHANNEL"),476                    _not_approved[user.id],477                    f"#DISAPPROVED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was disapproved to PM you.</code>",478                    buttons=[479                        Button.inline("Approve PM", data=f"approve_{user.id}"),480                        Button.inline("Block", data=f"block_{user.id}"),481                    ],482                    parse_mode="html",483                )484            except KeyError:485                _not_approved[user.id] = await asst.send_message(486                    udB.get_key("LOG_CHANNEL"),487                    f"#DISAPPROVED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was disapproved to PM you.</code>",488                    buttons=[489                        Button.inline("Approve PM", data=f"approve_{user.id}"),490                        Button.inline("Block", data=f"block_{user.id}"),491                    ],492                    parse_mode="html",493                )494            except MessageNotModifiedError:495                pass496        else:497            await eod(498                e,499                f"<b>{inline_mention(user, html=True)}</b> <code>was never approved!</code>",500                parse_mode="html",501            )502 503 504@ultroid_cmd(pattern="block( (.*)|$)", fullsudo=True)505async def blockpm(block):506    match = block.pattern_match.group(1).strip()507    if block.reply_to_msg_id:508        user = (await block.get_reply_message()).sender_id509    elif match:510        try:511            user = await block.client.parse_id(match)512        except Exception as er:513            return await block.eor(str(er))514    elif block.is_private:515        user = block.chat_id516    else:517        return await eor(block, NO_REPLY, time=10)518 519    await block.client(BlockRequest(user))520    aname = await block.client.get_entity(user)521    await block.eor(f"{inline_mention(aname)} [`{user}`] `has been blocked!`")522    try:523        keym.remove(user)524    except AttributeError:525        pass526    try:527        await asst.edit_message(528            udB.get_key("LOG_CHANNEL"),529            _not_approved[user],530            f"#BLOCKED\n\n{inline_mention(aname)} [`{user}`] has been **blocked**.",531            buttons=[532                Button.inline("UnBlock", data=f"unblock_{user}"),533            ],534        )535    except KeyError:536        _not_approved[user] = await asst.send_message(537            udB.get_key("LOG_CHANNEL"),538            f"#BLOCKED\n\n{inline_mention(aname)} [`{user}`] has been **blocked**.",539            buttons=[540                Button.inline("UnBlock", data=f"unblock_{user}"),541            ],542        )543    except MessageNotModifiedError:544        pass545 546 547@ultroid_cmd(pattern="unblock( (.*)|$)", fullsudo=True)548async def unblockpm(event):549    match = event.pattern_match.group(1).strip()550    reply = await event.get_reply_message()551    if reply:552        user = reply.sender_id553    elif match:554        if match == "all":555            msg = await event.eor(get_string("com_1"))556            u_s = await event.client(GetBlockedRequest(0, 0))557            count = len(u_s.users)558            if not count:559                return await eor(msg, "__You have not blocked Anyone...__")560            for user in u_s.users:561                await asyncio.sleep(1)562                await event.client(UnblockRequest(user.id))563            # GetBlockedRequest return 20 users at most.564            if count < 20:565                return await eor(msg, f"__Unblocked {count} Users!__")566            while u_s.users:567                u_s = await event.client(GetBlockedRequest(0, 0))568                for user in u_s.users:569                    await asyncio.sleep(3)570                    await event.client(UnblockRequest(user.id))571                count += len(u_s.users)572            return await eor(msg, f"__Unblocked {count} users.__")573 574        try:575            user = await event.client.parse_id(match)576        except Exception as er:577            return await event.eor(str(er))578    elif event.is_private:579        user = event.chat_id580    else:581        return await event.eor(NO_REPLY, time=10)582    try:583        await event.client(UnblockRequest(user))584        aname = await event.client.get_entity(user)585        await event.eor(f"{inline_mention(aname)} [`{user}`] `has been UnBlocked!`")586    except Exception as et:587        return await event.eor(f"ERROR - {et}")588    try:589        await asst.edit_message(590            udB.get_key("LOG_CHANNEL"),591            _not_approved[user],592            f"#UNBLOCKED\n\n{inline_mention(aname)} [`{user}`] has been **unblocked**.",593            buttons=[594                Button.inline("Block", data=f"block_{user}"),595            ],596        )597    except KeyError:598        _not_approved[user] = await asst.send_message(599            udB.get_key("LOG_CHANNEL"),600            f"#UNBLOCKED\n\n{inline_mention(aname)} [`{user}`] has been **unblocked**.",601            buttons=[602                Button.inline("Block", data=f"block_{user}"),603            ],604        )605    except MessageNotModifiedError:606        pass607 608 609@ultroid_cmd(pattern="listapproved$", owner=True)610async def list_approved(event):611    xx = await event.eor(get_string("com_1"))612    all = keym.get()613    if not all:614        return await xx.eor("`You haven't approved anyone yet!`", time=5)615    users = []616    for i in all:617        try:618            name = get_display_name(await ultroid_bot.get_entity(i))619        except BaseException:620            name = ""621        users.append([name.strip(), str(i)])622    with open("approved_pms.txt", "w") as list_appr:623        if tabulate:624            list_appr.write(625                tabulate(users, headers=["UserName", "UserID"], showindex="always")626            )627        else:628            text = "".join(f"[{user[-1]}] - {user[0]}" for user in users)629            list_appr.write(text)630    await event.reply(631        f"List of users approved by [{OWNER_NAME}](tg://user?id={OWNER_ID})",632        file="approved_pms.txt",633    )634 635    await xx.delete()636    remove("approved_pms.txt")637 638 639@callback(640    re.compile(641        b"approve_(.*)",642    ),643    from_users=[ultroid_bot.uid],644)645async def apr_in(event):646    uid = int(event.data_match.group(1).decode("UTF-8"))647    if uid in DEVLIST:648        await event.edit("It's a dev! Approved!")649    if not keym.contains(uid):650        keym.add(uid)651        try:652            await ultroid_bot.edit_folder(uid, folder=0)653        except BaseException:654            pass655        try:656            user = await ultroid_bot.get_entity(uid)657        except BaseException:658            return await event.delete()659        await event.edit(660            f"#APPROVED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was approved to PM you!</code>",661            buttons=[662                [663                    Button.inline("Disapprove PM", data=f"disapprove_{uid}"),664                    Button.inline("Block", data=f"block_{uid}"),665                ],666            ],667            parse_mode="html",668        )669        await delete_pm_warn_msgs(uid)670        await event.answer("Approved.", alert=True)671    else:672        await event.edit(673            "`User may already be approved.`",674            buttons=[675                [676                    Button.inline("Disapprove PM", data=f"disapprove_{uid}"),677                    Button.inline("Block", data=f"block_{uid}"),678                ],679            ],680        )681 682 683@callback(684    re.compile(685        b"disapprove_(.*)",686    ),687    from_users=[ultroid_bot.uid],688)689async def disapr_in(event):690    uid = int(event.data_match.group(1).decode("UTF-8"))691    if keym.contains(uid):692        keym.remove(uid)693        try:694            user = await ultroid_bot.get_entity(uid)695        except BaseException:696            return await event.delete()697        await event.edit(698            f"#DISAPPROVED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was disapproved to PM you!</code>",699            buttons=[700                [701                    Button.inline("Approve PM", data=f"approve_{uid}"),702                    Button.inline("Block", data=f"block_{uid}"),703                ],704            ],705            parse_mode="html",706        )707        await event.answer("Disapproved.", alert=True)708    else:709        await event.edit(710            "`User was never approved!`",711            buttons=[712                [713                    Button.inline("Disapprove PM", data=f"disapprove_{uid}"),714                    Button.inline("Block", data=f"block_{uid}"),715                ],716            ],717        )718 719 720@callback(721    re.compile(722        b"block_(.*)",723    ),724    from_users=[ultroid_bot.uid],725)726async def blck_in(event):727    uid = int(event.data_match.group(1).decode("UTF-8"))728    try:729        await ultroid_bot(BlockRequest(uid))730    except BaseException:731        pass732    try:733        user = await ultroid_bot.get_entity(uid)734    except BaseException:735        return await event.delete()736    await event.edit(737        f"BLOCKED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was blocked!</code>",738        buttons=Button.inline("UnBlock", data=f"unblock_{uid}"),739        parse_mode="html",740    )741    await event.answer("Blocked.", alert=True)742 743 744@callback(745    re.compile(746        b"unblock_(.*)",747    ),748    from_users=[ultroid_bot.uid],749)750async def unblck_in(event):751    uid = int(event.data_match.group(1).decode("UTF-8"))752    try:753        await ultroid_bot(UnblockRequest(uid))754    except BaseException:755        pass756    try:757        user = await ultroid_bot.get_entity(uid)758    except BaseException:759        return await event.delete()760    await event.edit(761        f"#UNBLOCKED\n\n<b>{inline_mention(user, html=True)}</b> [<code>{user.id}</code>] <code>was unblocked!</code>",762        buttons=Button.inline("Block", data=f"block_{uid}"),763        parse_mode="html",764    )765    await event.answer("Unblocked.", alert=True)766 767 768@callback("deletedissht")769async def ytfuxist(e):770    try:771        await e.answer("Deleted.")772        await e.delete()773    except BaseException:774        await ultroid_bot.delete_messages(e.chat_id, e.id)775 776 777@in_pattern(re.compile("ip_(.*)"), owner=True)778async def in_pm_ans(event):779    from_user = int(event.pattern_match.group(1).strip())780    try:781        warns = U_WARNS[from_user]782    except Exception as e:783        LOGS.info(e)784        warns = "?"785    try:786        msg_ = WARN_MSGS[from_user]787    except KeyError:788        msg_ = "**PMSecurity of {OWNER_NAME}**"789    wrns = f"{warns}/{WARNS}"790    buttons = [791        [792            Button.inline("Warns", data=f"admin_only{from_user}"),793            Button.inline(wrns, data=f"don_{wrns}"),794        ]795    ]796    include_media = True797    mime_type, res = None, None798    cont = None799    try:800        ext = PMPIC.split(".")[-1].lower()801    except (AttributeError, IndexError):802        ext = None803    if ext in ["img", "jpg", "png"]:804        _type = "photo"805        mime_type = "image/jpg"806    elif ext in ["mp4", "mkv", "gif"]:807        mime_type = "video/mp4"808        _type = "gif"809    else:810        try:811            res = resolve_bot_file_id(PMPIC)812        except ValueError:813            pass814        if res:815            res = [816                await event.builder.document(817                    res,818                    title="Inline PmPermit",819                    description="~ @TeamUltroid",820                    text=msg_,821                    buttons=buttons,822                    link_preview=False,823                )824            ]825        else:826            _type = "article"827            include_media = False828    if not res:829        if include_media:830            cont = types.InputWebDocument(PMPIC, 0, mime_type, [])831        res = [832            event.builder.article(833                title="Inline PMPermit.",834                type=_type,835                text=msg_,836                description="@TeamUltroid",837                include_media=include_media,838                buttons=buttons,839                thumb=cont,840                content=cont,841            )842        ]843    await event.answer(res, switch_pm="• Ultroid •", switch_pm_param="start")844 845 846@callback(re.compile("admin_only(.*)"), from_users=[ultroid_bot.uid])847async def _admin_tools(event):848    chat = int(event.pattern_match.group(1).strip())849    await event.edit(850        buttons=[851            [852                Button.inline("Approve PM", data=f"approve_{chat}"),853                Button.inline("Block PM", data=f"block_{chat}"),854            ],855            [Button.inline("« Back", data=f"pmbk_{chat}")],856        ],857    )858 859 860@callback(re.compile("don_(.*)"))861async def _mejik(e):862    data = e.pattern_match.group(1).strip().decode("utf-8").split("/")863    text = "👮‍♂ Warn Count : " + data[0]864    text += "\n🤖 Total Warn Count : " + data[1]865    await e.answer(text, alert=True)866 867 868@callback(re.compile("pmbk_(.*)"))869async def edt(event):870    from_user = int(event.pattern_match.group(1).strip())871    try:872        warns = U_WARNS[from_user]873    except Exception as e:874        LOGS.info(str(e))875        warns = "0"876    wrns = f"{warns}/{WARNS}"877    await event.edit(878        buttons=[879            [880                Button.inline("Warns", data=f"admin_only{from_user}"),881                Button.inline(wrns, data=f"don_{wrns}"),882            ]883        ],884    )885