Spaces:
Paused
Paused
Download modules/reminders.py from saske560/userbotsaske: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/spaces/saske560/userbotsaske/resolve/main/modules/reminders.py
- Command line
-
hf download hf://spaces/saske560/userbotsaske/modules/reminders.py
-
curl -L -o reminders.py https://huggingface.co/spaces/saske560/userbotsaske/resolve/main/modules/reminders.py
2.64 kB
| import html | |
| import time | |
| def human(seconds: int) -> str: | |
| days, rem = divmod(seconds, 86400) | |
| hours, rem = divmod(rem, 3600) | |
| minutes, secs = divmod(rem, 60) | |
| parts = [] | |
| if days: | |
| parts.append(f"{days}d") | |
| if hours: | |
| parts.append(f"{hours}h") | |
| if minutes: | |
| parts.append(f"{minutes}m") | |
| if secs or not parts: | |
| parts.append(f"{secs}s") | |
| return " ".join(parts) | |
| def parse_duration(raw: str): | |
| raw = raw.strip().lower() | |
| if not raw: | |
| return None | |
| unit = raw[-1] | |
| if unit not in {"s", "m", "h", "d"}: | |
| return None | |
| if not raw[:-1].isdigit(): | |
| return None | |
| amount = int(raw[:-1]) | |
| return amount * {"s": 1, "m": 60, "h": 3600, "d": 86400}[unit] | |
| def setup(registry): | |
| async def remind_cmd(ctx): | |
| if not ctx.args.strip(): | |
| await ctx.respond("⚠️ Usa <code>.remind 10m llamar al cliente</code>") | |
| return | |
| parts = ctx.args.split(maxsplit=1) | |
| if len(parts) < 2: | |
| await ctx.respond("⚠️ Debes indicar duración y texto. Ejemplo: <code>.remind 30m beber agua</code>") | |
| return | |
| seconds = parse_duration(parts[0]) | |
| if seconds is None: | |
| await ctx.respond("⚠️ Tiempo inválido. Usa formatos como <code>10m</code>, <code>2h</code>, <code>1d</code>.") | |
| return | |
| text = parts[1] | |
| item = await ctx.app.reminder_manager.create(ctx.message.chat.id, text, seconds) | |
| await ctx.respond( | |
| "⏰ <b>Recordatorio creado</b>\n\n" | |
| f"📝 <b>Texto:</b> {html.escape(text)}\n" | |
| f"⌛ <b>Se enviará en:</b> <code>{human(seconds)}</code>\n" | |
| f"🆔 <b>ID:</b> <code>{item['id']}</code>" | |
| ) | |
| async def timers_cmd(ctx): | |
| reminders = ctx.app.state.data.get("reminders", []) | |
| if not reminders: | |
| await ctx.respond("⏰ No hay recordatorios activos.") | |
| return | |
| lines = ["⏰ <b>Recordatorios activos</b>", ""] | |
| now = time.time() | |
| for item in reminders[:20]: | |
| remaining = max(0, int(item.get("due_at", now) - now)) | |
| lines.append( | |
| f"• <code>{item['id']}</code> — {html.escape(item['text'][:40])}\n" | |
| f" vence en <code>{human(remaining)}</code>" | |
| ) | |
| await ctx.respond("\n".join(lines)) | |
| registry.add("remind", remind_cmd, "Crea un recordatorio local.", usage=".remind 15m revisar correo", category="Recordatorios") | |
| registry.add("timers", timers_cmd, "Lista recordatorios activos.", usage=".timers", aliases=["reminders"], category="Recordatorios") | |