get phone
This commit is contained in:
@ -10,7 +10,14 @@ from telethon import TelegramClient
|
|||||||
from telethon.tl.functions.account import UpdateStatusRequest
|
from telethon.tl.functions.account import UpdateStatusRequest
|
||||||
from telethon.tl.functions.help import GetCountriesListRequest, GetNearestDcRequest
|
from telethon.tl.functions.help import GetCountriesListRequest, GetNearestDcRequest
|
||||||
from telethon.tl.functions.langpack import GetLangPackRequest
|
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.base_data import BaseData
|
||||||
from basethon.models import ThonOptions, ThonSearchCodeOptions
|
from basethon.models import ThonOptions, ThonSearchCodeOptions
|
||||||
@ -28,6 +35,7 @@ class BaseThon(BaseData):
|
|||||||
self._async_check_timeout = options.async_check_timeout
|
self._async_check_timeout = options.async_check_timeout
|
||||||
super().__init__(options.json_data, options.raise_error)
|
super().__init__(options.json_data, options.raise_error)
|
||||||
self.__client = self.__get_client()
|
self.__client = self.__get_client()
|
||||||
|
self.me: User | InputPeerUser | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client(self) -> TelegramClient:
|
def client(self) -> TelegramClient:
|
||||||
@ -87,6 +95,7 @@ class BaseThon(BaseData):
|
|||||||
await self.get_additional_data()
|
await self.get_additional_data()
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
await self.client(UpdateStatusRequest(offline=False))
|
await self.client(UpdateStatusRequest(offline=False))
|
||||||
|
self.me = await self.client.get_me()
|
||||||
return "OK"
|
return "OK"
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
await self.disconnect()
|
await self.disconnect()
|
||||||
@ -107,6 +116,13 @@ class BaseThon(BaseData):
|
|||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
return "ERROR_AUTH:CONNECTION_ERROR:TIMEOUT"
|
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:
|
async def search_code(self, options: ThonSearchCodeOptions | None = None) -> str:
|
||||||
options = options or ThonSearchCodeOptions()
|
options = options or ThonSearchCodeOptions()
|
||||||
future = datetime.now() + timedelta(seconds=options.wait_time)
|
future = datetime.now() + timedelta(seconds=options.wait_time)
|
||||||
|
|||||||
Reference in New Issue
Block a user