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); } } })