mirror of
https://github.com/paul-nameless/tg
synced 2025-02-16 10:38:23 +00:00
When entered markdown formatted text, parse it to display propely on official clients (#140)
This commit is contained in:
parent
4aaf9d9d1f
commit
c020ba1ea7
2 changed files with 40 additions and 3 deletions
|
@ -465,9 +465,7 @@ class MsgModel:
|
|||
return True
|
||||
|
||||
def send_message(self, chat_id: int, text: str) -> None:
|
||||
log.info("Sending msg")
|
||||
result = self.tg.send_message(chat_id=chat_id, text=text)
|
||||
|
||||
result = self.tg.send_message(chat_id, text)
|
||||
result.wait()
|
||||
if result.error:
|
||||
log.info(f"send message error: {result.error_info}")
|
||||
|
|
39
tg/tdlib.py
39
tg/tdlib.py
|
@ -37,7 +37,46 @@ class UserStatus(Enum):
|
|||
userStatusLastMonth = "last month"
|
||||
|
||||
|
||||
class TextParseModeInput(Enum):
|
||||
textParseModeMarkdown = "markdown"
|
||||
textParseModeHTML = "html"
|
||||
|
||||
|
||||
class Tdlib(Telegram):
|
||||
def parse_text_entities(
|
||||
self,
|
||||
text: str,
|
||||
parse_mode: TextParseModeInput = TextParseModeInput.textParseModeMarkdown,
|
||||
version: int = 2,
|
||||
) -> AsyncResult:
|
||||
"""Offline synchronous method which returns parsed entities"""
|
||||
data = {
|
||||
"@type": "parseTextEntities",
|
||||
"text": text,
|
||||
"parse_mode": {"@type": parse_mode.name, "version": version},
|
||||
}
|
||||
|
||||
return self._send_data(data)
|
||||
|
||||
def send_message(self, chat_id: int, msg: str) -> AsyncResult:
|
||||
result = self.parse_text_entities(msg)
|
||||
result.wait()
|
||||
if result.error:
|
||||
return result
|
||||
|
||||
text = result.update
|
||||
|
||||
data = {
|
||||
"@type": "sendMessage",
|
||||
"chat_id": chat_id,
|
||||
"input_message_content": {
|
||||
"@type": "inputMessageText",
|
||||
"text": text,
|
||||
},
|
||||
}
|
||||
|
||||
return self._send_data(data)
|
||||
|
||||
def download_file(
|
||||
self,
|
||||
file_id: int,
|
||||
|
|
Loading…
Add table
Reference in a new issue