abuse: полный пересчёт индекса только по явному вызову (env не тормозит scan)
Some checks failed
ci / test (3.10) (push) Has been cancelled
ci / test (3.11) (push) Has been cancelled
ci / test (3.12) (push) Has been cancelled

This commit is contained in:
Vlad Gothbreach
2026-10-27 01:21:01 +03:00
parent d0b2187319
commit 42a864419b
12 changed files with 1844 additions and 983 deletions

View File

@@ -132,3 +132,43 @@ def search(query, limit=40):
api_id = int(os.environ["OMNI_TG_API_ID"])
api_hash = os.environ["OMNI_TG_API_HASH"]
return asyncio.run(_search(query, limit, session, api_id, api_hash))
_ME = {}
async def _me(session, api_id, api_hash, timeout=40):
from telethon import TelegramClient
client = TelegramClient(session, api_id, api_hash, connection_retries=1, timeout=timeout / 2)
await asyncio.wait_for(client.connect(), timeout)
try:
u = await asyncio.wait_for(client.get_me(), timeout)
if not u:
return {}
return {"id": getattr(u, "id", None), "username": getattr(u, "username", None),
"first_name": getattr(u, "first_name", None), "premium": bool(getattr(u, "premium", False)),
"phone_tail": (str(getattr(u, "phone", "") or "")[-4:] or None)}
finally:
try:
await asyncio.wait_for(client.disconnect(), 10)
except Exception:
pass
def me():
"""Аккаунт сессии: {id, username, first_name, premium}. Кэш на процесс."""
if _ME:
return _ME
if not enabled():
return {}
try:
from . import config
config.tg_cfg()
except Exception:
pass
session = os.environ["OMNI_TG_SESSION"]
api_id = int(os.environ["OMNI_TG_API_ID"])
api_hash = os.environ["OMNI_TG_API_HASH"]
_ME.update(asyncio.run(_me(session, api_id, api_hash)) or {})
return _ME