chore: 修复 clippy 错误(loop never loops → if-let)并应用自动修复

This commit is contained in:
2026-06-10 10:17:25 +08:00
parent 19dc54f842
commit f7d0781090
15 changed files with 60 additions and 123 deletions
+13 -22
View File
@@ -371,7 +371,6 @@ async fn cmd_listen(
.send_text(&uid, &msg, None)
.await
.map(|_| ())
.map_err(|e| e)
})
})
};
@@ -536,8 +535,8 @@ async fn listen_loop(
info!("收到消息 from={}: {}", from, text);
// === 入库:收到的消息 ===
if let Some(db) = database {
if let Err(e) = db::models::insert_chat_record(
if let Some(db) = database
&& let Err(e) = db::models::insert_chat_record(
db.pool(),
"inbound",
from,
@@ -551,7 +550,6 @@ async fn listen_loop(
{
error!("保存聊天记录失败: {}", e);
}
}
// Echo 模式
if echo {
@@ -559,8 +557,8 @@ async fn listen_loop(
Ok(sent_id) => {
info!("回显成功 msg_id={}", sent_id);
// === 入库:发送的回显 ===
if let Some(db) = database {
if let Err(e) = db::models::insert_chat_record(
if let Some(db) = database
&& let Err(e) = db::models::insert_chat_record(
db.pool(),
"outbound",
from,
@@ -574,7 +572,6 @@ async fn listen_loop(
{
error!("保存聊天记录失败: {}", e);
}
}
}
Err(e) => error!("回显失败: {}", e),
}
@@ -612,8 +609,8 @@ async fn listen_loop(
}
// LLM 回复(异步执行,避免审批阻塞主循环)
if enable_llm {
if let Some(conv) = &conversation {
if enable_llm
&& let Some(conv) = &conversation {
let conv = conv.clone();
let client = client.clone();
let database = database.clone();
@@ -639,8 +636,8 @@ async fn listen_loop(
{
Ok(sent_id) => {
info!("LLM 回复成功 msg_id={}", sent_id);
if let Some(db) = database {
if let Err(e) = db::models::insert_chat_record(
if let Some(db) = database
&& let Err(e) = db::models::insert_chat_record(
db.pool(),
"outbound",
&from_owned,
@@ -654,13 +651,11 @@ async fn listen_loop(
{
error!("保存聊天记录失败: {}", e);
}
}
}
Err(e) => error!("发送 LLM 回复失败: {}", e),
}
});
}
}
}
}
Err(e) => {
@@ -722,8 +717,8 @@ async fn store_usage(
provider: &str,
u: &Usage,
) {
if let Some(db) = db {
if let Err(e) = db::models::insert_llm_usage(
if let Some(db) = db
&& let Err(e) = db::models::insert_llm_usage(
db.pool(),
user_id,
model,
@@ -737,7 +732,6 @@ async fn store_usage(
{
tracing::error!("存储 LLM 用量失败: {}", e);
}
}
}
async fn cmd_whoami(database: &Option<Arc<Database>>, file_state: &state::StateManager) {
@@ -863,8 +857,8 @@ async fn cmd_send(
println!("✅ 消息已发送, msg_id={}", msg_id);
// 入库:发送的消息
if let Some(db) = database {
if let Err(e) = db::models::insert_chat_record(
if let Some(db) = database
&& let Err(e) = db::models::insert_chat_record(
db.pool(),
"outbound",
to,
@@ -878,7 +872,6 @@ async fn cmd_send(
{
error!("保存聊天记录失败: {}", e);
}
}
}
Err(e) => error!("发送失败: {}", e),
}
@@ -898,9 +891,7 @@ async fn builtin_approve(ctx: &ExecutionContext, name: &str) -> Result<bool, Str
name, code
);
if let Some(ref send) = ctx.send_wechat {
if let Err(e) = send(&ctx.user_id, &msg).await {
return Err(e);
}
send(&ctx.user_id, &msg).await?
}
match tokio::time::timeout(std::time::Duration::from_secs(300), rx).await {