添加 ica config 到 clientStatus

This commit is contained in:
shenjack 2024-02-20 17:47:45 +08:00
parent 85f4c6088c
commit 8aae68ae6b
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 15 additions and 1 deletions

View File

@ -11,6 +11,7 @@ pub struct IcalinguaStatus {
pub login: bool, pub login: bool,
pub online_data: Option<OnlineData>, pub online_data: Option<OnlineData>,
pub rooms: Option<Vec<Room>>, pub rooms: Option<Vec<Room>>,
pub config: Option<IcaConfig>,
} }
impl IcalinguaStatus { impl IcalinguaStatus {
@ -19,6 +20,7 @@ impl IcalinguaStatus {
login: false, login: false,
online_data: None, online_data: None,
rooms: None, rooms: None,
config: Some(IcaConfig::new_from_cli()),
} }
} }
@ -33,6 +35,14 @@ impl IcalinguaStatus {
pub fn update_login_status(&mut self, login: bool) { pub fn update_login_status(&mut self, login: bool) {
self.login = login; 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 { pub struct IcalinguaSinger {

View File

@ -5,7 +5,7 @@ use serde::Deserialize;
use toml::from_str; use toml::from_str;
/// Icalingua bot 的配置 /// Icalingua bot 的配置
#[derive(Debug, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct IcaConfig { pub struct IcaConfig {
/// icalingua 私钥 /// icalingua 私钥
pub private_key: String, pub private_key: String,

View File

@ -14,6 +14,7 @@ pub static mut ClientStatus: client::IcalinguaStatus = client::IcalinguaStatus {
login: false, login: false,
online_data: None, online_data: None,
rooms: None, rooms: None,
config: None,
}; };
fn main() { fn main() {
@ -25,6 +26,9 @@ fn main() {
// 从命令行获取 host 和 key // 从命令行获取 host 和 key
// 从命令行获取配置文件路径 // 从命令行获取配置文件路径
let ica_config = config::IcaConfig::new_from_cli(); 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 ica_singer = client::IcalinguaSinger::new_from_config(ica_config);
let socket = ClientBuilder::new(ica_singer.host.clone()) let socket = ClientBuilder::new(ica_singer.host.clone())