Spaces:
Runtime error
Runtime error
| # PATH: bot/ui/keyboards.py | |
| from __future__ import annotations | |
| from hydrogram.types import InlineKeyboardButton, InlineKeyboardMarkup | |
| from bot.ui.callbacks import ( | |
| make, | |
| AUTH_JSON, AUTH_CI, CANCEL, BACK, | |
| MENU_HELP, MENU_AUTH, MENU_PROFILES, MENU_SPEEDTEST, | |
| UP_GO, UP_EDIT, UP_PRIV, UP_CANCEL, | |
| NAME_ORIGINAL, NAME_CAPTION, NAME_CUSTOM, | |
| ) | |
| def main_menu_keyboard() -> InlineKeyboardMarkup: | |
| return InlineKeyboardMarkup( | |
| [ | |
| [ | |
| InlineKeyboardButton("π Add Profile", callback_data=make(MENU_AUTH)), | |
| InlineKeyboardButton("π€ Profiles", callback_data=make(MENU_PROFILES)), | |
| ], | |
| [ | |
| InlineKeyboardButton("β‘ Speedtest", callback_data=make(MENU_SPEEDTEST)), | |
| InlineKeyboardButton("β Help", callback_data=make(MENU_HELP)), | |
| ], | |
| ] | |
| ) | |
| def auth_menu_keyboard() -> InlineKeyboardMarkup: | |
| return InlineKeyboardMarkup( | |
| [ | |
| [InlineKeyboardButton("π Send .json / Paste JSON", callback_data=make(AUTH_JSON))], | |
| [InlineKeyboardButton("π Send Client ID + Secret", callback_data=make(AUTH_CI))], | |
| [InlineKeyboardButton("β¬ οΈ Back", callback_data=make(BACK))], | |
| ] | |
| ) | |
| def profiles_keyboard(profiles: list[dict], default_profile_id: str = "") -> InlineKeyboardMarkup: | |
| """ | |
| Must match handlers.py: | |
| profiles_keyboard(profiles, default_id) | |
| Expected callback actions: | |
| pdef:<profile_id> set default | |
| plog:<profile_id> get login url | |
| pdel:<profile_id> delete profile (confirm by YES message) | |
| """ | |
| rows: list[list[InlineKeyboardButton]] = [] | |
| default_profile_id = str(default_profile_id or "") | |
| for i, p in enumerate(profiles or [], start=1): | |
| pid = str(p.get("profile_id") or "") | |
| label = (p.get("channel_title") or p.get("label") or "Profile").strip() | |
| has_refresh = bool(p.get("has_refresh")) | |
| channel_id = str(p.get("channel_id") or "") | |
| last_error = (p.get("last_error") or "").strip() | |
| is_connected = has_refresh and bool(channel_id) | |
| is_default = bool(pid and pid == default_profile_id) | |
| prefix = "β " if is_default else "" | |
| status = "β " if is_connected else ("π" if not has_refresh else "β οΈ") | |
| title = f"{prefix}{status} [{i}] {label}"[:50] | |
| # Title/info row (noop) | |
| rows.append([InlineKeyboardButton(title, callback_data=make("noop", pid[:8] or "p"))]) | |
| # Action row | |
| btns: list[InlineKeyboardButton] = [] | |
| if pid: | |
| btns.append(InlineKeyboardButton("β Set default", callback_data=make("pdef", pid))) | |
| btns.append(InlineKeyboardButton("π Login", callback_data=make("plog", pid))) | |
| btns.append(InlineKeyboardButton("π Delete", callback_data=make("pdel", pid))) | |
| if btns: | |
| rows.append(btns) | |
| # Optional error row | |
| if last_error: | |
| rows.append([InlineKeyboardButton(f"β οΈ {last_error[:48]}", callback_data=make("noop", "err"))]) | |
| rows.append([InlineKeyboardButton("β¬ οΈ Back", callback_data=make(BACK))]) | |
| return InlineKeyboardMarkup(rows) | |
| def upload_confirm_keyboard(privacy: str) -> InlineKeyboardMarkup: | |
| priv_label = {"private": "π Private", "unlisted": "π Unlisted", "public": "π Public"}.get( | |
| (privacy or "private").lower(), "π Private" | |
| ) | |
| return InlineKeyboardMarkup( | |
| [ | |
| [InlineKeyboardButton("β Upload", callback_data=make(UP_GO))], | |
| [ | |
| InlineKeyboardButton("βοΈ Edit title/desc", callback_data=make(UP_EDIT)), | |
| InlineKeyboardButton(priv_label, callback_data=make(UP_PRIV)), | |
| ], | |
| [ | |
| InlineKeyboardButton("β Cancel", callback_data=make(UP_CANCEL)), | |
| InlineKeyboardButton("β¬ οΈ Back", callback_data=make(BACK)), | |
| ], | |
| ] | |
| ) | |
| def filename_keyboard() -> InlineKeyboardMarkup: | |
| """ | |
| Used before upload to let user pick title source: | |
| - Original filename | |
| - Caption | |
| - Custom | |
| """ | |
| return InlineKeyboardMarkup( | |
| [ | |
| [InlineKeyboardButton("π Original filename", callback_data=make(NAME_ORIGINAL))], | |
| [InlineKeyboardButton("π From caption", callback_data=make(NAME_CAPTION))], | |
| [InlineKeyboardButton("βοΈ Custom name", callback_data=make(NAME_CUSTOM))], | |
| [InlineKeyboardButton("β Cancel", callback_data=make(CANCEL))], | |
| ] | |
| ) |