diff --git a/src/handlers/receive.rs b/src/handlers/receive.rs index 508a906..9c779ed 100644 --- a/src/handlers/receive.rs +++ b/src/handlers/receive.rs @@ -1,3 +1,5 @@ +use std::fmt::Write; + use arcstr::ArcStr; use color_eyre::eyre::Result; use lateinit::LateInit; @@ -93,20 +95,11 @@ async fn msg_handler(mut message: Message, target: i64) -> Result<()> { for single in message.chain { trace!(target:TARGET,element = ?single,"正在处理消息链中的元素"); + let mut reunite_text = String::new(); match single { MessageType::Text { content } => { - let content = format!( - "{}:\n{}", - html::bold(sender_name.as_str()), - html::escape(content.as_str()) - ); - let receipt = if let Some(reply_to) = &message.reply { - let local_id = DB.get_msg_id_1(&target, reply_to)?; - TG_BOT.send_text(chat_id, content, local_id).await? - } else { - TG_BOT.send_text(chat_id, content, None).await? - }; - DB.put_msg_id_1(&target, &message.id, &receipt.id)?; + reunite_text.write_str(&html::escape(content.as_str()))?; + reunite_text.write_str("\n")?; } MessageType::Image { id, url } => { let channel = CONFIG.mapper(&target).expect("频道不存在"); @@ -130,6 +123,20 @@ async fn msg_handler(mut message: Message, target: i64) -> Result<()> { MessageType::Edit { content: _ } => {} _ => {} } + if !reunite_text.is_empty() { + let content = format!( + "{}:\n{}", + html::bold(sender_name.as_str()), + html::escape(reunite_text.trim_end()) + ); + let receipt = if let Some(reply_to) = &message.reply { + let local_id = DB.get_msg_id_1(&target, reply_to)?; + TG_BOT.send_text(chat_id, content, local_id).await? + } else { + TG_BOT.send_text(chat_id, content, None).await? + }; + DB.put_msg_id_1(&target, &message.id, &receipt.id)?; + } } Ok(())