Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Merged
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
28 changes: 22 additions & 6 deletions pyrogram/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class Client(Methods, BaseClient):
Your Smart Plugins settings as dict, e.g.: *dict(root="plugins")*.
This is an alternative way to setup plugins if you don't want to use the *config.ini* file.

parse_mode (``str``, *optional*):
The parse mode, can be any of: *"combined"*, for the default combined mode. *"markdown"* or *"md"*
to force Markdown-only styles. *"html"* to force HTML-only styles. *None* to disable the parser
completely.

no_updates (``bool``, *optional*):
Pass True to completely disable incoming updates for the current session.
When updates are disabled your client can't receive any new message.
Expand Down Expand Up @@ -184,6 +189,7 @@ def __init__(
workdir: str = BaseClient.WORKDIR,
config_file: str = BaseClient.CONFIG_FILE,
plugins: dict = None,
parse_mode: str = BaseClient.PARSE_MODES[0],
no_updates: bool = None,
takeout: bool = None,
sleep_threshold: int = Session.SLEEP_THRESHOLD
Expand All @@ -210,6 +216,7 @@ def __init__(
self.workdir = Path(workdir)
self.config_file = Path(config_file)
self.plugins = plugins
self.parse_mode = parse_mode
self.no_updates = no_updates
self.takeout = takeout
self.sleep_threshold = sleep_threshold
Expand Down Expand Up @@ -1145,6 +1152,21 @@ def export_session_string(self):
"""
return self.storage.export_session_string()

@property
def parse_mode(self):
return self._parse_mode

@parse_mode.setter
def parse_mode(self, parse_mode: Union[str, None] = "combined"):
if parse_mode not in self.PARSE_MODES:
raise ValueError('parse_mode must be one of {} or None. Not "{}"'.format(
", ".join('"{}"'.format(m) for m in self.PARSE_MODES[:-1]),
parse_mode
))

self._parse_mode = parse_mode

# TODO: redundant, remove in next major version
def set_parse_mode(self, parse_mode: Union[str, None] = "combined"):
"""Set the parse mode to be used globally by the client.

Expand Down Expand Up @@ -1190,12 +1212,6 @@ def set_parse_mode(self, parse_mode: Union[str, None] = "combined"):
app.send_message("haskell", "5. **markdown** and <i>html</i>")
"""

if parse_mode not in self.PARSE_MODES:
raise ValueError('parse_mode must be one of {} or None. Not "{}"'.format(
", ".join('"{}"'.format(m) for m in self.PARSE_MODES[:-1]),
parse_mode
))

self.parse_mode = parse_mode

def fetch_peers(self, peers: List[Union[types.User, types.Chat, types.Channel]]) -> bool:
Expand Down