Spaces:
Runtime error
Runtime error
Update bot/ui/keyboards.py
Browse files- bot/ui/keyboards.py +31 -14
bot/ui/keyboards.py
CHANGED
|
@@ -38,6 +38,15 @@ def auth_menu_keyboard() -> InlineKeyboardMarkup:
|
|
| 38 |
|
| 39 |
|
| 40 |
def profiles_keyboard(profiles: list[dict], default_profile_id: str = "") -> InlineKeyboardMarkup:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
rows: list[list[InlineKeyboardButton]] = []
|
| 42 |
|
| 43 |
default_profile_id = str(default_profile_id or "")
|
|
@@ -56,17 +65,19 @@ def profiles_keyboard(profiles: list[dict], default_profile_id: str = "") -> Inl
|
|
| 56 |
status = "β
" if is_connected else ("π" if not has_refresh else "β οΈ")
|
| 57 |
title = f"{prefix}{status} [{i}] {label}"[:50]
|
| 58 |
|
| 59 |
-
|
|
|
|
| 60 |
|
|
|
|
| 61 |
btns: list[InlineKeyboardButton] = []
|
| 62 |
if pid:
|
| 63 |
btns.append(InlineKeyboardButton("β
Set default", callback_data=make("pdef", pid)))
|
| 64 |
btns.append(InlineKeyboardButton("π Login", callback_data=make("plog", pid)))
|
| 65 |
btns.append(InlineKeyboardButton("π Delete", callback_data=make("pdel", pid)))
|
| 66 |
-
|
| 67 |
if btns:
|
| 68 |
rows.append(btns)
|
| 69 |
|
|
|
|
| 70 |
if last_error:
|
| 71 |
rows.append([InlineKeyboardButton(f"β οΈ {last_error[:48]}", callback_data=make("noop", "err"))])
|
| 72 |
|
|
@@ -74,23 +85,12 @@ def profiles_keyboard(profiles: list[dict], default_profile_id: str = "") -> Inl
|
|
| 74 |
return InlineKeyboardMarkup(rows)
|
| 75 |
|
| 76 |
|
| 77 |
-
def upload_confirm_keyboard(privacy: str
|
| 78 |
priv_label = {"private": "π Private", "unlisted": "π Unlisted", "public": "π Public"}.get(
|
| 79 |
(privacy or "private").lower(), "π Private"
|
| 80 |
)
|
| 81 |
-
|
| 82 |
-
tm = (title_mode or "").lower().strip()
|
| 83 |
-
b1 = "β
Filename" if tm == "filename" else "Filename"
|
| 84 |
-
b2 = "β
Caption" if tm == "caption" else "Caption"
|
| 85 |
-
b3 = "β
Custom" if tm == "custom" else "Custom"
|
| 86 |
-
|
| 87 |
return InlineKeyboardMarkup(
|
| 88 |
[
|
| 89 |
-
[
|
| 90 |
-
InlineKeyboardButton(b1, callback_data=make(NAME_ORIGINAL)),
|
| 91 |
-
InlineKeyboardButton(b2, callback_data=make(NAME_CAPTION)),
|
| 92 |
-
InlineKeyboardButton(b3, callback_data=make(NAME_CUSTOM)),
|
| 93 |
-
],
|
| 94 |
[InlineKeyboardButton("β
Upload", callback_data=make(UP_GO))],
|
| 95 |
[
|
| 96 |
InlineKeyboardButton("βοΈ Edit title/desc", callback_data=make(UP_EDIT)),
|
|
@@ -101,4 +101,21 @@ def upload_confirm_keyboard(privacy: str, title_mode: str = "caption") -> Inline
|
|
| 101 |
InlineKeyboardButton("β¬
οΈ Back", callback_data=make(BACK)),
|
| 102 |
],
|
| 103 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
)
|
|
|
|
| 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 |
+
Expected 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 "")
|
|
|
|
| 65 |
status = "β
" if is_connected else ("π" if not has_refresh else "β οΈ")
|
| 66 |
title = f"{prefix}{status} [{i}] {label}"[:50]
|
| 67 |
|
| 68 |
+
# Title/info row (noop)
|
| 69 |
+
rows.append([InlineKeyboardButton(title, callback_data=make("noop", pid[:8] or "p"))])
|
| 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 |
if btns:
|
| 78 |
rows.append(btns)
|
| 79 |
|
| 80 |
+
# Optional error row
|
| 81 |
if last_error:
|
| 82 |
rows.append([InlineKeyboardButton(f"β οΈ {last_error[:48]}", callback_data=make("noop", "err"))])
|
| 83 |
|
|
|
|
| 85 |
return InlineKeyboardMarkup(rows)
|
| 86 |
|
| 87 |
|
| 88 |
+
def upload_confirm_keyboard(privacy: str) -> InlineKeyboardMarkup:
|
| 89 |
priv_label = {"private": "π Private", "unlisted": "π Unlisted", "public": "π Public"}.get(
|
| 90 |
(privacy or "private").lower(), "π Private"
|
| 91 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
return InlineKeyboardMarkup(
|
| 93 |
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
[InlineKeyboardButton("β
Upload", callback_data=make(UP_GO))],
|
| 95 |
[
|
| 96 |
InlineKeyboardButton("βοΈ Edit title/desc", callback_data=make(UP_EDIT)),
|
|
|
|
| 101 |
InlineKeyboardButton("β¬
οΈ Back", callback_data=make(BACK)),
|
| 102 |
],
|
| 103 |
]
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def filename_keyboard() -> InlineKeyboardMarkup:
|
| 108 |
+
"""
|
| 109 |
+
Used before upload to let user pick title source:
|
| 110 |
+
- Original filename
|
| 111 |
+
- Caption
|
| 112 |
+
- Custom
|
| 113 |
+
"""
|
| 114 |
+
return InlineKeyboardMarkup(
|
| 115 |
+
[
|
| 116 |
+
[InlineKeyboardButton("π Original filename", callback_data=make(NAME_ORIGINAL))],
|
| 117 |
+
[InlineKeyboardButton("π From caption", callback_data=make(NAME_CAPTION))],
|
| 118 |
+
[InlineKeyboardButton("βοΈ Custom name", callback_data=make(NAME_CUSTOM))],
|
| 119 |
+
[InlineKeyboardButton("β Cancel", callback_data=make(CANCEL))],
|
| 120 |
+
]
|
| 121 |
)
|