缝缝补补又三年

This commit is contained in:
shenjack 2024-08-18 12:35:37 +08:00
parent 38ba77ce42
commit 32f1797edc
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 20 additions and 15 deletions

View File

@ -56,12 +56,10 @@ pub async fn add_message(payload: Payload, client: Client) {
} }
if MainStatus::global_config().ica().admin_list.contains(&message.sender_id()) { if MainStatus::global_config().ica().admin_list.contains(&message.sender_id()) {
// admin 区 // admin 区
if message.content().starts_with("/bot-enable") {
// 先判定是否为 admin // 先判定是否为 admin
if message.content().starts_with("/bot-enable") {
// 尝试获取后面的信息 // 尝试获取后面的信息
let mut content = message.content().split_whitespace(); if let Some((_, name)) = message.content().split_once(" ") {
content.next();
if let Some(name) = content.next() {
let path_name = PathBuf::from(name); let path_name = PathBuf::from(name);
match py::PyStatus::get_status(&path_name) { match py::PyStatus::get_status(&path_name) {
None => { None => {
@ -80,9 +78,7 @@ pub async fn add_message(payload: Payload, client: Client) {
} }
} }
} else if message.content().starts_with("/bot-disable") { } else if message.content().starts_with("/bot-disable") {
let mut content = message.content().split_whitespace(); if let Some((_, name)) = message.content().split_once(" ") {
content.next();
if let Some(name) = content.next() {
let path_name = PathBuf::from(name); let path_name = PathBuf::from(name);
match py::PyStatus::get_status(&path_name) { match py::PyStatus::get_status(&path_name) {
None => { None => {

View File

@ -1,4 +1,4 @@
use std::time::Duration; use std::{hash::{DefaultHasher, Hash, Hasher}, time::Duration};
mod config; mod config;
mod data_struct; mod data_struct;
@ -42,7 +42,20 @@ const HELP_MSG: &str = r#"/bot-rs
by shenjackyuanjie"#; by shenjackyuanjie"#;
/// 获取帮助信息
pub fn help_msg() -> String { format!("{}\n{}", version_str(), HELP_MSG) } 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 { pub fn version_str() -> String {
format!( format!(
"shenbot-rs v{}-{} ica v{}({}) tailchat v{}", "shenbot-rs v{}-{} ica v{}({}) tailchat v{}",
@ -56,7 +69,7 @@ pub fn version_str() -> String {
/// 是否为稳定版本 /// 是否为稳定版本
/// 会在 release 的时候设置为 true /// 会在 release 的时候设置为 true
pub const STABLE: bool = true; pub const STABLE: bool = false;
#[macro_export] #[macro_export]
macro_rules! async_callback_with_state { macro_rules! async_callback_with_state {

View File

@ -103,9 +103,7 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
if message.content.starts_with("/bot-enable") { if message.content.starts_with("/bot-enable") {
// 先判定是否为 admin // 先判定是否为 admin
// 尝试获取后面的信息 // 尝试获取后面的信息
let mut content = message.content.split_whitespace(); if let Some((_, name)) = message.content.split_once(" ") {
content.next();
if let Some(name) = content.next() {
let path_name = PathBuf::from(name); let path_name = PathBuf::from(name);
match py::PyStatus::get_status(&path_name) { match py::PyStatus::get_status(&path_name) {
None => { None => {
@ -124,9 +122,7 @@ pub async fn on_message(payload: Payload, client: Client, _status: Arc<BotStatus
} }
} }
} else if message.content.starts_with("/bot-disable") { } else if message.content.starts_with("/bot-disable") {
let mut content = message.content.split_whitespace(); if let Some((_, name)) = message.content.split_once(" ") {
content.next();
if let Some(name) = content.next() {
let path_name = PathBuf::from(name); let path_name = PathBuf::from(name);
match py::PyStatus::get_status(&path_name) { match py::PyStatus::get_status(&path_name) {
None => { None => {