2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

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

View File

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

View File

@ -16,12 +16,15 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class DeleteChatPhoto(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. """Use this method to delete a chat photo.
Photos can't be changed for private chats. 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. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class ExportChatInviteLink(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. """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. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class GetChat(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 """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.) one-on-one conversations, current username of a user, group or channel, etc.)
@ -45,4 +48,4 @@ class GetChat(BaseClient):
else: else:
r = self.send(functions.messages.GetFullChat(peer.chat_id)) 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types, errors from pyrogram.api import functions, types, errors
from ...ext import BaseClient from ...ext import BaseClient
@ -23,8 +25,8 @@ from ...ext import BaseClient
class GetChatMember(BaseClient): class GetChatMember(BaseClient):
def get_chat_member(self, def get_chat_member(self,
chat_id: int or str, chat_id: Union[int, str],
user_id: int or str): user_id: Union[int, str]):
"""Use this method to get information about one member of a chat. """Use this method to get information about one member of a chat.
Args: 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: if member.user.id == user_id.user_id:
return member return member
else: else:
@ -65,7 +67,7 @@ class GetChatMember(BaseClient):
) )
) )
return pyrogram.ChatMembers.parse( return pyrogram.ChatMembers._parse(
self, self,
types.channels.ChannelParticipants( types.channels.ChannelParticipants(
count=1, count=1,

View File

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

View File

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

View File

@ -23,7 +23,7 @@ from ...ext import BaseClient
class GetDialogs(BaseClient): class GetDialogs(BaseClient):
def get_dialogs(self, def get_dialogs(self,
offset_dialog=None, offset_dialog: "pyrogram.Dialog" = None,
limit: int = 100, limit: int = 100,
pinned_only: bool = False): pinned_only: bool = False):
"""Use this method to get the user's dialogs """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): 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. """Use this method to join a group chat or channel.
Args: Args:

View File

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

View File

@ -16,12 +16,17 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class PinChatMessage(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. """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 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. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class PromoteChatMember(BaseClient): class PromoteChatMember(BaseClient):
def promote_chat_member(self, def promote_chat_member(self,
chat_id: int or str, chat_id: Union[int, str],
user_id: int or str, user_id: Union[int, str],
can_change_info: bool = True, can_change_info: bool = True,
can_post_messages: bool = False, can_post_messages: bool = False,
can_edit_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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class RestrictChatMember(BaseClient): class RestrictChatMember(BaseClient):
def restrict_chat_member(self, def restrict_chat_member(self,
chat_id: int or str, chat_id: Union[int, str],
user_id: int or str, user_id: Union[int, str],
until_date: int = 0, until_date: int = 0,
can_send_messages: bool = False, can_send_messages: bool = False,
can_send_media_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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class SetChatDescription(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. """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. 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 import os
from base64 import b64decode from base64 import b64decode
from struct import unpack from struct import unpack
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class SetChatPhoto(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. """Use this method to set a new profile photo for the chat.
Photos can't be changed for private chats. 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. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class SetChatTitle(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. """Use this method to change the title of a chat.
Titles can't be changed for private chats. 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. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class UnbanChatMember(BaseClient): class UnbanChatMember(BaseClient):
def unban_chat_member(self, def unban_chat_member(self,
chat_id: int or str, chat_id: Union[int, str],
user_id: int or str): user_id: Union[int, str]):
"""Use this method to unban a previously kicked user in a supergroup or channel. """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. 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. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class UnpinChatMessage(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. """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 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. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import List
import pyrogram
from pyrogram.api import functions from pyrogram.api import functions
from ...ext import BaseClient from ...ext import BaseClient
class AddContacts(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. """Use this method to add contacts to your Telegram address book.
Args: Args:
contacts (``list``): contacts (List of :obj:`InputPhoneContact <pyrogram.InputPhoneContact>`):
A list of :obj:`InputPhoneContact <pyrogram.InputPhoneContact>` The contact list to be added
Returns: Returns:
On success, the added contacts are returned. 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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import List
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.api.errors import PeerIdInvalid from pyrogram.api.errors import PeerIdInvalid
from ...ext import BaseClient from ...ext import BaseClient
class DeleteContacts(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 """Use this method to delete contacts from your Telegram address book
Args: Args:
ids (``list``): ids (List of ``int``):
A list of unique identifiers for the target users. A list of unique identifiers for the target users.
Can be an ID (int), a username (string) or phone number (string). 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): 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 """Use this decorator to automatically register a function for handling
callback queries. This does the same thing as :meth:`add_handler` using the callback queries. This does the same thing as :meth:`add_handler` using the
:class:`CallbackQueryHandler`. :class:`CallbackQueryHandler`.

View File

@ -22,7 +22,9 @@ from ...ext import BaseClient
class OnDeletedMessages(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 """Use this decorator to automatically register a function for handling
deleted messages. This does the same thing as :meth:`add_handler` using the deleted messages. This does the same thing as :meth:`add_handler` using the
:class:`DeletedMessagesHandler`. :class:`DeletedMessagesHandler`.

View File

@ -22,7 +22,9 @@ from ...ext import BaseClient
class OnMessage(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 """Use this decorator to automatically register a function for handling
messages. This does the same thing as :meth:`add_handler` using the messages. This does the same thing as :meth:`add_handler` using the
:class:`MessageHandler`. :class:`MessageHandler`.

View File

@ -21,7 +21,8 @@ from ...ext import BaseClient
class OnRawUpdate(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 """Use this decorator to automatically register a function for handling
raw updates. This does the same thing as :meth:`add_handler` using the raw updates. This does the same thing as :meth:`add_handler` using the
:class:`RawUpdateHandler`. :class:`RawUpdateHandler`.

View File

@ -22,7 +22,9 @@ from ...ext import BaseClient
class OnUserStatus(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 """Use this decorator to automatically register a function for handling
user status updates. This does the same thing as :meth:`add_handler` using the user status updates. This does the same thing as :meth:`add_handler` using the
:class:`UserStatusHandler`. :class:`UserStatusHandler`.

View File

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

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes import mimetypes
import os import os
import struct import struct
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
@ -29,14 +30,15 @@ from pyrogram.client.types import (
InputMediaPhoto, InputMediaVideo, InputMediaAudio, InputMediaPhoto, InputMediaVideo, InputMediaAudio,
InputMediaAnimation, InputMediaDocument InputMediaAnimation, InputMediaDocument
) )
from pyrogram.client.types.input_media import InputMedia
class EditMessageMedia(BaseClient): class EditMessageMedia(BaseClient):
def edit_message_media(self, def edit_message_media(self,
chat_id: int or str, chat_id: Union[int, str],
message_id: int, message_id: int,
media, media: InputMedia,
reply_markup=None): reply_markup: "pyrogram.InlineKeyboardMarkup" = None):
"""Use this method to edit audio, document, photo, or video messages. """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, 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: for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient from pyrogram.client.ext import BaseClient
@ -23,9 +25,9 @@ from pyrogram.client.ext import BaseClient
class EditMessageReplyMarkup(BaseClient): class EditMessageReplyMarkup(BaseClient):
def edit_message_reply_markup(self, def edit_message_reply_markup(self,
chat_id: int or str, chat_id: Union[int, str],
message_id: int, 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). """Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
Args: Args:
@ -58,7 +60,7 @@ class EditMessageReplyMarkup(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient from pyrogram.client.ext import BaseClient
@ -23,12 +25,12 @@ from pyrogram.client.ext import BaseClient
class EditMessageText(BaseClient): class EditMessageText(BaseClient):
def edit_message_text(self, def edit_message_text(self,
chat_id: int or str, chat_id: Union[int, str],
message_id: int, message_id: int,
text: str, text: str,
parse_mode: str = "", parse_mode: str = "",
disable_web_page_preview: bool = None, disable_web_page_preview: bool = None,
reply_markup=None): reply_markup: "pyrogram.InlineKeyboardMarkup" = None):
"""Use this method to edit text messages. """Use this method to edit text messages.
Args: Args:
@ -74,7 +76,7 @@ class EditMessageText(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): if isinstance(i, (types.UpdateEditMessage, types.UpdateEditChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union, Iterable
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
@ -23,9 +25,9 @@ from ...ext import BaseClient
class ForwardMessages(BaseClient): class ForwardMessages(BaseClient):
def forward_messages(self, def forward_messages(self,
chat_id: int or str, chat_id: Union[int, str],
from_chat_id: int or str, from_chat_id: Union[int, str],
message_ids, message_ids: Iterable[int],
disable_notification: bool = None): disable_notification: bool = None):
"""Use this method to forward messages of any kind. """Use this method to forward messages of any kind.
@ -78,7 +80,7 @@ class ForwardMessages(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
messages.append( messages.append(
pyrogram.Message.parse( pyrogram.Message._parse(
self, i.message, self, i.message,
users, chats users, chats
) )

View File

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

View File

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

View File

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

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes import mimetypes
import os import os
import struct import struct
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
@ -29,7 +30,7 @@ from pyrogram.client.ext import BaseClient, utils
class SendAudio(BaseClient): class SendAudio(BaseClient):
def send_audio(self, def send_audio(self,
chat_id: int or str, chat_id: Union[int, str],
audio: str, audio: str,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
@ -39,7 +40,10 @@ class SendAudio(BaseClient):
thumb: str = None, thumb: str = None,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = 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: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send audio files. """Use this method to send audio files.
@ -185,7 +189,7 @@ class SendAudio(BaseClient):
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import functions from pyrogram.api import functions
from pyrogram.client.ext import BaseClient, ChatAction from pyrogram.client.ext import BaseClient, ChatAction
class SendChatAction(BaseClient): class SendChatAction(BaseClient):
def send_chat_action(self, def send_chat_action(self,
chat_id: int or str, chat_id: Union[int, str],
action: ChatAction or str, action: Union[ChatAction, str],
progress: int = 0): progress: int = 0):
"""Use this method when you need to tell the other party that something is happening on your side. """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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient from pyrogram.client.ext import BaseClient
@ -23,14 +25,17 @@ from pyrogram.client.ext import BaseClient
class SendContact(BaseClient): class SendContact(BaseClient):
def send_contact(self, def send_contact(self,
chat_id: int or str, chat_id: Union[int, str],
phone_number: str, phone_number: str,
first_name: str, first_name: str,
last_name: str = "", last_name: str = "",
vcard: str = "", vcard: str = "",
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = 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. """Use this method to send phone contacts.
Args: Args:
@ -87,7 +92,7 @@ class SendContact(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

@ -20,6 +20,7 @@ import binascii
import mimetypes import mimetypes
import os import os
import struct import struct
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
@ -29,14 +30,17 @@ from pyrogram.client.ext import BaseClient, utils
class SendDocument(BaseClient): class SendDocument(BaseClient):
def send_document(self, def send_document(self,
chat_id: int or str, chat_id: Union[int, str],
document: str, document: str,
thumb: str = None, thumb: str = None,
caption: str = "", caption: str = "",
parse_mode: str = "", parse_mode: str = "",
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = 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: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send general files. """Use this method to send general files.
@ -166,7 +170,7 @@ class SendDocument(BaseClient):
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient from pyrogram.client.ext import BaseClient
@ -23,12 +25,15 @@ from pyrogram.client.ext import BaseClient
class SendLocation(BaseClient): class SendLocation(BaseClient):
def send_location(self, def send_location(self,
chat_id: int or str, chat_id: Union[int, str],
latitude: float, latitude: float,
longitude: float, longitude: float,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = 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. """Use this method to send points on the map.
Args: Args:
@ -79,7 +84,7 @@ class SendLocation(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

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

View File

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

View File

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

View File

@ -19,6 +19,7 @@
import binascii import binascii
import os import os
import struct import struct
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
@ -28,11 +29,14 @@ from pyrogram.client.ext import BaseClient, utils
class SendSticker(BaseClient): class SendSticker(BaseClient):
def send_sticker(self, def send_sticker(self,
chat_id: int or str, chat_id: Union[int, str],
sticker: str, sticker: str,
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = 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: callable = None,
progress_args: tuple = ()): progress_args: tuple = ()):
"""Use this method to send .webp stickers. """Use this method to send .webp stickers.
@ -145,7 +149,7 @@ class SendSticker(BaseClient):
else: else:
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {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 # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram import pyrogram
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient from pyrogram.client.ext import BaseClient
@ -23,7 +25,7 @@ from pyrogram.client.ext import BaseClient
class SendVenue(BaseClient): class SendVenue(BaseClient):
def send_venue(self, def send_venue(self,
chat_id: int or str, chat_id: Union[int, str],
latitude: float, latitude: float,
longitude: float, longitude: float,
title: str, title: str,
@ -32,7 +34,10 @@ class SendVenue(BaseClient):
foursquare_type: str = "", foursquare_type: str = "",
disable_notification: bool = None, disable_notification: bool = None,
reply_to_message_id: int = 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. """Use this method to send information about a venue.
Args: Args:
@ -101,7 +106,7 @@ class SendVenue(BaseClient):
for i in r.updates: for i in r.updates:
if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)):
return pyrogram.Message.parse( return pyrogram.Message._parse(
self, i.message, self, i.message,
{i.id: i for i in r.users}, {i.id: i for i in r.users},
{i.id: i for i in r.chats} {i.id: i for i in r.chats}

View File

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

View File

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

View File

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

View File

@ -24,7 +24,10 @@ from ...ext import BaseClient
class ChangeCloudPassword(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. """Use this method to change your Two-Step Verification password (Cloud Password) with a new one.
Args: Args:

View File

@ -24,7 +24,10 @@ from ...ext import BaseClient
class EnableCloudPassword(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. """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. 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): 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. """Use this method to turn off the Two-Step Verification security feature (Cloud Password) on your account.
Args: Args:

View File

@ -18,13 +18,15 @@
from base64 import b64decode from base64 import b64decode
from struct import unpack from struct import unpack
from typing import List, Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from ...ext import BaseClient from ...ext import BaseClient
class DeleteUserProfilePhotos(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 """Use this method to delete your own profile photos
Args: Args:

View File

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

View File

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

View File

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

View File

@ -21,7 +21,8 @@ from ...ext import BaseClient
class SetUserProfilePhoto(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. """Use this method to set a new profile photo.
This method only works for Users. This method only works for Users.

View File

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

View File

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