Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
filter.py101 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 8from . import get_help9 10__doc__ = get_help("help_filter")11 12import os13import re14 15from telethon.tl.types import User16from telethon.utils import pack_bot_file_id17 18from pyUltroid.dB.filter_db import add_filter, get_filter, list_filter, rem_filter19from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button20 21from . import events, get_string, mediainfo, udB, ultroid_bot, ultroid_cmd, upload_file22from ._inline import something23 24 25@ultroid_cmd(pattern="addfilter( (.*)|$)")26async def af(e):27    wrd = (e.pattern_match.group(1).strip()).lower()28    wt = await e.get_reply_message()29    chat = e.chat_id30    if not (wt and wrd):31        return await e.eor(get_string("flr_1"))32    btn = format_btn(wt.buttons) if wt.buttons else None33    if wt and wt.media:34        wut = mediainfo(wt.media)35        if wut.startswith(("pic", "gif")):36            dl = await wt.download_media()37            m = upload_file(dl)38            os.remove(dl)39        elif wut == "video":40            if wt.media.document.size > 8 * 1000 * 1000:41                return await e.eor(get_string("com_4"), time=5)42            dl = await wt.download_media()43            m = upload_file(dl)44            os.remove(dl)45        else:46            m = pack_bot_file_id(wt.media)47        if wt.text:48            txt = wt.text49            if not btn:50                txt, btn = get_msg_button(wt.text)51            add_filter(chat, wrd, txt, m, btn)52        else:53            add_filter(chat, wrd, None, m, btn)54    else:55        txt = wt.text56        if not btn:57            txt, btn = get_msg_button(wt.text)58        add_filter(chat, wrd, txt, None, btn)59    await e.eor(get_string("flr_4").format(wrd))60    ultroid_bot.add_handler(filter_func, events.NewMessage())61 62 63@ultroid_cmd(pattern="remfilter( (.*)|$)")64async def rf(e):65    wrd = (e.pattern_match.group(1).strip()).lower()66    chat = e.chat_id67    if not wrd:68        return await e.eor(get_string("flr_3"))69    rem_filter(int(chat), wrd)70    await e.eor(get_string("flr_5").format(wrd))71 72 73@ultroid_cmd(pattern="listfilter$")74async def lsnote(e):75    if x := list_filter(e.chat_id):76        sd = "Filters Found In This Chats Are\n\n"77        return await e.eor(sd + x)78    await e.eor(get_string("flr_6"))79 80 81async def filter_func(e):82    if isinstance(e.sender, User) and e.sender.bot:83        return84    xx = (e.text).lower()85    chat = e.chat_id86    if x := get_filter(chat):87        for c in x:88            pat = r"( |^|[^\w])" + re.escape(c) + r"( |$|[^\w])"89            if re.search(pat, xx):90                if k := x.get(c):91                    msg = k["msg"]92                    media = k["media"]93                    if k.get("button"):94                        btn = create_tl_btn(k["button"])95                        return await something(e, msg, media, btn)96                    await e.reply(msg, file=media)97 98 99if udB.get_key("FILTERS"):100    ultroid_bot.add_handler(filter_func, events.NewMessage())101