Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
snips.py117 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}addsnip <word><reply to a message>`11    add the used word as snip relating to replied message.12 13• `{i}remsnip <word>`14    Remove the snip word..15 16• `{i}listsnip`17    list all snips.18 19• Use :20    type `$(ur snip word)` get setted reply.21"""22import os23 24from . import upload_file as uf25from telethon.utils import pack_bot_file_id26 27from pyUltroid._misc import sudoers28from pyUltroid.dB.snips_db import add_snip, get_snips, list_snip, rem_snip29from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button30 31from . import events, get_string, mediainfo, udB, ultroid_bot, ultroid_cmd32from ._inline import something33 34 35@ultroid_cmd(pattern="addsnip( (.*)|$)")36async def an(e):37    wrd = (e.pattern_match.group(1).strip()).lower()38    wt = await e.get_reply_message()39    if not (wt and wrd):40        return await e.eor(get_string("snip_1"))41    if "$" in wrd:42        wrd = wrd.replace("$", "")43    btn = format_btn(wt.buttons) if wt.buttons else None44    if wt and wt.media:45        wut = mediainfo(wt.media)46        if wut.startswith(("pic", "gif")):47            dl = await wt.download_media()48            m = uf(dl)49            os.remove(dl)50        elif wut == "video":51            if wt.media.document.size > 8 * 1000 * 1000:52                return await e.eor(get_string("com_4"), time=5)53            dl = await wt.download_media()54            m = uf(dl)55            os.remove(dl)56        else:57            m = pack_bot_file_id(wt.media)58        if wt.text:59            txt = wt.text60            if not btn:61                txt, btn = get_msg_button(wt.text)62            add_snip(wrd, txt, m, btn)63        else:64            add_snip(wrd, None, m, btn)65    else:66        txt = wt.text67        if not btn:68            txt, btn = get_msg_button(wt.text)69        add_snip(wrd, txt, None, btn)70    await e.eor(f"Done : snip `${wrd}` Saved.")71    ultroid_bot.add_handler(add_snips, events.NewMessage())72 73 74@ultroid_cmd(pattern="remsnip( (.*)|$)")75async def rs(e):76    wrd = (e.pattern_match.group(1).strip()).lower()77    if not wrd:78        return await e.eor(get_string("snip_2"))79    if wrd.startswith("$"):80        wrd = wrd.replace("$", "")81    rem_snip(wrd)82    await e.eor(f"Done : snip `${wrd}` Removed.")83 84 85@ultroid_cmd(pattern="listsnip")86async def lsnote(e):87    if x := list_snip():88        sd = "SNIPS Found :\n\n"89        return await e.eor(sd + x)90    await e.eor("No Snips Found Here")91 92 93async def add_snips(e):94    if not e.out and e.sender_id not in sudoers():95        return96    xx = [z.replace("$", "") for z in e.text.lower().split() if z.startswith("$")]97    for z in xx:98        if k := get_snips(z):99            msg = k["msg"]100            media = k["media"]101            rep = await e.get_reply_message()102            if rep:103                if k.get("button"):104                    btn = create_tl_btn(k["button"])105                    return await something(rep, msg, media, btn)106                await rep.reply(msg, file=media)107            else:108                await e.delete()109                if k.get("button"):110                    btn = create_tl_btn(k["button"])111                    return await something(e, msg, media, btn, reply=None)112                await ultroid_bot.send_message(e.chat_id, msg, file=media)113 114 115if udB.get_key("SNIP"):116    ultroid_bot.add_handler(add_snips, events.NewMessage())117