mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2024-11-23 04:31:05 +08:00
更新消息格式和房间ID处理***
***更新消息格式和房间ID处理
This commit is contained in:
parent
b41617bb06
commit
f2624dbcca
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() }
|
||||
}
|
||||
|
|
|
@ -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<on_new_message>: {:?}", e);
|
||||
warn!("failed to call function<on_message>: {:?}", e);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user