diff --git a/ica-rs/src/data_struct/tailchat/status.rs b/ica-rs/src/data_struct/tailchat/status.rs index 8c8ba84..7abdd61 100644 --- a/ica-rs/src/data_struct/tailchat/status.rs +++ b/ica-rs/src/data_struct/tailchat/status.rs @@ -51,11 +51,13 @@ pub struct UpdateDMConverse { #[allow(unused)] pub type Writeable = Arc>; +#[allow(unused)] #[derive(Debug, Clone)] pub struct BotStatus { user_id: UserId, } +#[allow(unused)] impl BotStatus { pub fn new(user_id: UserId) -> Self { Self { user_id } } diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index ccc921f..bb27cb3 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -11,7 +11,7 @@ use crate::error::{ClientResult, IcaError}; use crate::{version_str, StopGetter}; /// icalingua 客户端的兼容版本号 -pub const ICA_PROTOCOL_VERSION: &str = "2.12.20"; +pub const ICA_PROTOCOL_VERSION: &str = "2.12.21"; pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> { let span = span!(Level::INFO, "Icalingua Client"); diff --git a/ica-rs/src/ica/client.rs b/ica-rs/src/ica/client.rs index 2bd6892..ab98839 100644 --- a/ica-rs/src/ica/client.rs +++ b/ica-rs/src/ica/client.rs @@ -43,7 +43,6 @@ pub async fn delete_message(client: &Client, message: &DeleteMessage) -> bool { /// ``` // #[allow(dead_code)] // pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false } - async fn inner_sign(payload: Payload, client: Client) -> ClientResult<(), IcaError> { let span = span!(Level::INFO, "signing icalingua"); let _guard = span.enter(); diff --git a/ica-rs/src/ica/events.rs b/ica-rs/src/ica/events.rs index 6ea0d1e..24147d0 100644 --- a/ica-rs/src/ica/events.rs +++ b/ica-rs/src/ica/events.rs @@ -187,7 +187,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) { "closeLoading", // 发送消息/加载新聊天 有一个 loading "renewMessage", // 我也不确定到底是啥事件 "requestSetup", // 需要登录 - "updateRoom", + "updateRoom", // 更新房间 ]; match &event { Event::Custom(event_name) => { diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 160d753..3c78e23 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -95,8 +95,15 @@ macro_rules! async_any_callback_with_state { }}; } -#[tokio::main] -async fn main() -> anyhow::Result<()> { inner_main().await } +fn main() -> anyhow::Result<()> { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .thread_name("shenbot-rs") + .worker_threads(4) + .build() + .unwrap() + .block_on(inner_main()) +} async fn inner_main() -> anyhow::Result<()> { // -d -> debug diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index d126378..f019568 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -64,6 +64,14 @@ pub fn verify_and_reload_plugins() { let mut need_reload_files: Vec = Vec::new(); let plugin_path = MainStatus::global_config().py().plugin_path.clone(); + // 先检查是否有插件被删除 + for path in PyStatus::get_map_mut().keys() { + if !path.exists() { + event!(Level::INFO, "Python 插件: {:?} 已被删除", path); + PyStatus::delete_file(path); + } + } + for entry in std::fs::read_dir(plugin_path).unwrap().flatten() { let path = entry.path(); if let Some(ext) = path.extension() { @@ -76,7 +84,7 @@ pub fn verify_and_reload_plugins() { if need_reload_files.is_empty() { return; } - info!("file change list: {:?}", need_reload_files); + event!(Level::INFO, "更改列表: {:?}", need_reload_files); let exist_plugins = PyStatus::get_map_mut(); for reload_file in need_reload_files { if let Some(plugin) = exist_plugins.get_mut(&reload_file) { diff --git a/ica-rs/src/py/class/tailchat.rs b/ica-rs/src/py/class/tailchat.rs index 4c2df42..0283bd7 100644 --- a/ica-rs/src/py/class/tailchat.rs +++ b/ica-rs/src/py/class/tailchat.rs @@ -73,7 +73,12 @@ impl TailchatClientPy { #[getter] pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() } #[pyo3(signature = (content, converse_id, group_id = None))] - pub fn new_message(&self, content: String, converse_id: ConverseId, group_id: Option) -> TailchatSendingMessagePy { + pub fn new_message( + &self, + content: String, + converse_id: ConverseId, + group_id: Option, + ) -> TailchatSendingMessagePy { TailchatSendingMessagePy { message: SendingMessage::new(content, converse_id, group_id, None), } diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index d9b243f..44011ab 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -42,9 +42,7 @@ impl PyStatus { pub fn add_file(path: PathBuf, plugin: PyPlugin) { Self::get_map_mut().insert(path, plugin); } /// 删除一个插件 - pub fn delete_file(path: &PathBuf) -> Option { - Self::get_map_mut().remove(path) - } + pub fn delete_file(path: &PathBuf) -> Option { Self::get_map_mut().remove(path) } pub fn verify_file(path: &PathBuf) -> bool { Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy()) @@ -52,11 +50,13 @@ impl PyStatus { pub fn get_map() -> &'static PyPlugins { unsafe { - match PYSTATUS.files.as_ref() { + let ptr = &raw const PYSTATUS.files; + let ptr = &*ptr; + match ptr.as_ref() { Some(files) => files, None => { Self::init(); - PYSTATUS.files.as_ref().unwrap() + ptr.as_ref().unwrap() } } } @@ -64,11 +64,13 @@ impl PyStatus { pub fn get_map_mut() -> &'static mut PyPlugins { unsafe { - match PYSTATUS.files.as_mut() { + let ptr = &raw mut PYSTATUS.files; + let ptr = &mut *ptr; + match ptr { Some(files) => files, None => { Self::init(); - PYSTATUS.files.as_mut().unwrap() + ptr.as_mut().unwrap() } } } @@ -76,11 +78,13 @@ impl PyStatus { pub fn get_config() -> &'static config::PluginConfigFile { unsafe { - match PYSTATUS.config.as_ref() { + let ptr = &raw const PYSTATUS.config; + let ptr = &*ptr; + match ptr { Some(config) => config, None => { Self::init(); - PYSTATUS.config.as_ref().unwrap() + ptr.as_ref().unwrap() } } } @@ -88,11 +92,13 @@ impl PyStatus { pub fn get_config_mut() -> &'static mut config::PluginConfigFile { unsafe { - match PYSTATUS.config.as_mut() { + let ptr = &raw mut PYSTATUS.config; + let ptr = &mut *ptr; + match ptr { Some(config) => config, None => { Self::init(); - PYSTATUS.config.as_mut().unwrap() + ptr.as_mut().unwrap() } } } diff --git a/ica-rs/src/status.rs b/ica-rs/src/status.rs index b884bc0..4b96b7f 100644 --- a/ica-rs/src/status.rs +++ b/ica-rs/src/status.rs @@ -44,20 +44,37 @@ impl BotStatus { unsafe { MAIN_STATUS.startup_time.unwrap() } } - pub fn global_config() -> &'static BotConfig { unsafe { MAIN_STATUS.config.as_ref().unwrap() } } + pub fn global_config() -> &'static BotConfig { + unsafe { + let ptr = &raw const MAIN_STATUS.config; + (*ptr).as_ref().unwrap() + } + } pub fn global_ica_status() -> &'static ica::MainStatus { - unsafe { MAIN_STATUS.ica_status.as_ref().unwrap() } + unsafe { + let ptr = &raw const MAIN_STATUS.ica_status; + (*ptr).as_ref().unwrap() + } } pub fn global_tailchat_status() -> &'static tailchat::MainStatus { - unsafe { MAIN_STATUS.tailchat_status.as_ref().unwrap() } + unsafe { + let ptr = &raw const MAIN_STATUS.tailchat_status; + (*ptr).as_ref().unwrap() + } } pub fn global_ica_status_mut() -> &'static mut ica::MainStatus { - unsafe { MAIN_STATUS.ica_status.as_mut().unwrap() } + unsafe { + let ptr = &raw mut MAIN_STATUS.ica_status; + (*ptr).as_mut().unwrap() + } } pub fn global_tailchat_status_mut() -> &'static mut tailchat::MainStatus { - unsafe { MAIN_STATUS.tailchat_status.as_mut().unwrap() } + unsafe { + let ptr = &raw mut MAIN_STATUS.tailchat_status; + (*ptr).as_mut().unwrap() + } } } diff --git a/news.md b/news.md index 702d6fd..eb178cf 100644 --- a/news.md +++ b/news.md @@ -2,6 +2,8 @@ ## 0.7.3 +- 也许修复了删除插件不会立即生效的问题 +- ica 兼容版本号更新到 `2.12.21` 添加了一些新的 api ### ica 1.6.4