From 334fb8d0ba63d72fc6f9cf4c6683c86072af837a Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Sat, 15 Dec 2018 21:40:44 +0100
Subject: [PATCH] Refactor Sticker, Contact and Document
---
.../types/messages_and_media/contact.py | 27 +++++++---
.../types/messages_and_media/document.py | 41 ++++++++++----
.../types/messages_and_media/sticker.py | 53 ++++++++++++++-----
3 files changed, 90 insertions(+), 31 deletions(-)
diff --git a/pyrogram/client/types/messages_and_media/contact.py b/pyrogram/client/types/messages_and_media/contact.py
index 2569f03a..2c686a5f 100644
--- a/pyrogram/client/types/messages_and_media/contact.py
+++ b/pyrogram/client/types/messages_and_media/contact.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+from pyrogram.api import types
from pyrogram.api.core import Object
@@ -41,16 +42,26 @@ class Contact(Object):
ID = 0xb0700011
- def __init__(
- self,
- phone_number: str,
- first_name: str,
- last_name: str = None,
- user_id: int = None,
- vcard: str = None
- ):
+ def __init__(self, phone_number: str, first_name: str, *,
+ last_name: str = None, user_id: int = None, vcard: str = None,
+ client=None, raw=None):
self.phone_number = phone_number
self.first_name = first_name
self.last_name = last_name
self.user_id = user_id
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
+ )
diff --git a/pyrogram/client/types/messages_and_media/document.py b/pyrogram/client/types/messages_and_media/document.py
index d87fa666..5aa047cf 100644
--- a/pyrogram/client/types/messages_and_media/document.py
+++ b/pyrogram/client/types/messages_and_media/document.py
@@ -16,7 +16,12 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+from struct import pack
+
+from pyrogram.api import types
from pyrogram.api.core import Object
+from .photo_size import PhotoSize
+from ...ext.utils import encode
class Document(Object):
@@ -44,18 +49,36 @@ class Document(Object):
ID = 0xb0700007
- def __init__(
- self,
- file_id: str,
- thumb=None,
- file_name: str = None,
- mime_type: str = None,
- file_size: int = None,
- date: int = None
- ):
+ def __init__(self, file_id: str, *,
+ thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
+ client=None, raw=None):
self.file_id = file_id
self.thumb = thumb
self.file_name = file_name
self.mime_type = mime_type
self.file_size = file_size
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(
+ ".
+from struct import pack
+
+from pyrogram.api import types
from pyrogram.api.core import Object
+from .photo_size import PhotoSize
+from ...ext.utils import encode
class Sticker(Object):
@@ -57,20 +62,10 @@ class Sticker(Object):
# TODO: Add mask position
ID = 0xb0700017
- def __init__(
- self,
- file_id: str,
- width: int,
- 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
- ):
+ def __init__(self, file_id: str, width: int, 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,
+ client=None, raw=None):
self.file_id = file_id
self.thumb = thumb
self.file_name = file_name
@@ -82,3 +77,33 @@ class Sticker(Object):
self.emoji = emoji
self.set_name = set_name
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(
+ "