From 62a0a8d3fa7dcab3fa269fdcc5689f90bd5600fa Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 18 Jan 2025 12:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=B8=AA=20abi3-py38?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ica-rs/Cargo.toml | 2 +- ica-rs/src/data_struct/ica/all_rooms.rs | 14 +++++++------- ica-rs/src/py/class/ica.rs | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) 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);