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

Add __slots__ to every single Pyrogram types

This commit is contained in:
Dan 2019-03-16 16:15:27 +01:00
parent ef9ed31589
commit e0f1f6aaeb
46 changed files with 592 additions and 386 deletions

View File

@ -25,5 +25,7 @@ class CallbackGame(PyrogramType):
Use BotFather to set up your game.
"""
__slots__ = []
def __init__(self):
super().__init__(None)

View File

@ -58,7 +58,10 @@ class CallbackQuery(PyrogramType, Update):
"""
def __init__(self,
__slots__ = ["id", "from_user", "chat_instance", "message", "inline_message_id", "data", "game_short_name"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
id: str,
@ -67,7 +70,8 @@ class CallbackQuery(PyrogramType, Update):
message: "pyrogram.Message" = None,
inline_message_id: str = None,
data: bytes = None,
game_short_name: str = None):
game_short_name: str = None
):
super().__init__(client)
self.id = id

View File

@ -33,8 +33,12 @@ class ForceReply(PyrogramType):
2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
"""
def __init__(self,
selective: bool = None):
__slots__ = ["selective"]
def __init__(
self,
selective: bool = None
):
super().__init__(None)
self.selective = selective

View File

@ -37,12 +37,16 @@ class GameHighScore(PyrogramType):
Position in high score table for the game.
"""
def __init__(self,
__slots__ = ["user", "score", "position"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
user: User,
score: int,
position: int = None):
position: int = None
):
super().__init__(client)
self.user = user

View File

@ -35,11 +35,15 @@ class GameHighScores(PyrogramType):
Game scores.
"""
def __init__(self,
__slots__ = ["total_count", "game_high_scores"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
total_count: int,
game_high_scores: List[GameHighScore]):
game_high_scores: List[GameHighScore]
):
super().__init__(client)
self.total_count = total_count

View File

@ -54,13 +54,19 @@ class InlineKeyboardButton(PyrogramType):
# TODO: Add callback_game and pay fields
def __init__(self,
__slots__ = [
"text", "url", "callback_data", "switch_inline_query", "switch_inline_query_current_chat", "callback_game"
]
def __init__(
self,
text: str,
callback_data: bytes = None,
url: str = None,
switch_inline_query: str = None,
switch_inline_query_current_chat: str = None,
callback_game: CallbackGame = None):
callback_game: CallbackGame = None
):
super().__init__(None)
self.text = str(text)

View File

@ -31,8 +31,12 @@ class InlineKeyboardMarkup(PyrogramType):
List of button rows, each represented by a List of InlineKeyboardButton objects.
"""
def __init__(self,
inline_keyboard: List[List[InlineKeyboardButton]]):
__slots__ = ["inline_keyboard"]
def __init__(
self,
inline_keyboard: List[List[InlineKeyboardButton]]
):
super().__init__(None)
self.inline_keyboard = inline_keyboard

View File

@ -40,10 +40,14 @@ class KeyboardButton(PyrogramType):
Available in private chats only.
"""
def __init__(self,
__slots__ = ["text", "request_contact", "request_location"]
def __init__(
self,
text: str,
request_contact: bool = None,
request_location: bool = None):
request_location: bool = None
):
super().__init__(None)
self.text = str(text)

View File

@ -49,11 +49,15 @@ class ReplyKeyboardMarkup(PyrogramType):
select the new language. Other users in the group don't see the keyboard.
"""
def __init__(self,
__slots__ = ["keyboard", "resize_keyboard", "one_time_keyboard", "selective"]
def __init__(
self,
keyboard: List[List[Union[KeyboardButton, str]]],
resize_keyboard: bool = None,
one_time_keyboard: bool = None,
selective: bool = None):
selective: bool = None
):
super().__init__(None)
self.keyboard = keyboard

View File

@ -35,8 +35,12 @@ class ReplyKeyboardRemove(PyrogramType):
keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
"""
def __init__(self,
selective: bool = None):
__slots__ = ["selective"]
def __init__(
self,
selective: bool = None
):
super().__init__(None)
self.selective = selective

View File

@ -18,10 +18,14 @@
class InputMedia:
def __init__(self,
__slots__ = ["media", "caption", "parse_mode"]
def __init__(
self,
media: str,
caption: str,
parse_mode: str):
parse_mode: str
):
self.media = media
self.caption = caption
self.parse_mode = parse_mode

View File

@ -52,14 +52,18 @@ class InputMediaAnimation(InputMedia):
Animation duration.
"""
def __init__(self,
__slots__ = ["thumb", "width", "height", "duration"]
def __init__(
self,
media: str,
thumb: str = None,
caption: str = "",
parse_mode: str = "",
width: int = 0,
height: int = 0,
duration: int = 0):
duration: int = 0
):
super().__init__(media, caption, parse_mode)
self.thumb = thumb

View File

@ -53,14 +53,18 @@ class InputMediaAudio(InputMedia):
Title of the audio
"""
def __init__(self,
__slots__ = ["thumb", "duration", "performer", "title"]
def __init__(
self,
media: str,
thumb: str = None,
caption: str = "",
parse_mode: str = "",
duration: int = 0,
performer: int = "",
title: str = ""):
title: str = ""
):
super().__init__(media, caption, parse_mode)
self.thumb = thumb

View File

@ -43,11 +43,15 @@ class InputMediaDocument(InputMedia):
Defaults to Markdown.
"""
def __init__(self,
__slots__ = ["thumb"]
def __init__(
self,
media: str,
thumb: str = None,
caption: str = "",
parse_mode: str = ""):
parse_mode: str = ""
):
super().__init__(media, caption, parse_mode)
self.thumb = thumb

View File

@ -39,8 +39,12 @@ class InputMediaPhoto(InputMedia):
Defaults to Markdown.
"""
def __init__(self,
__slots__ = []
def __init__(
self,
media: str,
caption: str = "",
parse_mode: str = ""):
parse_mode: str = ""
):
super().__init__(media, caption, parse_mode)

View File

@ -57,7 +57,10 @@ class InputMediaVideo(InputMedia):
Pass True, if the uploaded video is suitable for streaming.
"""
def __init__(self,
__slots__ = ["thumb", "width", "height", "duration", "supports_streaming"]
def __init__(
self,
media: str,
thumb: str = None,
caption: str = "",
@ -65,7 +68,8 @@ class InputMediaVideo(InputMedia):
width: int = 0,
height: int = 0,
duration: int = 0,
supports_streaming: bool = True):
supports_streaming: bool = True
):
super().__init__(media, caption, parse_mode)
self.thumb = thumb

View File

@ -35,10 +35,14 @@ class InputPhoneContact:
Contact's last name
"""
def __init__(self,
__slots__ = []
def __init__(
self,
phone: str,
first_name: str,
last_name: str = ""):
last_name: str = ""
):
pass
def __new__(cls,

View File

@ -57,7 +57,10 @@ class Animation(PyrogramType):
Date the animation was sent in Unix time.
"""
def __init__(self,
__slots__ = ["file_id", "thumb", "file_name", "mime_type", "file_size", "date", "width", "height", "duration"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
@ -68,7 +71,8 @@ class Animation(PyrogramType):
file_name: str = None,
mime_type: str = None,
file_size: int = None,
date: int = None):
date: int = None
):
super().__init__(client)
self.file_id = file_id

View File

@ -57,7 +57,10 @@ class Audio(PyrogramType):
Title of the audio as defined by sender or by audio tags.
"""
def __init__(self,
__slots__ = ["file_id", "thumb", "file_name", "mime_type", "file_size", "date", "duration", "performer", "title"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
@ -68,7 +71,8 @@ class Audio(PyrogramType):
file_size: int = None,
date: int = None,
performer: str = None,
title: str = None):
title: str = None
):
super().__init__(client)
self.file_id = file_id

View File

@ -42,14 +42,18 @@ class Contact(PyrogramType):
Additional data about the contact in the form of a vCard.
"""
def __init__(self,
__slots__ = ["phone_number", "first_name", "last_name", "user_id", "vcard"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
phone_number: str,
first_name: str,
last_name: str = None,
user_id: int = None,
vcard: str = None):
vcard: str = None
):
super().__init__(client)
self.phone_number = phone_number

View File

@ -48,7 +48,10 @@ class Document(PyrogramType):
Date the document was sent in Unix time.
"""
def __init__(self,
__slots__ = ["file_id", "thumb", "file_name", "mime_type", "file_size", "date"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
@ -56,7 +59,8 @@ class Document(PyrogramType):
file_name: str = None,
mime_type: str = None,
file_size: int = None,
date: int = None):
date: int = None
):
super().__init__(client)
self.file_id = file_id

View File

@ -48,7 +48,10 @@ class Game(PyrogramType):
Upload via BotFather.
"""
def __init__(self,
__slots__ = ["id", "title", "short_name", "description", "photo", "animation"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
id: int,
@ -56,7 +59,8 @@ class Game(PyrogramType):
short_name: str,
description: str,
photo: Photo,
animation: Animation = None):
animation: Animation = None
):
super().__init__(client)
self.id = id

View File

@ -33,11 +33,15 @@ class Location(PyrogramType):
Latitude as defined by sender.
"""
def __init__(self,
__slots__ = ["longitude", "latitude"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
longitude: float,
latitude: float):
latitude: float
):
super().__init__(client)
self.longitude = longitude

View File

@ -234,7 +234,19 @@ class Message(PyrogramType, Update):
# TODO: Add game missing field. Also invoice, successful_payment, connected_website
def __init__(self,
__slots__ = [
"message_id", "date", "chat", "from_user", "forward_from", "forward_from_chat", "forward_from_message_id",
"forward_signature", "forward_date", "reply_to_message", "mentioned", "empty", "service", "media", "edit_date",
"media_group_id", "author_signature", "text", "entities", "caption_entities", "audio", "document", "photo",
"sticker", "animation", "game", "video", "voice", "video_note", "caption", "contact", "location", "venue",
"web_page", "poll", "new_chat_members", "left_chat_member", "new_chat_title", "new_chat_photo",
"delete_chat_photo", "group_chat_created", "supergroup_chat_created", "channel_chat_created",
"migrate_to_chat_id", "migrate_from_chat_id", "pinned_message", "game_high_score", "views", "via_bot",
"outgoing", "matches", "command", "reply_markup"
]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
message_id: int,
@ -289,10 +301,13 @@ class Message(PyrogramType, Update):
outgoing: bool = None,
matches: List[Match] = None,
command: List[str] = None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
reply_markup: Union[
"pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None):
"pyrogram.ForceReply"
] = None
):
super().__init__(client)
self.message_id = message_id

View File

@ -47,6 +47,8 @@ class MessageEntity(PyrogramType):
For "text_mention" only, the mentioned user.
"""
__slots__ = ["type", "offset", "length", "url", "user"]
ENTITIES = {
types.MessageEntityMention.ID: "mention",
types.MessageEntityHashtag.ID: "hashtag",
@ -63,14 +65,16 @@ class MessageEntity(PyrogramType):
types.MessageEntityPhone.ID: "phone_number"
}
def __init__(self,
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
type: str,
offset: int,
length: int,
url: str = None,
user: User = None):
user: User = None
):
super().__init__(client)
self.type = type

View File

@ -37,11 +37,15 @@ class Messages(PyrogramType, Update):
Requested messages.
"""
def __init__(self,
__slots__ = ["total_count", "messages"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
total_count: int,
messages: List[Message]):
messages: List[Message]
):
super().__init__(client)
self.total_count = total_count

View File

@ -41,12 +41,16 @@ class Photo(PyrogramType):
Available sizes of this photo.
"""
def __init__(self,
__slots__ = ["id", "date", "sizes"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
id: str,
date: int,
sizes: List[PhotoSize]):
sizes: List[PhotoSize]
):
super().__init__(client)
self.id = id

View File

@ -42,13 +42,17 @@ class PhotoSize(PyrogramType):
File size.
"""
def __init__(self,
__slots__ = ["file_id", "width", "height", "file_size"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
width: int,
height: int,
file_size: int):
file_size: int
):
super().__init__(client)
self.file_id = file_id

View File

@ -47,7 +47,10 @@ class Poll(PyrogramType):
The index of your chosen option (in case you voted already), None otherwise.
"""
def __init__(self,
__slots__ = ["id", "closed", "question", "options", "total_voters", "option_chosen"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
id: int,
@ -55,7 +58,8 @@ class Poll(PyrogramType):
question: str,
options: List[PollOption],
total_voters: int,
option_chosen: int = None):
option_chosen: int = None
):
super().__init__(client)
self.id = id

View File

@ -34,12 +34,16 @@ class PollOption(PyrogramType):
Unique data that identifies this option among all the other options in a poll.
"""
def __init__(self,
__slots__ = ["text", "voters", "data"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
text: str,
voters: int,
data: bytes):
data: bytes
):
super().__init__(client)
self.text = text

View File

@ -64,7 +64,12 @@ class Sticker(PyrogramType):
# TODO: Add mask position
def __init__(self,
__slots__ = [
"file_id", "thumb", "file_name", "mime_type", "file_size", "date", "width", "height", "emoji", "set_name"
]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
@ -76,7 +81,8 @@ class Sticker(PyrogramType):
file_size: int = None,
date: int = None,
emoji: str = None,
set_name: str = None):
set_name: str = None
):
super().__init__(client)
self.file_id = file_id

View File

@ -34,11 +34,15 @@ class UserProfilePhotos(PyrogramType):
Requested profile pictures.
"""
def __init__(self,
__slots__ = ["total_count", "photos"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
total_count: int,
photos: List[Photo]):
photos: List[Photo]
):
super().__init__(client)
self.total_count = total_count

View File

@ -44,14 +44,18 @@ class Venue(PyrogramType):
"""
def __init__(self,
__slots__ = ["location", "title", "address", "foursquare_id", "foursquare_type"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
location: Location,
title: str,
address: str,
foursquare_id: str = None,
foursquare_type: str = None):
foursquare_type: str = None
):
super().__init__(client)
self.location = location

View File

@ -57,7 +57,10 @@ class Video(PyrogramType):
Date the video was sent in Unix time.
"""
def __init__(self,
__slots__ = ["file_id", "thumb", "file_name", "mime_type", "file_size", "date", "width", "height", "duration"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
@ -68,7 +71,8 @@ class Video(PyrogramType):
file_name: str = None,
mime_type: str = None,
file_size: int = None,
date: int = None):
date: int = None
):
super().__init__(client)
self.file_id = file_id

View File

@ -51,7 +51,10 @@ class VideoNote(PyrogramType):
Date the video note was sent in Unix time.
"""
def __init__(self,
__slots__ = ["file_id", "thumb", "mime_type", "file_size", "date", "length", "duration"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
@ -60,7 +63,8 @@ class VideoNote(PyrogramType):
thumb: PhotoSize = None,
mime_type: str = None,
file_size: int = None,
date: int = None):
date: int = None
):
super().__init__(client)
self.file_id = file_id

View File

@ -47,7 +47,10 @@ class Voice(PyrogramType):
Date the voice was sent in Unix time.
"""
def __init__(self,
__slots__ = ["file_id", "duration", "waveform", "mime_type", "file_size", "date"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
file_id: str,
@ -55,7 +58,8 @@ class Voice(PyrogramType):
waveform: bytes = None,
mime_type: str = None,
file_size: int = None,
date: int = None):
date: int = None
):
super().__init__(client)
self.file_id = file_id

View File

@ -80,7 +80,14 @@ class Chat(PyrogramType):
Information about the chat default permissions.
"""
def __init__(self,
__slots__ = [
"id", "type", "title", "username", "first_name", "last_name", "photo", "description", "invite_link",
"pinned_message", "sticker_set_name", "can_set_sticker_set", "members_count", "restriction_reason",
"permissions"
]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
id: int,
@ -97,7 +104,8 @@ class Chat(PyrogramType):
can_set_sticker_set: bool = None,
members_count: int = None,
restriction_reason: str = None,
permissions: "pyrogram.ChatPermissions" = None):
permissions: "pyrogram.ChatPermissions" = None
):
super().__init__(client)
self.id = id

View File

@ -51,7 +51,10 @@ class ChatMember(PyrogramType):
Information about the member permissions.
"""
def __init__(self,
__slots__ = ["user", "status", "date", "invited_by", "promoted_by", "restricted_by", "permissions"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
user: "pyrogram.User",
@ -60,7 +63,8 @@ class ChatMember(PyrogramType):
invited_by: "pyrogram.User" = None,
promoted_by: "pyrogram.User" = None,
restricted_by: "pyrogram.User" = None,
permissions: "pyrogram.ChatPermissions" = None):
permissions: "pyrogram.ChatPermissions" = None
):
super().__init__(client)
self.user = user

View File

@ -21,7 +21,6 @@ from typing import List
import pyrogram
from pyrogram.api import types
from .chat_member import ChatMember
from .user import User
from ..pyrogram_type import PyrogramType
@ -36,11 +35,15 @@ class ChatMembers(PyrogramType):
Requested chat members.
"""
def __init__(self,
__slots__ = ["total_count", "chat_members"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
total_count: int,
chat_members: List[ChatMember]):
chat_members: List[ChatMember]
):
super().__init__(client)
self.total_count = total_count

View File

@ -94,6 +94,13 @@ class ChatPermissions(PyrogramType):
True, if polls can be sent, implies can_send_media_messages.
"""
__slots__ = [
"until_date", "can_be_edited", "can_change_info", "can_post_messages", "can_edit_messages",
"can_delete_messages", "can_restrict_members", "can_invite_users", "can_pin_messages", "can_promote_members",
"can_send_messages", "can_send_media_messages", "can_send_other_messages", "can_add_web_page_previews",
"can_send_polls"
]
def __init__(
self,
*,

View File

@ -35,11 +35,15 @@ class ChatPhoto(PyrogramType):
Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download.
"""
def __init__(self,
__slots__ = ["small_file_id", "big_file_id"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
small_file_id: str,
big_file_id: str):
big_file_id: str
):
super().__init__(client)
self.small_file_id = small_file_id

View File

@ -45,14 +45,18 @@ class ChatPreview(PyrogramType):
Preview of some of the chat members.
"""
def __init__(self,
__slots__ = ["title", "photo", "type", "members_count", "members"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
title: str,
photo: ChatPhoto,
type: str,
members_count: int,
members: List[User] = None):
members: List[User] = None
):
super().__init__(client)
self.title = title

View File

@ -46,7 +46,10 @@ class Dialog(PyrogramType):
True, if the dialog is pinned.
"""
def __init__(self,
__slots__ = ["chat", "top_message", "unread_messages_count", "unread_mentions_count", "unread_mark", "is_pinned"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
chat: Chat,
@ -54,7 +57,8 @@ class Dialog(PyrogramType):
unread_messages_count: int,
unread_mentions_count: int,
unread_mark: bool,
is_pinned: bool):
is_pinned: bool
):
super().__init__(client)
self.chat = chat

View File

@ -36,11 +36,15 @@ class Dialogs(PyrogramType):
Requested dialogs.
"""
def __init__(self,
__slots__ = ["total_count", "dialogs"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
total_count: int,
dialogs: List[Dialog]):
dialogs: List[Dialog]
):
super().__init__(client)
self.total_count = total_count

View File

@ -70,7 +70,13 @@ class User(PyrogramType):
The reason why this bot might be unavailable to some users.
"""
def __init__(self,
__slots__ = [
"id", "is_self", "is_contact", "is_mutual_contact", "is_deleted", "is_bot", "first_name", "last_name", "status",
"username", "language_code", "phone_number", "photo", "restriction_reason"
]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
id: int,
@ -86,7 +92,8 @@ class User(PyrogramType):
language_code: str = None,
phone_number: str = None,
photo: ChatPhoto = None,
restriction_reason: str = None):
restriction_reason: str = None
):
super().__init__(client)
self.id = id

View File

@ -65,7 +65,10 @@ class UserStatus(PyrogramType, Update):
always shown to blocked users), None otherwise.
"""
def __init__(self,
__slots__ = ["user_id", "online", "offline", "date", "recently", "within_week", "within_month", "long_time_ago"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
user_id: int,
@ -75,7 +78,8 @@ class UserStatus(PyrogramType, Update):
recently: bool = None,
within_week: bool = None,
within_month: bool = None,
long_time_ago: bool = None):
long_time_ago: bool = None
):
super().__init__(client)
self.user_id = user_id