Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 108 additions & 31 deletions compiler/api/source/main_api.tl

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions compiler/errors/source/400_BAD_REQUEST.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ CHANNEL_TOO_LARGE The channel is too large
CHAT_ABOUT_NOT_MODIFIED The chat about text was not modified because you tried to edit it using the same content
CHAT_ABOUT_TOO_LONG The chat about text is too long
CHAT_ADMIN_REQUIRED The method requires chat admin privileges
CHAT_DISCUSSION_UNALLOWED The chat discussion is not allowed
CHAT_FORWARDS_RESTRICTED The chat restricts forwarding content
CHAT_ID_EMPTY The provided chat id is empty
CHAT_ID_INVALID The chat id being used is invalid or not known yet. Make sure you see the chat before interacting with it
Expand Down Expand Up @@ -168,9 +169,12 @@ MAX_QTS_INVALID The provided QTS is invalid
MD5_CHECKSUM_INVALID The file's checksum did not match the md5_checksum parameter
MEDIA_CAPTION_TOO_LONG The media caption is too long
MEDIA_EMPTY The media you tried to send is invalid
MEDIA_FILE_INVALID The provided media file is invalid
MEDIA_INVALID The media is invalid
MEDIA_NEW_INVALID The new media to edit the message with is invalid
MEDIA_PREV_INVALID The previous media cannot be edited with anything else
MEDIA_TTL_INVALID The media ttl is invalid
MEDIA_VIDEO_STORY_MISSING The media does not have a photo or a video
MEGAGROUP_ID_INVALID The supergroup is invalid
MEGAGROUP_PREHISTORY_HIDDEN The action failed because the supergroup has the pre-history hidden
MEGAGROUP_REQUIRED The request can only be used with a supergroup
Expand All @@ -183,6 +187,7 @@ MESSAGE_POLL_CLOSED You can't interact with a closed poll
MESSAGE_TOO_LONG The message text is too long
METHOD_INVALID The API method is invalid and cannot be used
MSG_ID_INVALID The message ID used in the peer was invalid
MSG_VOICE_MISSING The message does not contain a voice message
MSG_WAIT_FAILED A waiting call returned an error
MULTI_MEDIA_TOO_LONG The album/media group contains too many items
NEW_SALT_INVALID The new salt is invalid
Expand Down Expand Up @@ -240,6 +245,7 @@ POLL_OPTION_INVALID A poll option used invalid data (the data may be too long)
POLL_QUESTION_INVALID The poll question is invalid
POLL_UNSUPPORTED This layer does not support polls in the invoked method
POLL_VOTE_REQUIRED Cast a vote in the poll before calling this method
PREMIUM_ACCOUNT_REQUIRED The method requires a premium user account
PRIVACY_KEY_INVALID The privacy key is invalid
PRIVACY_TOO_LONG Your privacy exception list has exceeded the maximum capacity
PRIVACY_VALUE_INVALID The privacy value is invalid
Expand Down Expand Up @@ -302,6 +308,7 @@ STICKER_PNG_NOPNG Stickers must be png files but the provided image was not a pn
STICKER_TGS_NOTGS A tgs sticker file was expected, but something else was provided
STICKER_THUMB_PNG_NOPNG A png sticker thumbnail file was expected, but something else was provided
STICKER_VIDEO_NOWEBM A webm video file was expected, but something else was provided
STORIES_TOO_MUCH Too many stories in the current account
TAKEOUT_INVALID The takeout id is invalid
TAKEOUT_REQUIRED The method must be invoked inside a takeout session
TEMP_AUTH_KEY_EMPTY The temporary auth key provided is empty
Expand All @@ -312,6 +319,7 @@ THEME_MIME_INVALID You cannot create this theme because the mime-type is invalid
TMP_PASSWORD_DISABLED The temporary password is disabled
TMP_PASSWORD_INVALID The temporary password is invalid
TOKEN_INVALID The provided token is invalid
TRANSCRIPTION_FAILED Telegram is having internal problems. Please try again later to transcribe the audio.
TTL_DAYS_INVALID The provided TTL days is invalid
TTL_MEDIA_INVALID The media does not support self-destruction
TYPES_EMPTY The types parameter is empty
Expand Down Expand Up @@ -361,3 +369,6 @@ WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media
YOU_BLOCKED_USER You blocked this user
TOPIC_DELETED The specified topic was deleted
TOPIC_CLOSED This topic was closed, you can't send messages to it anymore
STORIES_NEVER_CREATED You have never created any stories
STORIES_TOO_MUCH Too many stories posted by the user
GROUPCALL_FORBIDDEN The group call has already ended.
3 changes: 2 additions & 1 deletion compiler/errors/source/403_FORBIDDEN.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ CHAT_SEND_STICKERS_FORBIDDEN You can't send stickers in this chat
CHAT_SEND_VIDEOS_FORBIDDEN You can't send videos in this chat
CHAT_SEND_VOICES_FORBIDDEN You can't send voice recordings in this chat
CHAT_WRITE_FORBIDDEN You can't write in this chat
GROUPCALL_FORBIDDEN The group call has already ended
GROUPCALL_FORBIDDEN The group call has already ended
LIVE_DISABLED Story is disabled server-side
2 changes: 1 addition & 1 deletion compiler/errors/source/503_SERVICE_UNAVAILABLE.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id message
ApiCallError Telegram is having internal problems. Please try again later.
Timeout Telegram is having internal problems. Please try again later.
Timedout Telegram is having internal problems. Please try again later.
Timedout Telegram is having internal problems. Please try again later.
2 changes: 1 addition & 1 deletion pyrogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

__version__ = "2.0.106"
__version__ = "2.0.107"
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
__copyright__ = "Copyright (C) 2017-present Dan <https://github.com/delivrance>"

Expand Down
8 changes: 7 additions & 1 deletion pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class Client(Methods):
Number of maximum concurrent workers for handling incoming updates.
Defaults to ``min(32, os.cpu_count() + 4)``.

message_cache (``int``, *optional*):
Number of maximum incoming messages to cache.
Cached messages are used in answering callback queries and replying to old messages.
Defaults to 10000 messages.

workdir (``str``, *optional*):
Define a custom working directory.
The working directory is the location in the filesystem where Pyrogram will store the session files.
Expand Down Expand Up @@ -218,6 +223,7 @@ def __init__(
phone_code: str = None,
password: str = None,
workers: int = WORKERS,
message_cache: int = 10000,
workdir: str = WORKDIR,
plugins: dict = None,
parse_mode: "enums.ParseMode" = enums.ParseMode.DEFAULT,
Expand Down Expand Up @@ -287,7 +293,7 @@ def __init__(

self.me: Optional[User] = None

self.message_cache = Cache(10000)
self.message_cache = Cache(message_cache)

# Sometimes, for some reason, the server will stop sending updates and will only respond to pings.
# This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again
Expand Down
3 changes: 3 additions & 0 deletions pyrogram/enums/chat_members_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ class ChatMembersFilter(AutoName):

ADMINISTRATORS = raw.types.ChannelParticipantsAdmins
"Administrators"

DELETED = raw.types.ChannelParticipantsBanned
"Deleted accounts"
12 changes: 9 additions & 3 deletions pyrogram/methods/bots/send_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from typing import Union

import pyrogram
from pyrogram import raw
from pyrogram import types
from pyrogram import raw, utils, types


class SendGame:
Expand All @@ -30,6 +29,7 @@ async def send_game(
game_short_name: str,
disable_notification: bool = None,
reply_to_message_id: int = None,
message_thread_id: int = None,
protect_content: bool = None,
reply_markup: Union[
"types.InlineKeyboardMarkup",
Expand Down Expand Up @@ -58,6 +58,9 @@ async def send_game(
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.

message_thread_id (``int``, *optional*):
If the message is in a thread, ID of the original message.

protect_content (``bool``, *optional*):
Protects the contents of the sent message from forwarding and saving.

Expand All @@ -73,6 +76,9 @@ async def send_game(

await app.send_game(chat_id, "gamename")
"""

reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)

r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
Expand All @@ -84,7 +90,7 @@ async def send_game(
),
message="",
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
reply_to=reply_to,
random_id=self.rnd_id(),
noforwards=protect_content,
reply_markup=await reply_markup.write(self) if reply_markup else None
Expand Down
15 changes: 11 additions & 4 deletions pyrogram/methods/bots/send_inline_bot_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Union

import pyrogram
from pyrogram import raw
from pyrogram import raw, utils


class SendInlineBotResult:
Expand All @@ -29,7 +29,8 @@ async def send_inline_bot_result(
query_id: int,
result_id: str,
disable_notification: bool = None,
reply_to_message_id: int = None
reply_to_message_id: int = None,
message_thread_id: int = None
) -> "raw.base.Updates":
"""Send an inline bot result.
Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results`
Expand All @@ -52,9 +53,12 @@ async def send_inline_bot_result(
Sends the message silently.
Users will receive a notification with no sound.

reply_to_message_id (``bool``, *optional*):
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.

message_thread_id (``int``, *optional*):
If the message is in a thread, ID of the original message.

Returns:
:obj:`~pyrogram.raw.base.Updates`: Currently, on success, a raw result is returned.

Expand All @@ -63,13 +67,16 @@ async def send_inline_bot_result(

await app.send_inline_bot_result(chat_id, query_id, result_id)
"""

reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)

return await self.invoke(
raw.functions.messages.SendInlineBotResult(
peer=await self.resolve_peer(chat_id),
query_id=query_id,
id=result_id,
random_id=self.rnd_id(),
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id
reply_to=reply_to
)
)
2 changes: 1 addition & 1 deletion pyrogram/methods/chats/join_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def join_chat(
else:
chat = await self.invoke(
raw.functions.channels.JoinChannel(
channel=await self.resolve_peer(chat_id)
channel=await self.resolve_peer(chat_id.split('/')[-1])
)
)

Expand Down
8 changes: 7 additions & 1 deletion pyrogram/methods/messages/copy_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def copy_media_group(
captions: Union[List[str], str] = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
message_thread_id: int = None,
schedule_date: datetime = None,
) -> List["types.Message"]:
"""Copy a media group by providing one of the message ids.
Expand Down Expand Up @@ -68,6 +69,9 @@ async def copy_media_group(
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.

message_thread_id (``int``, *optional*):
If the message is in a thread, ID of the original message.

schedule_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the message will be automatically sent.

Expand Down Expand Up @@ -114,12 +118,14 @@ async def copy_media_group(
)
)

reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)

r = await self.invoke(
raw.functions.messages.SendMultiMedia(
peer=await self.resolve_peer(chat_id),
multi_media=multi_media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
reply_to=reply_to,
schedule_date=utils.datetime_to_timestamp(schedule_date)
),
sleep_threshold=60
Expand Down
3 changes: 2 additions & 1 deletion pyrogram/methods/messages/edit_inline_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ async def edit_inline_media(
"""
caption = media.caption
parse_mode = media.parse_mode
caption_entities = media.caption_entities

is_bytes_io = isinstance(media.media, io.BytesIO)
is_uploaded_file = is_bytes_io or os.path.isfile(media.media)
Expand Down Expand Up @@ -231,7 +232,7 @@ async def edit_inline_media(
id=unpacked,
media=actual_media,
reply_markup=await reply_markup.write(self) if reply_markup else None,
**await self.parser.parse(caption, parse_mode)
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
),
sleep_threshold=self.sleep_threshold
)
Expand Down
8 changes: 6 additions & 2 deletions pyrogram/methods/messages/edit_inline_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# 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 Optional
from typing import Optional, List

import pyrogram
from pyrogram import raw, enums
Expand All @@ -31,6 +31,7 @@ async def edit_inline_text(
inline_message_id: str,
text: str,
parse_mode: Optional["enums.ParseMode"] = None,
entities: List["types.MessageEntity"] = None,
disable_web_page_preview: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None
) -> bool:
Expand All @@ -49,6 +50,9 @@ async def edit_inline_text(
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.

entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in message text, which can be specified instead of *parse_mode*.

disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.

Expand Down Expand Up @@ -82,7 +86,7 @@ async def edit_inline_text(
id=unpacked,
no_webpage=disable_web_page_preview or None,
reply_markup=await reply_markup.write(self) if reply_markup else None,
**await self.parser.parse(text, parse_mode)
**await utils.parse_text_entities(self, text, parse_mode, entities)
),
sleep_threshold=self.sleep_threshold
)
3 changes: 2 additions & 1 deletion pyrogram/methods/messages/edit_message_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ async def edit_message_media(
"""
caption = media.caption
parse_mode = media.parse_mode
caption_entities = media.caption_entities

message, entities = None, None

if caption is not None:
message, entities = (await self.parser.parse(caption, parse_mode)).values()
message, entities = (await utils.parse_text_entities(self, caption, parse_mode, caption_entities)).values()

if isinstance(media, types.InputMediaPhoto):
if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media):
Expand Down
8 changes: 7 additions & 1 deletion pyrogram/methods/messages/send_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async def send_animation(
file_name: str = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
message_thread_id: int = None,
schedule_date: datetime = None,
protect_content: bool = None,
reply_markup: Union[
Expand Down Expand Up @@ -118,6 +119,9 @@ async def send_animation(
reply_to_message_id (``int``, *optional*):
If the message is a reply, ID of the original message.

message_thread_id (``int``, *optional*):
If the message is in a thread, ID of the original message.

schedule_date (:py:obj:`~datetime.datetime`, *optional*):
Date when the message will be automatically sent.

Expand Down Expand Up @@ -223,14 +227,16 @@ async def progress(current, total):
]
)

reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)

while True:
try:
r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
media=media,
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
reply_to=reply_to,
random_id=self.rnd_id(),
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
Expand Down
Loading