diff --git a/ica-rs/src/config.rs b/ica-rs/src/config.rs index 650b986..b0f8b85 100644 --- a/ica-rs/src/config.rs +++ b/ica-rs/src/config.rs @@ -102,7 +102,7 @@ impl BotConfig { pub fn new_from_cli() -> Self { // let config_file_path = env::args().nth(1).expect("No config path given"); // -c - let mut config_file_path = String::new(); + let mut config_file_path = "./config.toml".to_string(); let mut args = env::args(); while let Some(arg) = args.next() { if arg == "-c" { diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index 21138de..da0460b 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -15,31 +15,31 @@ use crate::{version_str, StopGetter}; /// icalingua 客户端的兼容版本号 pub const ICA_PROTOCOL_VERSION: &str = "2.12.26"; -mod status { - use crate::data_struct::ica::all_rooms::Room; - pub use crate::data_struct::ica::online_data::OnlineData; +// mod status { +// use crate::data_struct::ica::all_rooms::Room; +// pub use crate::data_struct::ica::online_data::OnlineData; - #[derive(Debug, Clone)] - pub struct MainStatus { - /// 是否启用 ica - pub enable: bool, - /// qq 是否登录 - pub qq_login: bool, - /// 当前已加载的消息数量 - pub current_loaded_messages_count: u64, - /// 房间数据 - pub rooms: Vec, - /// 在线数据 (Icalingua 信息) - pub online_status: OnlineData, - } +// #[derive(Debug, Clone)] +// pub struct MainStatus { +// /// 是否启用 ica +// pub enable: bool, +// /// qq 是否登录 +// pub qq_login: bool, +// /// 当前已加载的消息数量 +// pub current_loaded_messages_count: u64, +// /// 房间数据 +// pub rooms: Vec, +// /// 在线数据 (Icalingua 信息) +// pub online_status: OnlineData, +// } - impl MainStatus { - pub fn update_rooms(&mut self, room: Vec) { self.rooms = room; } - pub fn update_online_status(&mut self, status: OnlineData) { self.online_status = status; } - } -} +// impl MainStatus { +// pub fn update_rooms(&mut self, room: Vec) { self.rooms = room; } +// pub fn update_online_status(&mut self, status: OnlineData) { self.online_status = status; } +// } +// } -static ICA_STATUS: OnceLock = OnceLock::new(); +// static ICA_STATUS: OnceLock = OnceLock::new(); pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> { let span = span!(Level::INFO, "Icalingua Client"); diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index c04082d..bcdc05b 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -101,10 +101,41 @@ macro_rules! async_any_callback_with_state { }}; } +const CLI_HELP_MSG: &str = r#"{VERSION} + -d + debug 模式 + -t + trace 模式 + -h + 显示帮助信息 + -c + 指定配置文件路径 +"#; + fn main() -> anyhow::Result<()> { let start_up_time = SystemTime::now(); STARTUP_TIME.set(start_up_time).expect("WTF, why did you panic?"); + // -d -> debug + // none -> info + let args = std::env::args(); + let args = args.collect::>(); + if args.contains(&"-h".to_string()) { + println!("{}", CLI_HELP_MSG.replace("{VERSION}", version_str().as_str())); + return Ok(()); + } + let level = { + if args.contains(&"-d".to_string()) { + Level::DEBUG + } else if args.contains(&"-t".to_string()) { + Level::TRACE + } else { + Level::INFO + } + }; + + tracing_subscriber::fmt().with_max_level(level).init(); + tokio::runtime::Builder::new_multi_thread() .enable_all() .thread_name("shenbot-rs") @@ -115,21 +146,6 @@ fn main() -> anyhow::Result<()> { } async fn inner_main() -> anyhow::Result<()> { - // -d -> debug - // none -> info - let level = { - let args = std::env::args(); - let args = args.collect::>(); - if args.contains(&"-d".to_string()) { - Level::DEBUG - } else if args.contains(&"-t".to_string()) { - Level::TRACE - } else { - Level::INFO - } - }; - - tracing_subscriber::fmt().with_max_level(level).init(); let span = span!(Level::INFO, "Shenbot Main"); let _enter = span.enter(); diff --git a/ica-rs/src/py/config.rs b/ica-rs/src/py/config.rs index cc5a418..15a9d24 100644 --- a/ica-rs/src/py/config.rs +++ b/ica-rs/src/py/config.rs @@ -1,7 +1,4 @@ -use std::{ - path::{Path, PathBuf}, - str::FromStr, -}; +use std::{path::Path, str::FromStr}; use toml_edit::{value, DocumentMut, Key, Table, TomlError, Value}; use tracing::{event, Level}; @@ -46,7 +43,7 @@ impl PluginConfigFile { pub fn default_init() -> anyhow::Result { let config_path = MainStatus::global_config().py().config_path.clone(); let path = Path::new(&config_path); - Self::from_config_path(&path) + Self::from_config_path(path) } pub fn reload_from_default(&mut self) -> bool { @@ -165,7 +162,7 @@ impl PluginConfigFile { pub fn write_to_default(&self) -> Result<(), std::io::Error> { let config_path = MainStatus::global_config().py().config_path.clone(); let config_path = Path::new(&config_path); - self.write_to_file(&config_path) + self.write_to_file(config_path) } pub fn write_to_file(&self, path: &Path) -> Result<(), std::io::Error> { diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index d9c366a..6038629 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -439,7 +439,8 @@ pub fn init_py() { #[cfg(target_os = "windows")] use std::os::windows::ffi::OsStrExt; - let wide_path = OsStr::new(&virtual_env).encode_wide().chain(Some(0)).collect::>(); + let wide_path = + OsStr::new(&virtual_env).encode_wide().chain(Some(0)).collect::>(); // 设置 prefix 和 exec_prefix pyo3::ffi::PyConfig_SetString( diff --git a/news.md b/news.md index c9fca43..77b1492 100644 --- a/news.md +++ b/news.md @@ -4,6 +4,7 @@ - 现在支持通过读取环境变量里的 `VIRTUAL_ENV` 来获取虚拟环境路径 - 用于在虚拟环境中运行插件 +- 现在加入了默认的配置文件路径 `./config.toml` ## 0.8.1