File size: 4,558 Bytes
286d605
6b6c6e6
 
 
0b4a60f
40d9cf1
 
7ec2e33
 
0b4a60f
 
40d9cf1
286d605
6b6c6e6
7ec2e33
 
 
 
 
 
 
 
 
 
 
 
 
4a4c06a
6b6c6e6
4a4c06a
 
 
0b4a60f
7ec2e33
 
4a4c06a
40d9cf1
 
6b6c6e6
 
42291ba
 
 
 
 
 
 
 
 
6b6c6e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42291ba
 
6b6c6e6
42291ba
6b6c6e6
 
 
 
 
 
 
 
42291ba
6b6c6e6
 
 
7ec2e33
 
 
6b6c6e6
42291ba
7ec2e33
0b4a60f
7ec2e33
40d9cf1
 
7ec2e33
40d9cf1
7ec2e33
 
40d9cf1
 
7ec2e33
 
40d9cf1
 
42291ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a4c06a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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))],
        ]
    )