Skip to content

Commit 384f4eb

Browse files
committed
Add support for manual text entities.
1 parent 72db61a commit 384f4eb

18 files changed

+270
-59
lines changed

pyrogram/methods/messages/edit_message_caption.py

Lines changed: 6 additions & 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-
from typing import Union
19+
from typing import Union, List
2020

2121
from pyrogram import types
2222
from pyrogram.scaffold import Scaffold
@@ -29,6 +29,7 @@ async def edit_message_caption(
2929
message_id: int,
3030
caption: str,
3131
parse_mode: Union[str, None] = object,
32+
caption_entities: List["types.MessageEntity"] = None,
3233
reply_markup: "types.InlineKeyboardMarkup" = None
3334
) -> "types.Message":
3435
"""Edit the caption of media messages.
@@ -52,6 +53,9 @@ async def edit_message_caption(
5253
Pass "html" to enable HTML-style parsing only.
5354
Pass None to completely disable style parsing.
5455
56+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
57+
List of special entities that appear in the caption, which can be specified instead of __parse_mode__.
58+
5559
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
5660
An InlineKeyboardMarkup object.
5761
@@ -68,5 +72,6 @@ async def edit_message_caption(
6872
message_id=message_id,
6973
text=caption,
7074
parse_mode=parse_mode,
75+
entities=caption_entities,
7176
reply_markup=reply_markup
7277
)

pyrogram/methods/messages/edit_message_text.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
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-
from typing import Union
19+
from typing import Union, List
2020

2121
from pyrogram import raw
2222
from pyrogram import types
23+
from pyrogram import utils
2324
from pyrogram.scaffold import Scaffold
2425

2526

@@ -30,6 +31,7 @@ async def edit_message_text(
3031
message_id: int,
3132
text: str,
3233
parse_mode: Union[str, None] = object,
34+
entities: List["types.MessageEntity"] = None,
3335
disable_web_page_preview: bool = None,
3436
reply_markup: "types.InlineKeyboardMarkup" = None
3537
) -> "types.Message":
@@ -54,6 +56,9 @@ async def edit_message_text(
5456
Pass "html" to enable HTML-style parsing only.
5557
Pass None to completely disable style parsing.
5658
59+
entities (List of :obj:`~pyrogram.types.MessageEntity`):
60+
List of special entities that appear in message text, which can be specified instead of __parse_mode__.
61+
5762
disable_web_page_preview (``bool``, *optional*):
5863
Disables link previews for links in this message.
5964
@@ -81,7 +86,7 @@ async def edit_message_text(
8186
id=message_id,
8287
no_webpage=disable_web_page_preview or None,
8388
reply_markup=reply_markup.write() if reply_markup else None,
84-
**await self.parser.parse(text, parse_mode)
89+
**await utils.parse_text_entities(self, text, parse_mode, entities)
8590
)
8691
)
8792

pyrogram/methods/messages/send_animation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import os
2020
import re
21-
from typing import Union, BinaryIO
21+
from typing import Union, BinaryIO, List
2222

2323
from pyrogram import StopTransmission
2424
from pyrogram import raw
@@ -37,6 +37,7 @@ async def send_animation(
3737
caption: str = "",
3838
unsave: bool = False,
3939
parse_mode: Union[str, None] = object,
40+
caption_entities: List["types.MessageEntity"] = None,
4041
duration: int = 0,
4142
width: int = 0,
4243
height: int = 0,
@@ -83,6 +84,9 @@ async def send_animation(
8384
Pass "html" to enable HTML-style parsing only.
8485
Pass None to completely disable style parsing.
8586
87+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
88+
List of special entities that appear in the caption, which can be specified instead of __parse_mode__.
89+
8690
duration (``int``, *optional*):
8791
Duration of sent animation in seconds.
8892
@@ -219,7 +223,7 @@ def progress(current, total):
219223
random_id=self.rnd_id(),
220224
schedule_date=schedule_date,
221225
reply_markup=reply_markup.write() if reply_markup else None,
222-
**await self.parser.parse(caption, parse_mode)
226+
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
223227
)
224228
)
225229
except FilePartMissing as e:

pyrogram/methods/messages/send_audio.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import os
2020
import re
21-
from typing import Union, BinaryIO
21+
from typing import Union, BinaryIO, List
2222

2323
from pyrogram import StopTransmission
2424
from pyrogram import raw
@@ -36,10 +36,12 @@ async def send_audio(
3636
audio: Union[str, BinaryIO],
3737
caption: str = "",
3838
parse_mode: Union[str, None] = object,
39+
caption_entities: List["types.MessageEntity"] = None,
3940
duration: int = 0,
4041
performer: str = None,
4142
title: str = None,
42-
thumb: Union[str, BinaryIO] = None, file_name: str = None,
43+
thumb: Union[str, BinaryIO] = None,
44+
file_name: str = None,
4345
disable_notification: bool = None,
4446
reply_to_message_id: int = None,
4547
schedule_date: int = None,
@@ -79,6 +81,9 @@ async def send_audio(
7981
Pass "html" to enable HTML-style parsing only.
8082
Pass None to completely disable style parsing.
8183
84+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
85+
List of special entities that appear in the caption, which can be specified instead of __parse_mode__.
86+
8287
duration (``int``, *optional*):
8388
Duration of the audio in seconds.
8489
@@ -213,7 +218,7 @@ def progress(current, total):
213218
random_id=self.rnd_id(),
214219
schedule_date=schedule_date,
215220
reply_markup=reply_markup.write() if reply_markup else None,
216-
**await self.parser.parse(caption, parse_mode)
221+
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
217222
)
218223
)
219224
except FilePartMissing as e:

pyrogram/methods/messages/send_document.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import os
2020
import re
21-
from typing import Union, BinaryIO
21+
from typing import Union, BinaryIO, List
2222

2323
from pyrogram import StopTransmission
2424
from pyrogram import raw
@@ -37,6 +37,7 @@ async def send_document(
3737
thumb: Union[str, BinaryIO] = None,
3838
caption: str = "",
3939
parse_mode: Union[str, None] = object,
40+
caption_entities: List["types.MessageEntity"] = None,
4041
file_name: str = None,
4142
force_document: bool = None,
4243
disable_notification: bool = None,
@@ -82,6 +83,9 @@ async def send_document(
8283
Pass "html" to enable HTML-style parsing only.
8384
Pass None to completely disable style parsing.
8485
86+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
87+
List of special entities that appear in the caption, which can be specified instead of __parse_mode__.
88+
8589
file_name (``str``, *optional*):
8690
File name of the document sent.
8791
Defaults to file's path basename.
@@ -191,7 +195,7 @@ def progress(current, total):
191195
random_id=self.rnd_id(),
192196
schedule_date=schedule_date,
193197
reply_markup=reply_markup.write() if reply_markup else None,
194-
**await self.parser.parse(caption, parse_mode)
198+
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
195199
)
196200
)
197201
except FilePartMissing as e:

pyrogram/methods/messages/send_message.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
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-
from typing import Union
19+
from typing import Union, List
2020

21-
from pyrogram import raw
21+
from pyrogram import raw, utils
2222
from pyrogram import types
2323
from pyrogram.scaffold import Scaffold
2424

@@ -29,6 +29,7 @@ async def send_message(
2929
chat_id: Union[int, str],
3030
text: str,
3131
parse_mode: Union[str, None] = object,
32+
entities: List["types.MessageEntity"] = None,
3233
disable_web_page_preview: bool = None,
3334
disable_notification: bool = None,
3435
reply_to_message_id: int = None,
@@ -58,6 +59,9 @@ async def send_message(
5859
Pass "html" to enable HTML-style parsing only.
5960
Pass None to completely disable style parsing.
6061
62+
entities (List of :obj:`~pyrogram.types.MessageEntity`):
63+
List of special entities that appear in message text, which can be specified instead of __parse_mode__.
64+
6165
disable_web_page_preview (``bool``, *optional*):
6266
Disables link previews for links in this message.
6367
@@ -116,7 +120,7 @@ async def send_message(
116120
]))
117121
"""
118122

119-
message, entities = (await self.parser.parse(text, parse_mode)).values()
123+
message, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values()
120124

121125
r = await self.send(
122126
raw.functions.messages.SendMessage(

pyrogram/methods/messages/send_photo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import os
2020
import re
21-
from typing import Union, BinaryIO
21+
from typing import Union, BinaryIO, List
2222

2323
import pyrogram
2424
from pyrogram import raw
@@ -36,6 +36,7 @@ async def send_photo(
3636
photo: Union[str, BinaryIO],
3737
caption: str = "",
3838
parse_mode: Union[str, None] = object,
39+
caption_entities: List["types.MessageEntity"] = None,
3940
ttl_seconds: int = None,
4041
disable_notification: bool = None,
4142
reply_to_message_id: int = None,
@@ -74,6 +75,9 @@ async def send_photo(
7475
Pass "html" to enable HTML-style parsing only.
7576
Pass None to completely disable style parsing.
7677
78+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
79+
List of special entities that appear in the caption, which can be specified instead of __parse_mode__.
80+
7781
ttl_seconds (``int``, *optional*):
7882
Self-Destruct Timer.
7983
If you set a timer, the photo will self-destruct in *ttl_seconds*
@@ -169,7 +173,7 @@ async def send_photo(
169173
random_id=self.rnd_id(),
170174
schedule_date=schedule_date,
171175
reply_markup=reply_markup.write() if reply_markup else None,
172-
**await self.parser.parse(caption, parse_mode)
176+
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
173177
)
174178
)
175179
except FilePartMissing as e:

pyrogram/methods/messages/send_video.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import os
2020
import re
21-
from typing import Union, BinaryIO
21+
from typing import Union, BinaryIO, List
2222

2323
from pyrogram import StopTransmission
2424
from pyrogram import raw
@@ -36,6 +36,7 @@ async def send_video(
3636
video: Union[str, BinaryIO],
3737
caption: str = "",
3838
parse_mode: Union[str, None] = object,
39+
caption_entities: List["types.MessageEntity"] = None,
3940
duration: int = 0,
4041
width: int = 0,
4142
height: int = 0,
@@ -79,6 +80,9 @@ async def send_video(
7980
Pass "html" to enable HTML-style parsing only.
8081
Pass None to completely disable style parsing.
8182
83+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
84+
List of special entities that appear in the caption, which can be specified instead of __parse_mode__.
85+
8286
duration (``int``, *optional*):
8387
Duration of sent video in seconds.
8488
@@ -213,7 +217,7 @@ def progress(current, total):
213217
random_id=self.rnd_id(),
214218
schedule_date=schedule_date,
215219
reply_markup=reply_markup.write() if reply_markup else None,
216-
**await self.parser.parse(caption, parse_mode)
220+
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
217221
)
218222
)
219223
except FilePartMissing as e:

pyrogram/methods/messages/send_voice.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import os
2020
import re
21-
from typing import Union, BinaryIO
21+
from typing import Union, BinaryIO, List
2222

2323
from pyrogram import StopTransmission
2424
from pyrogram import raw
@@ -36,6 +36,7 @@ async def send_voice(
3636
voice: Union[str, BinaryIO],
3737
caption: str = "",
3838
parse_mode: Union[str, None] = object,
39+
caption_entities: List["types.MessageEntity"] = None,
3940
duration: int = 0,
4041
disable_notification: bool = None,
4142
reply_to_message_id: int = None,
@@ -74,6 +75,9 @@ async def send_voice(
7475
Pass "html" to enable HTML-style parsing only.
7576
Pass None to completely disable style parsing.
7677
78+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
79+
List of special entities that appear in the caption, which can be specified instead of __parse_mode__.
80+
7781
duration (``int``, *optional*):
7882
Duration of the voice message in seconds.
7983
@@ -175,7 +179,7 @@ async def send_voice(
175179
random_id=self.rnd_id(),
176180
schedule_date=schedule_date,
177181
reply_markup=reply_markup.write() if reply_markup else None,
178-
**await self.parser.parse(caption, parse_mode)
182+
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
179183
)
180184
)
181185
except FilePartMissing as e:

pyrogram/types/input_media/input_media.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
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+
from typing import List
20+
21+
from ..messages_and_media import MessageEntity
1922
from ..object import Object
2023

2124

@@ -31,9 +34,16 @@ class InputMedia(Object):
3134
- :obj:`~pyrogram.types.InputMediaVideo`
3235
"""
3336

34-
def __init__(self, media: str, caption: str, parse_mode: str):
37+
def __init__(
38+
self,
39+
media: str,
40+
caption: str = None,
41+
parse_mode: str = None,
42+
caption_entities: List[MessageEntity] = None
43+
):
3544
super().__init__()
3645

3746
self.media = media
3847
self.caption = caption
3948
self.parse_mode = parse_mode
49+
self.caption_entities = caption_entities

0 commit comments

Comments
 (0)