Spaces:
Paused
Paused
Download plugins/filters_cmd.py from saske560/userbotsaskeds: direct link, hf CLI and curl.
- Browser
- Download file 5.58 kB
-
https://huggingface.co/spaces/saske560/userbotsaskeds/resolve/main/plugins/filters_cmd.py
- Command line
-
hf download hf://spaces/saske560/userbotsaskeds/plugins/filters_cmd.py
-
curl -L -o filters_cmd.py https://huggingface.co/spaces/saske560/userbotsaskeds/resolve/main/plugins/filters_cmd.py
5.58 kB
| """ | |
| plugins/filters_cmd.py β Filtros de texto para limpiar captions. | |
| Guarda frases a filtrar (en JSON). El comando .limpiar quita esas frases | |
| del texto de un mensaje respondido. | |
| Comandos: | |
| .filteradd <frase> β Agrega una frase al filtro | |
| .filterdel <frase> β Elimina una frase del filtro | |
| .filterlist β Lista todas las frases filtradas | |
| .filterclear β Elimina todos los filtros | |
| .limpiar β Responde a un msg: devuelve el texto sin las frases filtradas | |
| """ | |
| import asyncio | |
| import json | |
| from pathlib import Path | |
| from pyrogram import filters | |
| from pyrogram.types import Message | |
| from bot import app | |
| from config import Config | |
| P = Config.CMD_PREFIX | |
| DB = Path("data/filters.json") | |
| DB.parent.mkdir(exist_ok=True) | |
| # ββ Storage βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def _load() -> list: | |
| if DB.exists(): | |
| try: | |
| return json.loads(DB.read_text()) | |
| except Exception: | |
| return [] | |
| return [] | |
| def _save(data: list): | |
| DB.write_text(json.dumps(data, ensure_ascii=False, indent=2)) | |
| async def _tmp(client, chat_id: int, text: str, delay: int = 6): | |
| m = await client.send_message(chat_id, text) | |
| await asyncio.sleep(delay) | |
| await m.delete() | |
| # ββ .filteradd ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_filteradd(client, msg: Message): | |
| await msg.delete() | |
| args = msg.text.split(None, 1) | |
| if len(args) < 2: | |
| await _tmp(client, msg.chat.id, f"β **Uso:** `{P}filteradd <frase>`") | |
| return | |
| frase = args[1].strip() | |
| lst = _load() | |
| if frase in lst: | |
| await _tmp(client, msg.chat.id, f"βΉοΈ La frase ya estΓ‘ en el filtro: `{frase}`") | |
| return | |
| lst.append(frase) | |
| _save(lst) | |
| await _tmp(client, msg.chat.id, f"β Filtro aΓ±adido: `{frase}`") | |
| # ββ .filterdel ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_filterdel(client, msg: Message): | |
| await msg.delete() | |
| args = msg.text.split(None, 1) | |
| if len(args) < 2: | |
| await _tmp(client, msg.chat.id, f"β **Uso:** `{P}filterdel <frase>`") | |
| return | |
| frase = args[1].strip() | |
| lst = _load() | |
| if frase in lst: | |
| lst.remove(frase) | |
| _save(lst) | |
| await _tmp(client, msg.chat.id, f"β Filtro eliminado: `{frase}`") | |
| else: | |
| await _tmp(client, msg.chat.id, f"β No se encontrΓ³ la frase: `{frase}`") | |
| # ββ .filterlist βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_filterlist(client, msg: Message): | |
| await msg.delete() | |
| lst = _load() | |
| if not lst: | |
| await _tmp(client, msg.chat.id, "π No hay filtros configurados.") | |
| return | |
| lines = ["π **Filtros activos:**\n"] | |
| for i, f in enumerate(lst[:30], 1): | |
| lines.append(f"`{i}.` {f}") | |
| lines.append(f"\n**Total:** `{len(lst)}`") | |
| m = await client.send_message(msg.chat.id, "\n".join(lines)) | |
| await asyncio.sleep(12) | |
| await m.delete() | |
| # ββ .filterclear ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_filterclear(client, msg: Message): | |
| await msg.delete() | |
| lst = _load() | |
| _save([]) | |
| await _tmp(client, msg.chat.id, f"ποΈ **{len(lst)}** filtros eliminados.") | |
| # ββ .limpiar ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_limpiar(client, msg: Message): | |
| await msg.delete() | |
| if not msg.reply_to_message: | |
| await _tmp(client, msg.chat.id, | |
| f"β Responde a un mensaje con `{P}limpiar` para limpiar su texto.") | |
| return | |
| texto = ( | |
| msg.reply_to_message.text | |
| or msg.reply_to_message.caption | |
| or "" | |
| ) | |
| if not texto: | |
| await _tmp(client, msg.chat.id, "β El mensaje no tiene texto.") | |
| return | |
| lst = _load() | |
| resultado = texto | |
| for frase in lst: | |
| resultado = resultado.replace(frase, "") | |
| # Limpiar lΓneas vacΓas sobrantes | |
| lineas = [l.strip() for l in resultado.splitlines() if l.strip()] | |
| resultado = "\n".join(lineas).strip() | |
| if not resultado: | |
| await _tmp(client, msg.chat.id, "β οΈ El texto quedΓ³ vacΓo tras aplicar los filtros.") | |
| return | |
| m = await client.send_message(msg.chat.id, | |
| f"βοΈ **Texto limpiado:**\n\n{resultado}") | |
| await asyncio.sleep(15) | |
| await m.delete() | |