diff --git a/app/modules/telegram/telegram.py b/app/modules/telegram/telegram.py index 2bddd1ba3..59d4c4090 100644 --- a/app/modules/telegram/telegram.py +++ b/app/modules/telegram/telegram.py @@ -88,6 +88,8 @@ def send_msg(self, title: str, text: str = "", image: str = "", try: if text: + # 对text进行Markdown特殊字符转义 + text = re.sub(r"([_`])", r"\\\1", text) caption = f"*{title}*\n{text}" else: caption = f"*{title}*" @@ -208,8 +210,6 @@ def __send_request(self, userid: str = None, image="", caption="") -> bool: image_file = Path(settings.TEMP_PATH) / str(uuid.uuid4()) image_file.write_bytes(res.content) photo = InputFile(image_file) - # 对caption进行Markdown特殊字符转义 - caption = re.sub(r"([_`])", r"\\\1", caption) # 发送图片到Telegram ret = self._bot.send_photo(chat_id=userid or self._telegram_chat_id, photo=photo,