Skip to content

Commit d916aaa

Browse files
null-nickSpEcHiDebarsikus007alissonlaufferdanigbaameiro
authored
Update to Layer 161 + Added New Errors + Some BugFixes (#9)
* Update API schema to Layer 160 * Added some story error * Renamed `reply_to_msg_id` to `reply_to` * Added some new error * SomeFixes with Layer160 Co-Authored-By: Shrimadhav U K <SpEcHiDe@users.noreply.github.com> * Add missing `caption_entities` parameters and `utils.parse_text_entities calls` PR (pyrogram#1253) * Add `full_name` property to `User` and `Chat` objects PR (pyrogram#1194) * Version bump to `2.0.107` * Improvements to automate tasks using pyrogram When a user has automated reading of chats/channels/groups content or has the message handler active, the links to the channels usually also appear in the following format: "https://t.me/telegram". Right now, we get a 400 error if we want to authenticate using the "https://t.me/telegram" link. With this improvement in line 70, the user can use either just the public channel nickname or the full link. It makes it easier for the user to use any type of link and he will have no problem accessing it. With this change, apart from improving the usability of the library, some issues such as "https://github.com/pyrogram/pyrogram/issues/1077" from August 2022 are also fixed. * Add `MEDIA_FILE_INVALID` to known errors * Control the number of cached messages via `message_cache` in Client This commit adds the optional parameter message_cache to Client to control the number of cached messages. This can significantly help low-end machines control their memory usage. * Update API scheme on layer 161 * Added some new errors + BugFixes Co-Authored-By: Shrimadhav U K <SpEcHiDe@users.noreply.github.com> * Update API scheme on layer 161 (v2) --------- Co-authored-by: Shrimadhav U K <SpEcHiDe@users.noreply.github.com> Co-authored-by: barsikus007 <barsikus07@gmail.com> Co-authored-by: Alisson Lauffer <alissonvitortc@gmail.com> Co-authored-by: Daniel García Baameiro <dagaba13@gmail.com> Co-authored-by: KurimuzonAkuma <arturgayauskas@gmail.com> Co-authored-by: k4rim <49250671+xk4rim@users.noreply.github.com>
1 parent b956e14 commit d916aaa

36 files changed

Lines changed: 340 additions & 76 deletions

compiler/api/source/main_api.tl

Lines changed: 108 additions & 31 deletions
Large diffs are not rendered by default.

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ CHANNEL_TOO_LARGE The channel is too large
5555
CHAT_ABOUT_NOT_MODIFIED The chat about text was not modified because you tried to edit it using the same content
5656
CHAT_ABOUT_TOO_LONG The chat about text is too long
5757
CHAT_ADMIN_REQUIRED The method requires chat admin privileges
58+
CHAT_DISCUSSION_UNALLOWED The chat discussion is not allowed
5859
CHAT_FORWARDS_RESTRICTED The chat restricts forwarding content
5960
CHAT_ID_EMPTY The provided chat id is empty
6061
CHAT_ID_INVALID The chat id being used is invalid or not known yet. Make sure you see the chat before interacting with it
@@ -168,9 +169,12 @@ MAX_QTS_INVALID The provided QTS is invalid
168169
MD5_CHECKSUM_INVALID The file's checksum did not match the md5_checksum parameter
169170
MEDIA_CAPTION_TOO_LONG The media caption is too long
170171
MEDIA_EMPTY The media you tried to send is invalid
172+
MEDIA_FILE_INVALID The provided media file is invalid
171173
MEDIA_INVALID The media is invalid
172174
MEDIA_NEW_INVALID The new media to edit the message with is invalid
173175
MEDIA_PREV_INVALID The previous media cannot be edited with anything else
176+
MEDIA_TTL_INVALID The media ttl is invalid
177+
MEDIA_VIDEO_STORY_MISSING The media does not have a photo or a video
174178
MEGAGROUP_ID_INVALID The supergroup is invalid
175179
MEGAGROUP_PREHISTORY_HIDDEN The action failed because the supergroup has the pre-history hidden
176180
MEGAGROUP_REQUIRED The request can only be used with a supergroup
@@ -183,6 +187,7 @@ MESSAGE_POLL_CLOSED You can't interact with a closed poll
183187
MESSAGE_TOO_LONG The message text is too long
184188
METHOD_INVALID The API method is invalid and cannot be used
185189
MSG_ID_INVALID The message ID used in the peer was invalid
190+
MSG_VOICE_MISSING The message does not contain a voice message
186191
MSG_WAIT_FAILED A waiting call returned an error
187192
MULTI_MEDIA_TOO_LONG The album/media group contains too many items
188193
NEW_SALT_INVALID The new salt is invalid
@@ -240,6 +245,7 @@ POLL_OPTION_INVALID A poll option used invalid data (the data may be too long)
240245
POLL_QUESTION_INVALID The poll question is invalid
241246
POLL_UNSUPPORTED This layer does not support polls in the invoked method
242247
POLL_VOTE_REQUIRED Cast a vote in the poll before calling this method
248+
PREMIUM_ACCOUNT_REQUIRED The method requires a premium user account
243249
PRIVACY_KEY_INVALID The privacy key is invalid
244250
PRIVACY_TOO_LONG Your privacy exception list has exceeded the maximum capacity
245251
PRIVACY_VALUE_INVALID The privacy value is invalid
@@ -302,6 +308,7 @@ STICKER_PNG_NOPNG Stickers must be png files but the provided image was not a pn
302308
STICKER_TGS_NOTGS A tgs sticker file was expected, but something else was provided
303309
STICKER_THUMB_PNG_NOPNG A png sticker thumbnail file was expected, but something else was provided
304310
STICKER_VIDEO_NOWEBM A webm video file was expected, but something else was provided
311+
STORIES_TOO_MUCH Too many stories in the current account
305312
TAKEOUT_INVALID The takeout id is invalid
306313
TAKEOUT_REQUIRED The method must be invoked inside a takeout session
307314
TEMP_AUTH_KEY_EMPTY The temporary auth key provided is empty
@@ -312,6 +319,7 @@ THEME_MIME_INVALID You cannot create this theme because the mime-type is invalid
312319
TMP_PASSWORD_DISABLED The temporary password is disabled
313320
TMP_PASSWORD_INVALID The temporary password is invalid
314321
TOKEN_INVALID The provided token is invalid
322+
TRANSCRIPTION_FAILED Telegram is having internal problems. Please try again later to transcribe the audio.
315323
TTL_DAYS_INVALID The provided TTL days is invalid
316324
TTL_MEDIA_INVALID The media does not support self-destruction
317325
TYPES_EMPTY The types parameter is empty
@@ -361,3 +369,6 @@ WEBPAGE_MEDIA_EMPTY The URL doesn't contain any valid media
361369
YOU_BLOCKED_USER You blocked this user
362370
TOPIC_DELETED The specified topic was deleted
363371
TOPIC_CLOSED This topic was closed, you can't send messages to it anymore
372+
STORIES_NEVER_CREATED You have never created any stories
373+
STORIES_TOO_MUCH Too many stories posted by the user
374+
GROUPCALL_FORBIDDEN The group call has already ended.

compiler/errors/source/403_FORBIDDEN.tsv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ CHAT_SEND_STICKERS_FORBIDDEN You can't send stickers in this chat
3737
CHAT_SEND_VIDEOS_FORBIDDEN You can't send videos in this chat
3838
CHAT_SEND_VOICES_FORBIDDEN You can't send voice recordings in this chat
3939
CHAT_WRITE_FORBIDDEN You can't write in this chat
40-
GROUPCALL_FORBIDDEN The group call has already ended
40+
GROUPCALL_FORBIDDEN The group call has already ended
41+
LIVE_DISABLED Story is disabled server-side
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
id message
22
ApiCallError Telegram is having internal problems. Please try again later.
33
Timeout Telegram is having internal problems. Please try again later.
4-
Timedout Telegram is having internal problems. Please try again later.
4+
Timedout Telegram is having internal problems. Please try again later.

pyrogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

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

pyrogram/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ class Client(Methods):
137137
Number of maximum concurrent workers for handling incoming updates.
138138
Defaults to ``min(32, os.cpu_count() + 4)``.
139139
140+
message_cache (``int``, *optional*):
141+
Number of maximum incoming messages to cache.
142+
Cached messages are used in answering callback queries and replying to old messages.
143+
Defaults to 10000 messages.
144+
140145
workdir (``str``, *optional*):
141146
Define a custom working directory.
142147
The working directory is the location in the filesystem where Pyrogram will store the session files.
@@ -218,6 +223,7 @@ def __init__(
218223
phone_code: str = None,
219224
password: str = None,
220225
workers: int = WORKERS,
226+
message_cache: int = 10000,
221227
workdir: str = WORKDIR,
222228
plugins: dict = None,
223229
parse_mode: "enums.ParseMode" = enums.ParseMode.DEFAULT,
@@ -287,7 +293,7 @@ def __init__(
287293

288294
self.me: Optional[User] = None
289295

290-
self.message_cache = Cache(10000)
296+
self.message_cache = Cache(message_cache)
291297

292298
# Sometimes, for some reason, the server will stop sending updates and will only respond to pings.
293299
# This watchdog will invoke updates.GetState in order to wake up the server and enable it sending updates again

pyrogram/enums/chat_members_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ class ChatMembersFilter(AutoName):
4040

4141
ADMINISTRATORS = raw.types.ChannelParticipantsAdmins
4242
"Administrators"
43+
44+
DELETED = raw.types.ChannelParticipantsBanned
45+
"Deleted accounts"

pyrogram/methods/bots/send_game.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from typing import Union
2020

2121
import pyrogram
22-
from pyrogram import raw
23-
from pyrogram import types
22+
from pyrogram import raw, utils, types
2423

2524

2625
class SendGame:
@@ -30,6 +29,7 @@ async def send_game(
3029
game_short_name: str,
3130
disable_notification: bool = None,
3231
reply_to_message_id: int = None,
32+
message_thread_id: int = None,
3333
protect_content: bool = None,
3434
reply_markup: Union[
3535
"types.InlineKeyboardMarkup",
@@ -58,6 +58,9 @@ async def send_game(
5858
reply_to_message_id (``int``, *optional*):
5959
If the message is a reply, ID of the original message.
6060
61+
message_thread_id (``int``, *optional*):
62+
If the message is in a thread, ID of the original message.
63+
6164
protect_content (``bool``, *optional*):
6265
Protects the contents of the sent message from forwarding and saving.
6366
@@ -73,6 +76,9 @@ async def send_game(
7376
7477
await app.send_game(chat_id, "gamename")
7578
"""
79+
80+
reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)
81+
7682
r = await self.invoke(
7783
raw.functions.messages.SendMedia(
7884
peer=await self.resolve_peer(chat_id),
@@ -84,7 +90,7 @@ async def send_game(
8490
),
8591
message="",
8692
silent=disable_notification or None,
87-
reply_to_msg_id=reply_to_message_id,
93+
reply_to=reply_to,
8894
random_id=self.rnd_id(),
8995
noforwards=protect_content,
9096
reply_markup=await reply_markup.write(self) if reply_markup else None

pyrogram/methods/bots/send_inline_bot_result.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing import Union
2020

2121
import pyrogram
22-
from pyrogram import raw
22+
from pyrogram import raw, utils
2323

2424

2525
class SendInlineBotResult:
@@ -29,7 +29,8 @@ async def send_inline_bot_result(
2929
query_id: int,
3030
result_id: str,
3131
disable_notification: bool = None,
32-
reply_to_message_id: int = None
32+
reply_to_message_id: int = None,
33+
message_thread_id: int = None
3334
) -> "raw.base.Updates":
3435
"""Send an inline bot result.
3536
Bot results can be retrieved using :meth:`~pyrogram.Client.get_inline_bot_results`
@@ -52,9 +53,12 @@ async def send_inline_bot_result(
5253
Sends the message silently.
5354
Users will receive a notification with no sound.
5455
55-
reply_to_message_id (``bool``, *optional*):
56+
reply_to_message_id (``int``, *optional*):
5657
If the message is a reply, ID of the original message.
5758
59+
message_thread_id (``int``, *optional*):
60+
If the message is in a thread, ID of the original message.
61+
5862
Returns:
5963
:obj:`~pyrogram.raw.base.Updates`: Currently, on success, a raw result is returned.
6064
@@ -63,13 +67,16 @@ async def send_inline_bot_result(
6367
6468
await app.send_inline_bot_result(chat_id, query_id, result_id)
6569
"""
70+
71+
reply_to = utils.get_reply_head_fm(message_thread_id, reply_to_message_id)
72+
6673
return await self.invoke(
6774
raw.functions.messages.SendInlineBotResult(
6875
peer=await self.resolve_peer(chat_id),
6976
query_id=query_id,
7077
id=result_id,
7178
random_id=self.rnd_id(),
7279
silent=disable_notification or None,
73-
reply_to_msg_id=reply_to_message_id
80+
reply_to=reply_to
7481
)
7582
)

pyrogram/methods/chats/join_chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def join_chat(
6767
else:
6868
chat = await self.invoke(
6969
raw.functions.channels.JoinChannel(
70-
channel=await self.resolve_peer(chat_id)
70+
channel=await self.resolve_peer(chat_id.split('/')[-1])
7171
)
7272
)
7373

0 commit comments

Comments
 (0)