feat: telegram commands, app settings, bot polling, webhook handling, UI improvements
Adds telegram bot command system with 13 commands (search, latest, random, etc.), webhook/polling handlers, rate limiting, app settings page, and various UI/UX improvements across all entity pages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Command text parsing — extracts command name, arguments, and optional count."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def parse_command(text: str) -> tuple[str, str, int | None]:
|
||||
"""Parse a command message into (command, args, count).
|
||||
|
||||
Examples:
|
||||
"/search sunset" -> ("search", "sunset", None)
|
||||
"/latest Family 5" -> ("latest", "Family", 5)
|
||||
"/events 10" -> ("events", "", 10)
|
||||
"/help@mybot" -> ("help", "", None)
|
||||
"""
|
||||
text = text.strip()
|
||||
if not text.startswith("/"):
|
||||
return ("", text, None)
|
||||
|
||||
# Strip @botname suffix: /command@botname args
|
||||
parts = text[1:].split(None, 1)
|
||||
cmd = parts[0].split("@")[0].lower()
|
||||
rest = parts[1] if len(parts) > 1 else ""
|
||||
|
||||
# Try to extract trailing count
|
||||
count = None
|
||||
rest_parts = rest.rsplit(None, 1)
|
||||
if len(rest_parts) == 2:
|
||||
try:
|
||||
count = int(rest_parts[1])
|
||||
rest = rest_parts[0]
|
||||
except ValueError:
|
||||
pass
|
||||
elif rest_parts and rest_parts[0]:
|
||||
try:
|
||||
count = int(rest_parts[0])
|
||||
rest = ""
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return (cmd, rest.strip(), count)
|
||||
Reference in New Issue
Block a user