2024-01-24 18:14:50 +08:00
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
use serde::Deserialize;
|
2024-02-20 17:15:14 +08:00
|
|
|
use toml::from_str;
|
2024-01-24 18:14:50 +08:00
|
|
|
|
2024-02-18 22:43:54 +08:00
|
|
|
/// Icalingua bot 的配置
|
2024-02-20 17:47:45 +08:00
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
2024-01-24 18:14:50 +08:00
|
|
|
pub struct IcaConfig {
|
|
|
|
/// icalingua 私钥
|
|
|
|
pub private_key: String,
|
|
|
|
/// icalingua 服务器地址
|
|
|
|
pub host: String,
|
|
|
|
/// bot 的 qq
|
|
|
|
pub self_id: u64,
|
|
|
|
/// 提醒的房间
|
|
|
|
pub notice_room: Vec<i64>,
|
|
|
|
/// 是否提醒
|
|
|
|
pub notice_start: Option<bool>,
|
|
|
|
/// Python 插件路径
|
2024-01-25 22:08:02 +08:00
|
|
|
pub py_plugin_path: Option<String>,
|
2024-01-24 18:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl IcaConfig {
|
|
|
|
pub fn new_from_path(config_file_path: String) -> Self {
|
|
|
|
// try read config from file
|
|
|
|
let config = fs::read_to_string(&config_file_path).expect("Failed to read config file");
|
2024-02-20 17:15:14 +08:00
|
|
|
let ret: Self = from_str(&config)
|
2024-01-24 18:14:50 +08:00
|
|
|
.expect(format!("Failed to parse config file {}", &config_file_path).as_str());
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
pub fn new_from_cli() -> Self {
|
|
|
|
let config_file_path = env::args().nth(1).expect("No config path given");
|
|
|
|
Self::new_from_path(config_file_path)
|
|
|
|
}
|
|
|
|
}
|