2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Ditch raw attribute. There's no use for it now

This commit is contained in:
Dan 2018-12-18 08:48:20 +01:00
parent 761a07bda8
commit dc2792fbea
32 changed files with 122 additions and 152 deletions

View File

@ -56,9 +56,9 @@ class CallbackQuery(PyrogramType):
""" """
def __init__(self, *, client, raw, id: str, from_user, chat_instance: str, message=None, def __init__(self, *, client, id: str, from_user, chat_instance: str, message=None,
inline_message_id: str = None, data: bytes = None, game_short_name: str = None): inline_message_id: str = None, data: bytes = None, game_short_name: str = None):
super().__init__(client, raw) super().__init__(client)
self.id = id self.id = id
self.from_user = from_user self.from_user = from_user
@ -103,8 +103,7 @@ class CallbackQuery(PyrogramType):
chat_instance=str(callback_query.chat_instance), chat_instance=str(callback_query.chat_instance),
data=callback_query.data, data=callback_query.data,
game_short_name=callback_query.game_short_name, game_short_name=callback_query.game_short_name,
client=client, client=client
raw=callback_query
) )
def answer(self, text: str = None, show_alert: bool = None, url: str = None, cache_time: int = 0): def answer(self, text: str = None, show_alert: bool = None, url: str = None, cache_time: int = 0):

View File

@ -34,12 +34,12 @@ class ForceReply(PyrogramType):
""" """
def __init__(self, selective: bool = None): def __init__(self, selective: bool = None):
super().__init__(None, None) super().__init__(None)
self.selective = selective self.selective = selective
@staticmethod @staticmethod
def read(o, *args): def read(o):
return ForceReply( return ForceReply(
selective=o.selective selective=o.selective
) )

View File

@ -55,7 +55,7 @@ class InlineKeyboardButton(PyrogramType):
def __init__(self, text: str, callback_data: bytes = None, url: str = None, def __init__(self, text: str, callback_data: bytes = None, url: str = None,
switch_inline_query: str = None, switch_inline_query_current_chat: str = None): switch_inline_query: str = None, switch_inline_query_current_chat: str = None):
super().__init__(None, None) super().__init__(None)
self.text = text self.text = text
self.url = url self.url = url
@ -66,29 +66,29 @@ class InlineKeyboardButton(PyrogramType):
# self.pay = pay # self.pay = pay
@staticmethod @staticmethod
def read(b, *args): def read(o):
if isinstance(b, KeyboardButtonUrl): if isinstance(o, KeyboardButtonUrl):
return InlineKeyboardButton( return InlineKeyboardButton(
text=b.text, text=o.text,
url=b.url url=o.url
) )
if isinstance(b, KeyboardButtonCallback): if isinstance(o, KeyboardButtonCallback):
return InlineKeyboardButton( return InlineKeyboardButton(
text=b.text, text=o.text,
callback_data=b.data callback_data=o.data
) )
if isinstance(b, KeyboardButtonSwitchInline): if isinstance(o, KeyboardButtonSwitchInline):
if b.same_peer: if o.same_peer:
return InlineKeyboardButton( return InlineKeyboardButton(
text=b.text, text=o.text,
switch_inline_query_current_chat=b.query switch_inline_query_current_chat=o.query
) )
else: else:
return InlineKeyboardButton( return InlineKeyboardButton(
text=b.text, text=o.text,
switch_inline_query=b.query switch_inline_query=o.query
) )
def write(self): def write(self):

View File

@ -30,15 +30,15 @@ class InlineKeyboardMarkup(PyrogramType):
""" """
def __init__(self, inline_keyboard: list): def __init__(self, inline_keyboard: list):
super().__init__(None, None) super().__init__(None)
self.inline_keyboard = inline_keyboard self.inline_keyboard = inline_keyboard
@staticmethod @staticmethod
def read(kb, *args): def read(o):
inline_keyboard = [] inline_keyboard = []
for i in kb.rows: for i in o.rows:
row = [] row = []
for j in i.buttons: for j in i.buttons:

View File

@ -41,26 +41,26 @@ class KeyboardButton(PyrogramType):
""" """
def __init__(self, text: str, request_contact: bool = None, request_location: bool = None): def __init__(self, text: str, request_contact: bool = None, request_location: bool = None):
super().__init__(None, None) super().__init__(None)
self.text = text self.text = text
self.request_contact = request_contact self.request_contact = request_contact
self.request_location = request_location self.request_location = request_location
@staticmethod @staticmethod
def read(b, *args): def read(o):
if isinstance(b, RawKeyboardButton): if isinstance(o, RawKeyboardButton):
return b.text return o.text
if isinstance(b, KeyboardButtonRequestPhone): if isinstance(o, KeyboardButtonRequestPhone):
return KeyboardButton( return KeyboardButton(
text=b.text, text=o.text,
request_contact=True request_contact=True
) )
if isinstance(b, KeyboardButtonRequestGeoLocation): if isinstance(o, KeyboardButtonRequestGeoLocation):
return KeyboardButton( return KeyboardButton(
text=b.text, text=o.text,
request_location=True request_location=True
) )

View File

@ -49,7 +49,7 @@ class ReplyKeyboardMarkup(PyrogramType):
def __init__(self, keyboard: list, resize_keyboard: bool = None, one_time_keyboard: bool = None, def __init__(self, keyboard: list, resize_keyboard: bool = None, one_time_keyboard: bool = None,
selective: bool = None): selective: bool = None):
super().__init__(None, None) super().__init__(None)
self.keyboard = keyboard self.keyboard = keyboard
self.resize_keyboard = resize_keyboard self.resize_keyboard = resize_keyboard
@ -57,7 +57,7 @@ class ReplyKeyboardMarkup(PyrogramType):
self.selective = selective self.selective = selective
@staticmethod @staticmethod
def read(kb, *args): def read(kb):
keyboard = [] keyboard = []
for i in kb.rows: for i in kb.rows:

View File

@ -36,12 +36,12 @@ class ReplyKeyboardRemove(PyrogramType):
""" """
def __init__(self, selective: bool = None): def __init__(self, selective: bool = None):
super().__init__(None, None) super().__init__(None)
self.selective = selective self.selective = selective
@staticmethod @staticmethod
def read(o, *args): def read(o):
return ReplyKeyboardRemove( return ReplyKeyboardRemove(
selective=o.selective selective=o.selective
) )

View File

@ -56,9 +56,9 @@ class Animation(PyrogramType):
Date the animation was sent in Unix time. Date the animation was sent in Unix time.
""" """
def __init__(self, *, client, raw, file_id: str, width: int, height: int, duration: int, thumb=None, def __init__(self, *, client, 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): file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.thumb = thumb self.thumb = thumb
@ -91,6 +91,5 @@ class Animation(PyrogramType):
file_size=animation.size, file_size=animation.size,
file_name=file_name, file_name=file_name,
date=animation.date, date=animation.date,
client=client, client=client
raw=animation
) )

View File

@ -56,10 +56,10 @@ class Audio(PyrogramType):
Title of the audio as defined by sender or by audio tags. Title of the audio as defined by sender or by audio tags.
""" """
def __init__(self, *, client, raw, file_id: str, duration: int, thumb=None, file_name: str = None, def __init__(self, *, client, 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, mime_type: str = None, file_size: int = None, date: int = None, performer: str = None,
title: str = None): title: str = None):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.thumb = thumb self.thumb = thumb
@ -91,6 +91,5 @@ class Audio(PyrogramType):
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
raw=audio
) )

View File

@ -40,9 +40,9 @@ class Contact(PyrogramType):
Additional data about the contact in the form of a vCard. Additional data about the contact in the form of a vCard.
""" """
def __init__(self, *, client, raw, phone_number: str, first_name: str, last_name: str = None, user_id: int = None, def __init__(self, *, client, phone_number: str, first_name: str, last_name: str = None, user_id: int = None,
vcard: str = None): vcard: str = None):
super().__init__(client, raw) super().__init__(client)
self.phone_number = phone_number self.phone_number = phone_number
self.first_name = first_name self.first_name = first_name
@ -58,6 +58,5 @@ class Contact(PyrogramType):
last_name=contact.last_name or None, last_name=contact.last_name or None,
vcard=contact.vcard or None, vcard=contact.vcard or None,
user_id=contact.user_id or None, user_id=contact.user_id or None,
client=client, client=client
raw=contact
) )

View File

@ -47,9 +47,9 @@ class Document(PyrogramType):
Date the document was sent in Unix time. Date the document was sent in Unix time.
""" """
def __init__(self, *, client, raw, file_id: str, thumb=None, file_name: str = None, mime_type: str = None, def __init__(self, *, client, file_id: str, thumb=None, file_name: str = None, mime_type: str = None,
file_size: int = None, date: int = None): file_size: int = None, date: int = None):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.thumb = thumb self.thumb = thumb
@ -75,6 +75,5 @@ class Document(PyrogramType):
mime_type=document.mime_type, mime_type=document.mime_type,
file_size=document.size, file_size=document.size,
date=document.date, date=document.date,
client=client, client=client
raw=document
) )

View File

@ -31,8 +31,8 @@ class Location(PyrogramType):
Latitude as defined by sender. Latitude as defined by sender.
""" """
def __init__(self, *, client, raw, longitude: float, latitude: float, ): def __init__(self, *, client, longitude: float, latitude: float, ):
super().__init__(client, raw) super().__init__(client)
self.longitude = longitude self.longitude = longitude
self.latitude = latitude self.latitude = latitude
@ -43,6 +43,5 @@ class Location(PyrogramType):
return Location( return Location(
longitude=geo_point.long, longitude=geo_point.long,
latitude=geo_point.lat, latitude=geo_point.lat,
client=client, client=client
raw=geo_point
) )

View File

@ -224,7 +224,7 @@ class Message(PyrogramType):
# TODO: Add game missing field. Also invoice, successful_payment, connected_website # TODO: Add game missing field. Also invoice, successful_payment, connected_website
def __init__(self, *, client, raw, message_id: int, date: int = None, chat=None, from_user=None, forward_from=None, def __init__(self, *, client, message_id: int, date: int = None, chat=None, from_user=None, forward_from=None,
forward_from_chat=None, forward_from_message_id: int = None, forward_signature: str = None, forward_from_chat=None, forward_from_message_id: int = None, forward_signature: str = None,
forward_date: int = None, reply_to_message=None, mentioned=None, empty=None, service=None, media=None, forward_date: int = None, reply_to_message=None, mentioned=None, empty=None, service=None, media=None,
edit_date: int = None, media_group_id: str = None, author_signature: str = None, text: str = None, edit_date: int = None, media_group_id: str = None, author_signature: str = None, text: str = None,
@ -236,7 +236,7 @@ class Message(PyrogramType):
channel_chat_created: bool = None, migrate_to_chat_id: int = None, migrate_from_chat_id: int = None, channel_chat_created: bool = None, migrate_to_chat_id: int = None, migrate_from_chat_id: int = None,
pinned_message=None, views: int = None, via_bot=None, outgoing: bool = None, matches: list = None, pinned_message=None, views: int = None, via_bot=None, outgoing: bool = None, matches: list = None,
command: list = None, reply_markup=None): command: list = None, reply_markup=None):
super().__init__(client, raw) super().__init__(client)
self.message_id = message_id self.message_id = message_id
self.date = date self.date = date
@ -293,11 +293,7 @@ class Message(PyrogramType):
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( return Message(message_id=message.id, empty=True, client=client)
message_id=message.id,
client=client,
raw=message
)
if isinstance(message, types.MessageService): if isinstance(message, types.MessageService):
action = message.action action = message.action
@ -348,8 +344,7 @@ class Message(PyrogramType):
migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None, migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None,
group_chat_created=group_chat_created, group_chat_created=group_chat_created,
channel_chat_created=channel_chat_created, channel_chat_created=channel_chat_created,
client=client, client=client
raw=message
# TODO: supergroup_chat_created # TODO: supergroup_chat_created
) )
@ -504,8 +499,7 @@ class Message(PyrogramType):
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
raw=message
) )
if message.reply_to_msg_id and replies: if message.reply_to_msg_id and replies:

View File

@ -61,8 +61,8 @@ class MessageEntity(PyrogramType):
types.MessageEntityPhone.ID: "phone_number" types.MessageEntityPhone.ID: "phone_number"
} }
def __init__(self, *, client, raw, type: str, offset: int, length: int, url: str = None, user=None): def __init__(self, *, client, type: str, offset: int, length: int, url: str = None, user=None):
super().__init__(client, raw) super().__init__(client)
self.type = type self.type = type
self.offset = offset self.offset = offset
@ -83,6 +83,5 @@ class MessageEntity(PyrogramType):
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
raw=entity
) )

View File

@ -33,8 +33,8 @@ class Messages(PyrogramType):
Requested messages. Requested messages.
""" """
def __init__(self, *, client, raw, total_count: int, messages: list): def __init__(self, *, client, total_count: int, messages: list):
super().__init__(client, raw) super().__init__(client)
self.total_count = total_count self.total_count = total_count
self.messages = messages self.messages = messages
@ -47,8 +47,7 @@ class Messages(PyrogramType):
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
raw=messages
) )
@staticmethod @staticmethod
@ -65,17 +64,14 @@ class Messages(PyrogramType):
chat=Chat( chat=Chat(
id=int("-100" + str(channel_id)), id=int("-100" + str(channel_id)),
type="channel", type="channel",
client=client, client=client
raw=None
) if channel_id is not None else None, ) if channel_id is not None else None,
client=client, client=client
raw=None
) )
) )
return Messages( return Messages(
total_count=len(parsed_messages), total_count=len(parsed_messages),
messages=parsed_messages, messages=parsed_messages,
client=client, client=client
raw=update
) )

View File

@ -39,8 +39,8 @@ class Photo(PyrogramType):
Available sizes of this photo. Available sizes of this photo.
""" """
def __init__(self, *, client, raw, id: str, date: int, sizes: list): def __init__(self, *, client, id: str, date: int, sizes: list):
super().__init__(client, raw) super().__init__(client)
self.id = id self.id = id
self.date = date self.date = date
@ -74,8 +74,7 @@ class Photo(PyrogramType):
width=raw_size.w, width=raw_size.w,
height=raw_size.h, height=raw_size.h,
file_size=file_size, file_size=file_size,
client=client, client=client
raw=raw_size
) )
sizes.append(size) sizes.append(size)
@ -91,6 +90,5 @@ class Photo(PyrogramType):
).decode().rstrip("="), ).decode().rstrip("="),
date=photo.date, date=photo.date,
sizes=sizes, sizes=sizes,
client=client, client=client
raw=photo
) )

View File

@ -40,8 +40,8 @@ class PhotoSize(PyrogramType):
File size. File size.
""" """
def __init__(self, *, client, raw, file_id: str, width: int, height: int, file_size: int): def __init__(self, *, client, file_id: str, width: int, height: int, file_size: int):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.width = width self.width = width
@ -71,6 +71,5 @@ class PhotoSize(PyrogramType):
width=photo_size.w, width=photo_size.w,
height=photo_size.h, height=photo_size.h,
file_size=file_size, file_size=file_size,
client=client, client=client
raw=photo_size
) )

View File

@ -63,10 +63,10 @@ class Sticker(PyrogramType):
# TODO: Add mask position # TODO: Add mask position
def __init__(self, *, client, raw, file_id: str, width: int, height: int, thumb=None, file_name: str = None, def __init__(self, *, client, 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, mime_type: str = None, file_size: int = None, date: int = None, emoji: str = None,
set_name: str = None, mask_position=None): set_name: str = None, mask_position=None):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.thumb = thumb self.thumb = thumb
@ -123,6 +123,5 @@ class Sticker(PyrogramType):
mime_type=sticker.mime_type, mime_type=sticker.mime_type,
file_name=file_name, file_name=file_name,
date=sticker.date, date=sticker.date,
client=client, client=client
raw=sticker
) )

View File

@ -31,8 +31,8 @@ class UserProfilePhotos(PyrogramType):
Requested profile pictures. Requested profile pictures.
""" """
def __init__(self, *, client, raw, total_count: int, photos: list): def __init__(self, *, client, total_count: int, photos: list):
super().__init__(client, raw) super().__init__(client)
self.total_count = total_count self.total_count = total_count
self.photos = photos self.photos = photos
@ -42,6 +42,5 @@ class UserProfilePhotos(PyrogramType):
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
raw=photos
) )

View File

@ -43,9 +43,9 @@ class Venue(PyrogramType):
""" """
def __init__(self, *, client, raw, location, title: str, address: str, foursquare_id: str = None, def __init__(self, *, client, location, title: str, address: str, foursquare_id: str = None,
foursquare_type: str = None): foursquare_type: str = None):
super().__init__(client, raw) super().__init__(client)
self.location = location self.location = location
self.title = title self.title = title
@ -61,6 +61,5 @@ class Venue(PyrogramType):
address=venue.address, address=venue.address,
foursquare_id=venue.venue_id or None, foursquare_id=venue.venue_id or None,
foursquare_type=venue.venue_type, foursquare_type=venue.venue_type,
client=client, client=client
raw=venue
) )

View File

@ -56,9 +56,9 @@ class Video(PyrogramType):
Date the video was sent in Unix time. Date the video was sent in Unix time.
""" """
def __init__(self, *, client, raw, file_id: str, width: int, height: int, duration: int, thumb=None, def __init__(self, *, client, 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): file_name: str = None, mime_type: str = None, file_size: int = None, date: int = None):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.thumb = thumb self.thumb = thumb
@ -90,6 +90,5 @@ class Video(PyrogramType):
file_size=video.size, file_size=video.size,
file_name=file_name, file_name=file_name,
date=video.date, date=video.date,
client=client, client=client
raw=video
) )

View File

@ -50,9 +50,9 @@ class VideoNote(PyrogramType):
Date the video note was sent in Unix time. Date the video note was sent in Unix time.
""" """
def __init__(self, *, client, raw, file_id: str, length: int, duration: int, thumb=None, mime_type: str = None, def __init__(self, *, client, file_id: str, length: int, duration: int, thumb=None, mime_type: str = None,
file_size: int = None, date: int = None): file_size: int = None, date: int = None):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.thumb = thumb self.thumb = thumb
@ -79,5 +79,6 @@ class VideoNote(PyrogramType):
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,
client=client
) )

View File

@ -46,9 +46,9 @@ class Voice(PyrogramType):
Date the voice was sent in Unix time. Date the voice was sent in Unix time.
""" """
def __init__(self, *, client, raw, file_id: str, duration: int, waveform: bytes = None, mime_type: str = None, def __init__(self, *, client, file_id: str, duration: int, waveform: bytes = None, mime_type: str = None,
file_size: int = None, date: int = None): file_size: int = None, date: int = None):
super().__init__(client, raw) super().__init__(client)
self.file_id = file_id self.file_id = file_id
self.duration = duration self.duration = duration
@ -74,6 +74,5 @@ class Voice(PyrogramType):
file_size=voice.size, file_size=voice.size,
waveform=attributes.waveform, waveform=attributes.waveform,
date=voice.date, date=voice.date,
client=client, client=client
raw=voice
) )

View File

@ -21,9 +21,8 @@ from json import dumps, JSONEncoder
class PyrogramType: class PyrogramType:
def __init__(self, client, raw): def __init__(self, client):
self._client = client self._client = client
self._raw = raw
def __str__(self): def __str__(self):
return dumps(self, cls=Encoder, indent=4) return dumps(self, cls=Encoder, indent=4)

View File

@ -76,11 +76,11 @@ class Chat(PyrogramType):
The reason why this chat might be unavailable to some users. The reason why this chat might be unavailable to some users.
""" """
def __init__(self, *, client, raw, id: int, type: str, title: str = None, username: str = None, def __init__(self, *, client, 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, first_name: str = None, last_name: str = None, all_members_are_administrators: bool = None, photo=None,
description: str = None, invite_link: str = None, pinned_message=None, sticker_set_name: str = None, description: str = None, invite_link: str = None, pinned_message=None, sticker_set_name: str = None,
can_set_sticker_set: bool = None, members_count: int = None, restriction_reason: str = None): can_set_sticker_set: bool = None, members_count: int = None, restriction_reason: str = None):
super().__init__(client, raw) super().__init__(client)
self.id = id self.id = id
self.type = type self.type = type
@ -108,7 +108,7 @@ class Chat(PyrogramType):
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, raw=user client=client
) )
@staticmethod @staticmethod
@ -124,7 +124,7 @@ class Chat(PyrogramType):
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, raw=chat client=client
) )
@staticmethod @staticmethod
@ -136,7 +136,7 @@ class Chat(PyrogramType):
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, raw=channel client=client
) )
@staticmethod @staticmethod

View File

@ -79,13 +79,13 @@ class ChatMember(PyrogramType):
Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages.
""" """
def __init__(self, *, client, raw, user, status: str, until_date: int = None, can_be_edited: bool = None, def __init__(self, *, client, user, status: str, until_date: int = None, can_be_edited: bool = None,
can_change_info: bool = None, can_post_messages: bool = None, can_edit_messages: bool = None, can_change_info: bool = None, can_post_messages: bool = None, can_edit_messages: bool = None,
can_delete_messages: bool = None, can_invite_users: bool = None, can_restrict_members: bool = None, can_delete_messages: bool = None, can_invite_users: bool = None, can_restrict_members: bool = None,
can_pin_messages: bool = None, can_promote_members: bool = None, can_send_messages: bool = None, can_pin_messages: bool = None, can_promote_members: bool = None, can_send_messages: bool = None,
can_send_media_messages: bool = None, can_send_other_messages: bool = None, can_send_media_messages: bool = None, can_send_other_messages: bool = None,
can_add_web_page_previews: bool = None): can_add_web_page_previews: bool = None):
super().__init__(client, raw) super().__init__(client)
self.user = user self.user = user
self.status = status self.status = status
@ -107,13 +107,13 @@ class ChatMember(PyrogramType):
@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, raw=member) return ChatMember(user=user, status="member", client=client)
if isinstance(member, (types.ChannelParticipantCreator, types.ChatParticipantCreator)): if isinstance(member, (types.ChannelParticipantCreator, types.ChatParticipantCreator)):
return ChatMember(user=user, status="creator", client=client, raw=member) return ChatMember(user=user, status="creator", client=client)
if isinstance(member, types.ChatParticipantAdmin): if isinstance(member, types.ChatParticipantAdmin):
return ChatMember(user=user, status="administrator", client=client, raw=member) return ChatMember(user=user, status="administrator", client=client)
if isinstance(member, types.ChannelParticipantAdmin): if isinstance(member, types.ChannelParticipantAdmin):
rights = member.admin_rights rights = member.admin_rights
@ -130,7 +130,7 @@ class ChatMember(PyrogramType):
can_restrict_members=rights.ban_users, can_restrict_members=rights.ban_users,
can_pin_messages=rights.pin_messages, can_pin_messages=rights.pin_messages,
can_promote_members=rights.add_admins, can_promote_members=rights.add_admins,
client=client, raw=member client=client
) )
if isinstance(member, types.ChannelParticipantBanned): if isinstance(member, types.ChannelParticipantBanned):
@ -140,7 +140,7 @@ class ChatMember(PyrogramType):
user=user, user=user,
status="kicked" if rights.view_messages else "restricted", status="kicked" if rights.view_messages else "restricted",
until_date=0 if rights.until_date == (1 << 31) - 1 else rights.until_date, until_date=0 if rights.until_date == (1 << 31) - 1 else rights.until_date,
client=client, raw=member client=client
) )
if chat_member.status == "restricted": if chat_member.status == "restricted":

View File

@ -33,8 +33,8 @@ class ChatMembers(PyrogramType):
Requested chat members. Requested chat members.
""" """
def __init__(self, *, client, raw, total_count: int, chat_members: list): def __init__(self, *, client, total_count: int, chat_members: list):
super().__init__(client, raw) super().__init__(client)
self.total_count = total_count self.total_count = total_count
self.chat_members = chat_members self.chat_members = chat_members
@ -58,6 +58,5 @@ class ChatMembers(PyrogramType):
return ChatMembers( return ChatMembers(
total_count=total_count, total_count=total_count,
chat_members=chat_members, chat_members=chat_members,
client=client, client=client
raw=members
) )

View File

@ -19,11 +19,11 @@
from struct import pack from struct import pack
from pyrogram.api import types from pyrogram.api import types
from pyrogram.api.core import Object from ..pyrogram_type import PyrogramType
from ...ext.utils import encode from ...ext.utils import encode
class ChatPhoto(Object): class ChatPhoto(PyrogramType):
"""This object represents a chat photo. """This object represents a chat photo.
Args: Args:
@ -34,9 +34,9 @@ class ChatPhoto(Object):
Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download. Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download.
""" """
ID = 0xb0700015 def __init__(self, *, client, small_file_id: str, big_file_id: str):
super().__init__(client)
def __init__(self, *, client, raw, small_file_id: str, big_file_id: str):
self.small_file_id = small_file_id self.small_file_id = small_file_id
self.big_file_id = big_file_id self.big_file_id = big_file_id
@ -68,6 +68,5 @@ class ChatPhoto(Object):
1, loc_big.dc_id, photo_id, 0, loc_big.volume_id, loc_big.secret, loc_big.local_id 1, loc_big.dc_id, photo_id, 0, loc_big.volume_id, loc_big.secret, loc_big.local_id
) )
), ),
client=client, client=client
raw=chat_photo
) )

View File

@ -44,9 +44,9 @@ class Dialog(PyrogramType):
True, if the dialog is pinned. True, if the dialog is pinned.
""" """
def __init__(self, *, client, raw, chat, top_message, unread_messages_count: int, unread_mentions_count: int, def __init__(self, *, client, chat, top_message, unread_messages_count: int, unread_mentions_count: int,
unread_mark: bool, is_pinned: bool): unread_mark: bool, is_pinned: bool):
super().__init__(client, raw) super().__init__(client)
self.chat = chat self.chat = chat
self.top_message = top_message self.top_message = top_message
@ -73,6 +73,5 @@ class Dialog(PyrogramType):
unread_mentions_count=dialog.unread_mentions_count, unread_mentions_count=dialog.unread_mentions_count,
unread_mark=dialog.unread_mark, unread_mark=dialog.unread_mark,
is_pinned=dialog.pinned, is_pinned=dialog.pinned,
client=client, client=client
raw=dialog
) )

View File

@ -33,8 +33,8 @@ class Dialogs(PyrogramType):
Requested dialogs. Requested dialogs.
""" """
def __init__(self, *, client, raw, total_count: int, dialogs: list): def __init__(self, *, client, total_count: int, dialogs: list):
super().__init__(client, raw) super().__init__(client)
self.total_count = total_count self.total_count = total_count
self.dialogs = dialogs self.dialogs = dialogs
@ -64,6 +64,5 @@ class Dialogs(PyrogramType):
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
raw=dialogs
) )

View File

@ -69,11 +69,11 @@ class User(PyrogramType):
The reason why this bot might be unavailable to some users. The reason why this bot might be unavailable to some users.
""" """
def __init__(self, *, client, raw, id: int, is_self: bool, is_contact: bool, is_mutual_contact: bool, def __init__(self, *, client, 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, is_deleted: bool, is_bot: bool, first_name: str, last_name: str = None, status=None,
username: str = None, language_code: str = None, phone_number: str = None, photo=None, username: str = None, language_code: str = None, phone_number: str = None, photo=None,
restriction_reason: str = None): restriction_reason: str = None):
super().__init__(client, raw) super().__init__(client)
self.id = id self.id = id
self.is_self = is_self self.is_self = is_self
@ -110,6 +110,5 @@ class User(PyrogramType):
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
raw=user
) )

View File

@ -62,10 +62,10 @@ class UserStatus(PyrogramType):
always shown to blocked users), None otherwise. always shown to blocked users), None otherwise.
""" """
def __init__(self, *, client, raw, user_id: int, online: bool = None, offline: bool = None, date: int = None, def __init__(self, *, client, user_id: int, online: bool = None, offline: bool = None, date: int = None,
recently: bool = None, within_week: bool = None, within_month: bool = None, recently: bool = None, within_week: bool = None, within_month: bool = None,
long_time_ago: bool = None): long_time_ago: bool = None):
super().__init__(client, raw) super().__init__(client)
self.user_id = user_id self.user_id = user_id
self.online = online self.online = online
@ -81,7 +81,7 @@ class UserStatus(PyrogramType):
if is_bot: if is_bot:
return None return None
status = UserStatus(user_id=user_id, client=client, raw=user_status) status = UserStatus(user_id=user_id, client=client)
if isinstance(user_status, types.UserStatusOnline): if isinstance(user_status, types.UserStatusOnline):
status.online = True status.online = True