mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Add PyrogramType
This commit is contained in:
parent
5ecbfbf25f
commit
6ab1c87050
@ -19,12 +19,12 @@
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .photo_size import PhotoSize
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
|
||||
class Animation(Object):
|
||||
class Animation(PyrogramType):
|
||||
"""This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).
|
||||
|
||||
Args:
|
||||
@ -56,8 +56,6 @@ class Animation(Object):
|
||||
Date the animation was sent in Unix time.
|
||||
"""
|
||||
|
||||
ID = 0xb0700025
|
||||
|
||||
def __init__(self, file_id: str, width: int, height: int, duration: int, *,
|
||||
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||
client=None, raw=None):
|
||||
|
@ -19,12 +19,12 @@
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .photo_size import PhotoSize
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
|
||||
class Audio(Object):
|
||||
class Audio(PyrogramType):
|
||||
"""This object represents an audio file to be treated as music by the Telegram clients.
|
||||
|
||||
Args:
|
||||
@ -56,8 +56,6 @@ class Audio(Object):
|
||||
Title of the audio as defined by sender or by audio tags.
|
||||
"""
|
||||
|
||||
ID = 0xb0700006
|
||||
|
||||
def __init__(self, file_id: str, duration: int, *,
|
||||
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||
performer: str = None, title: str = None,
|
||||
|
@ -17,10 +17,10 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class Contact(Object):
|
||||
class Contact(PyrogramType):
|
||||
"""This object represents a phone contact.
|
||||
|
||||
Args:
|
||||
@ -40,8 +40,6 @@ class Contact(Object):
|
||||
Additional data about the contact in the form of a vCard.
|
||||
"""
|
||||
|
||||
ID = 0xb0700011
|
||||
|
||||
def __init__(self, phone_number: str, first_name: str, *,
|
||||
last_name: str = None, user_id: int = None, vcard: str = None,
|
||||
client=None, raw=None):
|
||||
|
@ -19,12 +19,12 @@
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .photo_size import PhotoSize
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
|
||||
class Document(Object):
|
||||
class Document(PyrogramType):
|
||||
"""This object represents a general file (as opposed to photos, voice messages, audio files, ...).
|
||||
|
||||
Args:
|
||||
@ -47,8 +47,6 @@ class Document(Object):
|
||||
Date the document was sent in Unix time.
|
||||
"""
|
||||
|
||||
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,
|
||||
client=None, raw=None):
|
||||
|
@ -17,10 +17,10 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class Location(Object):
|
||||
class Location(PyrogramType):
|
||||
"""This object represents a point on the map.
|
||||
|
||||
Args:
|
||||
@ -31,8 +31,6 @@ class Location(Object):
|
||||
Latitude as defined by sender.
|
||||
"""
|
||||
|
||||
ID = 0xb0700012
|
||||
|
||||
def __init__(self, longitude: float, latitude: float, *,
|
||||
client=None, raw=None):
|
||||
self.longitude = longitude
|
||||
|
@ -18,18 +18,18 @@
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import types, functions
|
||||
from pyrogram.api.core import Object
|
||||
from pyrogram.api.errors import MessageIdsEmpty, StickersetInvalid
|
||||
from .contact import Contact
|
||||
from .location import Location
|
||||
from .message_entity import MessageEntity
|
||||
from ..messages_and_media.photo import Photo
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ..user_and_chats.chat import Chat
|
||||
from ..user_and_chats.user import User
|
||||
from ...ext.utils import Str
|
||||
|
||||
|
||||
class Message(Object):
|
||||
class Message(PyrogramType):
|
||||
"""This object represents a message.
|
||||
|
||||
Args:
|
||||
@ -224,7 +224,6 @@ class Message(Object):
|
||||
"""
|
||||
|
||||
# TODO: Add game missing field. Also invoice, successful_payment, connected_website
|
||||
ID = 0xb0700003
|
||||
|
||||
def __init__(self, message_id: int, *,
|
||||
date: int = None, chat=None, from_user=None, forward_from=None, forward_from_chat=None,
|
||||
|
@ -17,11 +17,11 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ..user_and_chats.user import User
|
||||
|
||||
|
||||
class MessageEntity(Object):
|
||||
class MessageEntity(PyrogramType):
|
||||
"""This object represents one special entity in a text message.
|
||||
For example, hashtags, usernames, URLs, etc.
|
||||
|
||||
@ -45,8 +45,6 @@ class MessageEntity(Object):
|
||||
For "text_mention" only, the mentioned user.
|
||||
"""
|
||||
|
||||
ID = 0xb0700004
|
||||
|
||||
ENTITIES = {
|
||||
types.MessageEntityMention.ID: "mention",
|
||||
types.MessageEntityHashtag.ID: "hashtag",
|
||||
|
@ -16,10 +16,10 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api.core import Object
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class Messages(Object):
|
||||
class Messages(PyrogramType):
|
||||
"""This object represents a chat's messages.
|
||||
|
||||
Args:
|
||||
@ -30,8 +30,6 @@ class Messages(Object):
|
||||
Requested messages.
|
||||
"""
|
||||
|
||||
ID = 0xb0700026
|
||||
|
||||
def __init__(self, total_count: int, messages: list):
|
||||
self.total_count = total_count
|
||||
self.messages = messages
|
||||
|
@ -20,12 +20,12 @@ from base64 import b64encode
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .photo_size import PhotoSize
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
|
||||
class Photo(Object):
|
||||
class Photo(PyrogramType):
|
||||
"""This object represents a Photo.
|
||||
|
||||
Args:
|
||||
@ -39,8 +39,6 @@ class Photo(Object):
|
||||
Available sizes of this photo.
|
||||
"""
|
||||
|
||||
ID = 0xb0700027
|
||||
|
||||
def __init__(self, id: str, date: int, sizes: list, *,
|
||||
client=None, raw=None):
|
||||
self.id = id
|
||||
|
@ -19,11 +19,11 @@
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from pyrogram.client.ext.utils import encode
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class PhotoSize(Object):
|
||||
class PhotoSize(PyrogramType):
|
||||
"""This object represents one size of a photo or a file/sticker thumbnail.
|
||||
|
||||
Args:
|
||||
@ -40,8 +40,6 @@ class PhotoSize(Object):
|
||||
File size.
|
||||
"""
|
||||
|
||||
ID = 0xb0700005
|
||||
|
||||
def __init__(self, file_id: str, width: int, height: int, file_size: int, *,
|
||||
client=None, raw=None):
|
||||
self.file_id = file_id
|
||||
|
@ -19,12 +19,12 @@
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .photo_size import PhotoSize
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
|
||||
class Sticker(Object):
|
||||
class Sticker(PyrogramType):
|
||||
"""This object represents a sticker.
|
||||
|
||||
Args:
|
||||
@ -60,7 +60,6 @@ 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,
|
||||
|
@ -16,10 +16,10 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api.core import Object
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class UserProfilePhotos(Object):
|
||||
class UserProfilePhotos(PyrogramType):
|
||||
"""This object represents a user's profile pictures.
|
||||
|
||||
Args:
|
||||
@ -30,8 +30,6 @@ class UserProfilePhotos(Object):
|
||||
Requested profile pictures.
|
||||
"""
|
||||
|
||||
ID = 0xb0700014
|
||||
|
||||
def __init__(self, total_count: int, photos: list):
|
||||
self.total_count = total_count
|
||||
self.photos = photos
|
||||
|
@ -17,11 +17,11 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .location import Location
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class Venue(Object):
|
||||
class Venue(PyrogramType):
|
||||
"""This object represents a venue.
|
||||
|
||||
Args:
|
||||
@ -43,8 +43,6 @@ class Venue(Object):
|
||||
|
||||
"""
|
||||
|
||||
ID = 0xb0700013
|
||||
|
||||
def __init__(self, location, title: str, address: str, *,
|
||||
foursquare_id: str = None, foursquare_type: str = None,
|
||||
client=None, raw=None):
|
||||
|
@ -19,12 +19,12 @@
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .photo_size import PhotoSize
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
|
||||
class Video(Object):
|
||||
class Video(PyrogramType):
|
||||
"""This object represents a video file.
|
||||
|
||||
Args:
|
||||
@ -56,8 +56,6 @@ class Video(Object):
|
||||
Date the video was sent in Unix time.
|
||||
"""
|
||||
|
||||
ID = 0xb0700008
|
||||
|
||||
def __init__(self, file_id: str, width: int, height: int, duration: int, *,
|
||||
thumb=None, file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||
client=None, raw=None):
|
||||
|
@ -19,12 +19,12 @@
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .photo_size import PhotoSize
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
|
||||
class VideoNote(Object):
|
||||
class VideoNote(PyrogramType):
|
||||
"""This object represents a video message (available in Telegram apps as of v.4.0).
|
||||
|
||||
Args:
|
||||
@ -50,8 +50,6 @@ class VideoNote(Object):
|
||||
Date the video note was sent in Unix time.
|
||||
"""
|
||||
|
||||
ID = 0xb0700010
|
||||
|
||||
def __init__(self, file_id: str, length: int, duration: int, *,
|
||||
thumb=None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||
client=None, raw=None):
|
||||
|
@ -16,13 +16,14 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from ...ext.utils import encode
|
||||
from struct import pack
|
||||
|
||||
from pyrogram.api import types
|
||||
from ..pyrogram_type import PyrogramType
|
||||
from ...ext.utils import encode
|
||||
|
||||
class Voice(Object):
|
||||
|
||||
class Voice(PyrogramType):
|
||||
"""This object represents a voice note.
|
||||
|
||||
Args:
|
||||
@ -45,8 +46,6 @@ class Voice(Object):
|
||||
Date the voice was sent in Unix time.
|
||||
"""
|
||||
|
||||
ID = 0xb0700009
|
||||
|
||||
def __init__(self, file_id: str, duration: int, *,
|
||||
waveform: bytes = None, mime_type: str = None, file_size: int = None, date: int = None,
|
||||
client=None, raw=None):
|
||||
|
44
pyrogram/client/types/pyrogram_type.py
Normal file
44
pyrogram/client/types/pyrogram_type.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from collections import OrderedDict
|
||||
from json import dumps, JSONEncoder
|
||||
|
||||
|
||||
class PyrogramType:
|
||||
def __str__(self):
|
||||
return dumps(self, cls=Encoder, indent=4)
|
||||
|
||||
|
||||
def remove_none(obj):
|
||||
if isinstance(obj, (list, tuple, set)):
|
||||
return type(obj)(remove_none(x) for x in obj if x is not None)
|
||||
elif isinstance(obj, dict):
|
||||
return type(obj)((remove_none(k), remove_none(v)) for k, v in obj.items() if k is not None and v is not None)
|
||||
else:
|
||||
return obj
|
||||
|
||||
|
||||
class Encoder(JSONEncoder):
|
||||
def default(self, o: PyrogramType):
|
||||
content = {i: getattr(o, i) for i in filter(lambda x: not x.startswith("_"), o.__dict__)}
|
||||
|
||||
return OrderedDict(
|
||||
[("_", "pyrogram:{}".format(o.__class__.__name__))]
|
||||
+ [i for i in remove_none(content).items()]
|
||||
)
|
@ -17,11 +17,11 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .chat_photo import ChatPhoto
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class Chat(Object):
|
||||
class Chat(PyrogramType):
|
||||
"""This object represents a chat.
|
||||
|
||||
Args:
|
||||
@ -76,8 +76,6 @@ class Chat(Object):
|
||||
The reason why this chat might be unavailable to some users.
|
||||
"""
|
||||
|
||||
ID = 0xb0700002
|
||||
|
||||
def __init__(self, id: int, type: str, *,
|
||||
title: str = None, username: str = None, first_name: str = None, last_name: str = None,
|
||||
all_members_are_administrators: bool = None, photo=None, description: str = None,
|
||||
|
@ -42,7 +42,7 @@ class ChatPhoto(Object):
|
||||
self.big_file_id = big_file_id
|
||||
|
||||
self._client = client
|
||||
self.raw = raw
|
||||
self._raw = raw
|
||||
|
||||
@staticmethod
|
||||
def parse(client, chat_photo: types.UserProfilePhoto or types.ChatPhoto):
|
||||
|
@ -17,12 +17,12 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from .user_status import UserStatus
|
||||
from .chat_photo import ChatPhoto
|
||||
from .user_status import UserStatus
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class User(Object):
|
||||
class User(PyrogramType):
|
||||
"""This object represents a Telegram user or bot.
|
||||
|
||||
Args:
|
||||
@ -69,8 +69,6 @@ class User(Object):
|
||||
The reason why this bot might be unavailable to some users.
|
||||
"""
|
||||
|
||||
ID = 0xb0700001
|
||||
|
||||
def __init__(self, id: int, is_self: bool, is_contact: bool, is_mutual_contact: bool, is_deleted: bool,
|
||||
is_bot: bool, first_name: str, *,
|
||||
last_name: str = None, status=None, username: str = None, language_code: str = None,
|
||||
|
@ -17,10 +17,10 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyrogram.api import types
|
||||
from pyrogram.api.core import Object
|
||||
from ..pyrogram_type import PyrogramType
|
||||
|
||||
|
||||
class UserStatus(Object):
|
||||
class UserStatus(PyrogramType):
|
||||
"""This object represents a User status (Last Seen privacy).
|
||||
|
||||
.. note::
|
||||
@ -62,8 +62,6 @@ class UserStatus(Object):
|
||||
always shown to blocked users), None otherwise.
|
||||
"""
|
||||
|
||||
ID = 0xb0700031
|
||||
|
||||
def __init__(self, user_id: int, *,
|
||||
online: bool = None, offline: bool = None, date: int = None, recently: bool = None,
|
||||
within_week: bool = None, within_month: bool = None, long_time_ago: bool = None,
|
||||
|
Loading…
Reference in New Issue
Block a user