abuse: полный пересчёт индекса только по явному вызову (env не тормозит scan)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user