更新SendMessage类以支持链式调用

This commit is contained in:
shenjack 2024-02-24 19:26:21 +08:00
parent d6443f27bb
commit db3905eec3
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 27 additions and 2 deletions

View File

@ -38,7 +38,18 @@ class ReplyMessage:
class SendMessage: class SendMessage:
... @property
def content(self) -> str:
...
@content.setter
def content(self, value: str) -> None:
...
def with_content(self, content: str) -> "SendMessage":
"""
为了链式调用, 返回自身
"""
self.content = content
return self
class NewMessage: class NewMessage:
@ -64,7 +75,7 @@ class IcaClient:
@staticmethod @staticmethod
async def send_message_a(client: "IcaClient", message: SendMessage) -> bool: async def send_message_a(client: "IcaClient", message: SendMessage) -> bool:
""" """
仅作占位 仅作占位, 不能使用
(因为目前来说, rust调用 Python端没法启动一个异步运行时 (因为目前来说, rust调用 Python端没法启动一个异步运行时
所以只能 tokio::task::block_in_place 转换成同步调用) 所以只能 tokio::task::block_in_place 转换成同步调用)
""" """

View File

@ -182,6 +182,20 @@ impl SendMessagePy {
pub fn __str__(&self) -> String { pub fn __str__(&self) -> String {
format!("{:?}", self.msg) format!("{:?}", self.msg)
} }
/// 设置消息内容
/// 用于链式调用
pub fn with_content(&mut self, content: String) -> Self {
self.msg.content = content;
self.clone()
}
#[getter]
pub fn get_content(&self) -> String {
self.msg.content.clone()
}
#[setter]
pub fn set_content(&mut self, content: String) {
self.msg.content = content;
}
} }
impl SendMessagePy { impl SendMessagePy {