| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- """
- MIT License
- Copyright (c) 2023 TheHamkerCat
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- """
- import re
- from pyrogram import filters
- from wbb import app
- from wbb.core.decorators.errors import capture_err
- from wbb.core.decorators.permissions import adminsOnly
- from wbb.core.keyboard import ikb
- from wbb.utils.dbfunctions import (
- delete_filter,
- get_filter,
- get_filters_names,
- save_filter,
- )
- from wbb.utils.filter_groups import chat_filters_group
- from wbb.utils.functions import extract_text_and_keyb
- __MODULE__ = "Filters"
- __HELP__ = """/filters To Get All The Filters In The Chat.
- /filter [FILTER_NAME] To Save A Filter (Can be a sticker or text).
- /stop [FILTER_NAME] To Stop A Filter.
- You can use markdown or html to save text too.
- Checkout /markdownhelp to know more about formattings and other syntax.
- """
- @app.on_message(filters.command("filter") & ~filters.private)
- @adminsOnly("can_change_info")
- async def save_filters(_, message):
- if len(message.command) < 2 or not message.reply_to_message:
- return await message.reply_text(
- "**Usage:**\nReply to a text or sticker with /filter [FILTER_NAME] to save it."
- )
- if not message.reply_to_message.text and not message.reply_to_message.sticker:
- return await message.reply_text(
- "__**You can only save text or stickers in filters.**__"
- )
- name = message.text.split(None, 1)[1].strip()
- if not name:
- return await message.reply_text("**Usage:**\n__/filter [FILTER_NAME]__")
- chat_id = message.chat.id
- _type = "text" if message.reply_to_message.text else "sticker"
- _filter = {
- "type": _type,
- "data": message.reply_to_message.text.markdown
- if _type == "text"
- else message.reply_to_message.sticker.file_id,
- }
- await save_filter(chat_id, name, _filter)
- await message.reply_text(f"__**Saved filter {name}.**__")
- @app.on_message(filters.command("filters") & ~filters.private)
- @capture_err
- async def get_filterss(_, message):
- _filters = await get_filters_names(message.chat.id)
- if not _filters:
- return await message.reply_text("**No filters in this chat.**")
- _filters.sort()
- msg = f"List of filters in {message.chat.title} :\n"
- for _filter in _filters:
- msg += f"**-** `{_filter}`\n"
- await message.reply_text(msg)
- @app.on_message(filters.command("stop") & ~filters.private)
- @adminsOnly("can_change_info")
- async def del_filter(_, message):
- if len(message.command) < 2:
- return await message.reply_text("**Usage:**\n__/stop [FILTER_NAME]__")
- name = message.text.split(None, 1)[1].strip()
- if not name:
- return await message.reply_text("**Usage:**\n__/stop [FILTER_NAME]__")
- chat_id = message.chat.id
- deleted = await delete_filter(chat_id, name)
- if deleted:
- await message.reply_text(f"**Deleted filter {name}.**")
- else:
- await message.reply_text("**No such filter.**")
- @app.on_message(
- filters.text & ~filters.private & ~filters.via_bot & ~filters.forwarded,
- group=chat_filters_group,
- )
- @capture_err
- async def filters_re(_, message):
- text = message.text.lower().strip()
- if not text:
- return
- chat_id = message.chat.id
- list_of_filters = await get_filters_names(chat_id)
- for word in list_of_filters:
- pattern = r"( |^|[^\w])" + re.escape(word) + r"( |$|[^\w])"
- if re.search(pattern, text, flags=re.IGNORECASE):
- _filter = await get_filter(chat_id, word)
- data_type = _filter["type"]
- data = _filter["data"]
- if data_type == "text":
- keyb = None
- if re.findall(r"\[.+\,.+\]", data):
- keyboard = extract_text_and_keyb(ikb, data)
- if keyboard:
- data, keyb = keyboard
- if message.reply_to_message:
- await message.reply_to_message.reply_text(
- data,
- reply_markup=keyb,
- disable_web_page_preview=True,
- )
- if text.startswith("~"):
- await message.delete()
- return
- return await message.reply_text(
- data,
- reply_markup=keyb,
- disable_web_page_preview=True,
- )
- if message.reply_to_message:
- await message.reply_to_message.reply_sticker(data)
- if text.startswith("~"):
- await message.delete()
- return
- return await message.reply_sticker(data)
|