Type hint all the remaining method parameters

This commit is contained in:
Dan 2018-12-19 14:50:23 +01:00
parent 4fb9969470
commit b593463bd7
60 changed files with 295 additions and 139 deletions

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from pyrogram.api.errors import UnknownError
from pyrogram.client.ext import BaseClient
@ -23,7 +25,7 @@ from pyrogram.client.ext import BaseClient
class GetInlineBotResults(BaseClient):
def get_inline_bot_results(self,
bot: int or str,
bot: Union[int, str],
query: str,
offset: str = "",
latitude: float = None,

View File

@ -16,13 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions
from pyrogram.client.ext import BaseClient
class RequestCallbackAnswer(BaseClient):
def request_callback_answer(self,
chat_id: int or str,
chat_id: Union[int, str],
message_id: int,
callback_data: bytes):
"""Use this method to request a callback answer from bots. This is the equivalent of clicking an

View File

@ -16,13 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions
from pyrogram.client.ext import BaseClient
class SendInlineBotResult(BaseClient):
def send_inline_bot_result(self,
chat_id: int or str,
chat_id: Union[int, str],
query_id: int,
result_id: str,
disable_notification: bool = None,

View File

@ -16,12 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class DeleteChatPhoto(BaseClient):
def delete_chat_photo(self, chat_id: int or str):
def delete_chat_photo(self,
chat_id: Union[int, str]):
"""Use this method to delete a chat photo.
Photos can't be changed for private chats.
You must be an administrator in the chat for this to work and must have the appropriate admin rights.

View File

@ -16,12 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class ExportChatInviteLink(BaseClient):
def export_chat_invite_link(self, chat_id: int or str):
def export_chat_invite_link(self,
chat_id: Union[int, str]):
"""Use this method to generate a new invite link for a chat; any previously generated link is revoked.
You must be an administrator in the chat for this to work and have the appropriate admin rights.

View File

@ -16,13 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from ...ext import BaseClient
class GetChat(BaseClient):
def get_chat(self, chat_id: int or str):
def get_chat(self,
chat_id: Union[int, str]):
"""Use this method to get up to date information about the chat (current name of the user for
one-on-one conversations, current username of a user, group or channel, etc.)
@ -45,4 +48,4 @@ class GetChat(BaseClient):
else:
r = self.send(functions.messages.GetFullChat(peer.chat_id))
return pyrogram.Chat.parse_full(self, r)
return pyrogram.Chat._parse_full(self, r)

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types, errors
from ...ext import BaseClient
@ -23,8 +25,8 @@ from ...ext import BaseClient
class GetChatMember(BaseClient):
def get_chat_member(self,
chat_id: int or str,
user_id: int or str):
chat_id: Union[int, str],
user_id: Union[int, str]):
"""Use this method to get information about one member of a chat.
Args:
@ -52,7 +54,7 @@ class GetChatMember(BaseClient):
)
)
for member in pyrogram.ChatMembers.parse(self, full_chat).chat_members:
for member in pyrogram.ChatMembers._parse(self, full_chat).chat_members:
if member.user.id == user_id.user_id:
return member
else:
@ -65,7 +67,7 @@ class GetChatMember(BaseClient):
)
)
return pyrogram.ChatMembers.parse(
return pyrogram.ChatMembers._parse(
self,
types.channels.ChannelParticipants(
count=1,

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -32,7 +34,7 @@ class Filters:
class GetChatMembers(BaseClient):
def get_chat_members(self,
chat_id: int or str,
chat_id: Union[int, str],
offset: int = 0,
limit: int = 200,
query: str = "",
@ -84,7 +86,7 @@ class GetChatMembers(BaseClient):
peer = self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChat):
return pyrogram.ChatMembers.parse(
return pyrogram.ChatMembers._parse(
self,
self.send(
functions.messages.GetFullChat(
@ -110,7 +112,7 @@ class GetChatMembers(BaseClient):
else:
raise ValueError("Invalid filter \"{}\"".format(filter))
return pyrogram.ChatMembers.parse(
return pyrogram.ChatMembers._parse(
self,
self.send(
functions.channels.GetParticipants(

View File

@ -16,12 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class GetChatMembersCount(BaseClient):
def get_chat_members_count(self, chat_id: int or str):
def get_chat_members_count(self,
chat_id: Union[int, str]):
"""Use this method to get the number of members in a chat.
Args:

View File

@ -23,7 +23,7 @@ from ...ext import BaseClient
class GetDialogs(BaseClient):
def get_dialogs(self,
offset_dialog=None,
offset_dialog: "pyrogram.Dialog" = None,
limit: int = 100,
pinned_only: bool = False):
"""Use this method to get the user's dialogs
@ -64,4 +64,4 @@ class GetDialogs(BaseClient):
)
)
return pyrogram.Dialogs.parse(self, r)
return pyrogram.Dialogs._parse(self, r)

View File

@ -21,7 +21,8 @@ from ...ext import BaseClient
class JoinChat(BaseClient):
def join_chat(self, chat_id: str):
def join_chat(self,
chat_id: str):
"""Use this method to join a group chat or channel.
Args:

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -23,8 +25,8 @@ from ...ext import BaseClient
class KickChatMember(BaseClient):
def kick_chat_member(self,
chat_id: int or str,
user_id: int or str,
chat_id: Union[int, str],
user_id: Union[int, str],
until_date: int = 0):
"""Use this method to kick a user from a group, a supergroup or a channel.
In the case of supergroups and channels, the user will not be able to return to the group on their own using
@ -86,7 +88,7 @@ class KickChatMember(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -16,12 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class LeaveChat(BaseClient):
def leave_chat(self, chat_id: int or str, delete: bool = False):
def leave_chat(self,
chat_id: Union[int, str],
delete: bool = False):
"""Use this method to leave a group chat or channel.
Args:

View File

@ -16,12 +16,17 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class PinChatMessage(BaseClient):
def pin_chat_message(self, chat_id: int or str, message_id: int, disable_notification: bool = None):
def pin_chat_message(self,
chat_id: Union[int, str],
message_id: int,
disable_notification: bool = None):
"""Use this method to pin a message in a supergroup or a channel.
You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in
the supergroup or "can_edit_messages" admin right in the channel.

View File

@ -16,14 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class PromoteChatMember(BaseClient):
def promote_chat_member(self,
chat_id: int or str,
user_id: int or str,
chat_id: Union[int, str],
user_id: Union[int, str],
can_change_info: bool = True,
can_post_messages: bool = False,
can_edit_messages: bool = False,

View File

@ -16,14 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class RestrictChatMember(BaseClient):
def restrict_chat_member(self,
chat_id: int or str,
user_id: int or str,
chat_id: Union[int, str],
user_id: Union[int, str],
until_date: int = 0,
can_send_messages: bool = False,
can_send_media_messages: bool = False,

View File

@ -16,12 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class SetChatDescription(BaseClient):
def set_chat_description(self, chat_id: int or str, description: str):
def set_chat_description(self,
chat_id: Union[int, str],
description: str):
"""Use this method to change the description of a supergroup or a channel.
You must be an administrator in the chat for this to work and must have the appropriate admin rights.

View File

@ -19,13 +19,16 @@
import os
from base64 import b64decode
from struct import unpack
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class SetChatPhoto(BaseClient):
def set_chat_photo(self, chat_id: int or str, photo: str):
def set_chat_photo(self,
chat_id: Union[int, str],
photo: str):
"""Use this method to set a new profile photo for the chat.
Photos can't be changed for private chats.
You must be an administrator in the chat for this to work and must have the appropriate admin rights.

View File

@ -16,12 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class SetChatTitle(BaseClient):
def set_chat_title(self, chat_id: int or str, title: str):
def set_chat_title(self,
chat_id: Union[int, str],
title: str):
"""Use this method to change the title of a chat.
Titles can't be changed for private chats.
You must be an administrator in the chat for this to work and must have the appropriate admin rights.

View File

@ -16,14 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class UnbanChatMember(BaseClient):
def unban_chat_member(self,
chat_id: int or str,
user_id: int or str):
chat_id: Union[int, str],
user_id: Union[int, str]):
"""Use this method to unban a previously kicked user in a supergroup or channel.
The user will **not** return to the group or channel automatically, but will be able to join via link, etc.
You must be an administrator for this to work.

View File

@ -16,12 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class UnpinChatMessage(BaseClient):
def unpin_chat_message(self, chat_id: int or str):
def unpin_chat_message(self,
chat_id: Union[int, str]):
"""Use this method to unpin a message in a supergroup or a channel.
You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin
right in the supergroup or "can_edit_messages" admin right in the channel.

View File

@ -16,17 +16,21 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import List
import pyrogram
from pyrogram.api import functions
from ...ext import BaseClient
class AddContacts(BaseClient):
def add_contacts(self, contacts: list):
def add_contacts(self,
contacts: List["pyrogram.InputPhoneContact"]):
"""Use this method to add contacts to your Telegram address book.
Args:
contacts (``list``):
A list of :obj:`InputPhoneContact <pyrogram.InputPhoneContact>`
contacts (List of :obj:`InputPhoneContact <pyrogram.InputPhoneContact>`):
The contact list to be added
Returns:
On success, the added contacts are returned.

View File

@ -16,17 +16,20 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import List
from pyrogram.api import functions, types
from pyrogram.api.errors import PeerIdInvalid
from ...ext import BaseClient
class DeleteContacts(BaseClient):
def delete_contacts(self, ids: list):
def delete_contacts(self,
ids: List[int]):
"""Use this method to delete contacts from your Telegram address book
Args:
ids (``list``):
ids (List of ``int``):
A list of unique identifiers for the target users.
Can be an ID (int), a username (string) or phone number (string).

View File

@ -22,7 +22,9 @@ from ...ext import BaseClient
class OnCallbackQuery(BaseClient):
def on_callback_query(self=None, filters=None, group: int = 0):
def on_callback_query(self=None,
filters=None,
group: int = 0):
"""Use this decorator to automatically register a function for handling
callback queries. This does the same thing as :meth:`add_handler` using the
:class:`CallbackQueryHandler`.

View File

@ -22,7 +22,9 @@ from ...ext import BaseClient
class OnDeletedMessages(BaseClient):
def on_deleted_messages(self=None, filters=None, group: int = 0):
def on_deleted_messages(self=None,
filters=None,
group: int = 0):
"""Use this decorator to automatically register a function for handling
deleted messages. This does the same thing as :meth:`add_handler` using the
:class:`DeletedMessagesHandler`.

View File

@ -22,7 +22,9 @@ from ...ext import BaseClient
class OnMessage(BaseClient):
def on_message(self=None, filters=None, group: int = 0):
def on_message(self=None,
filters=None,
group: int = 0):
"""Use this decorator to automatically register a function for handling
messages. This does the same thing as :meth:`add_handler` using the
:class:`MessageHandler`.

View File

@ -21,7 +21,8 @@ from ...ext import BaseClient
class OnRawUpdate(BaseClient):
def on_raw_update(self=None, group: int = 0):
def on_raw_update(self=None,
group: int = 0):
"""Use this decorator to automatically register a function for handling
raw updates. This does the same thing as :meth:`add_handler` using the
:class:`RawUpdateHandler`.

View File

@ -22,7 +22,9 @@ from ...ext import BaseClient
class OnUserStatus(BaseClient):
def on_user_status(self=None, filters=None, group: int = 0):
def on_user_status(self=None,
filters=None,
group: int = 0):
"""Use this decorator to automatically register a function for handling
user status updates. This does the same thing as :meth:`add_handler` using the
:class:`UserStatusHandler`.

View File

@ -16,14 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, Iterable
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
class DeleteMessages(BaseClient):
def delete_messages(self,
chat_id: int or str,
message_ids,
chat_id: Union[int, str],
message_ids: Iterable[int],
revoke: bool = True):
"""Use this method to delete messages, including service messages, with the following limitations:

View File

@ -16,19 +16,20 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import pyrogram
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
class EditMessageCaption(BaseClient):
def edit_message_caption(self,
chat_id: int or str,
chat_id: Union[int, str],
message_id: int,
caption: str,
parse_mode: str = "",
reply_markup=None):
reply_markup: "pyrogram.InlineKeyboardMarkup" = None):
"""Use this method to edit captions of messages.
Args:
@ -70,7 +71,7 @@ class EditMessageCaption(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -29,14 +30,15 @@ from pyrogram.client.types import (
InputMediaPhoto, InputMediaVideo, InputMediaAudio,
InputMediaAnimation, InputMediaDocument
)
from pyrogram.client.types.input_media import InputMedia
class EditMessageMedia(BaseClient):
def edit_message_media(self,
chat_id: int or str,
chat_id: Union[int, str],
message_id: int,
media,
reply_markup=None):
media: InputMedia,
reply_markup: "pyrogram.InlineKeyboardMarkup" = None):
"""Use this method to edit audio, document, photo, or video messages.
If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise,
@ -334,7 +336,7 @@ class EditMessageMedia(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
@ -23,9 +25,9 @@ from pyrogram.client.ext import BaseClient
class EditMessageReplyMarkup(BaseClient):
def edit_message_reply_markup(self,
chat_id: int or str,
chat_id: Union[int, str],
message_id: int,
reply_markup=None):
reply_markup: "pyrogram.InlineKeyboardMarkup" = None):
"""Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
Args:
@ -58,7 +60,7 @@ class EditMessageReplyMarkup(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
@ -23,12 +25,12 @@ from pyrogram.client.ext import BaseClient
class EditMessageText(BaseClient):
def edit_message_text(self,
chat_id: int or str,
chat_id: Union[int, str],
message_id: int,
text: str,
parse_mode: str = "",
disable_web_page_preview: bool = None,
reply_markup=None):
reply_markup: "pyrogram.InlineKeyboardMarkup" = None):
"""Use this method to edit text messages.
Args:
@ -74,7 +76,7 @@ class EditMessageText(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, Iterable
import pyrogram
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -23,9 +25,9 @@ from ...ext import BaseClient
class ForwardMessages(BaseClient):
def forward_messages(self,
chat_id: int or str,
from_chat_id: int or str,
message_ids,
chat_id: Union[int, str],
from_chat_id: Union[int, str],
message_ids: Iterable[int],
disable_notification: bool = None):
"""Use this method to forward messages of any kind.
@ -78,7 +80,7 @@ class ForwardMessages(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
messages.append(
pyrogram.Message.parse(
pyrogram.Message._parse(
self, i.message,
users, chats
)

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions
from ...ext import BaseClient
@ -23,7 +25,7 @@ from ...ext import BaseClient
class GetHistory(BaseClient):
def get_history(self,
chat_id: int or str,
chat_id: Union[int, str],
offset: int = 0,
limit: int = 100,
offset_id: int = 0,
@ -59,7 +61,7 @@ class GetHistory(BaseClient):
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
"""
return pyrogram.Messages.parse(
return pyrogram.Messages._parse(
self,
self.send(
functions.messages.GetHistory(

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, Iterable
import pyrogram
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -23,9 +25,9 @@ from ...ext import BaseClient
class GetMessages(BaseClient):
def get_messages(self,
chat_id: int or str,
message_ids: int or list = None,
reply_to_message_ids: int or list = None,
chat_id: Union[int, str],
message_ids: Union[int, Iterable[int]] = None,
reply_to_message_ids: Union[int, Iterable[int]] = None,
replies: int = 1):
"""Use this method to get one or more messages that belong to a specific chat.
You can retrieve up to 200 messages at once.
@ -76,6 +78,6 @@ class GetMessages(BaseClient):
else:
rpc = functions.messages.GetMessages(id=ids)
messages = pyrogram.Messages.parse(self, self.send(rpc))
messages = pyrogram.Messages._parse(self, self.send(rpc))
return messages if is_iterable else messages.messages[0]

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -29,7 +30,7 @@ from pyrogram.client.ext import BaseClient, utils
class SendAnimation(BaseClient):
def send_animation(self,
chat_id: int or str,
chat_id: Union[int, str],
animation: str,
caption: str = "",
parse_mode: str = "",
@ -39,7 +40,10 @@ class SendAnimation(BaseClient):
thumb: str = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send animation files (animation or H.264/MPEG-4 AVC video without sound).
@ -185,7 +189,7 @@ class SendAnimation(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -29,7 +30,7 @@ from pyrogram.client.ext import BaseClient, utils
class SendAudio(BaseClient):
def send_audio(self,
chat_id: int or str,
chat_id: Union[int, str],
audio: str,
caption: str = "",
parse_mode: str = "",
@ -39,7 +40,10 @@ class SendAudio(BaseClient):
thumb: str = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send audio files.
@ -185,7 +189,7 @@ class SendAudio(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -16,14 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions
from pyrogram.client.ext import BaseClient, ChatAction
class SendChatAction(BaseClient):
def send_chat_action(self,
chat_id: int or str,
action: ChatAction or str,
chat_id: Union[int, str],
action: Union[ChatAction, str],
progress: int = 0):
"""Use this method when you need to tell the other party that something is happening on your side.

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
@ -23,14 +25,17 @@ from pyrogram.client.ext import BaseClient
class SendContact(BaseClient):
def send_contact(self,
chat_id: int or str,
chat_id: Union[int, str],
phone_number: str,
first_name: str,
last_name: str = "",
vcard: str = "",
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None):
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None):
"""Use this method to send phone contacts.
Args:
@ -87,7 +92,7 @@ class SendContact(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -29,14 +30,17 @@ from pyrogram.client.ext import BaseClient, utils
class SendDocument(BaseClient):
def send_document(self,
chat_id: int or str,
chat_id: Union[int, str],
document: str,
thumb: str = None,
caption: str = "",
parse_mode: str = "",
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send general files.
@ -166,7 +170,7 @@ class SendDocument(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
@ -23,12 +25,15 @@ from pyrogram.client.ext import BaseClient
class SendLocation(BaseClient):
def send_location(self,
chat_id: int or str,
chat_id: Union[int, str],
latitude: float,
longitude: float,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None):
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None):
"""Use this method to send points on the map.
Args:
@ -79,7 +84,7 @@ class SendLocation(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -20,10 +20,11 @@ import binascii
import mimetypes
import os
import struct
from typing import Union, List
import pyrogram
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid
from pyrogram.client import types as pyrogram_types
from pyrogram.client.ext import BaseClient, utils
@ -32,8 +33,8 @@ class SendMediaGroup(BaseClient):
# TODO: Return new Message object
# TODO: Figure out how to send albums using URLs
def send_media_group(self,
chat_id: int or str,
media: list,
chat_id: Union[int, str],
media: List[Union["pyrogram.InputMediaPhoto", "pyrogram.InputMediaVideo"]],
disable_notification: bool = None,
reply_to_message_id: int = None):
"""Use this method to send a group of photos or videos as an album.
@ -62,7 +63,7 @@ class SendMediaGroup(BaseClient):
for i in media:
style = self.html if i.parse_mode.lower() == "html" else self.markdown
if isinstance(i, pyrogram_types.InputMediaPhoto):
if isinstance(i, pyrogram.InputMediaPhoto):
if os.path.exists(i.media):
media = self.send(
functions.messages.UploadMedia(
@ -101,7 +102,7 @@ class SendMediaGroup(BaseClient):
access_hash=unpacked[3]
)
)
elif isinstance(i, pyrogram_types.InputMediaVideo):
elif isinstance(i, pyrogram.InputMediaVideo):
if os.path.exists(i.media):
media = self.send(
functions.messages.UploadMedia(

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from ...ext import BaseClient
@ -23,13 +25,16 @@ from ...ext import BaseClient
class SendMessage(BaseClient):
def send_message(self,
chat_id: int or str,
chat_id: Union[int, str],
text: str,
parse_mode: str = "",
disable_web_page_preview: bool = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None):
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None):
"""Use this method to send text messages.
Args:
@ -99,7 +104,7 @@ class SendMessage(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -19,6 +19,7 @@
import binascii
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -28,14 +29,17 @@ from pyrogram.client.ext import BaseClient, utils
class SendPhoto(BaseClient):
def send_photo(self,
chat_id: int or str,
chat_id: Union[int, str],
photo: str,
caption: str = "",
parse_mode: str = "",
ttl_seconds: int = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send photos.
@ -161,7 +165,7 @@ class SendPhoto(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -19,6 +19,7 @@
import binascii
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -28,11 +29,14 @@ from pyrogram.client.ext import BaseClient, utils
class SendSticker(BaseClient):
def send_sticker(self,
chat_id: int or str,
chat_id: Union[int, str],
sticker: str,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send .webp stickers.
@ -145,7 +149,7 @@ class SendSticker(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
@ -23,7 +25,7 @@ from pyrogram.client.ext import BaseClient
class SendVenue(BaseClient):
def send_venue(self,
chat_id: int or str,
chat_id: Union[int, str],
latitude: float,
longitude: float,
title: str,
@ -32,7 +34,10 @@ class SendVenue(BaseClient):
foursquare_type: str = "",
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None):
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None):
"""Use this method to send information about a venue.
Args:
@ -101,7 +106,7 @@ class SendVenue(BaseClient):
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -29,7 +30,7 @@ from pyrogram.client.ext import BaseClient, utils
class SendVideo(BaseClient):
def send_video(self,
chat_id: int or str,
chat_id: Union[int, str],
video: str,
caption: str = "",
parse_mode: str = "",
@ -40,7 +41,10 @@ class SendVideo(BaseClient):
supports_streaming: bool = True,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send video files.
@ -188,7 +192,7 @@ class SendVideo(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -29,14 +30,17 @@ from pyrogram.client.ext import BaseClient, utils
class SendVideoNote(BaseClient):
def send_video_note(self,
chat_id: int or str,
chat_id: Union[int, str],
video_note: str,
duration: int = 0,
length: int = 1,
thumb: str = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send video messages.
@ -164,7 +168,7 @@ class SendVideoNote(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes
import os
import struct
from typing import Union
import pyrogram
from pyrogram.api import functions, types
@ -29,14 +30,17 @@ from pyrogram.client.ext import BaseClient, utils
class SendVoice(BaseClient):
def send_voice(self,
chat_id: int or str,
chat_id: Union[int, str],
voice: str,
caption: str = "",
parse_mode: str = "",
duration: int = 0,
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup=None,
reply_markup: Union["pyrogram.InlineKeyboardMarkup",
"pyrogram.ReplyKeyboardMarkup",
"pyrogram.ReplyKeyboardRemove",
"pyrogram.ForceReply"] = None,
progress: callable = None,
progress_args: tuple = ()):
"""Use this method to send audio files.
@ -164,7 +168,7 @@ class SendVoice(BaseClient):
else:
for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse(
return pyrogram.Message._parse(
self, i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats}

View File

@ -24,7 +24,10 @@ from ...ext import BaseClient
class ChangeCloudPassword(BaseClient):
def change_cloud_password(self, current_password: str, new_password: str, new_hint: str = ""):
def change_cloud_password(self,
current_password: str,
new_password: str,
new_hint: str = ""):
"""Use this method to change your Two-Step Verification password (Cloud Password) with a new one.
Args:

View File

@ -24,7 +24,10 @@ from ...ext import BaseClient
class EnableCloudPassword(BaseClient):
def enable_cloud_password(self, password: str, hint: str = "", email: str = ""):
def enable_cloud_password(self,
password: str,
hint: str = "",
email: str = ""):
"""Use this method to enable the Two-Step Verification security feature (Cloud Password) on your account.
This password will be asked when you log in on a new device in addition to the SMS code.

View File

@ -23,7 +23,8 @@ from ...ext import BaseClient
class RemoveCloudPassword(BaseClient):
def remove_cloud_password(self, password: str):
def remove_cloud_password(self,
password: str):
"""Use this method to turn off the Two-Step Verification security feature (Cloud Password) on your account.
Args:

View File

@ -18,13 +18,15 @@
from base64 import b64decode
from struct import unpack
from typing import List, Union
from pyrogram.api import functions, types
from ...ext import BaseClient
class DeleteUserProfilePhotos(BaseClient):
def delete_user_profile_photos(self, id: str or list):
def delete_user_profile_photos(self,
id: Union[str, List[str]]):
"""Use this method to delete your own profile photos
Args:

View File

@ -31,7 +31,7 @@ class GetMe(BaseClient):
Raises:
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
"""
return pyrogram.User.parse(
return pyrogram.User._parse(
self,
self.send(
functions.users.GetFullUser(

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions
from ...ext import BaseClient
@ -23,7 +25,7 @@ from ...ext import BaseClient
class GetUserProfilePhotos(BaseClient):
def get_user_profile_photos(self,
user_id: int or str,
user_id: Union[int, str],
offset: int = 0,
limit: int = 100):
"""Use this method to get a list of profile pictures for a user.
@ -48,7 +50,7 @@ class GetUserProfilePhotos(BaseClient):
Raises:
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
"""
return pyrogram.UserProfilePhotos.parse(
return pyrogram.UserProfilePhotos._parse(
self,
self.send(
functions.photos.GetUserPhotos(

View File

@ -16,13 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Iterable, Union
import pyrogram
from pyrogram.api import functions
from ...ext import BaseClient
class GetUsers(BaseClient):
def get_users(self, user_ids):
def get_users(self,
user_ids: Iterable[Union[int, str]]):
"""Use this method to get information about a user.
You can retrieve up to 200 users at once.
@ -53,6 +56,6 @@ class GetUsers(BaseClient):
users = []
for i in r:
users.append(pyrogram.User.parse(self, i))
users.append(pyrogram.User._parse(self, i))
return users if is_iterable else users[0]

View File

@ -21,7 +21,8 @@ from ...ext import BaseClient
class SetUserProfilePhoto(BaseClient):
def set_user_profile_photo(self, photo: str):
def set_user_profile_photo(self,
photo: str):
"""Use this method to set a new profile photo.
This method only works for Users.

View File

@ -17,14 +17,15 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from threading import Event
from typing import Union
from pyrogram.client import types as pyrogram_types
import pyrogram
from ...ext import BaseClient
class DownloadMedia(BaseClient):
def download_media(self,
message: pyrogram_types.Message or str,
message: Union["pyrogram.Message", str],
file_name: str = "",
block: bool = True,
progress: callable = None,
@ -78,9 +79,9 @@ class DownloadMedia(BaseClient):
"""
error_message = "This message doesn't contain any downloadable media"
if isinstance(message, pyrogram_types.Message):
if isinstance(message, pyrogram.Message):
if message.photo:
media = pyrogram_types.Document(
media = pyrogram.Document(
file_id=message.photo.sizes[-1].file_id,
file_size=message.photo.sizes[-1].file_size,
mime_type="",
@ -104,18 +105,18 @@ class DownloadMedia(BaseClient):
else:
raise ValueError(error_message)
elif isinstance(message, (
pyrogram_types.Photo,
pyrogram_types.PhotoSize,
pyrogram_types.Audio,
pyrogram_types.Document,
pyrogram_types.Video,
pyrogram_types.Voice,
pyrogram_types.VideoNote,
pyrogram_types.Sticker,
pyrogram_types.Animation
pyrogram.Photo,
pyrogram.PhotoSize,
pyrogram.Audio,
pyrogram.Document,
pyrogram.Video,
pyrogram.Voice,
pyrogram.VideoNote,
pyrogram.Sticker,
pyrogram.Animation
)):
if isinstance(message, pyrogram_types.Photo):
media = pyrogram_types.Document(
if isinstance(message, pyrogram.Photo):
media = pyrogram.Document(
file_id=message.sizes[-1].file_id,
file_size=message.sizes[-1].file_size,
mime_type="",
@ -125,7 +126,7 @@ class DownloadMedia(BaseClient):
else:
media = message
elif isinstance(message, str):
media = pyrogram_types.Document(
media = pyrogram.Document(
file_id=message,
file_size=0,
mime_type="",

View File

@ -483,7 +483,7 @@ class Message(PyrogramType):
else:
video = pyrogram.Video._parse(client, doc, video_attributes, file_name)
elif types.DocumentAttributeSticker in attributes:
sticker = pyrogram.Sticker.parse(
sticker = pyrogram.Sticker._parse(
client, doc,
attributes.get(types.DocumentAttributeImageSize, None),
attributes[types.DocumentAttributeSticker],