diff --git a/ica-rs/src/client.rs b/ica-rs/src/client.rs index c8d2908..0f24728 100644 --- a/ica-rs/src/client.rs +++ b/ica-rs/src/client.rs @@ -11,6 +11,7 @@ pub struct IcalinguaStatus { pub login: bool, pub online_data: Option, pub rooms: Option>, + pub config: Option, } impl IcalinguaStatus { @@ -19,6 +20,7 @@ impl IcalinguaStatus { login: false, online_data: None, rooms: None, + config: Some(IcaConfig::new_from_cli()), } } @@ -33,6 +35,14 @@ impl IcalinguaStatus { pub fn update_login_status(&mut self, login: bool) { self.login = login; } + + pub fn update_config(&mut self, config: IcaConfig) { + self.config = Some(config); + } + + pub fn get_config(&self) -> &IcaConfig { + self.config.as_ref().unwrap() + } } pub struct IcalinguaSinger { diff --git a/ica-rs/src/config.rs b/ica-rs/src/config.rs index c19b7c7..e03e701 100644 --- a/ica-rs/src/config.rs +++ b/ica-rs/src/config.rs @@ -5,7 +5,7 @@ use serde::Deserialize; use toml::from_str; /// Icalingua bot 的配置 -#[derive(Debug, Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct IcaConfig { /// icalingua 私钥 pub private_key: String, diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index c68c606..6aff8d3 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -14,6 +14,7 @@ pub static mut ClientStatus: client::IcalinguaStatus = client::IcalinguaStatus { login: false, online_data: None, rooms: None, + config: None, }; fn main() { @@ -25,6 +26,9 @@ fn main() { // 从命令行获取 host 和 key // 从命令行获取配置文件路径 let ica_config = config::IcaConfig::new_from_cli(); + unsafe { + ClientStatus.update_config(ica_config.clone()); + } let ica_singer = client::IcalinguaSinger::new_from_config(ica_config); let socket = ClientBuilder::new(ica_singer.host.clone())