mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-20 12:09:54 +08:00
Compare commits
2 Commits
4656655017
...
48d4c8fd5d
Author | SHA1 | Date | |
---|---|---|---|
48d4c8fd5d | |||
51cc24e347 |
45
.github/workflows/publish.yml
vendored
Normal file
45
.github/workflows/publish.yml
vendored
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
name: publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish: # 全都要!
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest]
|
||||||
|
# python-version: ["3.8", "3.9", "3.10", "3.11",]
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: 获取版本号
|
||||||
|
id: get_version
|
||||||
|
uses: sravinet/toml-select@v1.0.1
|
||||||
|
with:
|
||||||
|
file: ./ica-rs/Cargo.toml
|
||||||
|
field: "package.version"
|
||||||
|
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v5.0.0
|
||||||
|
with:
|
||||||
|
# Version range or exact version of Python or PyPy to use, using SemVer's version range syntax. Reads from .python-version if unset.
|
||||||
|
python-version: 3.8
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --verbose
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --release
|
||||||
|
|
||||||
|
- name: 上传
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: ica-rs-b${{ github.run_number }}-${{ steps.get_version.outputs.value }}-py38-win-x64
|
||||||
|
path: ./target/release/ica-rs.exe
|
93
Cargo.lock
generated
93
Cargo.lock
generated
|
@ -57,7 +57,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -68,7 +68,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -256,7 +256,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -385,21 +385,6 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures"
|
|
||||||
version = "0.3.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
|
|
||||||
dependencies = [
|
|
||||||
"futures-channel",
|
|
||||||
"futures-core",
|
|
||||||
"futures-executor",
|
|
||||||
"futures-io",
|
|
||||||
"futures-sink",
|
|
||||||
"futures-task",
|
|
||||||
"futures-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
|
@ -407,7 +392,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
|
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-sink",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -416,17 +400,6 @@ version = "0.3.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-executor"
|
|
||||||
version = "0.3.30"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d"
|
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
"futures-task",
|
|
||||||
"futures-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-io"
|
name = "futures-io"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
|
@ -441,7 +414,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -462,7 +435,6 @@ version = "0.3.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-channel",
|
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"futures-macro",
|
"futures-macro",
|
||||||
|
@ -640,7 +612,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ica-rs"
|
name = "ica-rs"
|
||||||
version = "0.4.12"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"colored",
|
"colored",
|
||||||
|
@ -649,7 +621,6 @@ dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hex",
|
"hex",
|
||||||
"pyo3",
|
"pyo3",
|
||||||
"pyo3-asyncio",
|
|
||||||
"rust_socketio",
|
"rust_socketio",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -881,7 +852,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1016,31 +987,6 @@ dependencies = [
|
||||||
"unindent",
|
"unindent",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pyo3-asyncio"
|
|
||||||
version = "0.20.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ea6b68e93db3622f3bb3bf363246cf948ed5375afe7abff98ccbdd50b184995"
|
|
||||||
dependencies = [
|
|
||||||
"futures",
|
|
||||||
"once_cell",
|
|
||||||
"pin-project-lite",
|
|
||||||
"pyo3",
|
|
||||||
"pyo3-asyncio-macros",
|
|
||||||
"tokio",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pyo3-asyncio-macros"
|
|
||||||
version = "0.20.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "56c467178e1da6252c95c29ecf898b133f742e9181dca5def15dc24e19d45a39"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pyo3-build-config"
|
name = "pyo3-build-config"
|
||||||
version = "0.20.3"
|
version = "0.20.3"
|
||||||
|
@ -1070,7 +1016,7 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"pyo3-macros-backend",
|
"pyo3-macros-backend",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1083,7 +1029,7 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"pyo3-build-config",
|
"pyo3-build-config",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1325,7 +1271,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1450,17 +1396,6 @@ version = "2.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.109"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.50"
|
version = "2.0.50"
|
||||||
|
@ -1534,7 +1469,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1620,7 +1555,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1720,7 +1655,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1889,7 +1824,7 @@ dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1923,7 +1858,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.50",
|
"syn",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
|
|
||||||
|
# python 插件路径
|
||||||
|
py_plugin_path = "/path/to/your/plugin"
|
||||||
|
py_config_path = "/path/to/your/config"
|
||||||
|
|
||||||
|
enable_ica = true # 是否启用 ica
|
||||||
|
|
||||||
|
[ica]
|
||||||
|
|
||||||
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
|
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
|
||||||
host = "" # docker 版 icalingua 服务的地址
|
host = "" # docker 版 icalingua 服务的地址
|
||||||
self_id = 0 # 机器人的 qq 号
|
self_id = 0 # 机器人的 qq 号
|
||||||
|
@ -12,7 +20,3 @@ notice_start = true # 是否在启动 bot 后通知
|
||||||
admin_list = [0] # 机器人的管理员
|
admin_list = [0] # 机器人的管理员
|
||||||
# 过滤的人
|
# 过滤的人
|
||||||
filter_list = [0]
|
filter_list = [0]
|
||||||
|
|
||||||
# python 插件路径
|
|
||||||
py_plugin_path = "/path/to/your/plugin"
|
|
||||||
py_config_path = "/path/to/your/config"
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ica-rs"
|
name = "ica-rs"
|
||||||
version = "0.4.12"
|
version = "0.5.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
|
||||||
|
@ -21,7 +21,7 @@ tokio = { version = "1.0", features = ["full"] }
|
||||||
futures-util = "0.3.30"
|
futures-util = "0.3.30"
|
||||||
pyo3 = "0.20.3"
|
pyo3 = "0.20.3"
|
||||||
# pyo3-async = "0.3.2"
|
# pyo3-async = "0.3.2"
|
||||||
pyo3-asyncio = { version = "0.20.0", features = ["attributes", "tokio-runtime"] }
|
# pyo3-asyncio = { version = "0.20.0", features = ["attributes", "tokio-runtime"] }
|
||||||
|
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["time"] }
|
tracing-subscriber = { version = "0.3.18", features = ["time"] }
|
||||||
|
|
|
@ -146,6 +146,9 @@ on_delete_message = Callable[[MessageId, IcaClient], None]
|
||||||
# def on_delete_message(msg_id: MessageId, client: IcaClient) -> None:
|
# def on_delete_message(msg_id: MessageId, client: IcaClient) -> None:
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
|
# TODO: Matrix adapter
|
||||||
|
# on_matrix_room_message = Callable[[RoomId, NewMessage, IcaClient], None]
|
||||||
|
|
||||||
on_config = Callable[[None], Tuple[str, str]]
|
on_config = Callable[[None], Tuple[str, str]]
|
||||||
|
|
||||||
CONFIG_DATA: ConfigData = ConfigData()
|
CONFIG_DATA: ConfigData = ConfigData()
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::config::IcaConfig;
|
use crate::config::{BotConfig, IcaConfig};
|
||||||
use crate::data_struct::all_rooms::Room;
|
use crate::ica::data_struct::all_rooms::Room;
|
||||||
use crate::data_struct::messages::{DeleteMessage, SendMessage};
|
use crate::ica::data_struct::messages::{DeleteMessage, SendMessage};
|
||||||
use crate::data_struct::online_data::OnlineData;
|
use crate::ica::data_struct::online_data::OnlineData;
|
||||||
use crate::ClientStatus;
|
use crate::ClientStatus_Global;
|
||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use ed25519_dalek::{Signature, Signer, SigningKey};
|
use ed25519_dalek::{Signature, Signer, SigningKey};
|
||||||
|
@ -47,73 +47,85 @@ pub async fn delete_message(client: &Client, message: &DeleteMessage) -> bool {
|
||||||
// pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false }
|
// pub async fn fetch_history(client: &Client, roomd_id: RoomId) -> bool { false }
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct IcalinguaStatus {
|
pub struct BotStatus {
|
||||||
pub login: bool,
|
pub login: bool,
|
||||||
/// currentLoadedMessagesCount
|
/// currentLoadedMessagesCount
|
||||||
pub current_loaded_messages_count: u64,
|
pub current_loaded_messages_count: u64,
|
||||||
pub online_data: Option<OnlineData>,
|
pub online_data: Option<OnlineData>,
|
||||||
pub rooms: Option<Vec<Room>>,
|
pub rooms: Option<Vec<Room>>,
|
||||||
pub config: Option<IcaConfig>,
|
pub config: Option<BotConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IcalinguaStatus {
|
impl BotStatus {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
login: false,
|
login: false,
|
||||||
current_loaded_messages_count: 0,
|
current_loaded_messages_count: 0,
|
||||||
online_data: None,
|
online_data: None,
|
||||||
rooms: None,
|
rooms: None,
|
||||||
config: Some(IcaConfig::new_from_cli()),
|
config: Some(BotConfig::new_from_cli()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_online_data(online_data: OnlineData) {
|
pub fn update_online_data(online_data: OnlineData) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ClientStatus.online_data = Some(online_data);
|
ClientStatus_Global.online_data = Some(online_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_rooms(rooms: Vec<Room>) {
|
pub fn update_rooms(rooms: Vec<Room>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ClientStatus.rooms = Some(rooms);
|
ClientStatus_Global.rooms = Some(rooms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_login_status(login: bool) {
|
pub fn update_login_status(login: bool) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ClientStatus.login = login;
|
ClientStatus_Global.login = login;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_config(config: IcaConfig) {
|
pub fn update_config(config: BotConfig) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ClientStatus.config = Some(config);
|
ClientStatus_Global.config = Some(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_loaded_messages_count(count: u64) {
|
pub fn update_loaded_messages_count(count: u64) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ClientStatus.current_loaded_messages_count = count;
|
ClientStatus_Global.current_loaded_messages_count = count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_login_status() -> bool { unsafe { ClientStatus.login } }
|
pub fn get_login_status() -> bool { unsafe { ClientStatus_Global.login } }
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_rooms() -> &'static Vec<Room> {
|
pub fn get_rooms() -> &'static Vec<Room> {
|
||||||
unsafe { ClientStatus.rooms.as_ref().expect("rooms should be set") }
|
unsafe { ClientStatus_Global.rooms.as_ref().expect("rooms should be set") }
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_loaded_messages_count() -> u64 {
|
pub fn get_loaded_messages_count() -> u64 {
|
||||||
unsafe { ClientStatus.current_loaded_messages_count }
|
unsafe { ClientStatus_Global.current_loaded_messages_count }
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_online_data() -> &'static OnlineData {
|
pub fn get_online_data() -> &'static OnlineData {
|
||||||
unsafe { ClientStatus.online_data.as_ref().expect("online_data should be set") }
|
unsafe { ClientStatus_Global.online_data.as_ref().expect("online_data should be set") }
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_config() -> &'static IcaConfig {
|
pub fn get_config() -> &'static BotConfig {
|
||||||
unsafe { ClientStatus.config.as_ref().expect("config should be set") }
|
unsafe { ClientStatus_Global.config.as_ref().expect("config should be set") }
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn get_ica_config() -> &'static IcaConfig {
|
||||||
|
unsafe {
|
||||||
|
ClientStatus_Global
|
||||||
|
.config
|
||||||
|
.as_ref()
|
||||||
|
.expect("config should be set")
|
||||||
|
.ica
|
||||||
|
.as_ref()
|
||||||
|
.expect("ica should be set")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +146,7 @@ pub async fn sign_callback(payload: Payload, client: Client) {
|
||||||
.expect("auth_key should be string");
|
.expect("auth_key should be string");
|
||||||
let salt = hex::decode(auth_key).expect("Got an invalid salt from the server");
|
let salt = hex::decode(auth_key).expect("Got an invalid salt from the server");
|
||||||
// 签名
|
// 签名
|
||||||
let private_key = IcalinguaStatus::get_config().private_key.clone();
|
let private_key = BotStatus::get_config().ica().private_key.clone();
|
||||||
let array_key: [u8; 32] = hex::decode(private_key)
|
let array_key: [u8; 32] = hex::decode(private_key)
|
||||||
.expect("Not a vaild pub key")
|
.expect("Not a vaild pub key")
|
||||||
.try_into()
|
.try_into()
|
||||||
|
|
|
@ -21,13 +21,24 @@ pub struct IcaConfig {
|
||||||
pub admin_list: Vec<i64>,
|
pub admin_list: Vec<i64>,
|
||||||
/// 过滤列表
|
/// 过滤列表
|
||||||
pub filter_list: Vec<i64>,
|
pub filter_list: Vec<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 主配置
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct BotConfig {
|
||||||
|
/// 是否启用 icalingua
|
||||||
|
pub enable_ica: bool,
|
||||||
|
/// Ica 配置
|
||||||
|
pub ica: Option<IcaConfig>,
|
||||||
|
/// Matrix 配置
|
||||||
|
// TODO: MatrixConfig
|
||||||
/// Python 插件路径
|
/// Python 插件路径
|
||||||
pub py_plugin_path: Option<String>,
|
pub py_plugin_path: Option<String>,
|
||||||
/// Python 配置文件路径
|
/// Python 配置文件路径
|
||||||
pub py_config_path: Option<String>,
|
pub py_config_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IcaConfig {
|
impl BotConfig {
|
||||||
pub fn new_from_path(config_file_path: String) -> Self {
|
pub fn new_from_path(config_file_path: String) -> Self {
|
||||||
// try read config from file
|
// try read config from file
|
||||||
let config = fs::read_to_string(&config_file_path).expect("Failed to read config file");
|
let config = fs::read_to_string(&config_file_path).expect("Failed to read config file");
|
||||||
|
@ -39,4 +50,6 @@ impl IcaConfig {
|
||||||
let config_file_path = env::args().nth(1).expect("No config path given");
|
let config_file_path = env::args().nth(1).expect("No config path given");
|
||||||
Self::new_from_path(config_file_path)
|
Self::new_from_path(config_file_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ica(&self) -> IcaConfig { self.ica.clone().expect("No ica config found") }
|
||||||
}
|
}
|
||||||
|
|
52
ica-rs/src/ica.rs
Normal file
52
ica-rs/src/ica.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
pub mod data_struct;
|
||||||
|
pub mod events;
|
||||||
|
|
||||||
|
use futures_util::FutureExt;
|
||||||
|
use rust_socketio::asynchronous::{Client, ClientBuilder};
|
||||||
|
use rust_socketio::{Event, Payload, TransportType};
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
|
use crate::config::IcaConfig;
|
||||||
|
use crate::{wrap_any_callback, wrap_callback};
|
||||||
|
|
||||||
|
pub async fn start_ica(config: &IcaConfig, stop_reciver: tokio::sync::oneshot::Receiver<()>) {
|
||||||
|
let socket = ClientBuilder::new(config.host.clone())
|
||||||
|
.transport_type(TransportType::Websocket)
|
||||||
|
.on_any(wrap_any_callback!(events::any_event))
|
||||||
|
.on("requireAuth", wrap_callback!(crate::client::sign_callback))
|
||||||
|
.on("message", wrap_callback!(events::connect_callback))
|
||||||
|
.on("authSucceed", wrap_callback!(events::connect_callback))
|
||||||
|
.on("authFailed", wrap_callback!(events::connect_callback))
|
||||||
|
.on("messageSuccess", wrap_callback!(events::succes_message))
|
||||||
|
.on("messageFailed", wrap_callback!(events::failed_message))
|
||||||
|
.on("onlineData", wrap_callback!(events::get_online_data))
|
||||||
|
.on("setAllRooms", wrap_callback!(events::update_all_room))
|
||||||
|
.on("setMessages", wrap_callback!(events::set_messages))
|
||||||
|
.on("addMessage", wrap_callback!(events::add_message))
|
||||||
|
.on("deleteMessage", wrap_callback!(events::delete_message))
|
||||||
|
.connect()
|
||||||
|
.await
|
||||||
|
.expect("Connection failed");
|
||||||
|
|
||||||
|
info!("Connected");
|
||||||
|
|
||||||
|
if config.notice_start {
|
||||||
|
for room in config.notice_room.iter() {
|
||||||
|
let startup_msg = data_struct::messages::SendMessage::new(
|
||||||
|
format!("ica-async-rs bot v{}", crate::VERSION),
|
||||||
|
room.clone(),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
|
info!("发送启动消息到房间: {}", room);
|
||||||
|
if let Err(e) =
|
||||||
|
socket.emit("sendMessage", serde_json::to_value(startup_msg).unwrap()).await
|
||||||
|
{
|
||||||
|
info!("启动信息发送失败 房间:{}|e:{}", room, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 等待停止信号
|
||||||
|
stop_reciver.await.ok();
|
||||||
|
socket.disconnect().await.expect("Disconnect failed");
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::data_struct::messages::{At, LastMessage};
|
use crate::ica::data_struct::messages::{At, LastMessage};
|
||||||
use crate::data_struct::RoomId;
|
use crate::ica::data_struct::RoomId;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::data_struct::files::MessageFile;
|
use crate::ica::data_struct::files::MessageFile;
|
||||||
use crate::data_struct::{MessageId, RoomId, UserId};
|
use crate::ica::data_struct::{MessageId, RoomId, UserId};
|
||||||
|
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
|
@ -4,9 +4,9 @@ use chrono::NaiveDateTime;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
use crate::client::IcalinguaStatus;
|
use crate::client::BotStatus;
|
||||||
use crate::data_struct::messages::{At, Message, NewMessage};
|
use crate::ica::data_struct::messages::{At, Message, NewMessage};
|
||||||
use crate::data_struct::{MessageId, UserId};
|
use crate::ica::data_struct::{MessageId, UserId};
|
||||||
|
|
||||||
impl Serialize for At {
|
impl Serialize for At {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
@ -34,7 +34,7 @@ impl<'de> Deserialize<'de> for At {
|
||||||
pub trait MessageTrait {
|
pub trait MessageTrait {
|
||||||
fn is_reply(&self) -> bool;
|
fn is_reply(&self) -> bool;
|
||||||
fn is_from_self(&self) -> bool {
|
fn is_from_self(&self) -> bool {
|
||||||
let qq_id = IcalinguaStatus::get_online_data().qqid;
|
let qq_id = BotStatus::get_online_data().qqid;
|
||||||
self.sender_id() == qq_id
|
self.sender_id() == qq_id
|
||||||
}
|
}
|
||||||
fn msg_id(&self) -> &MessageId;
|
fn msg_id(&self) -> &MessageId;
|
|
@ -3,10 +3,10 @@ use rust_socketio::asynchronous::Client;
|
||||||
use rust_socketio::{Event, Payload};
|
use rust_socketio::{Event, Payload};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use crate::client::{send_message, IcalinguaStatus};
|
use crate::client::{send_message, BotStatus};
|
||||||
use crate::data_struct::all_rooms::Room;
|
use crate::ica::data_struct::all_rooms::Room;
|
||||||
use crate::data_struct::messages::{Message, MessageTrait, NewMessage};
|
use crate::ica::data_struct::messages::{Message, MessageTrait, NewMessage};
|
||||||
use crate::data_struct::online_data::OnlineData;
|
use crate::ica::data_struct::online_data::OnlineData;
|
||||||
use crate::{py, VERSION};
|
use crate::{py, VERSION};
|
||||||
|
|
||||||
/// 获取在线数据
|
/// 获取在线数据
|
||||||
|
@ -15,7 +15,7 @@ pub async fn get_online_data(payload: Payload, _client: Client) {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
let online_data = OnlineData::new_from_json(value);
|
let online_data = OnlineData::new_from_json(value);
|
||||||
info!("update_online_data {}", format!("{:?}", online_data).cyan());
|
info!("update_online_data {}", format!("{:?}", online_data).cyan());
|
||||||
IcalinguaStatus::update_online_data(online_data);
|
BotStatus::update_online_data(online_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ pub async fn add_message(payload: Payload, client: Client) {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
let message: NewMessage = serde_json::from_value(value.clone()).unwrap();
|
let message: NewMessage = serde_json::from_value(value.clone()).unwrap();
|
||||||
// 检测是否在过滤列表内
|
// 检测是否在过滤列表内
|
||||||
if IcalinguaStatus::get_config().filter_list.contains(&message.msg.sender_id) {
|
if BotStatus::get_ica_config().filter_list.contains(&message.msg.sender_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
info!("add_message {}", message.to_string().cyan());
|
info!("add_message {}", message.to_string().cyan());
|
||||||
|
@ -76,7 +76,7 @@ pub async fn update_all_room(payload: Payload, _client: Client) {
|
||||||
if let Some(raw_rooms) = value.as_array() {
|
if let Some(raw_rooms) = value.as_array() {
|
||||||
let rooms: Vec<Room> =
|
let rooms: Vec<Room> =
|
||||||
raw_rooms.iter().map(|room| Room::new_from_json(room)).collect();
|
raw_rooms.iter().map(|room| Room::new_from_json(room)).collect();
|
||||||
IcalinguaStatus::update_rooms(rooms.clone());
|
BotStatus::update_rooms(rooms.clone());
|
||||||
info!("update_all_room {}", rooms.len());
|
info!("update_all_room {}", rooms.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,16 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use futures_util::FutureExt;
|
use config::{BotConfig, IcaConfig};
|
||||||
use rust_socketio::asynchronous::{Client, ClientBuilder};
|
|
||||||
use rust_socketio::{Event, Payload, TransportType};
|
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
mod config;
|
mod config;
|
||||||
mod data_struct;
|
mod ica;
|
||||||
mod events;
|
mod matrix;
|
||||||
mod py;
|
mod py;
|
||||||
|
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
pub static mut ClientStatus: client::IcalinguaStatus = client::IcalinguaStatus {
|
pub static mut ClientStatus_Global: client::BotStatus = client::BotStatus {
|
||||||
login: false,
|
login: false,
|
||||||
current_loaded_messages_count: 0,
|
current_loaded_messages_count: 0,
|
||||||
online_data: None,
|
online_data: None,
|
||||||
|
@ -22,18 +20,19 @@ pub static mut ClientStatus: client::IcalinguaStatus = client::IcalinguaStatus {
|
||||||
|
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
macro_rules! wrap_callback {
|
macro_rules! wrap_callback {
|
||||||
($f:expr) => {
|
($f:expr) => {
|
||||||
|payload: Payload, client: Client| $f(payload, client).boxed()
|
|payload: Payload, client: Client| $f(payload, client).boxed()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
macro_rules! wrap_any_callback {
|
macro_rules! wrap_any_callback {
|
||||||
($f:expr) => {
|
($f:expr) => {
|
||||||
|event: Event, payload: Payload, client: Client| $f(event, payload, client).boxed()
|
|event: Event, payload: Payload, client: Client| $f(event, payload, client).boxed()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init();
|
tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init();
|
||||||
|
@ -41,45 +40,20 @@ async fn main() {
|
||||||
|
|
||||||
// 从命令行获取 host 和 key
|
// 从命令行获取 host 和 key
|
||||||
// 从命令行获取配置文件路径
|
// 从命令行获取配置文件路径
|
||||||
let ica_config = config::IcaConfig::new_from_cli();
|
let bot_config = config::BotConfig::new_from_cli();
|
||||||
client::IcalinguaStatus::update_config(ica_config.clone());
|
client::BotStatus::update_config(bot_config.clone());
|
||||||
py::init_py(&ica_config);
|
py::init_py(&bot_config);
|
||||||
|
|
||||||
let socket = ClientBuilder::new(ica_config.host.clone())
|
// 准备一个用于停止 socket 的变量
|
||||||
.transport_type(TransportType::Websocket)
|
let (send, recv) = tokio::sync::oneshot::channel::<()>();
|
||||||
.on_any(wrap_any_callback!(events::any_event))
|
if bot_config.enable_ica && bot_config.ica.is_some() {
|
||||||
.on("requireAuth", wrap_callback!(client::sign_callback))
|
info!("启动 ica");
|
||||||
.on("message", wrap_callback!(events::connect_callback))
|
let config = bot_config.ica();
|
||||||
.on("authSucceed", wrap_callback!(events::connect_callback))
|
tokio::spawn(async move {
|
||||||
.on("authFailed", wrap_callback!(events::connect_callback))
|
ica::start_ica(&config, recv).await;
|
||||||
.on("messageSuccess", wrap_callback!(events::succes_message))
|
});
|
||||||
.on("messageFailed", wrap_callback!(events::failed_message))
|
} else {
|
||||||
.on("onlineData", wrap_callback!(events::get_online_data))
|
info!("未启用 ica");
|
||||||
.on("setAllRooms", wrap_callback!(events::update_all_room))
|
|
||||||
.on("setMessages", wrap_callback!(events::set_messages))
|
|
||||||
.on("addMessage", wrap_callback!(events::add_message))
|
|
||||||
.on("deleteMessage", wrap_callback!(events::delete_message))
|
|
||||||
.connect()
|
|
||||||
.await
|
|
||||||
.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-async-rs bot v{}", VERSION),
|
|
||||||
room.clone(),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
||||||
info!("发送启动消息到房间: {}", room);
|
|
||||||
if let Err(e) =
|
|
||||||
socket.emit("sendMessage", serde_json::to_value(startup_msg).unwrap()).await
|
|
||||||
{
|
|
||||||
info!("启动信息发送失败 房间:{}|e:{}", room, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
|
@ -88,6 +62,7 @@ async fn main() {
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
|
|
||||||
socket.disconnect().await.expect("Disconnect failed");
|
// socket.disconnect().await.expect("Disconnect failed");
|
||||||
|
send.send(()).ok();
|
||||||
info!("Disconnected");
|
info!("Disconnected");
|
||||||
}
|
}
|
||||||
|
|
1
ica-rs/src/matrix.rs
Normal file
1
ica-rs/src/matrix.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -4,9 +4,9 @@ use pyo3::prelude::*;
|
||||||
use rust_socketio::asynchronous::Client;
|
use rust_socketio::asynchronous::Client;
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
use crate::client::IcalinguaStatus;
|
use crate::client::BotStatus;
|
||||||
use crate::data_struct::messages::NewMessage;
|
use crate::ica::data_struct::messages::NewMessage;
|
||||||
use crate::data_struct::MessageId;
|
use crate::ica::data_struct::MessageId;
|
||||||
use crate::py::{class, PyPlugin, PyStatus};
|
use crate::py::{class, PyPlugin, PyStatus};
|
||||||
|
|
||||||
pub fn get_func<'py>(py_module: &'py PyAny, path: &PathBuf, name: &'py str) -> Option<&'py PyAny> {
|
pub fn get_func<'py>(py_module: &'py PyAny, path: &PathBuf, name: &'py str) -> Option<&'py PyAny> {
|
||||||
|
@ -45,7 +45,7 @@ pub fn get_func<'py>(py_module: &'py PyAny, path: &PathBuf, name: &'py str) -> O
|
||||||
|
|
||||||
pub fn verify_plugins() {
|
pub fn verify_plugins() {
|
||||||
let mut need_reload_files: Vec<PathBuf> = Vec::new();
|
let mut need_reload_files: Vec<PathBuf> = Vec::new();
|
||||||
let plugin_path = IcalinguaStatus::get_config().py_plugin_path.as_ref();
|
let plugin_path = BotStatus::get_config().py_plugin_path.as_ref();
|
||||||
if let None = plugin_path {
|
if let None = plugin_path {
|
||||||
warn!("未配置 Python 插件路径");
|
warn!("未配置 Python 插件路径");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,12 +4,12 @@ use tokio::runtime::Runtime;
|
||||||
use toml::Value as TomlValue;
|
use toml::Value as TomlValue;
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
use crate::client::{delete_message, send_message, IcalinguaStatus};
|
use crate::client::{delete_message, send_message, BotStatus};
|
||||||
use crate::data_struct::messages::{
|
use crate::ica::data_struct::messages::{
|
||||||
DeleteMessage, MessageTrait, NewMessage, ReplyMessage, SendMessage,
|
DeleteMessage, MessageTrait, NewMessage, ReplyMessage, SendMessage,
|
||||||
};
|
};
|
||||||
use crate::data_struct::MessageId;
|
use crate::ica::data_struct::MessageId;
|
||||||
use crate::ClientStatus;
|
use crate::ClientStatus_Global;
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
#[pyo3(name = "IcaStatus")]
|
#[pyo3(name = "IcaStatus")]
|
||||||
|
@ -20,39 +20,37 @@ impl IcaStatusPy {
|
||||||
#[new]
|
#[new]
|
||||||
pub fn py_new() -> Self { Self {} }
|
pub fn py_new() -> Self { Self {} }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_login(&self) -> bool { unsafe { ClientStatus.login } }
|
pub fn get_login(&self) -> bool { unsafe { ClientStatus_Global.login } }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_online(&self) -> bool { IcalinguaStatus::get_online_data().online }
|
pub fn get_online(&self) -> bool { BotStatus::get_online_data().online }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_self_id(&self) -> i64 { IcalinguaStatus::get_online_data().qqid }
|
pub fn get_self_id(&self) -> i64 { BotStatus::get_online_data().qqid }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_nick_name(&self) -> String { IcalinguaStatus::get_online_data().nick.clone() }
|
pub fn get_nick_name(&self) -> String { BotStatus::get_online_data().nick.clone() }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_loaded_messages_count(&self) -> u64 { IcalinguaStatus::get_loaded_messages_count() }
|
pub fn get_loaded_messages_count(&self) -> u64 { BotStatus::get_loaded_messages_count() }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_ica_version(&self) -> String {
|
pub fn get_ica_version(&self) -> String {
|
||||||
IcalinguaStatus::get_online_data().icalingua_info.ica_version.clone()
|
BotStatus::get_online_data().icalingua_info.ica_version.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_os_info(&self) -> String {
|
pub fn get_os_info(&self) -> String {
|
||||||
IcalinguaStatus::get_online_data().icalingua_info.os_info.clone()
|
BotStatus::get_online_data().icalingua_info.os_info.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_resident_set_size(&self) -> String {
|
pub fn get_resident_set_size(&self) -> String {
|
||||||
IcalinguaStatus::get_online_data().icalingua_info.resident_set_size.clone()
|
BotStatus::get_online_data().icalingua_info.resident_set_size.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_heap_used(&self) -> String {
|
pub fn get_heap_used(&self) -> String {
|
||||||
IcalinguaStatus::get_online_data().icalingua_info.heap_used.clone()
|
BotStatus::get_online_data().icalingua_info.heap_used.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_load(&self) -> String {
|
pub fn get_load(&self) -> String { BotStatus::get_online_data().icalingua_info.load.clone() }
|
||||||
IcalinguaStatus::get_online_data().icalingua_info.load.clone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IcaStatusPy {
|
impl IcaStatusPy {
|
||||||
|
@ -180,16 +178,16 @@ impl IcaClientPy {
|
||||||
/// 仅作占位
|
/// 仅作占位
|
||||||
/// (因为目前来说, rust调用 Python端没法启动一个异步运行时
|
/// (因为目前来说, rust调用 Python端没法启动一个异步运行时
|
||||||
/// 所以只能 tokio::task::block_in_place 转换成同步调用)
|
/// 所以只能 tokio::task::block_in_place 转换成同步调用)
|
||||||
#[staticmethod]
|
// #[staticmethod]
|
||||||
pub fn send_message_a(
|
// pub fn send_message_a(
|
||||||
py: Python,
|
// py: Python,
|
||||||
client: IcaClientPy,
|
// client: IcaClientPy,
|
||||||
message: SendMessagePy,
|
// message: SendMessagePy,
|
||||||
) -> PyResult<&PyAny> {
|
// ) -> PyResult<&PyAny> {
|
||||||
pyo3_asyncio::tokio::future_into_py(py, async move {
|
// pyo3_asyncio::tokio::future_into_py(py, async move {
|
||||||
Ok(send_message(&client.client, &message.msg).await)
|
// Ok(send_message(&client.client, &message.msg).await)
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_status(&self) -> IcaStatusPy { IcaStatusPy::new() }
|
pub fn get_status(&self) -> IcaStatusPy { IcaStatusPy::new() }
|
||||||
|
|
|
@ -8,8 +8,8 @@ use pyo3::prelude::*;
|
||||||
use pyo3::types::PyTuple;
|
use pyo3::types::PyTuple;
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
use crate::client::IcalinguaStatus;
|
use crate::client::BotStatus;
|
||||||
use crate::config::IcaConfig;
|
use crate::config::{BotConfig, IcaConfig};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PyStatus {
|
pub struct PyStatus {
|
||||||
|
@ -75,7 +75,7 @@ impl TryFrom<RawPyPlugin> for PyPlugin {
|
||||||
if config.is_instance_of::<PyTuple>() {
|
if config.is_instance_of::<PyTuple>() {
|
||||||
let (config, default) = config.extract::<(String, String)>().unwrap();
|
let (config, default) = config.extract::<(String, String)>().unwrap();
|
||||||
let base_path =
|
let base_path =
|
||||||
IcalinguaStatus::get_config().py_config_path.as_ref().unwrap();
|
BotStatus::get_config().py_config_path.as_ref().unwrap();
|
||||||
|
|
||||||
let mut base_path: PathBuf = PathBuf::from(base_path);
|
let mut base_path: PathBuf = PathBuf::from(base_path);
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ pub fn load_py_file(path: &PathBuf) -> std::io::Result<RawPyPlugin> {
|
||||||
Ok((path.clone(), changed_time, content))
|
Ok((path.clone(), changed_time, content))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_py(config: &IcaConfig) {
|
pub fn init_py(config: &BotConfig) {
|
||||||
debug!("initing python threads");
|
debug!("initing python threads");
|
||||||
pyo3::prepare_freethreaded_python();
|
pyo3::prepare_freethreaded_python();
|
||||||
if let Some(plugin_path) = &config.py_plugin_path {
|
if let Some(plugin_path) = &config.py_plugin_path {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user