mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-27 06:35:06 +08:00
匹配版本号到 0.4.0, 准备写加载Python插件部分
This commit is contained in:
parent
8aae68ae6b
commit
f2ea1764ae
|
@ -2,7 +2,14 @@
|
||||||
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
|
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
|
||||||
host = "" # docker 版 icalingua 服务的地址
|
host = "" # docker 版 icalingua 服务的地址
|
||||||
self_id = 0 # 机器人的 qq 号
|
self_id = 0 # 机器人的 qq 号
|
||||||
|
|
||||||
|
# 启动时通知的群号/人
|
||||||
notice_room = [-0] # 启动 bot 后通知的群号/人
|
notice_room = [-0] # 启动 bot 后通知的群号/人
|
||||||
# 群号请使用群号的负数
|
# 群号请使用群号的负数
|
||||||
|
|
||||||
notice_start = true # 是否在启动 bot 后通知
|
notice_start = true # 是否在启动 bot 后通知
|
||||||
|
|
||||||
|
# 机器人的管理员
|
||||||
|
admin_list = [0] # 机器人的管理员
|
||||||
|
|
||||||
|
# python 插件路径
|
||||||
|
py_plugin_path = "/path/to/your/plugin"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ica-rs"
|
name = "ica-rs"
|
||||||
version = "0.2.0"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -51,9 +51,9 @@ pub struct IcalinguaSinger {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IcalinguaSinger {
|
impl IcalinguaSinger {
|
||||||
pub fn new_from_config(config: IcaConfig) -> Self {
|
pub fn new_from_config(config: &IcaConfig) -> Self {
|
||||||
let host = config.host;
|
let host = config.host.clone();
|
||||||
let pub_key = config.private_key;
|
let pub_key = config.private_key.clone();
|
||||||
Self::new_from_raw(host, pub_key)
|
Self::new_from_raw(host, pub_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,11 @@ pub struct IcaConfig {
|
||||||
/// 提醒的房间
|
/// 提醒的房间
|
||||||
pub notice_room: Vec<i64>,
|
pub notice_room: Vec<i64>,
|
||||||
/// 是否提醒
|
/// 是否提醒
|
||||||
pub notice_start: Option<bool>,
|
pub notice_start: bool,
|
||||||
|
/// 管理员列表
|
||||||
|
pub admin_list: Vec<i64>,
|
||||||
/// Python 插件路径
|
/// Python 插件路径
|
||||||
pub py_plugin_path: Option<String>,
|
pub py_plugin_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IcaConfig {
|
impl IcaConfig {
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
ClientStatus.update_config(ica_config.clone());
|
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())
|
let socket = ClientBuilder::new(ica_singer.host.clone())
|
||||||
.transport_type(rust_socketio::TransportType::Websocket)
|
.transport_type(rust_socketio::TransportType::Websocket)
|
||||||
|
@ -46,6 +46,22 @@ fn main() {
|
||||||
.expect("Connection failed");
|
.expect("Connection failed");
|
||||||
|
|
||||||
info!("Connected");
|
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));
|
std::thread::sleep(Duration::from_secs(3));
|
||||||
// 等待一个输入
|
// 等待一个输入
|
||||||
info!("Press any key to exit");
|
info!("Press any key to exit");
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
pub mod class;
|
pub mod class;
|
||||||
|
|
||||||
use pyo3::{prelude::*, types::{IntoPyDict, PyDict}};
|
use pyo3::{prelude::*, types::IntoPyDict};
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
Python::with_gil(|py| {
|
Python::with_gil(|py| {
|
||||||
let bot_status = class::IcaStatusPy::new();
|
let bot_status = class::IcaStatusPy::new();
|
||||||
let _bot_status: &PyCell<_> = PyCell::new(py, bot_status).unwrap();
|
let _bot_status: &PyCell<_> = PyCell::new(py, bot_status).unwrap();
|
||||||
|
|
||||||
let locals = [("state", _bot_status)].into_py_dict(py);
|
let locals = [("state", _bot_status)].into_py_dict(py);
|
||||||
py.run("print(state)", None, Some(locals)).unwrap();
|
py.run("print(state)", None, Some(locals)).unwrap();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user