Spaces:
Runtime error
Runtime error
Update bot/ui/keyboards.py
Browse files- bot/ui/keyboards.py +53 -7
bot/ui/keyboards.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
# PATH: bot/ui/keyboards.py
|
| 2 |
-
from
|
|
|
|
|
|
|
| 3 |
|
| 4 |
from bot.ui.callbacks import (
|
| 5 |
make,
|
|
@@ -9,6 +11,7 @@ from bot.ui.callbacks import (
|
|
| 9 |
NAME_ORIGINAL, NAME_CAPTION, NAME_CUSTOM,
|
| 10 |
)
|
| 11 |
|
|
|
|
| 12 |
def main_menu_keyboard() -> InlineKeyboardMarkup:
|
| 13 |
return InlineKeyboardMarkup(
|
| 14 |
[
|
|
@@ -23,6 +26,7 @@ def main_menu_keyboard() -> InlineKeyboardMarkup:
|
|
| 23 |
]
|
| 24 |
)
|
| 25 |
|
|
|
|
| 26 |
def auth_menu_keyboard() -> InlineKeyboardMarkup:
|
| 27 |
return InlineKeyboardMarkup(
|
| 28 |
[
|
|
@@ -32,15 +36,56 @@ def auth_menu_keyboard() -> InlineKeyboardMarkup:
|
|
| 32 |
]
|
| 33 |
)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
rows.append([InlineKeyboardButton("β¬
οΈ Back", callback_data=make(BACK))])
|
| 42 |
return InlineKeyboardMarkup(rows)
|
| 43 |
|
|
|
|
| 44 |
def upload_confirm_keyboard(privacy: str) -> InlineKeyboardMarkup:
|
| 45 |
priv_label = {"private": "π Private", "unlisted": "π Unlisted", "public": "π Public"}.get(
|
| 46 |
(privacy or "private").lower(), "π Private"
|
|
@@ -59,6 +104,7 @@ def upload_confirm_keyboard(privacy: str) -> InlineKeyboardMarkup:
|
|
| 59 |
]
|
| 60 |
)
|
| 61 |
|
|
|
|
| 62 |
def filename_keyboard() -> InlineKeyboardMarkup:
|
| 63 |
return InlineKeyboardMarkup(
|
| 64 |
[
|
|
|
|
| 1 |
# PATH: bot/ui/keyboards.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from hydrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
| 5 |
|
| 6 |
from bot.ui.callbacks import (
|
| 7 |
make,
|
|
|
|
| 11 |
NAME_ORIGINAL, NAME_CAPTION, NAME_CUSTOM,
|
| 12 |
)
|
| 13 |
|
| 14 |
+
|
| 15 |
def main_menu_keyboard() -> InlineKeyboardMarkup:
|
| 16 |
return InlineKeyboardMarkup(
|
| 17 |
[
|
|
|
|
| 26 |
]
|
| 27 |
)
|
| 28 |
|
| 29 |
+
|
| 30 |
def auth_menu_keyboard() -> InlineKeyboardMarkup:
|
| 31 |
return InlineKeyboardMarkup(
|
| 32 |
[
|
|
|
|
| 36 |
]
|
| 37 |
)
|
| 38 |
|
| 39 |
+
|
| 40 |
+
def profiles_keyboard(profiles: list[dict], default_profile_id: str = "") -> InlineKeyboardMarkup:
|
| 41 |
+
"""
|
| 42 |
+
Must match handlers.py:
|
| 43 |
+
profiles_keyboard(profiles, default_id)
|
| 44 |
+
|
| 45 |
+
handlers.py expects callback actions:
|
| 46 |
+
pdef:<profile_id> set default
|
| 47 |
+
plog:<profile_id> get login url
|
| 48 |
+
pdel:<profile_id> delete profile (confirm by YES message)
|
| 49 |
+
"""
|
| 50 |
+
rows: list[list[InlineKeyboardButton]] = []
|
| 51 |
+
|
| 52 |
+
default_profile_id = str(default_profile_id or "")
|
| 53 |
+
|
| 54 |
+
for i, p in enumerate(profiles or [], start=1):
|
| 55 |
+
pid = str(p.get("profile_id") or "")
|
| 56 |
+
label = (p.get("channel_title") or p.get("label") or "Profile").strip()
|
| 57 |
+
has_refresh = bool(p.get("has_refresh"))
|
| 58 |
+
channel_id = str(p.get("channel_id") or "")
|
| 59 |
+
last_error = (p.get("last_error") or "").strip()
|
| 60 |
+
|
| 61 |
+
is_connected = has_refresh and bool(channel_id)
|
| 62 |
+
is_default = bool(pid and pid == default_profile_id)
|
| 63 |
+
|
| 64 |
+
prefix = "β " if is_default else ""
|
| 65 |
+
status = "β
" if is_connected else ("π" if not has_refresh else "β οΈ")
|
| 66 |
+
title = f"{prefix}{status} [{i}] {label}"[:50]
|
| 67 |
+
|
| 68 |
+
# Title/info row
|
| 69 |
+
rows.append([InlineKeyboardButton(title, callback_data=make("noop", pid[:8]))])
|
| 70 |
+
|
| 71 |
+
# Action row
|
| 72 |
+
btns: list[InlineKeyboardButton] = []
|
| 73 |
+
if pid:
|
| 74 |
+
btns.append(InlineKeyboardButton("β
Set default", callback_data=make("pdef", pid)))
|
| 75 |
+
btns.append(InlineKeyboardButton("π Login", callback_data=make("plog", pid)))
|
| 76 |
+
btns.append(InlineKeyboardButton("π Delete", callback_data=make("pdel", pid)))
|
| 77 |
+
|
| 78 |
+
if btns:
|
| 79 |
+
rows.append(btns)
|
| 80 |
+
|
| 81 |
+
# Optional small error row (if present)
|
| 82 |
+
if last_error:
|
| 83 |
+
rows.append([InlineKeyboardButton(f"β οΈ {last_error[:48]}", callback_data=make("noop", "err"))])
|
| 84 |
+
|
| 85 |
rows.append([InlineKeyboardButton("β¬
οΈ Back", callback_data=make(BACK))])
|
| 86 |
return InlineKeyboardMarkup(rows)
|
| 87 |
|
| 88 |
+
|
| 89 |
def upload_confirm_keyboard(privacy: str) -> InlineKeyboardMarkup:
|
| 90 |
priv_label = {"private": "π Private", "unlisted": "π Unlisted", "public": "π Public"}.get(
|
| 91 |
(privacy or "private").lower(), "π Private"
|
|
|
|
| 104 |
]
|
| 105 |
)
|
| 106 |
|
| 107 |
+
|
| 108 |
def filename_keyboard() -> InlineKeyboardMarkup:
|
| 109 |
return InlineKeyboardMarkup(
|
| 110 |
[
|