diff --git a/ica-rs/Cargo.toml b/ica-rs/Cargo.toml index aa584a8..12a2aa6 100644 --- a/ica-rs/Cargo.toml +++ b/ica-rs/Cargo.toml @@ -42,7 +42,7 @@ colored = "3.0" # runtime tokio = { version = "1.43", features = ["full"] } futures-util = "0.3.30" -pyo3 = { version = "0.23", features = ["experimental-async", "py-clone"] } +pyo3 = { version = "0.23", features = ["experimental-async", "py-clone", "abi3-py38"] } anyhow = { version = "1.0", features = ["backtrace"] } # async 这玩意以后在搞 # pyo3-async = "0.3.2" diff --git a/ica-rs/src/data_struct/ica/all_rooms.rs b/ica-rs/src/data_struct/ica/all_rooms.rs index dde732b..f6e761e 100644 --- a/ica-rs/src/data_struct/ica/all_rooms.rs +++ b/ica-rs/src/data_struct/ica/all_rooms.rs @@ -2,7 +2,7 @@ use crate::data_struct::ica::messages::{At, LastMessage}; use crate::data_struct::ica::RoomId; use serde::{Deserialize, Serialize}; -use serde_json::Value as JsonValue; +use serde_json::{Number, Value as JsonValue}; /// export default interface Room { /// roomId: number @@ -39,14 +39,14 @@ pub struct Room { impl Room { pub fn new_from_json(raw_json: &JsonValue) -> Self { - let parse_json = raw_json.clone(); + let mut parse_json = raw_json.clone(); // 手动 patch 一下 roomId // ica issue: https://github.com/Icalingua-plus-plus/Icalingua-plus-plus/issues/793 - // if parse_json.get("roomId").is_none_or(|id| id.is_null()) { - // use tracing::warn; - // warn!("Room::new_from_json roomId is None, patching it to -1, raw: {:#?}", raw_json); - // parse_json["roomId"] = JsonValue::Number(Number::from(-1)); - // } + if parse_json.get("roomId").is_none_or(|id| id.is_null()) { + use tracing::warn; + warn!("Room::new_from_json roomId is None, patching it to -1, raw: {:?}", raw_json); + parse_json["roomId"] = JsonValue::Number(Number::from(-1)); + } // 现在 fix 了 let inner = match serde_json::from_value::(parse_json) { diff --git a/ica-rs/src/py/class/ica.rs b/ica-rs/src/py/class/ica.rs index 9b884c7..625ed0f 100644 --- a/ica-rs/src/py/class/ica.rs +++ b/ica-rs/src/py/class/ica.rs @@ -146,6 +146,10 @@ impl SendMessagePy { pub fn get_content(&self) -> String { self.msg.content.clone() } #[setter] pub fn set_content(&mut self, content: String) { self.msg.content = content; } + #[getter] + pub fn get_room_id(&self) -> RoomId { self.msg.room_id } + #[setter] + pub fn set_room_id(&mut self, room_id: RoomId) { self.msg.room_id = room_id; } /// 设置消息图片 pub fn set_img(&mut self, file: Vec, file_type: String, as_sticker: bool) { self.msg.set_img(&file, &file_type, as_sticker);