From c23b3ee67ac3a8239838a800d5bdb2cae387db01 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 12 Feb 2025 00:02:05 +0800 Subject: [PATCH] ica 1.6.7 & tailchat 1.2.6 --- ica-rs/src/data_struct/ica/messages/msg_trait.rs | 2 +- ica-rs/src/ica.rs | 7 ++++++- ica-rs/src/main.rs | 6 ++---- ica-rs/src/py/call.rs | 13 +++++++------ ica-rs/src/py/class/ica.rs | 8 ++++++++ ica-rs/src/py/class/tailchat.rs | 10 ++++++++++ news.md | 12 ++++++++++++ 7 files changed, 46 insertions(+), 12 deletions(-) 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 6d59d95..ed2aa40 100644 --- a/ica-rs/src/data_struct/ica/messages/msg_trait.rs +++ b/ica-rs/src/data_struct/ica/messages/msg_trait.rs @@ -151,7 +151,7 @@ impl Display for NewMessage { self.room_id, self.msg.sender_id, self.msg.sender_name, - self.msg.files[0].name + self.msg.files[0] ) } else { write!( diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index 8bfb289..dac8d4c 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -3,6 +3,7 @@ pub mod events; // use std::sync::OnceLock; +use colored::Colorize; use rust_socketio::asynchronous::{Client, ClientBuilder}; use rust_socketio::{async_any_callback, async_callback}; use rust_socketio::{Event, Payload, TransportType}; @@ -66,7 +67,11 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe .await { Ok(client) => { - event!(Level::INFO, "socketio connected time: {:?}", start_connect_time.elapsed()); + event!( + Level::INFO, + "{}", + format!("socketio connected time: {:?}", start_connect_time.elapsed()).on_cyan() + ); client } Err(e) => { diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 924eaa1..fb0d828 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -18,8 +18,6 @@ mod tailchat; use config::BotConfig; use tracing::{event, span, Level}; -use crate::py::call; - pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus { config: None, ica_status: None, @@ -31,8 +29,8 @@ pub type MainStatus = status::BotStatus; pub type StopGetter = tokio::sync::oneshot::Receiver<()>; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const ICA_VERSION: &str = "1.6.5"; -pub const TAILCHAT_VERSION: &str = "1.2.5"; +pub const ICA_VERSION: &str = "1.6.7"; +pub const TAILCHAT_VERSION: &str = "1.2.6"; const HELP_MSG: &str = r#"/bot-rs 展示 rust 侧信息 diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index 0032a1e..9d2fb70 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -18,12 +18,6 @@ pub struct PyTasks { } impl PyTasks { - pub fn clear(&mut self) { - self.ica_new_message.clear(); - self.ica_delete_message.clear(); - self.tailchat_new_message.clear(); - } - pub fn push_ica_new_message(&mut self, handle: tokio::task::JoinHandle<()>) { self.ica_new_message.push(handle); self.ica_new_message.retain(|handle| !handle.is_finished()); @@ -51,6 +45,13 @@ impl PyTasks { } } + pub fn len_check(&mut self) -> usize { + self.ica_delete_message.retain(|handle| !handle.is_finished()); + self.ica_new_message.retain(|handle| !handle.is_finished()); + self.tailchat_new_message.retain(|handle| !handle.is_finished()); + self.ica_new_message.len() + self.ica_delete_message.len() + self.tailchat_new_message.len() + } + pub fn len(&self) -> usize { self.ica_new_message.len() + self.ica_delete_message.len() + self.tailchat_new_message.len() } diff --git a/ica-rs/src/py/class/ica.rs b/ica-rs/src/py/class/ica.rs index 625ed0f..4eb051d 100644 --- a/ica-rs/src/py/class/ica.rs +++ b/ica-rs/src/py/class/ica.rs @@ -255,6 +255,14 @@ impl IcaClientPy { #[getter] pub fn get_startup_time(&self) -> SystemTime { crate::start_up_time() } + #[getter] + pub fn get_py_tasks_count(&self) -> usize { + tokio::task::block_in_place(|| { + let rt = Runtime::new().unwrap(); + rt.block_on(async { crate::py::call::PY_TASKS.lock().await.len_check() }) + }) + } + /// 重新加载插件状态 /// 返回是否成功 pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() } diff --git a/ica-rs/src/py/class/tailchat.rs b/ica-rs/src/py/class/tailchat.rs index a03996d..b82f5f7 100644 --- a/ica-rs/src/py/class/tailchat.rs +++ b/ica-rs/src/py/class/tailchat.rs @@ -3,6 +3,7 @@ use std::time::SystemTime; use pyo3::prelude::*; use rust_socketio::asynchronous::Client; +use tokio::runtime::Runtime; use tracing::{debug, info, warn}; use crate::data_struct::tailchat::messages::{ReceiveMessage, SendingFile, SendingMessage}; @@ -73,6 +74,15 @@ impl TailchatClientPy { pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() } #[getter] pub fn get_startup_time(&self) -> SystemTime { crate::start_up_time() } + + #[getter] + pub fn get_py_tasks_count(&self) -> usize { + tokio::task::block_in_place(|| { + let rt = Runtime::new().unwrap(); + rt.block_on(async { crate::py::call::PY_TASKS.lock().await.len_check() }) + }) + } + /// 重新加载插件状态 /// 返回是否成功 pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() } diff --git a/news.md b/news.md index da0bca3..e3b2c7c 100644 --- a/news.md +++ b/news.md @@ -14,6 +14,18 @@ - 现在会记录所有的 python 运行中 task 了 - 也会在退出的时候等待所有的 task 结束 - 二次 ctrl-c 会立即退出 +- 改进了一下 ica 的新消息显示 +- 添加了 ica 链接用时的显示 + +### ica 1.6.7 + +- 为 `IcaClinet` 添加了 `py_tasks_count -> int` 属性 + - 用于获取当前运行中的 python task 数量 + +### tailchat 1.2.6 + +- 为 `TailchatClient` 添加了 `py_tasks_count -> int` 属性 + - 用于获取当前运行中的 python task 数量 ## 0.8.1