Skip to content

Commit 8ef97f2

Browse files
committed
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/client/methods/messages/edit_message_text.py # pyrogram/client/methods/messages/send_animation.py # pyrogram/client/methods/messages/send_audio.py # pyrogram/client/methods/messages/send_cached_media.py # pyrogram/client/methods/messages/send_document.py # pyrogram/client/methods/messages/send_message.py # pyrogram/client/methods/messages/send_photo.py # pyrogram/client/methods/messages/send_video.py # pyrogram/client/methods/messages/send_voice.py # pyrogram/client/parser/html.py # pyrogram/client/parser/markdown.py # pyrogram/client/types/input_message_content/input_text_message_content.py
2 parents 7cd145b + 39e2514 commit 8ef97f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+291
-1608
lines changed

pyrogram/client/ext/base_client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from pathlib import Path
2525

2626
from pyrogram import __version__
27-
from ..style import Markdown, HTML
27+
from ..parser import Parser
2828
from ...session.internals import MsgId
2929

3030

@@ -91,8 +91,7 @@ def __init__(self):
9191

9292
self.rnd_id = MsgId
9393

94-
self.markdown = Markdown(self)
95-
self.html = HTML(self)
94+
self.parser = Parser(self)
9695

9796
self.session = None
9897
self.media_sessions = {}

pyrogram/client/methods/messages/edit_inline_caption.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ async def edit_inline_caption(
3838
New caption of the media message.
3939
4040
parse_mode (``str``, *optional*):
41-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
42-
URLs in your message. Defaults to "markdown".
41+
By default, texts are parsed using both Markdown and HTML styles.
42+
You can combine both syntaxes together.
43+
Pass "markdown" to enable Markdown-style parsing only.
44+
Pass "html" to enable HTML-style parsing only.
45+
Pass None to completely disable style parsing.
4346
4447
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
4548
An InlineKeyboardMarkup object.

pyrogram/client/methods/messages/edit_inline_text.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
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
20+
1921
import pyrogram
2022
from pyrogram.api import functions
2123
from pyrogram.client.ext import BaseClient, utils
@@ -26,7 +28,7 @@ async def edit_inline_text(
2628
self,
2729
inline_message_id: str,
2830
text: str,
29-
parse_mode: str = "",
31+
parse_mode: Union[str, None] = "",
3032
disable_web_page_preview: bool = None,
3133
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
3234
) -> bool:
@@ -40,8 +42,11 @@ async def edit_inline_text(
4042
New text of the message.
4143
4244
parse_mode (``str``, *optional*):
43-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
44-
URLs in your message. Defaults to "markdown".
45+
By default, texts are parsed using both Markdown and HTML styles.
46+
You can combine both syntaxes together.
47+
Pass "markdown" to enable Markdown-style parsing only.
48+
Pass "html" to enable HTML-style parsing only.
49+
Pass None to completely disable style parsing.
4550
4651
disable_web_page_preview (``bool``, *optional*):
4752
Disables link previews for links in this message.
@@ -55,13 +60,12 @@ async def edit_inline_text(
5560
Raises:
5661
RPCError: In case of a Telegram RPC error.
5762
"""
58-
style = self.html if parse_mode.lower() == "html" else self.markdown
5963

6064
return await self.send(
6165
functions.messages.EditInlineBotMessage(
6266
id=utils.unpack_inline_message_id(inline_message_id),
6367
no_webpage=disable_web_page_preview or None,
6468
reply_markup=reply_markup.write() if reply_markup else None,
65-
**style.parse(text)
69+
**self.parser.parse(text, parse_mode)
6670
)
6771
)

pyrogram/client/methods/messages/edit_message_caption.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ async def edit_message_caption(
4646
New caption of the media message.
4747
4848
parse_mode (``str``, *optional*):
49-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
50-
URLs in your message. Defaults to "markdown".
49+
By default, texts are parsed using both Markdown and HTML styles.
50+
You can combine both syntaxes together.
51+
Pass "markdown" to enable Markdown-style parsing only.
52+
Pass "html" to enable HTML-style parsing only.
53+
Pass None to completely disable style parsing.
5154
5255
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
5356
An InlineKeyboardMarkup object.

pyrogram/client/methods/messages/edit_message_text.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def edit_message_text(
2929
chat_id: Union[int, str],
3030
message_id: int,
3131
text: str,
32-
parse_mode: str = "",
32+
parse_mode: Union[str, None] = "",
3333
disable_web_page_preview: bool = None,
3434
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
3535
) -> "pyrogram.Message":
@@ -48,8 +48,11 @@ async def edit_message_text(
4848
New text of the message.
4949
5050
parse_mode (``str``, *optional*):
51-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
52-
URLs in your message. Defaults to "markdown".
51+
By default, texts are parsed using both Markdown and HTML styles.
52+
You can combine both syntaxes together.
53+
Pass "markdown" to enable Markdown-style parsing only.
54+
Pass "html" to enable HTML-style parsing only.
55+
Pass None to completely disable style parsing.
5356
5457
disable_web_page_preview (``bool``, *optional*):
5558
Disables link previews for links in this message.
@@ -63,15 +66,14 @@ async def edit_message_text(
6366
Raises:
6467
RPCError: In case of a Telegram RPC error.
6568
"""
66-
style = self.html if parse_mode.lower() == "html" else self.markdown
6769

6870
r = await self.send(
6971
functions.messages.EditMessage(
7072
peer=await self.resolve_peer(chat_id),
7173
id=message_id,
7274
no_webpage=disable_web_page_preview or None,
7375
reply_markup=reply_markup.write() if reply_markup else None,
74-
**await style.parse(text)
76+
**await self.parser.parse(text, parse_mode)
7577
)
7678
)
7779

pyrogram/client/methods/messages/send_animation.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def send_animation(
3232
animation: str,
3333
caption: str = "",
3434
unsave: bool = False,
35-
parse_mode: str = "",
35+
parse_mode: Union[str, None] = "",
3636
duration: int = 0,
3737
width: int = 0,
3838
height: int = 0,
@@ -70,8 +70,11 @@ async def send_animation(
7070
Pass True to automatically unsave the sent animation. Defaults to False.
7171
7272
parse_mode (``str``, *optional*):
73-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
74-
URLs in your caption. Defaults to "markdown".
73+
By default, texts are parsed using both Markdown and HTML styles.
74+
You can combine both syntaxes together.
75+
Pass "markdown" to enable Markdown-style parsing only.
76+
Pass "html" to enable HTML-style parsing only.
77+
Pass None to completely disable style parsing.
7578
7679
duration (``int``, *optional*):
7780
Duration of sent animation in seconds.
@@ -130,7 +133,6 @@ async def send_animation(
130133
RPCError: In case of a Telegram RPC error.
131134
"""
132135
file = None
133-
style = self.html if parse_mode.lower() == "html" else self.markdown
134136

135137
try:
136138
if os.path.exists(animation):
@@ -168,7 +170,7 @@ async def send_animation(
168170
reply_to_msg_id=reply_to_message_id,
169171
random_id=self.rnd_id(),
170172
reply_markup=reply_markup.write() if reply_markup else None,
171-
**await style.parse(caption)
173+
**await self.parser.parse(caption, parse_mode)
172174
)
173175
)
174176
except FilePartMissing as e:

pyrogram/client/methods/messages/send_audio.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def send_audio(
3131
chat_id: Union[int, str],
3232
audio: str,
3333
caption: str = "",
34-
parse_mode: str = "",
34+
parse_mode: Union[str, None] = "",
3535
duration: int = 0,
3636
performer: str = None,
3737
title: str = None,
@@ -66,8 +66,11 @@ async def send_audio(
6666
Audio caption, 0-1024 characters.
6767
6868
parse_mode (``str``, *optional*):
69-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
70-
URLs in your caption. Defaults to "markdown".
69+
By default, texts are parsed using both Markdown and HTML styles.
70+
You can combine both syntaxes together.
71+
Pass "markdown" to enable Markdown-style parsing only.
72+
Pass "html" to enable HTML-style parsing only.
73+
Pass None to completely disable style parsing.
7174
7275
duration (``int``, *optional*):
7376
Duration of the audio in seconds.
@@ -126,7 +129,6 @@ async def send_audio(
126129
RPCError: In case of a Telegram RPC error.
127130
"""
128131
file = None
129-
style = self.html if parse_mode.lower() == "html" else self.markdown
130132

131133
try:
132134
if os.path.exists(audio):
@@ -162,7 +164,7 @@ async def send_audio(
162164
reply_to_msg_id=reply_to_message_id,
163165
random_id=self.rnd_id(),
164166
reply_markup=reply_markup.write() if reply_markup else None,
165-
**await style.parse(caption)
167+
**await self.parser.parse(caption, parse_mode)
166168
)
167169
)
168170
except FilePartMissing as e:

pyrogram/client/methods/messages/send_cached_media.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def send_cached_media(
2929
chat_id: Union[int, str],
3030
file_id: str,
3131
caption: str = "",
32-
parse_mode: str = "",
32+
parse_mode: Union[str, None] = "",
3333
disable_notification: bool = None,
3434
reply_to_message_id: int = None,
3535
reply_markup: Union[
@@ -59,8 +59,11 @@ async def send_cached_media(
5959
Media caption, 0-1024 characters.
6060
6161
parse_mode (``str``, *optional*):
62-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
63-
URLs in your caption. Defaults to "markdown".
62+
By default, texts are parsed using both Markdown and HTML styles.
63+
You can combine both syntaxes together.
64+
Pass "markdown" to enable Markdown-style parsing only.
65+
Pass "html" to enable HTML-style parsing only.
66+
Pass None to completely disable style parsing.
6467
6568
disable_notification (``bool``, *optional*):
6669
Sends the message silently.
@@ -79,7 +82,6 @@ async def send_cached_media(
7982
Raises:
8083
RPCError: In case of a Telegram RPC error.
8184
"""
82-
style = self.html if parse_mode.lower() == "html" else self.markdown
8385

8486
r = await self.send(
8587
functions.messages.SendMedia(
@@ -89,7 +91,7 @@ async def send_cached_media(
8991
reply_to_msg_id=reply_to_message_id,
9092
random_id=self.rnd_id(),
9193
reply_markup=reply_markup.write() if reply_markup else None,
92-
**await style.parse(caption)
94+
**await self.parser.parse(caption, parse_mode)
9395
)
9496
)
9597

pyrogram/client/methods/messages/send_document.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def send_document(
3131
chat_id: Union[int, str],
3232
document: str,
3333
thumb: str = None, caption: str = "",
34-
parse_mode: str = "",
34+
parse_mode: Union[str, None] = "",
3535
disable_notification: bool = None,
3636
reply_to_message_id: int = None,
3737
reply_markup: Union[
@@ -67,8 +67,11 @@ async def send_document(
6767
Document caption, 0-1024 characters.
6868
6969
parse_mode (``str``, *optional*):
70-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
71-
URLs in your caption. Defaults to "markdown".
70+
By default, texts are parsed using both Markdown and HTML styles.
71+
You can combine both syntaxes together.
72+
Pass "markdown" to enable Markdown-style parsing only.
73+
Pass "html" to enable HTML-style parsing only.
74+
Pass None to completely disable style parsing.
7275
7376
disable_notification (``bool``, *optional*):
7477
Sends the message silently.
@@ -112,7 +115,6 @@ async def send_document(
112115
RPCError: In case of a Telegram RPC error.
113116
"""
114117
file = None
115-
style = self.html if parse_mode.lower() == "html" else self.markdown
116118

117119
try:
118120
if os.path.exists(document):
@@ -143,7 +145,7 @@ async def send_document(
143145
reply_to_msg_id=reply_to_message_id,
144146
random_id=self.rnd_id(),
145147
reply_markup=reply_markup.write() if reply_markup else None,
146-
**await style.parse(caption)
148+
**await self.parser(caption, parse_mode)
147149
)
148150
)
149151
except FilePartMissing as e:

pyrogram/client/methods/messages/send_message.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async def send_message(
2828
self,
2929
chat_id: Union[int, str],
3030
text: str,
31-
parse_mode: str = "",
31+
parse_mode: Union[str, None] = "",
3232
disable_web_page_preview: bool = None,
3333
disable_notification: bool = None,
3434
reply_to_message_id: int = None,
@@ -51,8 +51,11 @@ async def send_message(
5151
Text of the message to be sent.
5252
5353
parse_mode (``str``, *optional*):
54-
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
55-
URLs in your message. Defaults to "markdown".
54+
By default, texts are parsed using both Markdown and HTML styles.
55+
You can combine both syntaxes together.
56+
Pass "markdown" to enable Markdown-style parsing only.
57+
Pass "html" to enable HTML-style parsing only.
58+
Pass None to completely disable style parsing.
5659
5760
disable_web_page_preview (``bool``, *optional*):
5861
Disables link previews for links in this message.
@@ -74,8 +77,7 @@ async def send_message(
7477
Raises:
7578
RPCError: In case of a Telegram RPC error.
7679
"""
77-
style = self.html if parse_mode.lower() == "html" else self.markdown
78-
message, entities = (await style.parse(text)).values()
80+
message, entities = (await self.parser.parse(text, parse_mode)).values()
7981

8082
r = await self.send(
8183
functions.messages.SendMessage(

0 commit comments

Comments
 (0)