From 3ed0f5af1ef000347835b17627ed66f4cdbb0b2b Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 24 Feb 2024 23:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B1=BB=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=92=8C=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0=E7=AD=BE?= =?UTF-8?q?=E5=90=8D***?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ***更新类型定义和回调函数签名 --- ica-rs/ica_typing.py | 36 ++++++++++++++++++++++++++++-------- ica-rs/src/py/class.rs | 6 +++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/ica-rs/ica_typing.py b/ica-rs/ica_typing.py index 7ab5559..f293182 100644 --- a/ica-rs/ica_typing.py +++ b/ica-rs/ica_typing.py @@ -1,6 +1,16 @@ # Python 兼容版本 3.8+ -from typing import Optional +from typing import Optional, Callable + +""" +pub type RoomId = i64; +pub type UserId = i64; +pub type MessageId = String; +""" + +RoomId = int +UserId = int +MessageId = str class IcaStatus: @@ -11,7 +21,7 @@ class IcaStatus: def online(self) -> bool: ... @property - def self_id(self) -> Optional[bool]: + def self_id(self) -> Optional[UserId]: ... @property def nick_name(self) -> Optional[str]: @@ -58,10 +68,13 @@ class NewMessage: def __str__(self) -> str: ... @property + def id(self) -> MessageId: + ... + @property def content(self) -> str: ... @property - def sender_id(self) -> int: + def sender_id(self) -> UserId: ... @property def is_from_self(self) -> bool: @@ -82,12 +95,19 @@ class IcaClient: def send_message(self, message: SendMessage) -> bool: ... def debug(self, message: str) -> None: - ... + """向日志中输出调试信息""" def info(self, message: str) -> None: - ... + """向日志中输出信息""" def warn(self, message: str) -> None: - ... + """向日志中输出警告信息""" -def on_message(msg: NewMessage, client: IcaClient) -> None: - ... +on_load = Callable[[IcaClient], None] +# def on_load(client: IcaClient) -> None: +# ... + +on_message = Callable[[NewMessage, IcaClient], None] +# def on_message(msg: NewMessage, client: IcaClient) -> None: +# ... + +on_delete_message = Callable[[int, IcaClient], None] diff --git a/ica-rs/src/py/class.rs b/ica-rs/src/py/class.rs index 981a8a4..827fabb 100644 --- a/ica-rs/src/py/class.rs +++ b/ica-rs/src/py/class.rs @@ -5,6 +5,7 @@ use tracing::{debug, info, warn}; use crate::client::send_message; use crate::data_struct::messages::{NewMessage, ReplyMessage, SendMessage}; +use crate::data_struct::MessageId; use crate::ClientStatus; #[pyclass] @@ -126,7 +127,10 @@ impl NewMessagePy { pub fn __str__(&self) -> String { format!("{:?}", self.msg) } - + #[getter] + pub fn get_id(&self) -> MessageId { + self.msg.msg_id.clone() + } #[getter] pub fn get_content(&self) -> String { self.msg.content.clone()