mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 12:41:05 +08:00
进行一个虚心接受批评
This commit is contained in:
parent
98633aa5cc
commit
38cfd2dce7
|
@ -1,6 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
hash::{DefaultHasher, Hash, Hasher},
|
hash::{DefaultHasher, Hash, Hasher},
|
||||||
time::Duration,
|
sync::OnceLock,
|
||||||
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
@ -21,7 +22,6 @@ pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
|
||||||
config: None,
|
config: None,
|
||||||
ica_status: None,
|
ica_status: None,
|
||||||
tailchat_status: None,
|
tailchat_status: None,
|
||||||
startup_time: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type MainStatus = status::BotStatus;
|
pub type MainStatus = status::BotStatus;
|
||||||
|
@ -48,11 +48,17 @@ by shenjackyuanjie"#;
|
||||||
/// 获取帮助信息
|
/// 获取帮助信息
|
||||||
pub fn help_msg() -> String { format!("{}\n{}", version_str(), HELP_MSG) }
|
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
|
/// 获得当前客户端的 id
|
||||||
/// 防止串号
|
/// 防止串号
|
||||||
pub fn client_id() -> String {
|
pub fn client_id() -> String {
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
MainStatus::get_startup_time().hash(&mut hasher);
|
start_up_time().hash(&mut hasher);
|
||||||
let data = hasher.finish();
|
let data = hasher.finish();
|
||||||
// 取后6位
|
// 取后6位
|
||||||
format!("{:06}", data % 1_000_000)
|
format!("{:06}", data % 1_000_000)
|
||||||
|
@ -96,6 +102,9 @@ macro_rules! async_any_callback_with_state {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
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()
|
tokio::runtime::Builder::new_multi_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.thread_name("shenbot-rs")
|
.thread_name("shenbot-rs")
|
||||||
|
|
|
@ -228,7 +228,7 @@ impl IcaClientPy {
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_ica_version(&self) -> String { crate::ICA_VERSION.to_string() }
|
pub fn get_ica_version(&self) -> String { crate::ICA_VERSION.to_string() }
|
||||||
#[getter]
|
#[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) {
|
pub fn debug(&self, content: String) {
|
||||||
event!(Level::DEBUG, "{}", content);
|
event!(Level::DEBUG, "{}", content);
|
||||||
|
|
|
@ -71,7 +71,8 @@ impl TailchatClientPy {
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
|
pub fn get_tailchat_version(&self) -> String { crate::TAILCHAT_VERSION.to_string() }
|
||||||
#[getter]
|
#[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))]
|
#[pyo3(signature = (content, converse_id, group_id = None))]
|
||||||
pub fn new_message(
|
pub fn new_message(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl PyStatus {
|
||||||
pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> { Self::get_map_mut().remove(path) }
|
pub fn delete_file(path: &PathBuf) -> Option<PyPlugin> { Self::get_map_mut().remove(path) }
|
||||||
|
|
||||||
pub fn verify_file(path: &PathBuf) -> bool {
|
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 {
|
pub fn get_map() -> &'static PyPlugins {
|
||||||
|
|
|
@ -6,7 +6,6 @@ pub struct BotStatus {
|
||||||
pub config: Option<BotConfig>,
|
pub config: Option<BotConfig>,
|
||||||
pub ica_status: Option<ica::MainStatus>,
|
pub ica_status: Option<ica::MainStatus>,
|
||||||
pub tailchat_status: Option<tailchat::MainStatus>,
|
pub tailchat_status: Option<tailchat::MainStatus>,
|
||||||
pub startup_time: Option<std::time::SystemTime>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotStatus {
|
impl BotStatus {
|
||||||
|
@ -36,14 +35,9 @@ impl BotStatus {
|
||||||
online_status: ica::OnlineData::default(),
|
online_status: ica::OnlineData::default(),
|
||||||
});
|
});
|
||||||
MAIN_STATUS.config = Some(config);
|
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 {
|
pub fn global_config() -> &'static BotConfig {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = &raw const MAIN_STATUS.config;
|
let ptr = &raw const MAIN_STATUS.config;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user