Spaces:
Paused
Paused
Download modules/afk.py from saske560/userbotsaske: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/spaces/saske560/userbotsaske/resolve/main/modules/afk.py
- Command line
-
hf download hf://spaces/saske560/userbotsaske/modules/afk.py
-
curl -L -o afk.py https://huggingface.co/spaces/saske560/userbotsaske/resolve/main/modules/afk.py
2.4 kB
| import html | |
| import time | |
| def format_since(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") | |
| parts.append(f"{secs}s") | |
| return " ".join(parts) | |
| def setup(registry): | |
| async def afk_cmd(ctx): | |
| reason = ctx.args.strip() or "Sin motivo especificado" | |
| afk = ctx.app.state.data.setdefault("afk", {}) | |
| afk["enabled"] = True | |
| afk["reason"] = reason | |
| afk["since"] = time.time() | |
| afk["replied_to"] = {} | |
| await ctx.app.state.save() | |
| await ctx.respond( | |
| "💤 <b>Modo AFK activado</b>\n\n" | |
| f"📝 <b>Motivo:</b> {html.escape(reason)}\n" | |
| "ℹ️ Se desactivará automáticamente cuando envíes un mensaje." | |
| ) | |
| async def unafk_cmd(ctx): | |
| afk = ctx.app.state.data.setdefault("afk", {}) | |
| if not afk.get("enabled"): | |
| await ctx.respond("🌞 Ya no estabas AFK.") | |
| return | |
| elapsed = int(time.time() - afk.get("since", time.time())) | |
| afk["enabled"] = False | |
| afk["reason"] = "" | |
| afk["since"] = 0 | |
| afk["replied_to"] = {} | |
| await ctx.app.state.save() | |
| await ctx.respond( | |
| "🌞 <b>AFK desactivado</b>\n\n" | |
| f"⏳ Estuviste ausente durante <code>{format_since(elapsed)}</code>" | |
| ) | |
| async def afkstatus_cmd(ctx): | |
| afk = ctx.app.state.data.setdefault("afk", {}) | |
| if not afk.get("enabled"): | |
| await ctx.respond("💤 El modo AFK está desactivado.") | |
| return | |
| elapsed = int(time.time() - afk.get("since", time.time())) | |
| await ctx.respond( | |
| "💤 <b>AFK activo</b>\n\n" | |
| f"📝 <b>Motivo:</b> {html.escape(afk.get('reason') or 'Sin motivo')}\n" | |
| f"⏳ <b>Ausente desde hace:</b> <code>{format_since(elapsed)}</code>" | |
| ) | |
| registry.add("afk", afk_cmd, "Activa el modo AFK con motivo opcional.", usage=".afk comiendo", category="Afk") | |
| registry.add("unafk", unafk_cmd, "Desactiva el modo AFK manualmente.", usage=".unafk", category="Afk") | |
| registry.add("afkstatus", afkstatus_cmd, "Muestra el estado actual del AFK.", usage=".afkstatus", category="Afk") | |