From f2624dbcca50e5618df0ef986abeee911a413a8a Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 25 Feb 2024 02:26:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B6=88=E6=81=AF=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=92=8C=E6=88=BF=E9=97=B4ID=E5=A4=84=E7=90=86***?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ***更新消息格式和房间ID处理 --- ica-rs/src/data_struct/messages/msg_trait.rs | 10 +++++++--- ica-rs/src/data_struct/mod.rs | 16 ++++++++++++++++ ica-rs/src/py/call.rs | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ica-rs/src/data_struct/messages/msg_trait.rs b/ica-rs/src/data_struct/messages/msg_trait.rs index 1efcd23..f59945b 100644 --- a/ica-rs/src/data_struct/messages/msg_trait.rs +++ b/ica-rs/src/data_struct/messages/msg_trait.rs @@ -87,7 +87,7 @@ impl<'de> Deserialize<'de> for Message { impl Display for Message { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}|{}|{}", self.sender_id, self.sender_name, self.content) + write!(f, "{}|{}|{}|{}", self.msg_id(), self.sender_id, self.sender_name, self.content) } } @@ -115,8 +115,12 @@ impl Display for NewMessage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, - "{}|{}|{}|{}", - self.room_id, self.msg.sender_id, self.msg.sender_name, self.msg.content + "{}|{}|{}|{}|{}", + self.msg_id(), + self.room_id, + self.msg.sender_id, + self.msg.sender_name, + self.msg.content ) } } diff --git a/ica-rs/src/data_struct/mod.rs b/ica-rs/src/data_struct/mod.rs index c9916fb..4127497 100644 --- a/ica-rs/src/data_struct/mod.rs +++ b/ica-rs/src/data_struct/mod.rs @@ -4,6 +4,22 @@ pub mod messages; pub mod all_rooms; pub mod online_data; +/// 房间 id +/// 群聊 < 0 +/// 私聊 > 0 pub type RoomId = i64; pub type UserId = i64; pub type MessageId = String; + +pub trait RoomIdTrait { + fn is_room(&self) -> bool; + fn is_chat(&self) -> bool { !self.is_room() } + fn as_room_id(&self) -> RoomId; + fn as_chat_id(&self) -> RoomId; +} + +impl RoomIdTrait for RoomId { + fn is_room(&self) -> bool { (*self).is_negative() } + fn as_room_id(&self) -> RoomId { -(*self).abs() } + fn as_chat_id(&self) -> RoomId { (*self).abs() } +} diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index 0c92f07..549f089 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -8,7 +8,7 @@ use crate::data_struct::messages::NewMessage; use crate::data_struct::MessageId; use crate::py::{class, verify_plugins, PyStatus}; -pub fn get_func<'a>(py_module: &'a PyAny, path: &PathBuf, name: &'a str) -> Option<&'a PyAny> { +pub fn get_func<'py>(py_module: &'py PyAny, path: &PathBuf, name: &'py str) -> Option<&'py PyAny> { // 要处理的情况: // 1. 有这个函数 // 2. 没有这个函数 @@ -57,7 +57,7 @@ pub async fn new_message_py(message: &NewMessage, client: &Client) { let args = (msg, client); if let Some(py_func) = get_func(py_module.as_ref(py), &path, "on_message") { if let Err(e) = py_func.call1(args) { - warn!("failed to call function: {:?}", e); + warn!("failed to call function: {:?}", e); } } })