diff --git a/basethon/base_thon.py b/basethon/base_thon.py index bc82f26..d969dab 100644 --- a/basethon/base_thon.py +++ b/basethon/base_thon.py @@ -10,7 +10,14 @@ from telethon import TelegramClient from telethon.tl.functions.account import UpdateStatusRequest from telethon.tl.functions.help import GetCountriesListRequest, GetNearestDcRequest from telethon.tl.functions.langpack import GetLangPackRequest -from telethon.types import JsonNumber, JsonObject, JsonObjectValue, JsonString +from telethon.types import ( + InputPeerUser, + JsonNumber, + JsonObject, + JsonObjectValue, + JsonString, + User, +) from basethon.base_data import BaseData from basethon.models import ThonOptions, ThonSearchCodeOptions @@ -28,6 +35,7 @@ class BaseThon(BaseData): self._async_check_timeout = options.async_check_timeout super().__init__(options.json_data, options.raise_error) self.__client = self.__get_client() + self.me: User | InputPeerUser | None = None @property def client(self) -> TelegramClient: @@ -87,6 +95,7 @@ class BaseThon(BaseData): await self.get_additional_data() with contextlib.suppress(Exception): await self.client(UpdateStatusRequest(offline=False)) + self.me = await self.client.get_me() return "OK" except ConnectionError: await self.disconnect() @@ -107,6 +116,13 @@ class BaseThon(BaseData): except asyncio.TimeoutError: return "ERROR_AUTH:CONNECTION_ERROR:TIMEOUT" + async def get_phone(self) -> str: + if not self.me: + return "" + if isinstance(self.me, User): + return self.me.phone or "" + return "" + async def search_code(self, options: ThonSearchCodeOptions | None = None) -> str: options = options or ThonSearchCodeOptions() future = datetime.now() + timedelta(seconds=options.wait_time)