进行一个虚心接受批评

This commit is contained in:
shenjack 2024-11-19 22:17:55 +08:00
parent 98633aa5cc
commit 38cfd2dce7
Signed by: shenjack
GPG Key ID: 7B1134A979775551
5 changed files with 16 additions and 12 deletions

View File

@ -1,6 +1,7 @@
use std::{
hash::{DefaultHasher, Hash, Hasher},
time::Duration,
sync::OnceLock,
time::{Duration, SystemTime},
};
mod config;
@ -21,7 +22,6 @@ pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
config: None,
ica_status: None,
tailchat_status: None,
startup_time: None,
};
pub type MainStatus = status::BotStatus;
@ -48,11 +48,17 @@ by shenjackyuanjie"#;
/// 获取帮助信息
pub fn help_msg() -> String { format!("{}\n{}", version_str(), HELP_MSG) }
static STARTUP_TIME: OnceLock<SystemTime> = OnceLock::new();
pub fn start_up_time() -> SystemTime {
*STARTUP_TIME.get().expect("WTF, why did you panic?")
}
/// 获得当前客户端的 id
/// 防止串号
pub fn client_id() -> String {
let mut hasher = DefaultHasher::new();
MainStatus::get_startup_time().hash(&mut hasher);
start_up_time().hash(&mut hasher);
let data = hasher.finish();
// 取后6位
format!("{:06}", data % 1_000_000)
@ -96,6 +102,9 @@ macro_rules! async_any_callback_with_state {
}
fn main() -> anyhow::Result<()> {
let start_up_time = SystemTime::now();
STARTUP_TIME.set(start_up_time).expect("WTF, why did you panic?");
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("shenbot-rs")

View File

@ -228,7 +228,7 @@ impl IcaClientPy {
#[getter]
pub fn get_ica_version(&self) -> String { crate::ICA_VERSION.to_string() }
#[getter]
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }
pub fn get_startup_time(&self) -> SystemTime { crate::start_up_time() }
pub fn debug(&self, content: String) {
event!(Level::DEBUG, "{}", content);

View File

@ -71,7 +71,8 @@ impl TailchatClientPy {
#[getter]
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
#[getter]
pub fn get_startup_time(&self) -> SystemTime { crate::MainStatus::get_startup_time() }
pub fn get_startup_time(&self) -> SystemTime { crate::start_up_time() }
#[pyo3(signature = (content, converse_id, group_id = None))]
pub fn new_message(
&self,

View File

@ -45,7 +45,7 @@ impl PyStatus {
pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> { Self::get_map_mut().remove(path) }
pub fn verify_file(path: &PathBuf) -> bool {
Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy())
Self::get_map().get(path).is_some_and(|plugin| plugin.verifiy())
}
pub fn get_map() -> &'static PyPlugins {

View File

@ -6,7 +6,6 @@ pub struct BotStatus {
pub config: Option<BotConfig>,
pub ica_status: Option<ica::MainStatus>,
pub tailchat_status: Option<tailchat::MainStatus>,
pub startup_time: Option<std::time::SystemTime>,
}
impl BotStatus {
@ -36,14 +35,9 @@ impl BotStatus {
online_status: ica::OnlineData::default(),
});
MAIN_STATUS.config = Some(config);
MAIN_STATUS.startup_time = Some(std::time::SystemTime::now());
}
}
pub fn get_startup_time() -> std::time::SystemTime {
unsafe { MAIN_STATUS.startup_time.unwrap() }
}
pub fn global_config() -> &'static BotConfig {
unsafe {
let ptr = &raw const MAIN_STATUS.config;