Spaces:
Runtime error
Runtime error
Update bot/handlers.py
Browse files- bot/handlers.py +40 -17
bot/handlers.py
CHANGED
|
@@ -123,21 +123,35 @@ def setup_handlers(app: Client) -> None:
|
|
| 123 |
up = await up_task
|
| 124 |
p = await p_task
|
| 125 |
|
| 126 |
-
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
txt = (
|
| 132 |
-
"β‘ **
|
| 133 |
-
|
| 134 |
-
f"
|
| 135 |
-
|
| 136 |
-
f"
|
| 137 |
-
f"
|
| 138 |
-
f"
|
| 139 |
-
f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
)
|
|
|
|
| 141 |
await safe_edit(msg, txt)
|
| 142 |
|
| 143 |
# -------- OWNER allow/disallow via forward OR id --------
|
|
@@ -157,7 +171,9 @@ def setup_handlers(app: Client) -> None:
|
|
| 157 |
target = int(parts[1])
|
| 158 |
|
| 159 |
if not target:
|
| 160 |
-
return await safe_reply(
|
|
|
|
|
|
|
| 161 |
|
| 162 |
j = await allow_user(target)
|
| 163 |
await safe_reply(m, f"β
allowed: `{target}`\n`{j}`")
|
|
@@ -213,7 +229,7 @@ def setup_handlers(app: Client) -> None:
|
|
| 213 |
|
| 214 |
@app.on_message(filters.command(["cancel"]) & filters.private)
|
| 215 |
async def cancel_cmd(_: Client, m: Message):
|
| 216 |
-
_AWAIT_AUTH.pop(m.from_user.id, None)
|
| 217 |
await safe_reply(m, texts.CANCELLED)
|
| 218 |
|
| 219 |
@app.on_callback_query()
|
|
@@ -298,12 +314,17 @@ def setup_handlers(app: Client) -> None:
|
|
| 298 |
if not isinstance(j, dict):
|
| 299 |
return await safe_reply(m, f"β profile_add bad response: `{j}`")
|
| 300 |
|
| 301 |
-
if not j.get("ok") and not (
|
|
|
|
|
|
|
| 302 |
return await safe_reply(m, texts.PROFILE_ADD_FAIL.format(j))
|
| 303 |
|
| 304 |
login_url = _pick_login_url(j)
|
| 305 |
if not login_url:
|
| 306 |
-
return await safe_reply(
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
_AWAIT_AUTH.pop(uid, None)
|
| 309 |
await safe_reply(m, texts.SENT_AUTH_LINK + login_url)
|
|
@@ -331,7 +352,9 @@ def setup_handlers(app: Client) -> None:
|
|
| 331 |
ch = (p.get("channel_title") or "β").strip()
|
| 332 |
cid = p.get("client_id_hint") or "β"
|
| 333 |
sec = p.get("client_secret_hint") or "****β¦****"
|
| 334 |
-
connected =
|
|
|
|
|
|
|
| 335 |
cur = "π’ Current" if pid == default_id else ""
|
| 336 |
txt += f"[{i}] {ch} | {cur} | id: {cid} | secret: {sec} | {connected}\n"
|
| 337 |
|
|
@@ -392,7 +415,7 @@ def setup_handlers(app: Client) -> None:
|
|
| 392 |
dl_sec = max(0.001, time.time() - dl_t0)
|
| 393 |
|
| 394 |
# fallback size from disk if TG didn't give it
|
| 395 |
-
if not file_size and file_path and os.path.exists(file_path):
|
| 396 |
try:
|
| 397 |
file_size = os.path.getsize(file_path)
|
| 398 |
except Exception:
|
|
|
|
| 123 |
up = await up_task
|
| 124 |
p = await p_task
|
| 125 |
|
| 126 |
+
ping_val = int(round(p)) if p is not None else None
|
| 127 |
|
| 128 |
+
dl_bps = float(dl.get("bps") or 0.0)
|
| 129 |
+
dl_bytes = float(dl.get("bytes") or 0.0)
|
| 130 |
+
dl_sec = float(dl.get("seconds") or 0.0)
|
| 131 |
+
|
| 132 |
+
up_bps = float(up.get("bps") or 0.0)
|
| 133 |
+
up_bytes = float(up.get("bytes") or 0.0)
|
| 134 |
+
up_sec = float(up.get("seconds") or 0.0)
|
| 135 |
+
|
| 136 |
+
dl_mb_s = bytes_per_sec_to_mb_s(dl_bps)
|
| 137 |
+
up_mb_s = bytes_per_sec_to_mb_s(up_bps)
|
| 138 |
|
| 139 |
txt = (
|
| 140 |
+
"β‘ **Server Speed Test**\n\n"
|
| 141 |
+
"π **Uptime**\n"
|
| 142 |
+
f"β’ {up_txt}\n\n"
|
| 143 |
+
"π‘ **Network**\n"
|
| 144 |
+
f"β’ π’ Ping : {ping_val if ping_val is not None else 'N/A'} ms\n"
|
| 145 |
+
f"β’ β¬οΈ Download : {dl_mb_s:.2f} MB/s\n"
|
| 146 |
+
f" β³ {bytes_to_mb(dl_bytes):.2f} MB in {dl_sec:.2f}s\n"
|
| 147 |
+
f"β’ β¬οΈ Upload : {up_mb_s:.2f} MB/s\n"
|
| 148 |
+
f" β³ {bytes_to_mb(up_bytes):.2f} MB in {up_sec:.2f}s\n\n"
|
| 149 |
+
"πΎ **Storage**\n"
|
| 150 |
+
f"β’ Total Space : {total_gb:.1f} GB\n"
|
| 151 |
+
f"β’ Free Space : {free_gb:.1f} GB\n\n"
|
| 152 |
+
"π§ͺ _Measured directly from server (real MB/s, not Mbps)_"
|
| 153 |
)
|
| 154 |
+
|
| 155 |
await safe_edit(msg, txt)
|
| 156 |
|
| 157 |
# -------- OWNER allow/disallow via forward OR id --------
|
|
|
|
| 171 |
target = int(parts[1])
|
| 172 |
|
| 173 |
if not target:
|
| 174 |
+
return await safe_reply(
|
| 175 |
+
m, "Usage:\nβ’ Reply/forward user msg then /allow\nβ’ or /allow <user_id>"
|
| 176 |
+
)
|
| 177 |
|
| 178 |
j = await allow_user(target)
|
| 179 |
await safe_reply(m, f"β
allowed: `{target}`\n`{j}`")
|
|
|
|
| 229 |
|
| 230 |
@app.on_message(filters.command(["cancel"]) & filters.private)
|
| 231 |
async def cancel_cmd(_: Client, m: Message):
|
| 232 |
+
_AWAIT_AUTH.pop(m.from_user.id if m.from_user else 0, None)
|
| 233 |
await safe_reply(m, texts.CANCELLED)
|
| 234 |
|
| 235 |
@app.on_callback_query()
|
|
|
|
| 314 |
if not isinstance(j, dict):
|
| 315 |
return await safe_reply(m, f"β profile_add bad response: `{j}`")
|
| 316 |
|
| 317 |
+
if not j.get("ok") and not (
|
| 318 |
+
isinstance(j.get("data"), dict) and j["data"].get("ok")
|
| 319 |
+
):
|
| 320 |
return await safe_reply(m, texts.PROFILE_ADD_FAIL.format(j))
|
| 321 |
|
| 322 |
login_url = _pick_login_url(j)
|
| 323 |
if not login_url:
|
| 324 |
+
return await safe_reply(
|
| 325 |
+
m,
|
| 326 |
+
f"β profile_add OK but login link missing.\nBackend response:\n`{j}`",
|
| 327 |
+
)
|
| 328 |
|
| 329 |
_AWAIT_AUTH.pop(uid, None)
|
| 330 |
await safe_reply(m, texts.SENT_AUTH_LINK + login_url)
|
|
|
|
| 352 |
ch = (p.get("channel_title") or "β").strip()
|
| 353 |
cid = p.get("client_id_hint") or "β"
|
| 354 |
sec = p.get("client_secret_hint") or "****β¦****"
|
| 355 |
+
connected = (
|
| 356 |
+
"β
Connected" if (p.get("has_refresh") and p.get("channel_id")) else "β³ Pending"
|
| 357 |
+
)
|
| 358 |
cur = "π’ Current" if pid == default_id else ""
|
| 359 |
txt += f"[{i}] {ch} | {cur} | id: {cid} | secret: {sec} | {connected}\n"
|
| 360 |
|
|
|
|
| 415 |
dl_sec = max(0.001, time.time() - dl_t0)
|
| 416 |
|
| 417 |
# fallback size from disk if TG didn't give it
|
| 418 |
+
if (not file_size) and file_path and os.path.exists(file_path):
|
| 419 |
try:
|
| 420 |
file_size = os.path.getsize(file_path)
|
| 421 |
except Exception:
|