更新类型定义和回调函数签名***

***更新类型定义和回调函数签名
This commit is contained in:
shenjack 2024-02-24 23:07:31 +08:00
parent c366f6a735
commit 3ed0f5af1e
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 33 additions and 9 deletions

View File

@ -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]

View File

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