socket-bot/ica-rs/src/main.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

2024-02-18 21:25:42 +08:00
use std::time::Duration;
use rust_socketio::ClientBuilder;
mod client;
mod config;
2024-02-18 21:25:42 +08:00
mod data_struct;
mod events;
mod py;
fn ws_main() {
2024-02-10 21:26:57 +08:00
py::init_py();
2024-02-18 21:25:42 +08:00
2023-12-11 18:17:55 +08:00
// 从命令行获取 host 和 key
2023-12-24 17:27:15 +08:00
// 从命令行获取配置文件路径
let ica_config = config::IcaConfig::new_from_cli();
let ica_singer = client::IcalinguaSinger::new_from_config(ica_config);
2023-12-24 17:27:15 +08:00
let socket = ClientBuilder::new(ica_singer.host.clone())
2024-02-10 12:18:09 +08:00
.transport_type(rust_socketio::TransportType::Websocket)
2024-02-18 21:25:42 +08:00
.on_any(events::any_event)
.on("onlineData", events::get_online_data)
.on("message", events::connect_callback)
.on("requireAuth", move |a, b| ica_singer.sign_callback(a, b))
2024-02-18 21:25:42 +08:00
.on("authRequired", events::connect_callback)
.on("authSucceed", events::connect_callback)
.on("authFailed", events::connect_callback)
.connect()
.expect("Connection failed");
std::thread::sleep(Duration::from_secs(10));
socket.disconnect().expect("Disconnect failed")
}
fn main() {
2024-02-10 12:18:09 +08:00
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();
ws_main();
}