更新依赖库和修改函数命名

This commit is contained in:
shenjack 2024-03-13 01:32:28 +08:00
parent 8cd8d93a28
commit c83a2c4549
Signed by: shenjack
GPG Key ID: 7B1134A979775551
5 changed files with 16 additions and 7 deletions

10
Cargo.lock generated
View File

@ -47,6 +47,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "anyhow"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
dependencies = [
"backtrace",
]
[[package]] [[package]]
name = "as_variant" name = "as_variant"
version = "1.2.0" version = "1.2.0"
@ -641,6 +650,7 @@ dependencies = [
name = "ica-rs" name = "ica-rs"
version = "0.5.0" version = "0.5.0"
dependencies = [ dependencies = [
"anyhow",
"chrono", "chrono",
"colored", "colored",
"ed25519", "ed25519",

View File

@ -37,6 +37,7 @@ colored = "2.1.0"
tokio = { version = "1.0", features = ["full"] } tokio = { version = "1.0", features = ["full"] }
futures-util = "0.3.30" futures-util = "0.3.30"
pyo3 = "0.20.3" pyo3 = "0.20.3"
anyhow = { version = "1.0.81", features = ["backtrace"] }
# async 这玩意以后在搞 # async 这玩意以后在搞
# 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"] }

View File

@ -38,7 +38,7 @@ pub async fn add_message(payload: Payload, client: Client) {
send_message(&client, &reply).await; send_message(&client, &reply).await;
} }
// python 插件 // python 插件
py::call::new_message_py(&message, &client).await; py::call::ica_new_message_py(&message, &client).await;
} }
} }
} }
@ -64,7 +64,7 @@ pub async fn delete_message(payload: Payload, client: Client) {
if let Some(msg_id) = value.as_str() { if let Some(msg_id) = value.as_str() {
info!("delete_message {}", msg_id.to_string().yellow()); info!("delete_message {}", msg_id.to_string().yellow());
py::call::delete_message_py(msg_id.to_string(), &client).await; py::call::ica_delete_message_py(msg_id.to_string(), &client).await;
} }
} }
} }

View File

@ -78,7 +78,7 @@ pub fn verify_plugins() {
} }
/// 执行 new message 的 python 插件 /// 执行 new message 的 python 插件
pub async fn new_message_py(message: &NewMessage, client: &Client) { pub async fn ica_new_message_py(message: &NewMessage, client: &Client) {
// 验证插件是否改变 // 验证插件是否改变
verify_plugins(); verify_plugins();
@ -100,7 +100,7 @@ pub async fn new_message_py(message: &NewMessage, client: &Client) {
} }
} }
pub async fn delete_message_py(msg_id: MessageId, client: &Client) { pub async fn ica_delete_message_py(msg_id: MessageId, client: &Client) {
verify_plugins(); verify_plugins();
let plugins = PyStatus::get_files(); let plugins = PyStatus::get_files();

View File

@ -219,9 +219,7 @@ pub fn load_py_plugins(path: &PathBuf) {
); );
} }
pub fn get_change_time(path: &PathBuf) -> Option<SystemTime> { pub fn get_change_time(path: &Path) -> Option<SystemTime> { path.metadata().ok()?.modified().ok() }
path.metadata().ok()?.modified().ok()
}
pub fn py_module_from_code(content: &str, path: &Path) -> PyResult<Py<PyAny>> { pub fn py_module_from_code(content: &str, path: &Path) -> PyResult<Py<PyAny>> {
Python::with_gil(|py| -> PyResult<Py<PyAny>> { Python::with_gil(|py| -> PyResult<Py<PyAny>> {