Make consistent tdlib API

This commit is contained in:
Paul Nameless 2020-07-24 16:00:38 +08:00
parent d674c1d430
commit 98dbd21beb
2 changed files with 13 additions and 17 deletions

View file

@ -615,7 +615,8 @@ class UserModel:
if user.get("full_info"): if user.get("full_info"):
return user["full_info"] return user["full_info"]
result = self.tg.get_user_full_info(user_id, block=True) result = self.tg.get_user_full_info(user_id,)
result.wait()
if result.error: if result.error:
log.warning(f"get user full info error: {result.error_info}") log.warning(f"get user full info error: {result.error_info}")
return {} return {}

View file

@ -92,18 +92,15 @@ class Tdlib(Telegram):
limit: int = 0, limit: int = 0,
synchronous: bool = False, synchronous: bool = False,
) -> None: ) -> None:
result = self.call_method( data = {
"downloadFile", "@type": "downloadFile",
params=dict( "file_id": file_id,
file_id=file_id, "priority": priority,
priority=priority, "offset": offset,
offset=offset, "limit": limit,
limit=limit, "synchronous": synchronous,
synchronous=synchronous, }
), return self._send_data(data)
block=False,
)
result.wait()
def reply_message( def reply_message(
self, chat_id: int, reply_to_message_id: int, text: str self, chat_id: int, reply_to_message_id: int, text: str
@ -380,14 +377,12 @@ class Tdlib(Telegram):
} }
return self._send_data(data) return self._send_data(data)
def get_user_full_info( def get_user_full_info(self, user_id: int) -> AsyncResult:
self, user_id: int, block: bool = False
) -> AsyncResult:
data = { data = {
"@type": "getUserFullInfo", "@type": "getUserFullInfo",
"user_id": user_id, "user_id": user_id,
} }
return self._send_data(data, block=block) return self._send_data(data)
def get_chat_type(chat: Dict[str, Any]) -> Optional[ChatType]: def get_chat_type(chat: Dict[str, Any]) -> Optional[ChatType]: