understanding commited on
Commit
6b6c6e6
Β·
verified Β·
1 Parent(s): 33b99cd

Update bot/ui/keyboards.py

Browse files
Files changed (1) hide show
  1. bot/ui/keyboards.py +53 -7
bot/ui/keyboards.py CHANGED
@@ -1,5 +1,7 @@
1
  # PATH: bot/ui/keyboards.py
2
- from hydrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
 
 
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
- def profiles_keyboard(profiles: list[dict]) -> InlineKeyboardMarkup:
36
- rows = []
37
- for i, p in enumerate(profiles, start=1):
38
- pid = p.get("profile_id") or ""
39
- ch = (p.get("channel_title") or p.get("label") or "Profile").strip()
40
- rows.append([InlineKeyboardButton(f"🟒 Set current: [{i}] {ch[:32]}", callback_data=f"setdef:{pid}")])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  [