From d6443f27bb069a7421b8fdf70ee89f9909c8b3f6 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 23 Feb 2024 16:48:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E6=9B=B4=E6=96=B0=E4=B8=80=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=83=BD=E8=B7=91=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/src/data_struct/messages.rs | 14 ++++++-------- ica-rs/src/events.rs | 10 +++++----- ica-rs/src/py/class.rs | 2 +- ica-rs/src/py/mod.rs | 15 +++++++++------ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/ica-rs/src/data_struct/messages.rs b/ica-rs/src/data_struct/messages.rs index 2310729..8dbfd91 100644 --- a/ica-rs/src/data_struct/messages.rs +++ b/ica-rs/src/data_struct/messages.rs @@ -2,10 +2,10 @@ use crate::client::IcalinguaStatus; use crate::data_struct::files::MessageFile; use crate::data_struct::{MessageId, RoomId, UserId}; -use tracing::warn; use chrono::NaiveDateTime; use serde::{Deserialize, Serialize}; use serde_json::{json, Value as JsonValue}; +use tracing::warn; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum At { @@ -139,13 +139,11 @@ impl NewMessage { } // 回复的消息 let reply: Option = match message.get("replyMessage") { - Some(value) => { - match serde_json::from_value::(value.clone()) { - Ok(reply) => Some(reply), - Err(e) => { - warn!("Failed to parse reply message: {}", e); - None - } + Some(value) => match serde_json::from_value::(value.clone()) { + Ok(reply) => Some(reply), + Err(e) => { + warn!("Failed to parse reply message: {}", e); + None } }, None => None, diff --git a/ica-rs/src/events.rs b/ica-rs/src/events.rs index 8bfd340..3f46f81 100644 --- a/ica-rs/src/events.rs +++ b/ica-rs/src/events.rs @@ -14,10 +14,7 @@ pub async fn get_online_data(payload: Payload, _client: Client) { if let Payload::Text(values) = payload { if let Some(value) = values.first() { let online_data = OnlineData::new_from_json(value); - info!( - "update_online_data {}", - format!("{:?}", online_data).cyan() - ); + info!("update_online_data {}", format!("{:?}", online_data).cyan()); unsafe { crate::ClientStatus.update_online_data(online_data); } @@ -31,7 +28,10 @@ pub async fn add_message(payload: Payload, client: Client) { if let Some(value) = values.first() { let message = NewMessage::new_from_json(value); // 检测是否在过滤列表内 - if IcalinguaStatus::get_config().filter_list.contains(&message.sender_id) { + if IcalinguaStatus::get_config() + .filter_list + .contains(&message.sender_id) + { return; } info!("add_message {}", message.output().cyan()); diff --git a/ica-rs/src/py/class.rs b/ica-rs/src/py/class.rs index 09f5095..11cd42c 100644 --- a/ica-rs/src/py/class.rs +++ b/ica-rs/src/py/class.rs @@ -1,7 +1,7 @@ use pyo3::prelude::*; -use tracing::{debug, info, warn}; use rust_socketio::asynchronous::Client; use tokio::runtime::Runtime; +use tracing::{debug, info, warn}; use crate::client::send_message; use crate::data_struct::messages::{NewMessage, ReplyMessage, SendMessage}; diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index 09659d6..0441a38 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -57,7 +57,7 @@ impl PyStatus { } } true - }, + } None => false, }, None => false, @@ -108,7 +108,11 @@ pub fn load_py_plugins(path: &PathBuf) { pub fn verify_plugins() { let mut need_reload_files: Vec = Vec::new(); - let plugin_path = IcalinguaStatus::get_config().py_plugin_path.as_ref().unwrap().to_owned(); + let plugin_path = IcalinguaStatus::get_config() + .py_plugin_path + .as_ref() + .unwrap() + .to_owned(); for entry in std::fs::read_dir(&plugin_path).unwrap() { if let Ok(entry) = entry { let path = entry.path(); @@ -165,13 +169,12 @@ pub fn load_py_module(path: &PathBuf) -> Option<(Option, Py)> &path.to_string_lossy(), &path.to_string_lossy(), // !!!! 请注意, 一定要给他一个名字, cpython 会自动把后面的重名模块覆盖掉前面的 - ).map(|module| module.into()); + ) + .map(|module| module.into()); module }); match py_module { - Ok(py_module) => { - Some((changed_time, py_module)) - } + Ok(py_module) => Some((changed_time, py_module)), Err(e) => { warn!("failed to load file: {:?} | e: {:?}", path, e); None