mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-18 13:34:54 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/client/client.py # pyrogram/client/methods/messages/send_audio.py # pyrogram/session/session.py
This commit is contained in:
commit
4c290ba38a
@ -24,7 +24,7 @@ from . import Bytes
|
|||||||
class String(Bytes):
|
class String(Bytes):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read(b: BytesIO, *args) -> str:
|
def read(b: BytesIO, *args) -> str:
|
||||||
return super(String, String).read(b).decode()
|
return super(String, String).read(b).decode(errors="replace")
|
||||||
|
|
||||||
def __new__(cls, value: str) -> bytes:
|
def __new__(cls, value: str) -> bytes:
|
||||||
return super().__new__(cls, value.encode())
|
return super().__new__(cls, value.encode())
|
||||||
|
@ -218,28 +218,33 @@ class Client(Methods, BaseClient):
|
|||||||
await self.session.start()
|
await self.session.start()
|
||||||
self.is_started = True
|
self.is_started = True
|
||||||
|
|
||||||
if self.user_id is None:
|
try:
|
||||||
|
if self.user_id is None:
|
||||||
|
if self.bot_token is None:
|
||||||
|
await self.authorize_user()
|
||||||
|
else:
|
||||||
|
await self.authorize_bot()
|
||||||
|
|
||||||
|
self.save_session()
|
||||||
|
|
||||||
if self.bot_token is None:
|
if self.bot_token is None:
|
||||||
await self.authorize_user()
|
now = time.time()
|
||||||
|
|
||||||
|
if abs(now - self.date) > Client.OFFLINE_SLEEP:
|
||||||
|
self.peers_by_username = {}
|
||||||
|
self.peers_by_phone = {}
|
||||||
|
|
||||||
|
await self.get_initial_dialogs()
|
||||||
|
await self.get_contacts()
|
||||||
|
else:
|
||||||
|
await self.send(functions.messages.GetPinnedDialogs())
|
||||||
|
await self.get_initial_dialogs_chunk()
|
||||||
else:
|
else:
|
||||||
await self.authorize_bot()
|
await self.send(functions.updates.GetState())
|
||||||
|
except Exception as e:
|
||||||
self.save_session()
|
self.is_started = False
|
||||||
|
await self.session.stop()
|
||||||
if self.bot_token is None:
|
raise e
|
||||||
now = time.time()
|
|
||||||
|
|
||||||
if abs(now - self.date) > Client.OFFLINE_SLEEP:
|
|
||||||
self.peers_by_username = {}
|
|
||||||
self.peers_by_phone = {}
|
|
||||||
|
|
||||||
await self.get_initial_dialogs()
|
|
||||||
await self.get_contacts()
|
|
||||||
else:
|
|
||||||
await self.send(functions.messages.GetPinnedDialogs())
|
|
||||||
await self.get_initial_dialogs_chunk()
|
|
||||||
else:
|
|
||||||
await self.send(functions.updates.GetState())
|
|
||||||
|
|
||||||
self.updates_worker_task = asyncio.ensure_future(self.updates_worker())
|
self.updates_worker_task = asyncio.ensure_future(self.updates_worker())
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class SendAudio(BaseClient):
|
|||||||
duration: int = 0,
|
duration: int = 0,
|
||||||
performer: str = None,
|
performer: str = None,
|
||||||
title: str = None,
|
title: str = None,
|
||||||
disable_notification: bool = None,
|
thumb: str = None,disable_notification: bool = None,
|
||||||
reply_to_message_id: int = None,
|
reply_to_message_id: int = None,
|
||||||
reply_markup=None,
|
reply_markup=None,
|
||||||
progress: callable = None,
|
progress: callable = None,
|
||||||
@ -73,6 +73,12 @@ class SendAudio(BaseClient):
|
|||||||
title (``str``, *optional*):
|
title (``str``, *optional*):
|
||||||
Track name.
|
Track name.
|
||||||
|
|
||||||
|
thumb (``str``, *optional*):
|
||||||
|
Thumbnail of the music file album cover.
|
||||||
|
The thumbnail should be in JPEG format and less than 200 KB in size.
|
||||||
|
A thumbnail's width and height should not exceed 90 pixels.
|
||||||
|
Thumbnails can't be reused and can be only uploaded as a new file.
|
||||||
|
|
||||||
disable_notification (``bool``, *optional*):
|
disable_notification (``bool``, *optional*):
|
||||||
Sends the message silently.
|
Sends the message silently.
|
||||||
Users will receive a notification with no sound.
|
Users will receive a notification with no sound.
|
||||||
@ -117,10 +123,12 @@ class SendAudio(BaseClient):
|
|||||||
style = self.html if parse_mode.lower() == "html" else self.markdown
|
style = self.html if parse_mode.lower() == "html" else self.markdown
|
||||||
|
|
||||||
if os.path.exists(audio):
|
if os.path.exists(audio):
|
||||||
|
thumb = None if thumb is None else self.save_file(thumb)
|
||||||
file = await self.save_file(audio, progress=progress, progress_args=progress_args)
|
file = await self.save_file(audio, progress=progress, progress_args=progress_args)
|
||||||
media = types.InputMediaUploadedDocument(
|
media = types.InputMediaUploadedDocument(
|
||||||
mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"),
|
mime_type=mimetypes.types_map.get("." + audio.split(".")[-1], "audio/mpeg"),
|
||||||
file=file,
|
file=file,
|
||||||
|
thumb=thumb,
|
||||||
attributes=[
|
attributes=[
|
||||||
types.DocumentAttributeAudio(
|
types.DocumentAttributeAudio(
|
||||||
duration=duration,
|
duration=duration,
|
||||||
|
@ -74,9 +74,10 @@ class SendVideo(BaseClient):
|
|||||||
Video height.
|
Video height.
|
||||||
|
|
||||||
thumb (``str``, *optional*):
|
thumb (``str``, *optional*):
|
||||||
Video thumbnail.
|
Thumbnail of the video sent.
|
||||||
Pass a file path as string to send an image that exists on your local machine.
|
The thumbnail should be in JPEG format and less than 200 KB in size.
|
||||||
Thumbnail should have 90 or less pixels of width and 90 or less pixels of height.
|
A thumbnail's width and height should not exceed 90 pixels.
|
||||||
|
Thumbnails can't be reused and can be only uploaded as a new file.
|
||||||
|
|
||||||
supports_streaming (``bool``, *optional*):
|
supports_streaming (``bool``, *optional*):
|
||||||
Pass True, if the uploaded video is suitable for streaming.
|
Pass True, if the uploaded video is suitable for streaming.
|
||||||
|
@ -27,21 +27,22 @@ try:
|
|||||||
|
|
||||||
|
|
||||||
class AES:
|
class AES:
|
||||||
|
# TODO: Use new tgcrypto function names
|
||||||
@classmethod
|
@classmethod
|
||||||
def ige256_encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
|
def ige256_encrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
|
||||||
return tgcrypto.ige256_encrypt(data, key, iv)
|
return tgcrypto.ige_encrypt(data, key, iv)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ige256_decrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
|
def ige256_decrypt(cls, data: bytes, key: bytes, iv: bytes) -> bytes:
|
||||||
return tgcrypto.ige256_decrypt(data, key, iv)
|
return tgcrypto.ige_decrypt(data, key, iv)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
|
def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
|
||||||
return tgcrypto.ctr256_encrypt(data, key, iv, state or bytearray(1))
|
return tgcrypto.ctr_encrypt(data, key, iv, state or bytearray(1))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
|
def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = None) -> bytes:
|
||||||
return tgcrypto.ctr256_decrypt(data, key, iv, state or bytearray(1))
|
return tgcrypto.ctr_decrypt(data, key, iv, state or bytearray(1))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def xor(a: bytes, b: bytes) -> bytes:
|
def xor(a: bytes, b: bytes) -> bytes:
|
||||||
|
Loading…
Reference in New Issue
Block a user