Download bot/onboarding.py from Hfzune/Test: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/spaces/Hfzune/Test/resolve/main/bot/onboarding.py
- Command line
-
hf download hf://spaces/Hfzune/Test/bot/onboarding.py
-
curl -L -o onboarding.py https://huggingface.co/spaces/Hfzune/Test/resolve/main/bot/onboarding.py
2.33 kB
| import logging | |
| from bot.telegram_api import send_message | |
| from db import models as dbm | |
| log = logging.getLogger("onboarding") | |
| async def handle_start(chat_id, user_id, username=None): | |
| user = dbm.get_user(user_id) | |
| if user and dbm.user_has_valid_token(user_id): | |
| await send_message( | |
| chat_id, | |
| "**Welcome back!**\n\n" | |
| "Send any message to chat with the model.\n" | |
| "Use /help for commands.", | |
| ) | |
| return | |
| await send_message( | |
| chat_id, | |
| "**Welcome.**\n\n" | |
| "This bot requires an access token.\n\n" | |
| "Send `/token YOUR_TOKEN_HERE` to activate.\n" | |
| "If you don't have one, ask the admin.", | |
| ) | |
| async def handle_token_command(chat_id, user_id, token: str): | |
| if not token: | |
| await send_message(chat_id, "Usage: `/token YOUR_TOKEN_HERE`") | |
| return | |
| ok = dbm.bind_token(user_id, token) | |
| if ok: | |
| await send_message( | |
| chat_id, | |
| "**Token accepted.**\n\nYou can now send messages.", | |
| ) | |
| else: | |
| await send_message( | |
| chat_id, | |
| "**Invalid, revoked, or already-used token.**", | |
| ) | |
| async def handle_reset(chat_id, user_id): | |
| # 1. Wipe live context (SQLite) so the model starts fresh | |
| dbm.clear_history(user_id) | |
| # 2. Close the current session file. Next message opens a NEW file | |
| # at /data/chat_logs/{user_id}/{timestamp}.md — nothing is deleted. | |
| dbm.archive_close_session(user_id) | |
| await send_message( | |
| chat_id, | |
| "🧹 **Conversation memory cleared.**\n" | |
| "_A fresh session will start on your next message._", | |
| ) | |
| async def handle_help(chat_id): | |
| await send_message( | |
| chat_id, | |
| "**Commands**\n\n" | |
| "/start — welcome / onboarding\n" | |
| "/token VALUE — activate or replace token\n" | |
| "/reset — start a fresh session\n" | |
| "/stats — your usage stats\n" | |
| "/help — this message", | |
| ) | |
| async def handle_stats(chat_id, user_id): | |
| user = dbm.get_user(user_id) or {} | |
| sessions = dbm.archive_list(user_id) | |
| await send_message( | |
| chat_id, | |
| f"**Your stats**\n\n" | |
| f"Total turns: {user.get('total_turns', 0)}\n" | |
| f"Sessions: {len(sessions)}\n" | |
| f"Last seen: {user.get('last_seen', 'n/a')}", | |
| ) |