diff --git a/ica-rs/src/data_struct/ica/messages/msg_trait.rs b/ica-rs/src/data_struct/ica/messages/msg_trait.rs index f602880..6d59d95 100644 --- a/ica-rs/src/data_struct/ica/messages/msg_trait.rs +++ b/ica-rs/src/data_struct/ica/messages/msg_trait.rs @@ -88,12 +88,25 @@ impl<'de> Deserialize<'de> for Message { impl Display for Message { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if !self.content.is_empty() { + if !self.content.is_empty() && !self.content.trim().is_empty() { write!(f, "{}|{}|{}|{}", self.msg_id(), self.sender_id, self.sender_name, self.content) } else if !self.files.is_empty() { - write!(f, "{}|{}|{}|{:?}", self.msg_id(), self.sender_id, self.sender_name, self.files[0].name) + write!( + f, + "{}|{}|{}|{:?}", + self.msg_id(), + self.sender_id, + self.sender_name, + self.files[0].name + ) } else { - write!(f, "{}|{}|{}|empty content & empty files", self.msg_id(), self.sender_id, self.sender_name) + write!( + f, + "{}|{}|{}|empty content & empty files", + self.msg_id(), + self.sender_id, + self.sender_name + ) } } } @@ -120,14 +133,32 @@ impl MessageTrait for NewMessage { impl Display for NewMessage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}|{}|{}|{}|{}", - self.msg_id(), - self.room_id, - self.msg.sender_id, - self.msg.sender_name, - self.msg.content - ) + if !self.msg.content.trim().is_empty() { + write!( + f, + "{}|{}|{}|{}|{}", + self.msg.msg_id, + self.room_id, + self.msg.sender_id, + self.msg.sender_name, + self.msg.content + ) + } else if !self.msg.files.is_empty() { + write!( + f, + "{}|{}|{}|{}|{:?}", + self.msg.msg_id, + self.room_id, + self.msg.sender_id, + self.msg.sender_name, + self.msg.files[0].name + ) + } else { + write!( + f, + "{}|{}|{}|{}|empty content & empty files", + self.msg.msg_id, self.room_id, self.msg.sender_id, self.msg.sender_name + ) + } } } diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 9e4272e..924eaa1 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -54,9 +54,7 @@ pub fn help_msg() -> String { static STARTUP_TIME: OnceLock = OnceLock::new(); -pub fn start_up_time() -> SystemTime { - *STARTUP_TIME.get().expect("WTF, why did you panic?") -} +pub fn start_up_time() -> SystemTime { *STARTUP_TIME.get().expect("WTF, why did you panic?") } /// 获得当前客户端的 id /// 防止串号 @@ -149,7 +147,7 @@ fn main() -> anyhow::Result<()> { .build() .unwrap() .block_on(inner_main()); - + event!(Level::INFO, "shenbot-rs v{} exiting", VERSION); Ok(()) } diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index 3a03992..0032a1e 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -55,9 +55,7 @@ impl PyTasks { self.ica_new_message.len() + self.ica_delete_message.len() + self.tailchat_new_message.len() } - pub fn is_empty(&self) -> bool { - self.len() == 0 - } + pub fn is_empty(&self) -> bool { self.len() == 0 } pub fn cancel_all(&mut self) { for handle in self.ica_new_message.drain(..) { @@ -72,11 +70,13 @@ impl PyTasks { } } -pub static PY_TASKS: LazyLock> = LazyLock::new(|| Mutex::new(PyTasks { - ica_new_message: Vec::new(), - ica_delete_message: Vec::new(), - tailchat_new_message: Vec::new(), -})); +pub static PY_TASKS: LazyLock> = LazyLock::new(|| { + Mutex::new(PyTasks { + ica_new_message: Vec::new(), + ica_delete_message: Vec::new(), + tailchat_new_message: Vec::new(), + }) +}); pub fn get_func<'py>( py_module: &Bound<'py, PyAny>, diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index 7f2d224..8725aa3 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -39,18 +39,12 @@ impl PyStatus { let _ = unsafe { PyPluginStatus.get_or_init(|| status) }; } - pub fn get() -> &'static PyStatus { - unsafe { PyPluginStatus.get().unwrap() } - } + pub fn get() -> &'static PyStatus { unsafe { PyPluginStatus.get().unwrap() } } - pub fn get_mut() -> &'static mut PyStatus { - unsafe { PyPluginStatus.get_mut().unwrap() } - } + pub fn get_mut() -> &'static mut PyStatus { unsafe { PyPluginStatus.get_mut().unwrap() } } /// 添加一个插件 - pub fn add_file(&mut self, path: PathBuf, plugin: PyPlugin) { - self.files.insert(path, plugin); - } + pub fn add_file(&mut self, path: PathBuf, plugin: PyPlugin) { self.files.insert(path, plugin); } /// 重新加载一个插件 pub fn reload_plugin(&mut self, plugin_name: &str) -> bool { @@ -70,9 +64,7 @@ impl PyStatus { } /// 删除一个插件 - pub fn delete_file(&mut self, path: &PathBuf) -> Option { - self.files.remove(path) - } + pub fn delete_file(&mut self, path: &PathBuf) -> Option { self.files.remove(path) } pub fn get_status(&self, pluging_id: &str) -> Option { self.files.iter().find_map(|(_, plugin)| { @@ -195,9 +187,7 @@ impl PyPlugin { } } - pub fn get_id(&self) -> String { - plugin_path_as_id(&self.file_path) - } + pub fn get_id(&self) -> String { plugin_path_as_id(&self.file_path) } } impl Display for PyPlugin { @@ -398,9 +388,7 @@ pub fn load_py_plugins(path: &PathBuf) { ); } -pub fn get_change_time(path: &Path) -> Option { - path.metadata().ok()?.modified().ok() -} +pub fn get_change_time(path: &Path) -> Option { path.metadata().ok()?.modified().ok() } pub fn py_module_from_code(content: &str, path: &Path) -> PyResult> { Python::with_gil(|py| -> PyResult> { @@ -525,7 +513,7 @@ pub async fn post_py() -> anyhow::Result<()> { async fn stop_tasks() { if call::PY_TASKS.lock().await.is_empty() { - return ; + return; } let waiter = tokio::spawn(async { call::PY_TASKS.lock().await.join_all().await;