socket-bot/ica-rs/ica_typing.py

316 lines
7.9 KiB
Python
Raw Normal View History

2024-02-20 20:11:25 +08:00
# Python 兼容版本 3.8+
2024-06-28 23:19:10 +08:00
from typing import Callable, Tuple, NewType, Optional, Union
from datetime import datetime
"""
2024-03-30 14:24:19 +08:00
ica.rs
pub type RoomId = i64;
pub type UserId = i64;
pub type MessageId = String;
"""
2024-03-30 14:24:19 +08:00
class IcaType:
2024-06-10 16:25:17 +08:00
RoomId = NewType('RoomId', int)
UserId = NewType('UserId', int)
MessageId = NewType('MessageId', str)
2024-03-30 14:24:19 +08:00
"""
tailchat.rs
pub type GroupId = String;
pub type ConverseId = String;
pub type UserId = String;
pub type MessageId = String;
"""
class TailchatType:
2024-06-10 16:25:17 +08:00
GroupId = NewType('GroupId', str)
ConverseId = NewType('ConverseId', str)
UserId = NewType('UserId', str)
MessageId = NewType('MessageId', str)
2024-02-20 20:11:25 +08:00
2024-06-10 16:05:24 +08:00
class IcaStatus:
"""
ica状态信息
此类并不存储信息, 所有方法都是实时获取
"""
@property
def qq_login(self) -> bool:
...
@property
def online(self) -> bool:
...
@property
def self_id(self) -> IcaType.UserId:
...
@property
def nick_name(self) -> str:
...
@property
def ica_version(self) -> str:
...
@property
def os_info(self) -> str:
...
@property
def resident_set_size(self) -> str:
...
@property
def head_used(self) -> str:
...
@property
def load(self) -> str:
2024-02-20 20:11:25 +08:00
...
2024-06-10 16:05:24 +08:00
class IcaReplyMessage:
...
2024-02-21 23:07:21 +08:00
2024-06-10 16:05:24 +08:00
class IcaSendMessage:
@property
def content(self) -> str:
...
@content.setter
def content(self, value: str) -> None:
...
def with_content(self, content: str) -> "IcaSendMessage":
2024-06-09 20:01:44 +08:00
"""
2024-06-10 16:05:24 +08:00
为了链式调用, 返回自身
2024-06-09 20:01:44 +08:00
"""
2024-06-10 16:05:24 +08:00
self.content = content
return self
def set_img(self, file: bytes, file_type: str, as_sticker: bool):
2024-03-18 04:18:37 +08:00
"""
2024-06-10 16:05:24 +08:00
设置消息的图片
@param file: 图片文件 (实际上是 vec<u8>)
@param file_type: 图片类型 (MIME) (image/png; image/jpeg)
@param as_sticker: 是否作为贴纸发送
2024-03-18 04:18:37 +08:00
"""
2024-02-22 02:40:39 +08:00
2024-06-10 16:05:24 +08:00
class IcaDeleteMessage:
def __str__(self) -> str:
...
2024-02-22 02:40:39 +08:00
2024-06-03 23:52:16 +08:00
2024-06-10 16:05:24 +08:00
class IcaNewMessage:
"""
Icalingua 接收到新消息
"""
def reply_with(self, message: str) -> IcaSendMessage:
"""回复这条消息"""
...
def as_deleted(self) -> IcaDeleteMessage:
...
def __str__(self) -> str:
...
@property
def id(self) -> IcaType.MessageId:
...
@property
def content(self) -> str:
...
@property
def sender_id(self) -> IcaType.UserId:
...
@property
def is_from_self(self) -> bool:
...
@property
def is_reply(self) -> bool:
...
@property
def is_room_msg(self) -> bool:
"""是否是群聊消息"""
...
@property
def is_chat_msg(self) -> bool:
"""是否是私聊消息"""
...
@property
def room_id(self) -> IcaType.RoomId:
2024-06-09 20:01:44 +08:00
"""
2024-06-10 16:05:24 +08:00
如果是群聊消息, 返回 (-群号)
如果是私聊消息, 返回 对面qq
2024-06-09 20:01:44 +08:00
"""
2024-06-10 16:05:24 +08:00
...
2024-02-22 12:06:43 +08:00
2024-06-10 16:05:24 +08:00
class IcaClient:
"""
Icalingua 的客户端
"""
# @staticmethod
# async def send_message_a(client: "IcaClient", message: SendMessage) -> bool:
# """
# 仅作占位, 不能使用
# (因为目前来说, rust调用 Python端没法启动一个异步运行时
# 所以只能 tokio::task::block_in_place 转换成同步调用)
# """
def send_message(self, message: IcaSendMessage) -> bool:
...
def send_and_warn(self, message: IcaSendMessage) -> bool:
"""发送消息, 并在日志中输出警告信息"""
self.warn(message.content)
return self.send_message(message)
def delete_message(self, message: IcaDeleteMessage) -> bool:
...
@property
def status(self) -> IcaStatus:
...
@property
def version(self) -> str:
...
@property
def startup_time(self) -> datetime:
"""请注意, 此时刻为 UTC 时刻"""
...
@property
2024-06-10 16:05:24 +08:00
def ica_version(self) -> str:
"""shenbot ica 的版本号"""
...
def debug(self, message: str) -> None:
"""向日志中输出调试信息"""
...
def info(self, message: str) -> None:
"""向日志中输出信息"""
...
def warn(self, message: str) -> None:
"""向日志中输出警告信息"""
...
2024-06-03 23:52:16 +08:00
2024-06-10 16:05:24 +08:00
class TailchatReciveMessage:
"""
Tailchat 接收到的新消息
"""
@property
def id(self) -> TailchatType.MessageId:
...
@property
def content(self) -> str:
...
@property
def sender_id(self) -> TailchatType.UserId:
...
2024-06-15 02:46:46 +08:00
@property
def is_from_self(self) -> bool:
...
2024-06-10 16:05:24 +08:00
@property
def is_reply(self) -> bool:
...
@property
def group_id(self) -> Optional[TailchatType.GroupId]:
...
@property
def converse_id(self) -> TailchatType.ConverseId:
...
def reply_with(self, message: str) -> "TailchatSendingMessage":
"""回复这条消息"""
...
def as_reply(self, message: str) -> "TailchatSendingMessage":
"""回复这条消息"""
...
class TailchatSendingMessage:
"""
Tailchat 将要发送的信息
"""
@property
def content(self) -> str:
...
@content.setter
def content(self, value: str) -> None:
...
@property
def group_id(self) -> Optional[TailchatType.GroupId]:
...
@group_id.setter
def group_id(self, value: Optional[TailchatType.GroupId]) -> None:
...
@property
def converse_id(self) -> TailchatType.ConverseId:
...
@converse_id.setter
def converse_id(self, value: TailchatType.ConverseId) -> None:
...
def with_content(self, content: str) -> "TailchatSendingMessage":
2024-06-04 23:48:01 +08:00
"""
2024-06-10 16:05:24 +08:00
为了链式调用, 返回自身
2024-06-04 23:48:01 +08:00
"""
2024-06-10 16:05:24 +08:00
self.content = content
return self
2024-06-28 23:19:10 +08:00
def set_img(self, file: bytes, file_name: str):
"""
设置消息的图片
@param file: 图片文件 (实际上是 vec<u8>)
@param file_name: 图片名称 (just_img.png)
"""
2024-06-04 23:48:01 +08:00
2024-06-10 16:05:24 +08:00
class TailchatClient:
2024-03-18 04:18:37 +08:00
"""
2024-06-10 16:05:24 +08:00
Tailchat 的客户端
2024-03-18 04:18:37 +08:00
"""
2024-06-10 16:05:24 +08:00
def send_message(self, message: TailchatSendingMessage) -> bool:
...
def send_and_warn(self, message: TailchatSendingMessage) -> bool:
"""发送消息, 并在日志中输出警告信息"""
self.warn(message.content)
return self.send_message(message)
@property
def version(self) -> str:
...
@property
def tailchat_version(self) -> str:
"""tailchat 的版本号"""
...
@property
def startup_time(self) -> datetime:
"""请注意, 此时刻为 UTC 时刻"""
...
2024-06-10 16:05:24 +08:00
def debug(self, message: str) -> None:
"""向日志中输出调试信息"""
def info(self, message: str) -> None:
"""向日志中输出信息"""
def warn(self, message: str) -> None:
"""向日志中输出警告信息"""
2024-06-22 19:10:53 +08:00
class ReciveMessage(TailchatReciveMessage, IcaNewMessage):
"""
继承了两边的消息
只是用来类型标记, 不能实例化
"""
def reply_with(self, message: str) -> Union["IcaReplyMessage", "TailchatSendingMessage"]: # type: ignore
...
2024-06-10 16:05:24 +08:00
class ConfigData:
def __getitem__(self, key: str):
...
def have_key(self, key: str) -> bool:
...
2024-02-25 17:27:02 +08:00
on_load = Callable[[IcaClient], None]
# def on_load(client: IcaClient) -> None:
# ...
2024-03-16 16:58:18 +08:00
on_ica_message = Callable[[IcaNewMessage, IcaClient], None]
# def on_message(msg: NewMessage, client: IcaClient) -> None:
# ...
2024-03-30 14:24:19 +08:00
on_ica_delete_message = Callable[[IcaType.MessageId, IcaClient], None]
# def on_delete_message(msg_id: MessageId, client: IcaClient) -> None:
# ...
2024-02-25 17:27:02 +08:00
2024-06-04 23:48:01 +08:00
on_tailchat_message = Callable[[TailchatClient, TailchatReciveMessage], None]
# def on_tailchat_message(client: TailchatClient, msg: TailchatReciveMessage) -> None:
# ...
2024-03-12 00:16:12 +08:00
2024-02-25 18:20:03 +08:00
on_config = Callable[[None], Tuple[str, str]]
2024-06-10 16:05:24 +08:00
CONFIG_DATA: ConfigData = ConfigData()