2024-02-18 21:25:42 +08:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2024-01-24 18:14:50 +08:00
|
|
|
mod config;
|
2024-03-13 01:17:50 +08:00
|
|
|
mod data_struct;
|
|
|
|
#[cfg(feature = "ica")]
|
2024-03-12 00:47:00 +08:00
|
|
|
mod ica;
|
2024-03-13 01:17:50 +08:00
|
|
|
#[cfg(feature = "matrix")]
|
2024-03-12 00:16:12 +08:00
|
|
|
mod matrix;
|
2024-01-24 18:14:50 +08:00
|
|
|
mod py;
|
2024-03-14 01:12:08 +08:00
|
|
|
mod status;
|
2023-12-11 01:17:25 +08:00
|
|
|
|
2024-03-13 01:20:41 +08:00
|
|
|
use config::BotConfig;
|
2024-03-15 00:40:22 +08:00
|
|
|
use tracing::{event, info, Level};
|
2024-03-14 01:12:08 +08:00
|
|
|
|
|
|
|
pub static mut MAIN_STATUS: status::BotStatus = status::BotStatus {
|
2024-02-20 17:47:45 +08:00
|
|
|
config: None,
|
2024-03-14 01:12:08 +08:00
|
|
|
ica_status: None,
|
|
|
|
matrix_status: None,
|
2024-02-20 14:47:53 +08:00
|
|
|
};
|
|
|
|
|
2024-03-14 01:12:08 +08:00
|
|
|
pub type MainStatus = status::BotStatus;
|
|
|
|
|
2024-02-20 20:51:14 +08:00
|
|
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
2024-03-15 00:40:22 +08:00
|
|
|
pub const ICA_VERSION: &str = "0.5.0";
|
|
|
|
pub const MATRIX_VERSION: &str = "0.1.0";
|
2024-02-20 20:51:14 +08:00
|
|
|
|
2024-03-12 00:47:00 +08:00
|
|
|
#[macro_export]
|
2024-02-21 21:42:27 +08:00
|
|
|
macro_rules! wrap_callback {
|
|
|
|
($f:expr) => {
|
|
|
|
|payload: Payload, client: Client| $f(payload, client).boxed()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-03-12 00:47:00 +08:00
|
|
|
#[macro_export]
|
2024-02-21 21:42:27 +08:00
|
|
|
macro_rules! wrap_any_callback {
|
|
|
|
($f:expr) => {
|
|
|
|
|event: Event, payload: Payload, client: Client| $f(event, payload, client).boxed()
|
|
|
|
};
|
|
|
|
}
|
2024-03-13 01:17:50 +08:00
|
|
|
|
2024-03-12 00:16:12 +08:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init();
|
2024-03-15 00:40:22 +08:00
|
|
|
event!(Level::INFO, "shenbot-async-rs v{} main", VERSION);
|
2024-03-12 00:16:12 +08:00
|
|
|
|
2024-03-13 01:17:50 +08:00
|
|
|
let bot_config = BotConfig::new_from_cli();
|
2024-03-15 00:40:22 +08:00
|
|
|
MainStatus::static_init(bot_config);
|
|
|
|
let bot_config = MainStatus::global_config();
|
|
|
|
|
|
|
|
py::init_py();
|
2024-03-12 00:16:12 +08:00
|
|
|
|
|
|
|
// 准备一个用于停止 socket 的变量
|
|
|
|
let (send, recv) = tokio::sync::oneshot::channel::<()>();
|
2024-03-13 01:17:50 +08:00
|
|
|
|
|
|
|
if bot_config.check_ica() {
|
2024-03-12 00:16:12 +08:00
|
|
|
info!("启动 ica");
|
|
|
|
let config = bot_config.ica();
|
|
|
|
tokio::spawn(async move {
|
2024-03-12 00:47:00 +08:00
|
|
|
ica::start_ica(&config, recv).await;
|
2024-03-12 00:16:12 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
info!("未启用 ica");
|
|
|
|
}
|
2024-02-20 18:22:59 +08:00
|
|
|
|
2024-02-25 18:20:03 +08:00
|
|
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
2024-02-18 23:17:43 +08:00
|
|
|
// 等待一个输入
|
|
|
|
info!("Press any key to exit");
|
|
|
|
let mut input = String::new();
|
|
|
|
std::io::stdin().read_line(&mut input).unwrap();
|
2024-02-21 21:42:27 +08:00
|
|
|
|
2024-03-12 00:16:12 +08:00
|
|
|
send.send(()).ok();
|
2024-03-13 01:17:50 +08:00
|
|
|
|
2024-02-18 23:17:43 +08:00
|
|
|
info!("Disconnected");
|
2023-12-11 00:00:01 +08:00
|
|
|
}
|