Skip to content

Commit

Permalink
fix: avoid sending multi texts
Browse files Browse the repository at this point in the history
reunite text
  • Loading branch information
Itsusinn committed Jul 30, 2022
1 parent e46d693 commit a4708e2
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/handlers/receive.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Write;

use arcstr::ArcStr;
use color_eyre::eyre::Result;
use lateinit::LateInit;
Expand Down Expand Up @@ -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("频道不存在");
Expand All @@ -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(())
Expand Down

0 comments on commit a4708e2

Please sign in to comment.