mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-02-23 01:09:58 +08:00
add default config
This commit is contained in:
parent
79b306d089
commit
f8cd207923
|
@ -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 <config_file_path>
|
||||
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" {
|
||||
|
|
|
@ -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<Room>,
|
||||
/// 在线数据 (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<Room>,
|
||||
// /// 在线数据 (Icalingua 信息)
|
||||
// pub online_status: OnlineData,
|
||||
// }
|
||||
|
||||
impl MainStatus {
|
||||
pub fn update_rooms(&mut self, room: Vec<Room>) { 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<Room>) { self.rooms = room; }
|
||||
// pub fn update_online_status(&mut self, status: OnlineData) { self.online_status = status; }
|
||||
// }
|
||||
// }
|
||||
|
||||
static ICA_STATUS: OnceLock<status::MainStatus> = OnceLock::new();
|
||||
// static ICA_STATUS: OnceLock<status::MainStatus> = OnceLock::new();
|
||||
|
||||
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
|
||||
let span = span!(Level::INFO, "Icalingua Client");
|
||||
|
|
|
@ -101,10 +101,41 @@ macro_rules! async_any_callback_with_state {
|
|||
}};
|
||||
}
|
||||
|
||||
const CLI_HELP_MSG: &str = r#"{VERSION}
|
||||
-d
|
||||
debug 模式
|
||||
-t
|
||||
trace 模式
|
||||
-h
|
||||
显示帮助信息
|
||||
-c <config_file_path>
|
||||
指定配置文件路径
|
||||
"#;
|
||||
|
||||
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::<Vec<String>>();
|
||||
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::<Vec<String>>();
|
||||
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();
|
||||
|
||||
|
|
|
@ -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<Self> {
|
||||
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> {
|
||||
|
|
|
@ -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::<Vec<u16>>();
|
||||
let wide_path =
|
||||
OsStr::new(&virtual_env).encode_wide().chain(Some(0)).collect::<Vec<u16>>();
|
||||
|
||||
// 设置 prefix 和 exec_prefix
|
||||
pyo3::ffi::PyConfig_SetString(
|
||||
|
|
Loading…
Reference in New Issue
Block a user