Spaces:
Paused
Paused
Download plugins/notes.py from saske560/userbotsaskeds: direct link, hf CLI and curl.
- Browser
- Download file 4.91 kB
-
https://huggingface.co/spaces/saske560/userbotsaskeds/resolve/main/plugins/notes.py
- Command line
-
hf download hf://spaces/saske560/userbotsaskeds/plugins/notes.py
-
curl -L -o notes.py https://huggingface.co/spaces/saske560/userbotsaskeds/resolve/main/plugins/notes.py
4.91 kB
| """ | |
| plugins/notes.py β Notas persistentes por chat. | |
| Comandos: | |
| .save note <nombre> β Guarda el mensaje respondido como nota | |
| .note <nombre> β Muestra la nota | |
| .notes β Lista todas las notas del chat | |
| .delnote <nombre> β Elimina una nota | |
| """ | |
| 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 | |
| NOTES_FILE = Path("data/notes.json") | |
| NOTES_FILE.parent.mkdir(exist_ok=True) | |
| # ββ Storage helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def _load() -> dict: | |
| if NOTES_FILE.exists(): | |
| try: | |
| return json.loads(NOTES_FILE.read_text()) | |
| except Exception: | |
| return {} | |
| return {} | |
| def _save(data: dict): | |
| NOTES_FILE.write_text(json.dumps(data, ensure_ascii=False, indent=2)) | |
| def _key(chat_id: int) -> str: | |
| return str(chat_id) | |
| async def _respond(client, chat_id: int, text: str, delay: int = 5): | |
| note = await client.send_message(chat_id, text) | |
| await asyncio.sleep(delay) | |
| await note.delete() | |
| # ββ .save note <nombre> βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_save_note(client, msg: Message): | |
| args = msg.text.split(None, 2) | |
| # "save note <nombre>" flow | |
| if len(args) >= 3 and args[1].lower() == "note": | |
| note_name = args[2].lower().strip() | |
| await msg.delete() | |
| if not msg.reply_to_message: | |
| await _respond(client, msg.chat.id, "β Responde a un mensaje para guardarlo como nota.") | |
| return | |
| r = msg.reply_to_message | |
| content = r.text or r.caption or "" | |
| db = _load() | |
| cid = _key(msg.chat.id) | |
| if cid not in db: | |
| db[cid] = {} | |
| db[cid][note_name] = { | |
| "text": content, | |
| "media_type": str(r.media) if r.media else None, | |
| } | |
| _save(db) | |
| await _respond(client, msg.chat.id, f"β Nota `{note_name}` guardada.") | |
| # else: handled by chat.py's .save command (no "note" keyword) | |
| # ββ .note <nombre> ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_get_note(client, msg: Message): | |
| args = msg.text.split(None, 1) | |
| await msg.delete() | |
| if len(args) < 2: | |
| await _respond(client, msg.chat.id, f"β Uso: `{P}note <nombre>`"); return | |
| name = args[1].lower().strip() | |
| db = _load() | |
| cid = _key(msg.chat.id) | |
| if cid not in db or name not in db[cid]: | |
| await _respond(client, msg.chat.id, f"β No existe la nota `{name}`.") | |
| return | |
| entry = db[cid][name] | |
| text = entry.get("text") or "(sin texto)" | |
| await client.send_message(msg.chat.id, f"π **{name}**\n\n{text}") | |
| # ββ .notes ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_list_notes(client, msg: Message): | |
| await msg.delete() | |
| db = _load() | |
| cid = _key(msg.chat.id) | |
| if cid not in db or not db[cid]: | |
| await _respond(client, msg.chat.id, "π No hay notas en este chat.") | |
| return | |
| names = sorted(db[cid].keys()) | |
| text = "π **Notas guardadas:**\n\n" + "\n".join(f"β’ `{n}`" for n in names) | |
| note = await client.send_message(msg.chat.id, text) | |
| await asyncio.sleep(12) | |
| await note.delete() | |
| # ββ .delnote <nombre> βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def cmd_del_note(client, msg: Message): | |
| args = msg.text.split(None, 1) | |
| await msg.delete() | |
| if len(args) < 2: | |
| await _respond(client, msg.chat.id, f"β Uso: `{P}delnote <nombre>`"); return | |
| name = args[1].lower().strip() | |
| db = _load() | |
| cid = _key(msg.chat.id) | |
| if cid in db and name in db[cid]: | |
| del db[cid][name] | |
| _save(db) | |
| await _respond(client, msg.chat.id, f"ποΈ Nota `{name}` eliminada.") | |
| else: | |
| await _respond(client, msg.chat.id, f"β No existe la nota `{name}`.") | |