From 32f1797edc392c4be2bc2d7333a7ad3f3c5b6868 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 18 Aug 2024 12:35:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=9D=E7=BC=9D=E8=A1=A5=E8=A1=A5=E5=8F=88?= =?UTF-8?q?=E4=B8=89=E5=B9=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/src/ica/events.rs | 10 +++------- ica-rs/src/main.rs | 17 +++++++++++++++-- ica-rs/src/tailchat/events.rs | 8 ++------ 3 files changed, 20 insertions(+), 15 deletions(-) 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 {