mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-30 20:31:50 +08:00
Handle Telegramify 1.2 compatibility
This commit is contained in:
@@ -173,7 +173,7 @@ class MessageChain(ChainBase):
|
|||||||
images = CommingMessage.MessageImage.normalize_list(images)
|
images = CommingMessage.MessageImage.normalize_list(images)
|
||||||
|
|
||||||
processing_status = None
|
processing_status = None
|
||||||
continues_async = False
|
processing_finish_deferred = False
|
||||||
try:
|
try:
|
||||||
# 语音输入只用于转写为文本,不默认改变回复形式。
|
# 语音输入只用于转写为文本,不默认改变回复形式。
|
||||||
has_audio_input = bool(audio_refs)
|
has_audio_input = bool(audio_refs)
|
||||||
@@ -228,7 +228,7 @@ class MessageChain(ChainBase):
|
|||||||
text=text,
|
text=text,
|
||||||
)
|
)
|
||||||
|
|
||||||
continues_async = self._handle_message_core(
|
processing_finish_deferred = self._handle_message_core(
|
||||||
channel=channel,
|
channel=channel,
|
||||||
source=source,
|
source=source,
|
||||||
userid=userid,
|
userid=userid,
|
||||||
@@ -241,9 +241,9 @@ class MessageChain(ChainBase):
|
|||||||
files=files,
|
files=files,
|
||||||
has_audio_input=has_audio_input,
|
has_audio_input=has_audio_input,
|
||||||
processing_status=processing_status,
|
processing_status=processing_status,
|
||||||
)
|
) is True
|
||||||
finally:
|
finally:
|
||||||
if continues_async:
|
if not processing_finish_deferred:
|
||||||
self._mark_message_processing_finished(
|
self._mark_message_processing_finished(
|
||||||
channel=channel,
|
channel=channel,
|
||||||
source=source,
|
source=source,
|
||||||
|
|||||||
@@ -15,8 +15,15 @@ from telebot.types import (
|
|||||||
InlineKeyboardButton,
|
InlineKeyboardButton,
|
||||||
InputMediaPhoto,
|
InputMediaPhoto,
|
||||||
)
|
)
|
||||||
from telegramify_markdown import entities_to_markdownv2, standardize, telegramify # noqa
|
from telegramify_markdown import standardize, telegramify # noqa
|
||||||
from telegramify_markdown.content import ContentTypes, File, Photo, Text
|
try:
|
||||||
|
from telegramify_markdown import entities_to_markdownv2 # noqa
|
||||||
|
except ImportError:
|
||||||
|
entities_to_markdownv2 = None
|
||||||
|
try:
|
||||||
|
from telegramify_markdown.content import ContentTypes, File, Photo, Text
|
||||||
|
except ImportError:
|
||||||
|
from telegramify_markdown.type import ContentTypes, File, Photo, Text
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo, Context
|
from app.core.context import MediaInfo, Context
|
||||||
@@ -255,14 +262,22 @@ class Telegram:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _telegramify_item_text(item: Text) -> str:
|
def _telegramify_item_text(item: Text) -> str:
|
||||||
"""将 telegramify 文本片段转换为 Telegram MarkdownV2 字符串。"""
|
"""将 telegramify 文本片段转换为 Telegram MarkdownV2 字符串。"""
|
||||||
return entities_to_markdownv2(item.text, item.entities)
|
if hasattr(item, "content"):
|
||||||
|
return item.content
|
||||||
|
if entities_to_markdownv2:
|
||||||
|
return entities_to_markdownv2(item.text, item.entities)
|
||||||
|
return standardize(item.text)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _telegramify_item_caption(item: Text | File | Photo) -> str:
|
def _telegramify_item_caption(item: Text | File | Photo) -> str:
|
||||||
"""将 telegramify 文本或媒体片段转换为 Telegram MarkdownV2 caption。"""
|
"""将 telegramify 文本或媒体片段转换为 Telegram MarkdownV2 caption。"""
|
||||||
if isinstance(item, Text):
|
if isinstance(item, Text):
|
||||||
return Telegram._telegramify_item_text(item)
|
return Telegram._telegramify_item_text(item)
|
||||||
return entities_to_markdownv2(item.caption_text, item.caption_entities)
|
if hasattr(item, "caption"):
|
||||||
|
return item.caption
|
||||||
|
if entities_to_markdownv2:
|
||||||
|
return entities_to_markdownv2(item.caption_text, item.caption_entities)
|
||||||
|
return standardize(item.caption_text)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _normalize_parse_mode(parse_mode: Optional[str] = None) -> str:
|
def _normalize_parse_mode(parse_mode: Optional[str] = None) -> str:
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ beautifulsoup4~=4.15.0
|
|||||||
pillow~=12.2.0
|
pillow~=12.2.0
|
||||||
pillow-avif-plugin~=1.5.5
|
pillow-avif-plugin~=1.5.5
|
||||||
pyTelegramBotAPI~=4.34.0
|
pyTelegramBotAPI~=4.34.0
|
||||||
telegramify-markdown~=1.1.5
|
telegramify-markdown~=1.2.0
|
||||||
cloakbrowser~=0.3.31
|
cloakbrowser~=0.4.0
|
||||||
torrentool~=1.2.0
|
torrentool~=1.2.0
|
||||||
fast-bencode~=1.1.8
|
fast-bencode~=1.1.8
|
||||||
slack-bolt~=1.28.0
|
slack-bolt~=1.28.0
|
||||||
|
|||||||
@@ -253,6 +253,15 @@ def test_send_msg_markdown_escaping(telegram):
|
|||||||
assert send_kwargs["text"].startswith("*测试标题*\n")
|
assert send_kwargs["text"].startswith("*测试标题*\n")
|
||||||
|
|
||||||
|
|
||||||
|
def test_telegramify_new_content_fields_are_used_directly():
|
||||||
|
"""新版telegramify对象应直接使用已渲染的MarkdownV2字段"""
|
||||||
|
text_item = SimpleNamespace(content="已转义\\_文本")
|
||||||
|
file_item = SimpleNamespace(caption="已转义\\_说明")
|
||||||
|
|
||||||
|
assert Telegram._telegramify_item_text(text_item) == "已转义\\_文本"
|
||||||
|
assert Telegram._telegramify_item_caption(file_item) == "已转义\\_说明"
|
||||||
|
|
||||||
|
|
||||||
def test_send_msg_with_html_parse_mode_keeps_html(telegram):
|
def test_send_msg_with_html_parse_mode_keeps_html(telegram):
|
||||||
"""HTML模式发送时应保留调用方传入的HTML内容"""
|
"""HTML模式发送时应保留调用方传入的HTML内容"""
|
||||||
result = telegram.send_msg(
|
result = telegram.send_msg(
|
||||||
|
|||||||
Reference in New Issue
Block a user