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()