diff --git a/config-temp.toml b/config-temp.toml index 1d7838c..5b63501 100644 --- a/config-temp.toml +++ b/config-temp.toml @@ -15,3 +15,4 @@ filter_list = [0] # python 插件路径 py_plugin_path = "/path/to/your/plugin" +py_config_path = "/path/to/your/config" diff --git a/ica-rs/Cargo.toml b/ica-rs/Cargo.toml index 61acbd9..c02513f 100644 --- a/ica-rs/Cargo.toml +++ b/ica-rs/Cargo.toml @@ -19,7 +19,7 @@ colored = "2.1.0" tokio = { version = "1.0", features = ["full"] } futures-util = "0.3.30" -pyo3 = "0.20.2" +pyo3 = "0.20.3" # pyo3-async = "0.3.2" pyo3-asyncio = { version = "0.20.0", features = ["attributes", "tokio-runtime"] } diff --git a/ica-rs/ica_typing.py b/ica-rs/ica_typing.py index f0c7603..a6f75a5 100644 --- a/ica-rs/ica_typing.py +++ b/ica-rs/ica_typing.py @@ -1,6 +1,6 @@ # Python 兼容版本 3.8+ -from typing import Callable +from typing import Callable, Tuple """ pub type RoomId = i64; @@ -120,11 +120,6 @@ class IcaClient: """向日志中输出警告信息""" -class ConfigRequest: - def __init__(self, path: str, ) -> None: - ... - - class ConfigData: def __getitem__(self, key: str): ... @@ -144,6 +139,6 @@ on_delete_message = Callable[[MessageId, IcaClient], None] # def on_delete_message(msg_id: MessageId, client: IcaClient) -> None: # ... -config = Callable[[None], ConfigRequest] +on_config = Callable[[None], Tuple[str, str]] CONFIG_DATA: ConfigData = ConfigData() diff --git a/ica-rs/plugins/bmcl.py b/ica-rs/plugins/bmcl.py index 739cbaa..081f880 100644 --- a/ica-rs/plugins/bmcl.py +++ b/ica-rs/plugins/bmcl.py @@ -2,11 +2,13 @@ import re import time import requests -from typing import TYPE_CHECKING, TypeVar, Optional +from typing import TYPE_CHECKING, TypeVar, Optional, Tuple if TYPE_CHECKING: - from ica_typing import NewMessage, IcaClient + from ica_typing import NewMessage, IcaClient, ConfigData + CONFIG_DATA: ConfigData else: + CONFIG_DATA = None NewMessage = TypeVar("NewMessage") IcaClient = TypeVar("IcaClient") @@ -207,6 +209,7 @@ help = """/bmcl -> dashboard def on_message(msg: NewMessage, client: IcaClient) -> None: + print(CONFIG_DATA) if not (msg.is_from_self or msg.is_reply): if msg.content.startswith("/bmcl"): if msg.content == "/bmcl": @@ -228,3 +231,10 @@ def on_message(msg: NewMessage, client: IcaClient) -> None: if len(name) > 1: name = name[1] bmcl_rank(msg, client, name) + + +def on_config() -> Tuple[str, str]: + return ( + "bmcl.toml", + "" + ) diff --git a/ica-rs/plugins/save_eval.py b/ica-rs/plugins/save_eval.py index e3a20cc..d1ae428 100644 --- a/ica-rs/plugins/save_eval.py +++ b/ica-rs/plugins/save_eval.py @@ -10,7 +10,7 @@ else: NewMessage = TypeVar("NewMessage") IcaClient = TypeVar("IcaClient") -def safe_eval(code: str) -> str: +def safe_eval(code: str, msg: NewMessage) -> str: try: # code = code.replace('help', '坏东西!\n') # code = code.replace('bytes', '坏东西!\n') @@ -48,6 +48,7 @@ def safe_eval(code: str) -> str: "return": "别惦记你那个 return 了", "getattr": "", "setattr": "", + "msg": msg, } os.system = "不许" result = str(eval(code, global_val, {})) @@ -73,6 +74,6 @@ def on_message(message: NewMessage, client: IcaClient) -> None: if not (message.is_from_self or message.is_reply): if message.content.startswith("/="): code = message.content[2:] - result = safe_eval(code) + result = safe_eval(code, message) reply = message.reply_with(result) client.send_message(reply) diff --git a/ica-rs/src/main.rs b/ica-rs/src/main.rs index e5eee01..03307b4 100644 --- a/ica-rs/src/main.rs +++ b/ica-rs/src/main.rs @@ -72,7 +72,7 @@ async fn main() { room.clone(), None, ); - std::thread::sleep(Duration::from_secs(1)); + 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 @@ -82,7 +82,7 @@ async fn main() { } } - std::thread::sleep(Duration::from_secs(3)); + tokio::time::sleep(Duration::from_secs(2)).await; // 等待一个输入 info!("Press any key to exit"); let mut input = String::new();