更新 ica typing

This commit is contained in:
shenjack 2024-09-29 18:33:25 +08:00
parent 5ac6412943
commit e53534faa1
Signed by: shenjack
GPG Key ID: 7B1134A979775551

View File

@ -9,10 +9,13 @@ pub type RoomId = i64;
pub type UserId = i64; pub type UserId = i64;
pub type MessageId = String; pub type MessageId = String;
""" """
class IcaType: class IcaType:
RoomId = NewType('RoomId', int) RoomId = NewType("RoomId", int)
UserId = NewType('UserId', int) UserId = NewType("UserId", int)
MessageId = NewType('MessageId', str) MessageId = NewType("MessageId", str)
""" """
tailchat.rs tailchat.rs
@ -21,63 +24,56 @@ pub type ConverseId = String;
pub type UserId = String; pub type UserId = String;
pub type MessageId = String; pub type MessageId = String;
""" """
class TailchatType: class TailchatType:
GroupId = NewType('GroupId', str) GroupId = NewType("GroupId", str)
ConverseId = NewType('ConverseId', str) ConverseId = NewType("ConverseId", str)
UserId = NewType('UserId', str) UserId = NewType("UserId", str)
MessageId = NewType('MessageId', str) MessageId = NewType("MessageId", str)
class IcaStatus: class IcaStatus:
""" """
ica状态信息 ica状态信息
此类并不存储信息, 所有方法都是实时获取 此类并不存储信息, 所有方法都是实时获取
""" """
@property @property
def qq_login(self) -> bool: def qq_login(self) -> bool: ...
...
@property @property
def online(self) -> bool: def online(self) -> bool: ...
...
@property @property
def self_id(self) -> IcaType.UserId: def self_id(self) -> IcaType.UserId: ...
...
@property @property
def nick_name(self) -> str: def nick_name(self) -> str: ...
...
@property @property
def ica_version(self) -> str: def ica_version(self) -> str: ...
...
@property @property
def os_info(self) -> str: def os_info(self) -> str: ...
...
@property @property
def resident_set_size(self) -> str: def resident_set_size(self) -> str: ...
...
@property @property
def head_used(self) -> str: def head_used(self) -> str: ...
...
@property @property
def load(self) -> str: def load(self) -> str: ...
...
class IcaReplyMessage: class IcaReplyMessage: ...
...
class IcaSendMessage: class IcaSendMessage:
@property @property
def content(self) -> str: def content(self) -> str: ...
...
@content.setter @content.setter
def content(self, value: str) -> None: def content(self, value: str) -> None: ...
...
def with_content(self, content: str) -> "IcaSendMessage": def with_content(self, content: str) -> "IcaSendMessage":
""" """
为了链式调用, 返回自身 为了链式调用, 返回自身
""" """
self.content = content self.content = content
return self return self
def set_img(self, file: bytes, file_type: str, as_sticker: bool): def set_img(self, file: bytes, file_type: str, as_sticker: bool):
""" """
设置消息的图片 设置消息的图片
@ -85,54 +81,66 @@ class IcaSendMessage:
@param file_type: 图片类型 (MIME) (image/png; image/jpeg) @param file_type: 图片类型 (MIME) (image/png; image/jpeg)
@param as_sticker: 是否作为贴纸发送 @param as_sticker: 是否作为贴纸发送
""" """
def remove_reply(self) -> "IcaSendMessage":
"""删除回复"""
...
class IcaDeleteMessage: class IcaDeleteMessage:
def __str__(self) -> str: def __str__(self) -> str: ...
...
class IcaNewMessage: class IcaNewMessage:
""" """
Icalingua 接收到新消息 Icalingua 接收到新消息
""" """
def reply_with(self, message: str) -> IcaSendMessage: def reply_with(self, message: str) -> IcaSendMessage:
"""创建一条 回复这条消息 的可发送消息""" """创建一条 回复这条消息 的可发送消息"""
... ...
def as_deleted(self) -> IcaDeleteMessage: def as_deleted(self) -> IcaDeleteMessage:
"""作为一条要被撤回的消息"""
... ...
def __str__(self) -> str:
... def __str__(self) -> str: ...
@property @property
def id(self) -> IcaType.MessageId: def id(self) -> IcaType.MessageId:
"""消息的 Id"""
... ...
@property @property
def content(self) -> str: def content(self) -> str: ...
...
@property @property
def sender_id(self) -> IcaType.UserId: def sender_id(self) -> IcaType.UserId:
"""获取发送人id""" """获取发送人id"""
... ...
@property @property
def sender_name(self) -> str: def sender_name(self) -> str:
"""获取发送人名字""" """获取发送人名字"""
... ...
@property @property
def is_from_self(self) -> bool: def is_from_self(self) -> bool:
"""是不是自己发的消息""" """是不是自己发的消息"""
... ...
@property @property
def is_reply(self) -> bool: def is_reply(self) -> bool:
"""是不是回复消息""" """是不是回复消息"""
... ...
@property @property
def is_room_msg(self) -> bool: def is_room_msg(self) -> bool:
"""是否是群聊消息""" """是否是群聊消息"""
... ...
@property @property
def is_chat_msg(self) -> bool: def is_chat_msg(self) -> bool:
"""是否是私聊消息""" """是否是私聊消息"""
... ...
@property @property
def room_id(self) -> IcaType.RoomId: def room_id(self) -> IcaType.RoomId:
""" """
@ -146,6 +154,7 @@ class IcaClient:
""" """
Icalingua 的客户端 Icalingua 的客户端
""" """
# @staticmethod # @staticmethod
# async def send_message_a(client: "IcaClient", message: SendMessage) -> bool: # async def send_message_a(client: "IcaClient", message: SendMessage) -> bool:
# """ # """
@ -156,41 +165,46 @@ class IcaClient:
def send_message(self, message: IcaSendMessage) -> bool: def send_message(self, message: IcaSendMessage) -> bool:
"""发送一条消息""" """发送一条消息"""
... ...
def send_and_warn(self, message: IcaSendMessage) -> bool: def send_and_warn(self, message: IcaSendMessage) -> bool:
"""发送消息, 并在日志中输出警告信息""" """发送消息, 并在日志中输出警告信息"""
self.warn(message.content) self.warn(message.content)
return self.send_message(message) return self.send_message(message)
def delete_message(self, message: IcaDeleteMessage) -> bool:
... def delete_message(self, message: IcaDeleteMessage) -> bool: ...
@property @property
def status(self) -> IcaStatus: def status(self) -> IcaStatus: ...
...
@property @property
def version(self) -> str: def version(self) -> str: ...
...
@property @property
def version_str(self) -> str: def version_str(self) -> str:
"""获取一个更完善的版本号信息""" """获取一个更完善的版本号信息"""
... ...
@property @property
def client_id(self) -> str: def client_id(self) -> str:
"""返回一个"唯一"的客户端id""" """返回一个"唯一"的客户端id"""
... ...
@property @property
def ica_version(self) -> str: def ica_version(self) -> str:
"""shenbot ica 的版本号""" """shenbot ica 的版本号"""
... ...
@property @property
def startup_time(self) -> datetime: def startup_time(self) -> datetime:
"""请注意, 此时刻为 UTC 时刻""" """请注意, 此时刻为 UTC 时刻"""
... ...
def debug(self, message: str) -> None: def debug(self, message: str) -> None:
"""向日志中输出调试信息""" """向日志中输出调试信息"""
... ...
def info(self, message: str) -> None: def info(self, message: str) -> None:
"""向日志中输出信息""" """向日志中输出信息"""
... ...
def warn(self, message: str) -> None: def warn(self, message: str) -> None:
"""向日志中输出警告信息""" """向日志中输出警告信息"""
... ...
@ -200,30 +214,31 @@ class TailchatReciveMessage:
""" """
Tailchat 接收到的新消息 Tailchat 接收到的新消息
""" """
@property @property
def id(self) -> TailchatType.MessageId: def id(self) -> TailchatType.MessageId: ...
...
@property @property
def content(self) -> str: def content(self) -> str: ...
...
@property @property
def sender_id(self) -> TailchatType.UserId: def sender_id(self) -> TailchatType.UserId: ...
...
@property @property
def is_from_self(self) -> bool: def is_from_self(self) -> bool: ...
...
@property @property
def is_reply(self) -> bool: def is_reply(self) -> bool: ...
...
@property @property
def group_id(self) -> Optional[TailchatType.GroupId]: def group_id(self) -> Optional[TailchatType.GroupId]:
"""服务器 Id"""
... ...
@property @property
def converse_id(self) -> TailchatType.ConverseId: def converse_id(self) -> TailchatType.ConverseId:
"""会话 Id"""
... ...
def reply_with(self, message: str) -> "TailchatSendingMessage": def reply_with(self, message: str) -> "TailchatSendingMessage":
"""创建一条 回复这条消息 的可发送消息""" """创建一条 回复这条消息 的可发送消息"""
... ...
def as_reply(self, message: str) -> "TailchatSendingMessage": def as_reply(self, message: str) -> "TailchatSendingMessage":
"""回复这条消息""" """回复这条消息"""
... ...
@ -233,30 +248,36 @@ class TailchatSendingMessage:
""" """
Tailchat 将要发送的信息 Tailchat 将要发送的信息
""" """
@property @property
def content(self) -> str: def content(self) -> str:
"""内容"""
... ...
@content.setter @content.setter
def content(self, value: str) -> None: def content(self, value: str) -> None: ...
...
@property @property
def group_id(self) -> Optional[TailchatType.GroupId]: def group_id(self) -> Optional[TailchatType.GroupId]: ...
...
@group_id.setter @group_id.setter
def group_id(self, value: Optional[TailchatType.GroupId]) -> None: def group_id(self, value: Optional[TailchatType.GroupId]) -> None: ...
...
@property @property
def converse_id(self) -> TailchatType.ConverseId: def converse_id(self) -> TailchatType.ConverseId: ...
...
@converse_id.setter @converse_id.setter
def converse_id(self, value: TailchatType.ConverseId) -> None: def converse_id(self, value: TailchatType.ConverseId) -> None: ...
... def clear_meta(self) -> "TailchatSendingMessage":
"""
清除所有元数据, 可以用于取消 回复
"""
self.meta = None
return self
def with_content(self, content: str) -> "TailchatSendingMessage": def with_content(self, content: str) -> "TailchatSendingMessage":
""" """
为了链式调用, 返回自身 为了链式调用, 返回自身
""" """
self.content = content self.content = content
return self return self
def set_img(self, file: bytes, file_name: str): def set_img(self, file: bytes, file_name: str):
""" """
设置消息的图片 设置消息的图片
@ -269,35 +290,49 @@ class TailchatClient:
""" """
Tailchat 的客户端 Tailchat 的客户端
""" """
def send_message(self, message: TailchatSendingMessage) -> bool:
... def send_message(self, message: TailchatSendingMessage) -> bool: ...
def send_and_warn(self, message: TailchatSendingMessage) -> bool: def send_and_warn(self, message: TailchatSendingMessage) -> bool:
"""发送消息, 并在日志中输出警告信息""" """发送消息, 并在日志中输出警告信息"""
self.warn(message.content) self.warn(message.content)
return self.send_message(message) return self.send_message(message)
@property
def version(self) -> str: def new_message(
self,
content: str,
converse_id: TailchatType.ConverseId,
group_id: Optional[TailchatType.GroupId] = None,
) -> "TailchatSendingMessage":
"""创建一条新消息, 可用于发送"""
... ...
@property @property
def version(self) -> str: ...
@property
def version_str(self) -> str: def version_str(self) -> str:
"""获取一个更完善的版本号信息""" """获取一个更完善的版本号信息"""
... ...
@property @property
def client_id(self) -> str: def client_id(self) -> str:
"""返回一个"唯一"的客户端id""" """返回一个"唯一"的客户端id"""
... ...
@property @property
def tailchat_version(self) -> str: def tailchat_version(self) -> str:
"""tailchat 的版本号""" """tailchat 的版本号"""
... ...
@property @property
def startup_time(self) -> datetime: def startup_time(self) -> datetime:
"""请注意, 此时刻为 UTC 时刻""" """请注意, 此时刻为 UTC 时刻"""
... ...
def debug(self, message: str) -> None: def debug(self, message: str) -> None:
"""向日志中输出调试信息""" """向日志中输出调试信息"""
def info(self, message: str) -> None: def info(self, message: str) -> None:
"""向日志中输出信息""" """向日志中输出信息"""
def warn(self, message: str) -> None: def warn(self, message: str) -> None:
"""向日志中输出警告信息""" """向日志中输出警告信息"""
@ -307,15 +342,16 @@ class ReciveMessage(TailchatReciveMessage, IcaNewMessage):
继承了两边的消息 继承了两边的消息
只是用来类型标记, 不能实例化 只是用来类型标记, 不能实例化
""" """
def reply_with(self, message: str) -> Union["IcaReplyMessage", "TailchatSendingMessage"]: # type: ignore
def reply_with(
self, message: str
) -> Union["IcaReplyMessage", "TailchatSendingMessage"]: # type: ignore
... ...
class ConfigData: class ConfigData:
def __getitem__(self, key: str): def __getitem__(self, key: str): ...
... def have_key(self, key: str) -> bool: ...
def have_key(self, key: str) -> bool:
...
on_load = Callable[[IcaClient], None] on_load = Callable[[IcaClient], None]