style: simplify media accumulation - silent accumulate, immediate send on text
This commit is contained in:
@@ -477,25 +477,23 @@ def _handle_message(tg_cfg: TelegramConfig, cfg: Config, msg: dict):
|
|||||||
logger.info(" 上下文已丢失,清理")
|
logger.info(" 上下文已丢失,清理")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 有附件但没文字:累积附件,等用户输入文字
|
# 有附件但没文字:静默累积附件,等用户输入文字
|
||||||
if media and not text:
|
if media and not text:
|
||||||
pending = conv.get("pending_attachments", [])
|
pending = conv.get("pending_attachments", [])
|
||||||
for att in media:
|
pending.extend(media)
|
||||||
pending.append(att)
|
|
||||||
conv["pending_attachments"] = pending
|
conv["pending_attachments"] = pending
|
||||||
save_conversation(chat_id, conv)
|
save_conversation(chat_id, conv)
|
||||||
delete_message(tg_cfg, chat_id_str, user_msg_id)
|
delete_message(tg_cfg, chat_id_str, user_msg_id)
|
||||||
|
count = len(pending)
|
||||||
send_text(tg_cfg, chat_id_str,
|
send_text(tg_cfg, chat_id_str,
|
||||||
f"📎 已添加 {len(pending)} 个附件,请输入回复内容发送",
|
f"📎 已收到 {count} 个附件{',请输入回复文字' if count == 1 else ',请继续或输入回复文字'}")
|
||||||
reply_markup=_cancel_keyboard())
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# 有文字(可能也有附件):发送邮件
|
# 有文字(可能也有附件):合并所有附件,一起发送
|
||||||
delete_message(tg_cfg, chat_id_str, user_msg_id)
|
delete_message(tg_cfg, chat_id_str, user_msg_id)
|
||||||
if prompt_msg_id:
|
if prompt_msg_id:
|
||||||
delete_message(tg_cfg, chat_id_str, prompt_msg_id)
|
delete_message(tg_cfg, chat_id_str, prompt_msg_id)
|
||||||
|
|
||||||
# 合并累积的附件
|
|
||||||
all_attachments = conv.get("pending_attachments", [])
|
all_attachments = conv.get("pending_attachments", [])
|
||||||
all_attachments.extend(media)
|
all_attachments.extend(media)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user