diff --git a/config-temp.toml b/config-temp.toml index dfda7d5..8c005e4 100644 --- a/config-temp.toml +++ b/config-temp.toml @@ -2,7 +2,14 @@ private_key = "" # 与 icalingua 客户端使用的 private_key 一致 host = "" # docker 版 icalingua 服务的地址 self_id = 0 # 机器人的 qq 号 + +# 启动时通知的群号/人 notice_room = [-0] # 启动 bot 后通知的群号/人 # 群号请使用群号的负数 - notice_start = true # 是否在启动 bot 后通知 + +# 机器人的管理员 +admin_list = [0] # 机器人的管理员 + +# python 插件路径 +py_plugin_path = "/path/to/your/plugin" diff --git a/ica-rs/Cargo.toml b/ica-rs/Cargo.toml index 3a88190..fe0bdeb 100644 --- a/ica-rs/Cargo.toml +++ b/ica-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ica-rs" -version = "0.2.0" +version = "0.4.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ica-rs/src/client.rs b/ica-rs/src/client.rs index 0f24728..8faeccd 100644 --- a/ica-rs/src/client.rs +++ b/ica-rs/src/client.rs @@ -51,9 +51,9 @@ pub struct IcalinguaSinger { } impl IcalinguaSinger { - pub fn new_from_config(config: IcaConfig) -> Self { - let host = config.host; - let pub_key = config.private_key; + pub fn new_from_config(config: &IcaConfig) -> Self { + let host = config.host.clone(); + let pub_key = config.private_key.clone(); Self::new_from_raw(host, pub_key) } diff --git a/ica-rs/src/config.rs b/ica-rs/src/config.rs index e03e701..10614b1 100644 --- a/ica-rs/src/config.rs +++ b/ica-rs/src/config.rs @@ -16,9 +16,11 @@ pub struct IcaConfig { /// 提醒的房间 pub notice_room: Vec, /// 是否提醒 - pub notice_start: Option, + pub notice_start: bool, + /// 管理员列表 + pub admin_list: Vec, /// Python 插件路径 - pub py_plugin_path: Option, + pub py_plugin_path: String, } impl IcaConfig { diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index 6aff8d3..7ae804b 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -29,7 +29,7 @@ fn main() { unsafe { ClientStatus.update_config(ica_config.clone()); } - let ica_singer = client::IcalinguaSinger::new_from_config(ica_config); + let ica_singer = client::IcalinguaSinger::new_from_config(&ica_config); let socket = ClientBuilder::new(ica_singer.host.clone()) .transport_type(rust_socketio::TransportType::Websocket) @@ -46,6 +46,22 @@ fn main() { .expect("Connection failed"); info!("Connected"); + + if ica_config.notice_start { + for room in ica_config.notice_room.iter() { + let startup_msg = crate::data_struct::messages::SendMessage::new( + format!("ica-rs bot v{}", env!("CARGO_PKG_VERSION")), + room.clone(), + None, + ); + std::thread::sleep(Duration::from_secs(1)); + info!("发送启动消息到房间: {}", room); + if let Err(e) = socket.emit("sendMessage", serde_json::to_value(startup_msg).unwrap()) { + info!("启动信息发送失败 房间:{}|e:{}", room, e); + } + } + } + std::thread::sleep(Duration::from_secs(3)); // 等待一个输入 info!("Press any key to exit"); diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index c8c2dab..8843ffe 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -1,14 +1,13 @@ pub mod class; -use pyo3::{prelude::*, types::{IntoPyDict, PyDict}}; +use pyo3::{prelude::*, types::IntoPyDict}; use tracing::{debug, info}; - pub fn run() { Python::with_gil(|py| { let bot_status = class::IcaStatusPy::new(); let _bot_status: &PyCell<_> = PyCell::new(py, bot_status).unwrap(); - + let locals = [("state", _bot_status)].into_py_dict(py); py.run("print(state)", None, Some(locals)).unwrap(); });