mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Refactor Sticker, Contact and Document
This commit is contained in:
parent
c84fca30a2
commit
334fb8d0ba
@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from pyrogram.api import types
|
||||||
from pyrogram.api.core import Object
|
from pyrogram.api.core import Object
|
||||||
|
|
||||||
|
|
||||||
@ -41,16 +42,26 @@ class Contact(Object):
|
|||||||
|
|
||||||
ID = 0xb0700011
|
ID = 0xb0700011
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, phone_number: str, first_name: str, *,
|
||||||
self,
|
last_name: str = None, user_id: int = None, vcard: str = None,
|
||||||
phone_number: str,
|
client=None, raw=None):
|
||||||
first_name: str,
|
|
||||||
last_name: str = None,
|
|
||||||
user_id: int = None,
|
|
||||||
vcard: str = None
|
|
||||||
):
|
|
||||||
self.phone_number = phone_number
|
self.phone_number = phone_number
|
||||||
self.first_name = first_name
|
self.first_name = first_name
|
||||||
self.last_name = last_name
|
self.last_name = last_name
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
self.vcard = vcard
|
self.vcard = vcard
|
||||||
|
|
||||||
|
self._client = client
|
||||||
|
self._raw = raw
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse(client, contact: types.MessageMediaContact) -> "Contact":
|
||||||
|
return Contact(
|
||||||
|
phone_number=contact.phone_number,
|
||||||
|
first_name=contact.first_name,
|
||||||
|
last_name=contact.last_name or None,
|
||||||
|
vcard=contact.vcard or None,
|
||||||
|
user_id=contact.user_id or None,
|
||||||
|
client=client,
|
||||||
|
raw=contact
|
||||||
|
)
|
||||||
|
@ -16,7 +16,12 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from struct import pack
|
||||||
|
|
||||||
|
from pyrogram.api import types
|
||||||
from pyrogram.api.core import Object
|
from pyrogram.api.core import Object
|
||||||
|
from .photo_size import PhotoSize
|
||||||
|
from ...ext.utils import encode
|
||||||
|
|
||||||
|
|
||||||
class Document(Object):
|
class Document(Object):
|
||||||
@ -44,18 +49,36 @@ class Document(Object):
|
|||||||
|
|
||||||
ID = 0xb0700007
|
ID = 0xb0700007
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, file_id: str, *,
|
||||||
self,
|
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||||
file_id: str,
|
client=None, raw=None):
|
||||||
thumb=None,
|
|
||||||
file_name: str = None,
|
|
||||||
mime_type: str = None,
|
|
||||||
file_size: int = None,
|
|
||||||
date: int = None
|
|
||||||
):
|
|
||||||
self.file_id = file_id
|
self.file_id = file_id
|
||||||
self.thumb = thumb
|
self.thumb = thumb
|
||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
self.mime_type = mime_type
|
self.mime_type = mime_type
|
||||||
self.file_size = file_size
|
self.file_size = file_size
|
||||||
self.date = date
|
self.date = date
|
||||||
|
|
||||||
|
self._client = client
|
||||||
|
self._raw = raw
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse(client, document: types.Document, file_name: str) -> "Document":
|
||||||
|
return Document(
|
||||||
|
file_id=encode(
|
||||||
|
pack(
|
||||||
|
"<iiqq",
|
||||||
|
5,
|
||||||
|
document.dc_id,
|
||||||
|
document.id,
|
||||||
|
document.access_hash
|
||||||
|
)
|
||||||
|
),
|
||||||
|
thumb=PhotoSize.parse(client, document.thumb),
|
||||||
|
file_name=file_name,
|
||||||
|
mime_type=document.mime_type,
|
||||||
|
file_size=document.size,
|
||||||
|
date=document.date,
|
||||||
|
client=client,
|
||||||
|
raw=document
|
||||||
|
)
|
||||||
|
@ -16,7 +16,12 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from struct import pack
|
||||||
|
|
||||||
|
from pyrogram.api import types
|
||||||
from pyrogram.api.core import Object
|
from pyrogram.api.core import Object
|
||||||
|
from .photo_size import PhotoSize
|
||||||
|
from ...ext.utils import encode
|
||||||
|
|
||||||
|
|
||||||
class Sticker(Object):
|
class Sticker(Object):
|
||||||
@ -57,20 +62,10 @@ class Sticker(Object):
|
|||||||
# TODO: Add mask position
|
# TODO: Add mask position
|
||||||
ID = 0xb0700017
|
ID = 0xb0700017
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, file_id: str, width: int, height: int, *,
|
||||||
self,
|
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||||
file_id: str,
|
emoji: str = None, set_name: str = None, mask_position=None,
|
||||||
width: int,
|
client=None, raw=None):
|
||||||
height: int,
|
|
||||||
thumb=None,
|
|
||||||
file_name: str = None,
|
|
||||||
mime_type: str = None,
|
|
||||||
file_size: int = None,
|
|
||||||
date: int = None,
|
|
||||||
emoji: str = None,
|
|
||||||
set_name: str = None,
|
|
||||||
mask_position=None
|
|
||||||
):
|
|
||||||
self.file_id = file_id
|
self.file_id = file_id
|
||||||
self.thumb = thumb
|
self.thumb = thumb
|
||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
@ -82,3 +77,33 @@ class Sticker(Object):
|
|||||||
self.emoji = emoji
|
self.emoji = emoji
|
||||||
self.set_name = set_name
|
self.set_name = set_name
|
||||||
self.mask_position = mask_position
|
self.mask_position = mask_position
|
||||||
|
|
||||||
|
self._client = client
|
||||||
|
self._raw = raw
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def parse(client, sticker: types.Document, image_size_attributes: types.DocumentAttributeImageSize, set_name: str,
|
||||||
|
sticker_attributes: types.DocumentAttributeSticker, file_name: str) -> "Sticker":
|
||||||
|
return Sticker(
|
||||||
|
file_id=encode(
|
||||||
|
pack(
|
||||||
|
"<iiqq",
|
||||||
|
8,
|
||||||
|
sticker.dc_id,
|
||||||
|
sticker.id,
|
||||||
|
sticker.access_hash
|
||||||
|
)
|
||||||
|
),
|
||||||
|
width=image_size_attributes.w if image_size_attributes else 0,
|
||||||
|
height=image_size_attributes.h if image_size_attributes else 0,
|
||||||
|
thumb=PhotoSize.parse(client, sticker.thumb),
|
||||||
|
# TODO: mask_position
|
||||||
|
set_name=set_name,
|
||||||
|
emoji=sticker_attributes.alt or None,
|
||||||
|
file_size=sticker.size,
|
||||||
|
mime_type=sticker.mime_type,
|
||||||
|
file_name=file_name,
|
||||||
|
date=sticker.date,
|
||||||
|
client=client,
|
||||||
|
raw=sticker
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user