mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-29 23:45:03 +08:00
fix: isolate durable notification recovery
This commit is contained in:
@@ -472,8 +472,9 @@ class TelegramModule(_MessageChannelModuleBase[Telegram]):
|
||||
"""
|
||||
发送消息
|
||||
:param message: 消息体
|
||||
:return: 成功或失败
|
||||
未确认发送时抛错,由普通模块派发记录错误,持久派发保留重试意图。
|
||||
"""
|
||||
failures = []
|
||||
for conf in self.get_configs().values():
|
||||
if not self.check_message(message, conf.name):
|
||||
continue
|
||||
@@ -485,9 +486,10 @@ class TelegramModule(_MessageChannelModuleBase[Telegram]):
|
||||
logger.warn("用户没有指定 Telegram用户ID,消息无法发送")
|
||||
return
|
||||
client: Telegram = self.get_instance(conf.name)
|
||||
result = None
|
||||
if client:
|
||||
if message.file_path:
|
||||
client.send_file(
|
||||
result = client.send_file(
|
||||
file_path=message.file_path,
|
||||
file_name=message.file_name,
|
||||
title=message.title,
|
||||
@@ -497,7 +499,7 @@ class TelegramModule(_MessageChannelModuleBase[Telegram]):
|
||||
parse_mode=message.parse_mode,
|
||||
)
|
||||
elif message.voice_path:
|
||||
client.send_voice(
|
||||
result = client.send_voice(
|
||||
voice_path=message.voice_path,
|
||||
userid=userid,
|
||||
caption=message.voice_caption,
|
||||
@@ -511,7 +513,7 @@ class TelegramModule(_MessageChannelModuleBase[Telegram]):
|
||||
original_message_id = (
|
||||
message.original_message_id if has_interaction_context else None
|
||||
)
|
||||
client.send_msg(
|
||||
result = client.send_msg(
|
||||
title=message.title,
|
||||
text=message.text,
|
||||
image=message.image,
|
||||
@@ -525,6 +527,10 @@ class TelegramModule(_MessageChannelModuleBase[Telegram]):
|
||||
parse_mode=message.parse_mode,
|
||||
rich_message=self._notification_rich_message(message),
|
||||
)
|
||||
if not result or not result.get("success"):
|
||||
failures.append(conf.name or "Telegram")
|
||||
if failures:
|
||||
raise RuntimeError(f"Telegram 通知发送未确认:{', '.join(failures)}")
|
||||
|
||||
def post_medias_message(
|
||||
self, message: Message, medias: List[MediaInfo]
|
||||
|
||||
@@ -1927,9 +1927,10 @@ class Telegram:
|
||||
parse_mode = kwargs.get("parse_mode")
|
||||
try:
|
||||
if image:
|
||||
return self._api.send_photo(
|
||||
return self.__send_photo_or_text(
|
||||
photo=image,
|
||||
caption=self._prepare_text(caption, parse_mode),
|
||||
disable_web_page_preview=disable_web_page_preview,
|
||||
**kwargs,
|
||||
)
|
||||
else:
|
||||
@@ -1945,7 +1946,22 @@ class Telegram:
|
||||
raise NonRetryableTelegramError(
|
||||
f"发送 Telegram {'图片' if image else '文本'}消息被限流:{err}"
|
||||
) from err
|
||||
raise RetryException(f"发送{'图片' if image else '文本'}消息失败")
|
||||
raise RetryException(f"发送{'图片' if image else '文本'}消息失败:{err}") from err
|
||||
|
||||
def __send_photo_or_text(
|
||||
self, *, photo: Any, caption: Optional[str],
|
||||
disable_web_page_preview: Optional[bool] = None, **kwargs: Any,
|
||||
) -> Any:
|
||||
"""海报上传失败立即降级为同一正文,保留会话、话题和按钮;429 不追加请求。"""
|
||||
try:
|
||||
return self._api.send_photo(photo=photo, caption=caption, **kwargs)
|
||||
except Exception as error:
|
||||
if self._is_rate_limit_error(error) or not caption:
|
||||
raise
|
||||
logger.warning(f"Telegram 海报发送失败,改为发送文本:{error}")
|
||||
return self._api.send_message(
|
||||
text=caption, disable_web_page_preview=disable_web_page_preview, **kwargs,
|
||||
)
|
||||
|
||||
@retry(RetryException, logger=logger)
|
||||
def __send_long_plain_message(
|
||||
@@ -1966,11 +1982,12 @@ class Telegram:
|
||||
for index, chunk in enumerate(chunks):
|
||||
current_reply_markup = reply_markup if index == 0 else None
|
||||
if image and index == 0:
|
||||
ret = self._api.send_photo(
|
||||
ret = self.__send_photo_or_text(
|
||||
**kwargs,
|
||||
photo=image,
|
||||
caption=chunk,
|
||||
reply_markup=current_reply_markup,
|
||||
disable_web_page_preview=disable_web_page_preview,
|
||||
)
|
||||
continue
|
||||
msg_kwargs = dict(**kwargs)
|
||||
@@ -2028,7 +2045,7 @@ class Telegram:
|
||||
)
|
||||
|
||||
elif item.content_type == ContentTypes.PHOTO or (image and i == 0):
|
||||
ret = self._api.send_photo(
|
||||
ret = self.__send_photo_or_text(
|
||||
**kwargs,
|
||||
photo=(
|
||||
getattr(item, "file_name", ""),
|
||||
@@ -2036,6 +2053,7 @@ class Telegram:
|
||||
),
|
||||
caption=self._telegramify_item_caption(item),
|
||||
reply_markup=current_reply_markup,
|
||||
disable_web_page_preview=disable_web_page_preview,
|
||||
)
|
||||
|
||||
elif item.content_type == ContentTypes.FILE:
|
||||
|
||||
Reference in New Issue
Block a user