Repository navigation
Expand file tree
/
Copy pathui.py
More file actions
212 lines (150 loc) · 7.7 KB
/
Copy pathui.py
File metadata and controls
212 lines (150 loc) · 7.7 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup as Kb
from aiogram.enums.button_style import ButtonStyle
# ── Fancy font ──────────────────────────────────────────────────────────
# Mathematical Sans-Serif Bold block (U+1D5D4…U+1D7F5). Used for headers
# only — body copy stays in the regular font for readability.
_UPPER = 0x1D5D4 # 'A'
_LOWER = 0x1D5EE # 'a'
_DIGIT = 0x1D7EC # '0'
def bold(text: str) -> str:
out = []
for ch in text:
if "A" <= ch <= "Z":
out.append(chr(_UPPER + (ord(ch) - ord("A"))))
elif "a" <= ch <= "z":
out.append(chr(_LOWER + (ord(ch) - ord("a"))))
elif "0" <= ch <= "9":
out.append(chr(_DIGIT + (ord(ch) - ord("0"))))
else:
out.append(ch)
return "".join(out)
# ── Keyboards ───────────────────────────────────────────────────────────
def kb_welcome() -> Kb:
return Kb(inline_keyboard=[[InlineKeyboardButton(text="⚡ Generate Session", callback_data="gen_start", style=ButtonStyle.PRIMARY)]])
def kb_library() -> Kb:
return Kb(inline_keyboard=[
[
InlineKeyboardButton(text="Pyrogram", callback_data="lib:pyro", style=ButtonStyle.SUCCESS),
InlineKeyboardButton(text="Telethon", callback_data="lib:tele", style=ButtonStyle.PRIMARY),
],
[InlineKeyboardButton(text="✕ Cancel", callback_data="gen_cancel", style=ButtonStyle.DANGER)],
])
def kb_credentials() -> Kb:
return Kb(inline_keyboard=[
[
InlineKeyboardButton(text="Use Default", callback_data="cred:default", style=ButtonStyle.SUCCESS),
InlineKeyboardButton(text="Use My Own", callback_data="cred:custom", style=ButtonStyle.PRIMARY),
],
[InlineKeyboardButton(text="✕ Cancel", callback_data="gen_cancel", style=ButtonStyle.DANGER)],
])
def kb_cancel_only() -> Kb:
return Kb(inline_keyboard=[[InlineKeyboardButton(text="✕ Cancel", callback_data="gen_cancel", style=ButtonStyle.DANGER)]])
def kb_restart() -> Kb:
return Kb(inline_keyboard=[[InlineKeyboardButton(text="⚡ Generate Session", callback_data="gen_start", style=ButtonStyle.PRIMARY)]])
# ── Message templates ─────────────────────────────────────────────────
def welcome(username: str) -> str:
return (
f"{bold('SESSION GENERATOR')}\n\n"
"Generate a secure Pyrogram or Telethon session string for your own "
"Telegram account, directly in this chat.\n\n"
f"{bold('How it works')}\n"
"Logs in for a single use, exports a portable session string, and "
"closes the connection immediately after — nothing is stored or "
"logged on this server.\n\n"
"<i>⚠ A session string grants full account access. Treat it exactly "
"like a password — never share it, not even with this bot's admins.</i>"
)
def step_library() -> str:
return (
f"{bold('STEP 1 · LIBRARY')}\n\n"
"Select the client library this session string will be used with.\n\n"
"<b>Pyrogram</b> — modern async framework, common in current userbots.\n"
"<b>Telethon</b> — mature and widely supported, the target of most "
"existing userbot scripts.\n\n"
"Not sure? Pyrogram is the more common modern default."
)
def step_credentials() -> str:
return (
f"{bold('STEP 2 · API CREDENTIALS')}\n\n"
"Choose which API ID / API Hash pair to authenticate with.\n\n"
"<b>Default</b> — this bot's built-in credentials. Fastest option.\n"
"<b>Use My Own</b> — your personal API ID / Hash, issued to your "
"account only. Recommended for long-term or production use.\n\n"
'<i>Get your own free at <a href="https://my.telegram.org/apps">'
"my.telegram.org/apps</a> — log in with your number → API "
"development tools → create an app → copy the API ID and API Hash.</i>"
)
def ask_api_id() -> str:
return f"{bold('API ID')}\n\nSend your numeric API ID from my.telegram.org/apps."
def ask_api_hash() -> str:
return (
f"{bold('API HASH')}\n\n"
"Now send your API Hash — the 32-character string shown next to "
"your API ID on my.telegram.org/apps."
)
def invalid_api_id() -> str:
return f"{bold('INVALID API ID')}\n\nThat doesn't look numeric. Send just the digits."
def invalid_api_hash() -> str:
return f"{bold('INVALID API HASH')}\n\nExpected a 32-character hex string. Try again."
def ask_phone() -> str:
return (
f"{bold('STEP 3 · PHONE NUMBER')}\n\n"
"Send the phone number for the account you want a session for, "
"in international format:\n\n"
"<code>+15551234567</code>"
)
def invalid_phone() -> str:
return f"{bold('INVALID NUMBER')}\n\nUse international format, e.g. <code>+15551234567</code>."
def sending_code(phone: str) -> str:
return f"{bold('SENDING CODE')}\n\nRequesting a verification code for <code>{phone}</code>…"
def ask_code(phone: str) -> str:
return (
f"{bold('STEP 4 · VERIFICATION CODE')}\n\n"
f"A login code was just sent to <code>{phone}</code>.\n\n"
"Enter it with spaces between each digit — this stops Telegram from "
"auto-detecting and invalidating it:\n\n"
"<code>1 2 3 4 5</code>"
)
def code_invalid() -> str:
return f"{bold('INCORRECT CODE')}\n\nThat code didn't match. Try again:"
def ask_password() -> str:
return (
f"{bold('STEP 5 · TWO-FACTOR PASSWORD')}\n\n"
"This account has an extra password set. Enter it to finish signing in.\n\n"
"<i>It's removed from this chat immediately after processing.</i>"
)
def password_invalid() -> str:
return f"{bold('INCORRECT PASSWORD')}\n\nThat password didn't match. Try again:"
def success(flavor_name: str, session_string: str, bot_username: str) -> str:
return (
f"{bold('SESSION READY')}\n\n"
f"Your {flavor_name} session string:\n\n"
f"<code>{session_string}</code>\n\n"
f"{bold('Handle this like a password')}\n"
"Anyone holding this string has full control of the account — "
"messages, contacts, everything.\n\n"
f"{bold('Recommended')}\n"
"Store it in an environment variable or secret manager — never in "
"plain chat logs or public code.\n\n"
f"<i>Generated via @{bot_username} · nothing about this session was stored.</i>"
)
def cancelled() -> str:
return f"{bold('CANCELLED')}\n\nGeneration stopped. Nothing was kept.\n\nTap below to start again."
def expired() -> str:
return (
f"{bold('SESSION EXPIRED')}\n\n"
"No response for 5 minutes — this flow was cancelled automatically "
"and no credentials were retained.\n\nTap below to start again."
)
def generic_error(detail: str) -> str:
return f"{bold('SOMETHING WENT WRONG')}\n\n<i>{detail}</i>\n\nTap below to try again."
def flood_wait(seconds: str) -> str:
return f"{bold('TOO MANY ATTEMPTS')}\n\nTelegram is rate-limiting this action. Try again in {seconds}s."
def notice_60s() -> str:
return "⏳ <b>1 minute</b> remaining on this session — finish this step or it will be cancelled automatically."
def notice_30s() -> str:
return "⏳ <b>30 seconds</b> remaining."
def notice_10s() -> str:
return "⏳ <b>10 seconds</b> remaining."
def pong(ms: float) -> str:
return f"{bold('PONG')}\n\nResponse time: <code>{ms:.0f} ms</code>"