diff --git a/ica-rs/src/ica/events.rs b/ica-rs/src/ica/events.rs index 46e8b0d..96f1a39 100644 --- a/ica-rs/src/ica/events.rs +++ b/ica-rs/src/ica/events.rs @@ -56,12 +56,10 @@ pub async fn add_message(payload: Payload, client: Client) { } if MainStatus::global_config().ica().admin_list.contains(&message.sender_id()) { // admin 区 + // 先判定是否为 admin if message.content().starts_with("/bot-enable") { - // 先判定是否为 admin // 尝试获取后面的信息 - let mut content = message.content().split_whitespace(); - content.next(); - if let Some(name) = content.next() { + if let Some((_, name)) = message.content().split_once(" ") { let path_name = PathBuf::from(name); match py::PyStatus::get_status(&path_name) { None => { @@ -80,9 +78,7 @@ pub async fn add_message(payload: Payload, client: Client) { } } } else if message.content().starts_with("/bot-disable") { - let mut content = message.content().split_whitespace(); - content.next(); - if let Some(name) = content.next() { + if let Some((_, name)) = message.content().split_once(" ") { let path_name = PathBuf::from(name); match py::PyStatus::get_status(&path_name) { None => { diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index c2b4ce8..8d6bb13 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{hash::{DefaultHasher, Hash, Hasher}, time::Duration}; mod config; mod data_struct; @@ -42,7 +42,20 @@ const HELP_MSG: &str = r#"/bot-rs by shenjackyuanjie"#; +/// 获取帮助信息 pub fn help_msg() -> String { format!("{}\n{}", version_str(), HELP_MSG) } + +/// 获得当前客户端的 id +/// 防止串号 +pub fn client_id() -> String { + let mut hasher = DefaultHasher::new(); + MainStatus::get_startup_time().hash(&mut hasher); + let data = hasher.finish(); + // 取后6位 + format!("{:06}", data % 1_000_000) +} + +/// 获取版本信息 pub fn version_str() -> String { format!( "shenbot-rs v{}-{} ica v{}({}) tailchat v{}", @@ -56,7 +69,7 @@ pub fn version_str() -> String { /// 是否为稳定版本 /// 会在 release 的时候设置为 true -pub const STABLE: bool = true; +pub const STABLE: bool = false; #[macro_export] macro_rules! async_callback_with_state { diff --git a/ica-rs/src/tailchat/events.rs b/ica-rs/src/tailchat/events.rs index fe78814..1bb8a03 100644 --- a/ica-rs/src/tailchat/events.rs +++ b/ica-rs/src/tailchat/events.rs @@ -103,9 +103,7 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc { @@ -124,9 +122,7 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc {