From 8aae68ae6bd6a0268d47b4b52e88bcbb3a644f53 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 20 Feb 2024 17:47:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20ica=20config=20=E5=88=B0?= =?UTF-8?q?=20clientStatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/src/client.rs | 10 ++++++++++ ica-rs/src/config.rs | 2 +- ica-rs/src/main.rs | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) 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())