mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Make all parse methods protected to hide them from the lib user
This commit is contained in:
parent
b79f395d37
commit
e8fbae3166
@ -62,17 +62,17 @@ class Dispatcher:
|
|||||||
|
|
||||||
self.update_parsers = {
|
self.update_parsers = {
|
||||||
Dispatcher.MESSAGE_UPDATES:
|
Dispatcher.MESSAGE_UPDATES:
|
||||||
lambda upd, usr, cht: (pyrogram.Message.parse(self.client, upd.message, usr, cht), MessageHandler),
|
lambda upd, usr, cht: (pyrogram.Message._parse(self.client, upd.message, usr, cht), MessageHandler),
|
||||||
|
|
||||||
Dispatcher.DELETE_MESSAGES_UPDATES:
|
Dispatcher.DELETE_MESSAGES_UPDATES:
|
||||||
lambda upd, usr, cht: (pyrogram.Messages.parse_deleted(self.client, upd), DeletedMessagesHandler),
|
lambda upd, usr, cht: (pyrogram.Messages._parse_deleted(self.client, upd), DeletedMessagesHandler),
|
||||||
|
|
||||||
Dispatcher.CALLBACK_QUERY_UPDATES:
|
Dispatcher.CALLBACK_QUERY_UPDATES:
|
||||||
lambda upd, usr, cht: (pyrogram.CallbackQuery.parse(self.client, upd, usr), CallbackQueryHandler),
|
lambda upd, usr, cht: (pyrogram.CallbackQuery._parse(self.client, upd, usr), CallbackQueryHandler),
|
||||||
|
|
||||||
(types.UpdateUserStatus,):
|
(types.UpdateUserStatus,):
|
||||||
lambda upd, usr, cht: (
|
lambda upd, usr, cht: (
|
||||||
pyrogram.UserStatus.parse(self.client, upd.status, upd.user_id), UserStatusHandler
|
pyrogram.UserStatus._parse(self.client, upd.status, upd.user_id), UserStatusHandler
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class CallbackQuery(PyrogramType):
|
|||||||
self.game_short_name = game_short_name
|
self.game_short_name = game_short_name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, callback_query, users) -> "CallbackQuery":
|
def _parse(client, callback_query, users) -> "CallbackQuery":
|
||||||
message = None
|
message = None
|
||||||
inline_message_id = None
|
inline_message_id = None
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ class CallbackQuery(PyrogramType):
|
|||||||
|
|
||||||
return CallbackQuery(
|
return CallbackQuery(
|
||||||
id=str(callback_query.query_id),
|
id=str(callback_query.query_id),
|
||||||
from_user=User.parse(client, users[callback_query.user_id]),
|
from_user=User._parse(client, users[callback_query.user_id]),
|
||||||
message=message,
|
message=message,
|
||||||
inline_message_id=inline_message_id,
|
inline_message_id=inline_message_id,
|
||||||
chat_instance=str(callback_query.chat_instance),
|
chat_instance=str(callback_query.chat_instance),
|
||||||
|
@ -81,7 +81,7 @@ class Animation(PyrogramType):
|
|||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, animation: types.Document, video_attributes: types.DocumentAttributeVideo,
|
def _parse(client, animation: types.Document, video_attributes: types.DocumentAttributeVideo,
|
||||||
file_name: str) -> "Animation":
|
file_name: str) -> "Animation":
|
||||||
return Animation(
|
return Animation(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
@ -96,7 +96,7 @@ class Animation(PyrogramType):
|
|||||||
width=getattr(video_attributes, "w", 0),
|
width=getattr(video_attributes, "w", 0),
|
||||||
height=getattr(video_attributes, "h", 0),
|
height=getattr(video_attributes, "h", 0),
|
||||||
duration=getattr(video_attributes, "duration", 0),
|
duration=getattr(video_attributes, "duration", 0),
|
||||||
thumb=PhotoSize.parse(client, animation.thumb),
|
thumb=PhotoSize._parse(client, animation.thumb),
|
||||||
mime_type=animation.mime_type,
|
mime_type=animation.mime_type,
|
||||||
file_size=animation.size,
|
file_size=animation.size,
|
||||||
file_name=file_name,
|
file_name=file_name,
|
||||||
|
@ -81,7 +81,7 @@ class Audio(PyrogramType):
|
|||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, audio: types.Document, audio_attributes: types.DocumentAttributeAudio, file_name: str) -> "Audio":
|
def _parse(client, audio: types.Document, audio_attributes: types.DocumentAttributeAudio, file_name: str) -> "Audio":
|
||||||
return Audio(
|
return Audio(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
@ -97,7 +97,7 @@ class Audio(PyrogramType):
|
|||||||
title=audio_attributes.title,
|
title=audio_attributes.title,
|
||||||
mime_type=audio.mime_type,
|
mime_type=audio.mime_type,
|
||||||
file_size=audio.size,
|
file_size=audio.size,
|
||||||
thumb=PhotoSize.parse(client, audio.thumb),
|
thumb=PhotoSize._parse(client, audio.thumb),
|
||||||
file_name=file_name,
|
file_name=file_name,
|
||||||
date=audio.date,
|
date=audio.date,
|
||||||
client=client
|
client=client
|
||||||
|
@ -57,7 +57,7 @@ class Contact(PyrogramType):
|
|||||||
self.vcard = vcard
|
self.vcard = vcard
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, contact: types.MessageMediaContact) -> "Contact":
|
def _parse(client, contact: types.MessageMediaContact) -> "Contact":
|
||||||
return Contact(
|
return Contact(
|
||||||
phone_number=contact.phone_number,
|
phone_number=contact.phone_number,
|
||||||
first_name=contact.first_name,
|
first_name=contact.first_name,
|
||||||
|
@ -66,7 +66,7 @@ class Document(PyrogramType):
|
|||||||
self.date = date
|
self.date = date
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, document: types.Document, file_name: str) -> "Document":
|
def _parse(client, document: types.Document, file_name: str) -> "Document":
|
||||||
return Document(
|
return Document(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
@ -77,7 +77,7 @@ class Document(PyrogramType):
|
|||||||
document.access_hash
|
document.access_hash
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
thumb=PhotoSize.parse(client, document.thumb),
|
thumb=PhotoSize._parse(client, document.thumb),
|
||||||
file_name=file_name,
|
file_name=file_name,
|
||||||
mime_type=document.mime_type,
|
mime_type=document.mime_type,
|
||||||
file_size=document.size,
|
file_size=document.size,
|
||||||
|
@ -38,7 +38,7 @@ class Location(PyrogramType):
|
|||||||
self.latitude = latitude
|
self.latitude = latitude
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, geo_point: types.GeoPoint) -> "Location":
|
def _parse(client, geo_point: types.GeoPoint) -> "Location":
|
||||||
if isinstance(geo_point, types.GeoPoint):
|
if isinstance(geo_point, types.GeoPoint):
|
||||||
return Location(
|
return Location(
|
||||||
longitude=geo_point.long,
|
longitude=geo_point.long,
|
||||||
|
@ -336,7 +336,7 @@ class Message(PyrogramType):
|
|||||||
self.reply_markup = reply_markup
|
self.reply_markup = reply_markup
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, message: types.Message or types.MessageService or types.MessageEmpty, users: dict, chats: dict,
|
def _parse(client, message: types.Message or types.MessageService or types.MessageEmpty, users: dict, chats: dict,
|
||||||
replies: int = 1):
|
replies: int = 1):
|
||||||
if isinstance(message, types.MessageEmpty):
|
if isinstance(message, types.MessageEmpty):
|
||||||
return Message(message_id=message.id, empty=True, client=client)
|
return Message(message_id=message.id, empty=True, client=client)
|
||||||
@ -355,11 +355,11 @@ class Message(PyrogramType):
|
|||||||
new_chat_photo = None
|
new_chat_photo = None
|
||||||
|
|
||||||
if isinstance(action, types.MessageActionChatAddUser):
|
if isinstance(action, types.MessageActionChatAddUser):
|
||||||
new_chat_members = [User.parse(client, users[i]) for i in action.users]
|
new_chat_members = [User._parse(client, users[i]) for i in action.users]
|
||||||
elif isinstance(action, types.MessageActionChatJoinedByLink):
|
elif isinstance(action, types.MessageActionChatJoinedByLink):
|
||||||
new_chat_members = [User.parse(client, users[message.from_id])]
|
new_chat_members = [User._parse(client, users[message.from_id])]
|
||||||
elif isinstance(action, types.MessageActionChatDeleteUser):
|
elif isinstance(action, types.MessageActionChatDeleteUser):
|
||||||
left_chat_member = User.parse(client, users[action.user_id])
|
left_chat_member = User._parse(client, users[action.user_id])
|
||||||
elif isinstance(action, types.MessageActionChatEditTitle):
|
elif isinstance(action, types.MessageActionChatEditTitle):
|
||||||
new_chat_title = action.title
|
new_chat_title = action.title
|
||||||
elif isinstance(action, types.MessageActionChatDeletePhoto):
|
elif isinstance(action, types.MessageActionChatDeletePhoto):
|
||||||
@ -373,13 +373,13 @@ class Message(PyrogramType):
|
|||||||
elif isinstance(action, types.MessageActionChannelCreate):
|
elif isinstance(action, types.MessageActionChannelCreate):
|
||||||
channel_chat_created = True
|
channel_chat_created = True
|
||||||
elif isinstance(action, types.MessageActionChatEditPhoto):
|
elif isinstance(action, types.MessageActionChatEditPhoto):
|
||||||
new_chat_photo = Photo.parse(client, action.photo)
|
new_chat_photo = Photo._parse(client, action.photo)
|
||||||
|
|
||||||
parsed_message = Message(
|
parsed_message = Message(
|
||||||
message_id=message.id,
|
message_id=message.id,
|
||||||
date=message.date,
|
date=message.date,
|
||||||
chat=Chat.parse(client, message, users, chats),
|
chat=Chat._parse(client, message, users, chats),
|
||||||
from_user=User.parse(client, users.get(message.from_id, None)),
|
from_user=User._parse(client, users.get(message.from_id, None)),
|
||||||
service=True,
|
service=True,
|
||||||
new_chat_members=new_chat_members,
|
new_chat_members=new_chat_members,
|
||||||
left_chat_member=left_chat_member,
|
left_chat_member=left_chat_member,
|
||||||
@ -407,7 +407,7 @@ class Message(PyrogramType):
|
|||||||
return parsed_message
|
return parsed_message
|
||||||
|
|
||||||
if isinstance(message, types.Message):
|
if isinstance(message, types.Message):
|
||||||
entities = [MessageEntity.parse(client, entity, users) for entity in message.entities]
|
entities = [MessageEntity._parse(client, entity, users) for entity in message.entities]
|
||||||
entities = list(filter(lambda x: x is not None, entities))
|
entities = list(filter(lambda x: x is not None, entities))
|
||||||
|
|
||||||
forward_from = None
|
forward_from = None
|
||||||
@ -422,9 +422,9 @@ class Message(PyrogramType):
|
|||||||
forward_date = forward_header.date
|
forward_date = forward_header.date
|
||||||
|
|
||||||
if forward_header.from_id:
|
if forward_header.from_id:
|
||||||
forward_from = User.parse(client, users[forward_header.from_id])
|
forward_from = User._parse(client, users[forward_header.from_id])
|
||||||
else:
|
else:
|
||||||
forward_from_chat = Chat.parse_channel_chat(client, chats[forward_header.channel_id])
|
forward_from_chat = Chat._parse_channel_chat(client, chats[forward_header.channel_id])
|
||||||
forward_from_message_id = forward_header.channel_post
|
forward_from_message_id = forward_header.channel_post
|
||||||
forward_signature = forward_header.post_author
|
forward_signature = forward_header.post_author
|
||||||
|
|
||||||
@ -445,13 +445,13 @@ class Message(PyrogramType):
|
|||||||
|
|
||||||
if media:
|
if media:
|
||||||
if isinstance(media, types.MessageMediaPhoto):
|
if isinstance(media, types.MessageMediaPhoto):
|
||||||
photo = Photo.parse(client, media.photo)
|
photo = Photo._parse(client, media.photo)
|
||||||
elif isinstance(media, types.MessageMediaGeo):
|
elif isinstance(media, types.MessageMediaGeo):
|
||||||
location = Location.parse(client, media.geo)
|
location = Location._parse(client, media.geo)
|
||||||
elif isinstance(media, types.MessageMediaContact):
|
elif isinstance(media, types.MessageMediaContact):
|
||||||
contact = Contact.parse(client, media)
|
contact = Contact._parse(client, media)
|
||||||
elif isinstance(media, types.MessageMediaVenue):
|
elif isinstance(media, types.MessageMediaVenue):
|
||||||
venue = pyrogram.Venue.parse(client, media)
|
venue = pyrogram.Venue._parse(client, media)
|
||||||
elif isinstance(media, types.MessageMediaDocument):
|
elif isinstance(media, types.MessageMediaDocument):
|
||||||
doc = media.document
|
doc = media.document
|
||||||
|
|
||||||
@ -468,20 +468,20 @@ class Message(PyrogramType):
|
|||||||
audio_attributes = attributes[types.DocumentAttributeAudio]
|
audio_attributes = attributes[types.DocumentAttributeAudio]
|
||||||
|
|
||||||
if audio_attributes.voice:
|
if audio_attributes.voice:
|
||||||
voice = pyrogram.Voice.parse(client, doc, audio_attributes)
|
voice = pyrogram.Voice._parse(client, doc, audio_attributes)
|
||||||
else:
|
else:
|
||||||
audio = pyrogram.Audio.parse(client, doc, audio_attributes, file_name)
|
audio = pyrogram.Audio._parse(client, doc, audio_attributes, file_name)
|
||||||
elif types.DocumentAttributeAnimated in attributes:
|
elif types.DocumentAttributeAnimated in attributes:
|
||||||
video_attributes = attributes.get(types.DocumentAttributeVideo, None)
|
video_attributes = attributes.get(types.DocumentAttributeVideo, None)
|
||||||
|
|
||||||
animation = pyrogram.Animation.parse(client, doc, video_attributes, file_name)
|
animation = pyrogram.Animation._parse(client, doc, video_attributes, file_name)
|
||||||
elif types.DocumentAttributeVideo in attributes:
|
elif types.DocumentAttributeVideo in attributes:
|
||||||
video_attributes = attributes[types.DocumentAttributeVideo]
|
video_attributes = attributes[types.DocumentAttributeVideo]
|
||||||
|
|
||||||
if video_attributes.round_message:
|
if video_attributes.round_message:
|
||||||
video_note = pyrogram.VideoNote.parse(client, doc, video_attributes)
|
video_note = pyrogram.VideoNote._parse(client, doc, video_attributes)
|
||||||
else:
|
else:
|
||||||
video = pyrogram.Video.parse(client, doc, video_attributes, file_name)
|
video = pyrogram.Video._parse(client, doc, video_attributes, file_name)
|
||||||
elif types.DocumentAttributeSticker in attributes:
|
elif types.DocumentAttributeSticker in attributes:
|
||||||
sticker = pyrogram.Sticker.parse(
|
sticker = pyrogram.Sticker.parse(
|
||||||
client, doc,
|
client, doc,
|
||||||
@ -490,7 +490,7 @@ class Message(PyrogramType):
|
|||||||
file_name
|
file_name
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
document = pyrogram.Document.parse(client, doc, file_name)
|
document = pyrogram.Document._parse(client, doc, file_name)
|
||||||
elif isinstance(media, types.MessageMediaWebPage):
|
elif isinstance(media, types.MessageMediaWebPage):
|
||||||
web_page = True
|
web_page = True
|
||||||
media = None
|
media = None
|
||||||
@ -514,8 +514,8 @@ class Message(PyrogramType):
|
|||||||
parsed_message = Message(
|
parsed_message = Message(
|
||||||
message_id=message.id,
|
message_id=message.id,
|
||||||
date=message.date,
|
date=message.date,
|
||||||
chat=Chat.parse(client, message, users, chats),
|
chat=Chat._parse(client, message, users, chats),
|
||||||
from_user=User.parse(client, users.get(message.from_id, None)),
|
from_user=User._parse(client, users.get(message.from_id, None)),
|
||||||
text=Str(message.message).init(client, entities) or None if media is None else None,
|
text=Str(message.message).init(client, entities) or None if media is None else None,
|
||||||
caption=Str(message.message).init(client, entities) or None if media is not None else None,
|
caption=Str(message.message).init(client, entities) or None if media is not None else None,
|
||||||
entities=entities or None if media is None else None,
|
entities=entities or None if media is None else None,
|
||||||
@ -543,7 +543,7 @@ class Message(PyrogramType):
|
|||||||
document=document,
|
document=document,
|
||||||
web_page=web_page,
|
web_page=web_page,
|
||||||
views=message.views,
|
views=message.views,
|
||||||
via_bot=User.parse(client, users.get(message.via_bot_id, None)),
|
via_bot=User._parse(client, users.get(message.via_bot_id, None)),
|
||||||
outgoing=message.out,
|
outgoing=message.out,
|
||||||
reply_markup=reply_markup,
|
reply_markup=reply_markup,
|
||||||
client=client
|
client=client
|
||||||
|
@ -78,7 +78,7 @@ class MessageEntity(PyrogramType):
|
|||||||
self.user = user
|
self.user = user
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, entity, users: dict) -> "MessageEntity" or None:
|
def _parse(client, entity, users: dict) -> "MessageEntity" or None:
|
||||||
type = MessageEntity.ENTITIES.get(entity.ID, None)
|
type = MessageEntity.ENTITIES.get(entity.ID, None)
|
||||||
|
|
||||||
if type is None:
|
if type is None:
|
||||||
@ -89,6 +89,6 @@ class MessageEntity(PyrogramType):
|
|||||||
offset=entity.offset,
|
offset=entity.offset,
|
||||||
length=entity.length,
|
length=entity.length,
|
||||||
url=getattr(entity, "url", None),
|
url=getattr(entity, "url", None),
|
||||||
user=User.parse(client, users.get(getattr(entity, "user_id", None), None)),
|
user=User._parse(client, users.get(getattr(entity, "user_id", None), None)),
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
@ -44,18 +44,18 @@ class Messages(PyrogramType):
|
|||||||
self.messages = messages
|
self.messages = messages
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, messages: types.messages.Messages) -> "Messages":
|
def _parse(client, messages: types.messages.Messages) -> "Messages":
|
||||||
users = {i.id: i for i in messages.users}
|
users = {i.id: i for i in messages.users}
|
||||||
chats = {i.id: i for i in messages.chats}
|
chats = {i.id: i for i in messages.chats}
|
||||||
|
|
||||||
return Messages(
|
return Messages(
|
||||||
total_count=getattr(messages, "count", len(messages.messages)),
|
total_count=getattr(messages, "count", len(messages.messages)),
|
||||||
messages=[Message.parse(client, message, users, chats) for message in messages.messages],
|
messages=[Message._parse(client, message, users, chats) for message in messages.messages],
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_deleted(client, update) -> "Messages":
|
def _parse_deleted(client, update) -> "Messages":
|
||||||
messages = update.messages
|
messages = update.messages
|
||||||
channel_id = getattr(update, "channel_id", None)
|
channel_id = getattr(update, "channel_id", None)
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class Photo(PyrogramType):
|
|||||||
self.sizes = sizes
|
self.sizes = sizes
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, photo: types.Photo):
|
def _parse(client, photo: types.Photo):
|
||||||
if isinstance(photo, types.Photo):
|
if isinstance(photo, types.Photo):
|
||||||
raw_sizes = photo.sizes
|
raw_sizes = photo.sizes
|
||||||
sizes = []
|
sizes = []
|
||||||
|
@ -55,7 +55,7 @@ class PhotoSize(PyrogramType):
|
|||||||
self.file_size = file_size
|
self.file_size = file_size
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, photo_size: types.PhotoSize or types.PhotoCachedSize):
|
def _parse(client, photo_size: types.PhotoSize or types.PhotoCachedSize):
|
||||||
if isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize)):
|
if isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize)):
|
||||||
|
|
||||||
if isinstance(photo_size, types.PhotoSize):
|
if isinstance(photo_size, types.PhotoSize):
|
||||||
|
@ -104,7 +104,7 @@ class Sticker(PyrogramType):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, sticker: types.Document, image_size_attributes: types.DocumentAttributeImageSize,
|
def _parse(client, sticker: types.Document, image_size_attributes: types.DocumentAttributeImageSize,
|
||||||
sticker_attributes: types.DocumentAttributeSticker, file_name: str) -> "Sticker":
|
sticker_attributes: types.DocumentAttributeSticker, file_name: str) -> "Sticker":
|
||||||
sticker_set = sticker_attributes.stickerset
|
sticker_set = sticker_attributes.stickerset
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ class Sticker(PyrogramType):
|
|||||||
),
|
),
|
||||||
width=image_size_attributes.w if image_size_attributes else 0,
|
width=image_size_attributes.w if image_size_attributes else 0,
|
||||||
height=image_size_attributes.h if image_size_attributes else 0,
|
height=image_size_attributes.h if image_size_attributes else 0,
|
||||||
thumb=PhotoSize.parse(client, sticker.thumb),
|
thumb=PhotoSize._parse(client, sticker.thumb),
|
||||||
# TODO: mask_position
|
# TODO: mask_position
|
||||||
set_name=set_name,
|
set_name=set_name,
|
||||||
emoji=sticker_attributes.alt or None,
|
emoji=sticker_attributes.alt or None,
|
||||||
|
@ -42,9 +42,9 @@ class UserProfilePhotos(PyrogramType):
|
|||||||
self.photos = photos
|
self.photos = photos
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, photos) -> "UserProfilePhotos":
|
def _parse(client, photos) -> "UserProfilePhotos":
|
||||||
return UserProfilePhotos(
|
return UserProfilePhotos(
|
||||||
total_count=getattr(photos, "count", len(photos.photos)),
|
total_count=getattr(photos, "count", len(photos.photos)),
|
||||||
photos=[Photo.parse(client, photo) for photo in photos.photos],
|
photos=[Photo._parse(client, photo) for photo in photos.photos],
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
@ -60,9 +60,9 @@ class Venue(PyrogramType):
|
|||||||
self.foursquare_type = foursquare_type
|
self.foursquare_type = foursquare_type
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, venue: types.MessageMediaVenue):
|
def _parse(client, venue: types.MessageMediaVenue):
|
||||||
return Venue(
|
return Venue(
|
||||||
location=Location.parse(client, venue.geo),
|
location=Location._parse(client, venue.geo),
|
||||||
title=venue.title,
|
title=venue.title,
|
||||||
address=venue.address,
|
address=venue.address,
|
||||||
foursquare_id=venue.venue_id or None,
|
foursquare_id=venue.venue_id or None,
|
||||||
|
@ -81,7 +81,7 @@ class Video(PyrogramType):
|
|||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, video: types.Document, video_attributes: types.DocumentAttributeVideo, file_name: str) -> "Video":
|
def _parse(client, video: types.Document, video_attributes: types.DocumentAttributeVideo, file_name: str) -> "Video":
|
||||||
return Video(
|
return Video(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
@ -95,7 +95,7 @@ class Video(PyrogramType):
|
|||||||
width=video_attributes.w,
|
width=video_attributes.w,
|
||||||
height=video_attributes.h,
|
height=video_attributes.h,
|
||||||
duration=video_attributes.duration,
|
duration=video_attributes.duration,
|
||||||
thumb=PhotoSize.parse(client, video.thumb),
|
thumb=PhotoSize._parse(client, video.thumb),
|
||||||
mime_type=video.mime_type,
|
mime_type=video.mime_type,
|
||||||
file_size=video.size,
|
file_size=video.size,
|
||||||
file_name=file_name,
|
file_name=file_name,
|
||||||
|
@ -71,7 +71,7 @@ class VideoNote(PyrogramType):
|
|||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, video_note: types.Document, video_attributes: types.DocumentAttributeVideo) -> "VideoNote":
|
def _parse(client, video_note: types.Document, video_attributes: types.DocumentAttributeVideo) -> "VideoNote":
|
||||||
return VideoNote(
|
return VideoNote(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
@ -84,7 +84,7 @@ class VideoNote(PyrogramType):
|
|||||||
),
|
),
|
||||||
length=video_attributes.w,
|
length=video_attributes.w,
|
||||||
duration=video_attributes.duration,
|
duration=video_attributes.duration,
|
||||||
thumb=PhotoSize.parse(client, video_note.thumb),
|
thumb=PhotoSize._parse(client, video_note.thumb),
|
||||||
file_size=video_note.size,
|
file_size=video_note.size,
|
||||||
mime_type=video_note.mime_type,
|
mime_type=video_note.mime_type,
|
||||||
date=video_note.date,
|
date=video_note.date,
|
||||||
|
@ -65,7 +65,7 @@ class Voice(PyrogramType):
|
|||||||
self.date = date
|
self.date = date
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, voice: types.Document, attributes: types.DocumentAttributeAudio) -> "Voice":
|
def _parse(client, voice: types.Document, attributes: types.DocumentAttributeAudio) -> "Voice":
|
||||||
return Voice(
|
return Voice(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
|
@ -113,20 +113,20 @@ class Chat(PyrogramType):
|
|||||||
self.restriction_reason = restriction_reason
|
self.restriction_reason = restriction_reason
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_user_chat(client, user: types.User) -> "Chat":
|
def _parse_user_chat(client, user: types.User) -> "Chat":
|
||||||
return Chat(
|
return Chat(
|
||||||
id=user.id,
|
id=user.id,
|
||||||
type="private",
|
type="private",
|
||||||
username=user.username,
|
username=user.username,
|
||||||
first_name=user.first_name,
|
first_name=user.first_name,
|
||||||
last_name=user.last_name,
|
last_name=user.last_name,
|
||||||
photo=ChatPhoto.parse(client, user.photo),
|
photo=ChatPhoto._parse(client, user.photo),
|
||||||
restriction_reason=user.restriction_reason,
|
restriction_reason=user.restriction_reason,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_chat_chat(client, chat: types.Chat) -> "Chat":
|
def _parse_chat_chat(client, chat: types.Chat) -> "Chat":
|
||||||
admins_enabled = getattr(chat, "admins_enabled", None)
|
admins_enabled = getattr(chat, "admins_enabled", None)
|
||||||
|
|
||||||
if admins_enabled is not None:
|
if admins_enabled is not None:
|
||||||
@ -137,45 +137,45 @@ class Chat(PyrogramType):
|
|||||||
type="group",
|
type="group",
|
||||||
title=chat.title,
|
title=chat.title,
|
||||||
all_members_are_administrators=admins_enabled,
|
all_members_are_administrators=admins_enabled,
|
||||||
photo=ChatPhoto.parse(client, getattr(chat, "photo", None)),
|
photo=ChatPhoto._parse(client, getattr(chat, "photo", None)),
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_channel_chat(client, channel: types.Channel) -> "Chat":
|
def _parse_channel_chat(client, channel: types.Channel) -> "Chat":
|
||||||
return Chat(
|
return Chat(
|
||||||
id=int("-100" + str(channel.id)),
|
id=int("-100" + str(channel.id)),
|
||||||
type="supergroup" if channel.megagroup else "channel",
|
type="supergroup" if channel.megagroup else "channel",
|
||||||
title=channel.title,
|
title=channel.title,
|
||||||
username=getattr(channel, "username", None),
|
username=getattr(channel, "username", None),
|
||||||
photo=ChatPhoto.parse(client, getattr(channel, "photo", None)),
|
photo=ChatPhoto._parse(client, getattr(channel, "photo", None)),
|
||||||
restriction_reason=getattr(channel, "restriction_reason", None),
|
restriction_reason=getattr(channel, "restriction_reason", None),
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, message: types.Message or types.MessageService, users: dict, chats: dict) -> "Chat":
|
def _parse(client, message: types.Message or types.MessageService, users: dict, chats: dict) -> "Chat":
|
||||||
if isinstance(message.to_id, types.PeerUser):
|
if isinstance(message.to_id, types.PeerUser):
|
||||||
return Chat.parse_user_chat(client, users[message.to_id.user_id if message.out else message.from_id])
|
return Chat._parse_user_chat(client, users[message.to_id.user_id if message.out else message.from_id])
|
||||||
|
|
||||||
if isinstance(message.to_id, types.PeerChat):
|
if isinstance(message.to_id, types.PeerChat):
|
||||||
return Chat.parse_chat_chat(client, chats[message.to_id.chat_id])
|
return Chat._parse_chat_chat(client, chats[message.to_id.chat_id])
|
||||||
|
|
||||||
return Chat.parse_channel_chat(client, chats[message.to_id.channel_id])
|
return Chat._parse_channel_chat(client, chats[message.to_id.channel_id])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_dialog(client, peer, users: dict, chats: dict):
|
def _parse_dialog(client, peer, users: dict, chats: dict):
|
||||||
if isinstance(peer, types.PeerUser):
|
if isinstance(peer, types.PeerUser):
|
||||||
return Chat.parse_user_chat(client, users[peer.user_id])
|
return Chat._parse_user_chat(client, users[peer.user_id])
|
||||||
elif isinstance(peer, types.PeerChat):
|
elif isinstance(peer, types.PeerChat):
|
||||||
return Chat.parse_chat_chat(client, chats[peer.chat_id])
|
return Chat._parse_chat_chat(client, chats[peer.chat_id])
|
||||||
else:
|
else:
|
||||||
return Chat.parse_channel_chat(client, chats[peer.channel_id])
|
return Chat._parse_channel_chat(client, chats[peer.channel_id])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_full(client, chat_full: types.messages.ChatFull or types.UserFull) -> "Chat":
|
def _parse_full(client, chat_full: types.messages.ChatFull or types.UserFull) -> "Chat":
|
||||||
if isinstance(chat_full, types.UserFull):
|
if isinstance(chat_full, types.UserFull):
|
||||||
parsed_chat = Chat.parse_user_chat(client, chat_full.user)
|
_parsed_chat = Chat.parse_user_chat(client, chat_full.user)
|
||||||
parsed_chat.description = chat_full.about
|
parsed_chat.description = chat_full.about
|
||||||
else:
|
else:
|
||||||
full_chat = chat_full.full_chat
|
full_chat = chat_full.full_chat
|
||||||
@ -186,12 +186,12 @@ class Chat(PyrogramType):
|
|||||||
chat = i
|
chat = i
|
||||||
|
|
||||||
if isinstance(full_chat, types.ChatFull):
|
if isinstance(full_chat, types.ChatFull):
|
||||||
parsed_chat = Chat.parse_chat_chat(client, chat)
|
_parsed_chat = Chat.parse_chat_chat(client, chat)
|
||||||
|
|
||||||
if isinstance(full_chat.participants, types.ChatParticipants):
|
if isinstance(full_chat.participants, types.ChatParticipants):
|
||||||
parsed_chat.members_count = len(full_chat.participants.participants)
|
parsed_chat.members_count = len(full_chat.participants.participants)
|
||||||
else:
|
else:
|
||||||
parsed_chat = Chat.parse_channel_chat(client, chat)
|
_parsed_chat = Chat.parse_channel_chat(client, chat)
|
||||||
parsed_chat.members_count = full_chat.participants_count
|
parsed_chat.members_count = full_chat.participants_count
|
||||||
parsed_chat.description = full_chat.about or None
|
parsed_chat.description = full_chat.about or None
|
||||||
# TODO: Add StickerSet type
|
# TODO: Add StickerSet type
|
||||||
|
@ -118,7 +118,7 @@ class ChatMember(PyrogramType):
|
|||||||
self.can_add_web_page_previews = can_add_web_page_previews
|
self.can_add_web_page_previews = can_add_web_page_previews
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, member, user) -> "ChatMember":
|
def _parse(client, member, user) -> "ChatMember":
|
||||||
if isinstance(member, (types.ChannelParticipant, types.ChannelParticipantSelf, types.ChatParticipant)):
|
if isinstance(member, (types.ChannelParticipant, types.ChannelParticipantSelf, types.ChatParticipant)):
|
||||||
return ChatMember(user=user, status="member", client=client)
|
return ChatMember(user=user, status="member", client=client)
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class ChatMembers(PyrogramType):
|
|||||||
self.chat_members = chat_members
|
self.chat_members = chat_members
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, members):
|
def _parse(client, members):
|
||||||
users = {i.id: i for i in members.users}
|
users = {i.id: i for i in members.users}
|
||||||
chat_members = []
|
chat_members = []
|
||||||
|
|
||||||
@ -56,8 +56,8 @@ class ChatMembers(PyrogramType):
|
|||||||
total_count = len(members)
|
total_count = len(members)
|
||||||
|
|
||||||
for member in members:
|
for member in members:
|
||||||
user = User.parse(client, users[member.user_id])
|
user = User._parse(client, users[member.user_id])
|
||||||
chat_members.append(ChatMember.parse(client, member, user))
|
chat_members.append(ChatMember._parse(client, member, user))
|
||||||
|
|
||||||
return ChatMembers(
|
return ChatMembers(
|
||||||
total_count=total_count,
|
total_count=total_count,
|
||||||
|
@ -45,7 +45,7 @@ class ChatPhoto(PyrogramType):
|
|||||||
self.big_file_id = big_file_id
|
self.big_file_id = big_file_id
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, chat_photo: types.UserProfilePhoto or types.ChatPhoto):
|
def _parse(client, chat_photo: types.UserProfilePhoto or types.ChatPhoto):
|
||||||
if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)):
|
if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class Dialog(PyrogramType):
|
|||||||
self.is_pinned = is_pinned
|
self.is_pinned = is_pinned
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, dialog, messages, users, chats) -> "Dialog":
|
def _parse(client, dialog, messages, users, chats) -> "Dialog":
|
||||||
chat_id = dialog.peer
|
chat_id = dialog.peer
|
||||||
|
|
||||||
if isinstance(chat_id, types.PeerUser):
|
if isinstance(chat_id, types.PeerUser):
|
||||||
@ -74,7 +74,7 @@ class Dialog(PyrogramType):
|
|||||||
chat_id = int("-100" + str(chat_id.channel_id))
|
chat_id = int("-100" + str(chat_id.channel_id))
|
||||||
|
|
||||||
return Dialog(
|
return Dialog(
|
||||||
chat=Chat.parse_dialog(client, dialog.peer, users, chats),
|
chat=Chat._parse_dialog(client, dialog.peer, users, chats),
|
||||||
top_message=messages.get(chat_id),
|
top_message=messages.get(chat_id),
|
||||||
unread_messages_count=dialog.unread_count,
|
unread_messages_count=dialog.unread_count,
|
||||||
unread_mentions_count=dialog.unread_mentions_count,
|
unread_mentions_count=dialog.unread_mentions_count,
|
||||||
|
@ -44,7 +44,7 @@ class Dialogs(PyrogramType):
|
|||||||
self.dialogs = dialogs
|
self.dialogs = dialogs
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, dialogs) -> "Dialogs":
|
def _parse(client, dialogs) -> "Dialogs":
|
||||||
users = {i.id: i for i in dialogs.users}
|
users = {i.id: i for i in dialogs.users}
|
||||||
chats = {i.id: i for i in dialogs.chats}
|
chats = {i.id: i for i in dialogs.chats}
|
||||||
|
|
||||||
@ -63,10 +63,10 @@ class Dialogs(PyrogramType):
|
|||||||
else:
|
else:
|
||||||
chat_id = int("-100" + str(to_id.channel_id))
|
chat_id = int("-100" + str(to_id.channel_id))
|
||||||
|
|
||||||
messages[chat_id] = Message.parse(client, message, users, chats)
|
messages[chat_id] = Message._parse(client, message, users, chats)
|
||||||
|
|
||||||
return Dialogs(
|
return Dialogs(
|
||||||
total_count=getattr(dialogs, "count", len(dialogs.dialogs)),
|
total_count=getattr(dialogs, "count", len(dialogs.dialogs)),
|
||||||
dialogs=[Dialog.parse(client, dialog, messages, users, chats) for dialog in dialogs.dialogs],
|
dialogs=[Dialog._parse(client, dialog, messages, users, chats) for dialog in dialogs.dialogs],
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
@ -104,7 +104,7 @@ class User(PyrogramType):
|
|||||||
self.restriction_reason = restriction_reason
|
self.restriction_reason = restriction_reason
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, user: types.User) -> "User" or None:
|
def _parse(client, user: types.User) -> "User" or None:
|
||||||
if user is None:
|
if user is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -117,11 +117,11 @@ class User(PyrogramType):
|
|||||||
is_bot=user.bot,
|
is_bot=user.bot,
|
||||||
first_name=user.first_name,
|
first_name=user.first_name,
|
||||||
last_name=user.last_name,
|
last_name=user.last_name,
|
||||||
status=UserStatus.parse(client, user.status, user.id, user.bot),
|
status=UserStatus._parse(client, user.status, user.id, user.bot),
|
||||||
username=user.username,
|
username=user.username,
|
||||||
language_code=user.lang_code,
|
language_code=user.lang_code,
|
||||||
phone_number=user.phone,
|
phone_number=user.phone,
|
||||||
photo=ChatPhoto.parse(client, user.photo),
|
photo=ChatPhoto._parse(client, user.photo),
|
||||||
restriction_reason=user.restriction_reason,
|
restriction_reason=user.restriction_reason,
|
||||||
client=client
|
client=client
|
||||||
)
|
)
|
||||||
|
@ -85,7 +85,7 @@ class UserStatus(PyrogramType):
|
|||||||
self.long_time_ago = long_time_ago
|
self.long_time_ago = long_time_ago
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse(client, user_status, user_id: int, is_bot: bool = False):
|
def _parse(client, user_status, user_id: int, is_bot: bool = False):
|
||||||
if is_bot:
|
if is_bot:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user