2024-02-20 20:11:25 +08:00
|
|
|
# Python 兼容版本 3.8+
|
|
|
|
|
2024-02-25 18:20:03 +08:00
|
|
|
from typing import Callable, Tuple
|
2024-02-24 23:07:31 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
pub type RoomId = i64;
|
|
|
|
pub type UserId = i64;
|
|
|
|
pub type MessageId = String;
|
|
|
|
"""
|
|
|
|
|
|
|
|
RoomId = int
|
|
|
|
UserId = int
|
|
|
|
MessageId = str
|
2024-02-20 20:11:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
class IcaStatus:
|
2024-02-25 12:01:36 +08:00
|
|
|
"""
|
|
|
|
ica状态信息
|
|
|
|
此类并不存储信息, 所有方法都是实时获取
|
|
|
|
"""
|
2024-02-20 20:11:25 +08:00
|
|
|
@property
|
2024-03-15 12:27:00 +08:00
|
|
|
def qq_login(self) -> bool:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
@property
|
|
|
|
def online(self) -> bool:
|
|
|
|
...
|
|
|
|
@property
|
2024-02-25 12:01:36 +08:00
|
|
|
def self_id(self) -> UserId:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
@property
|
2024-02-25 12:01:36 +08:00
|
|
|
def nick_name(self) -> str:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
@property
|
2024-02-25 12:01:36 +08:00
|
|
|
def ica_version(self) -> str:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
@property
|
2024-02-25 12:01:36 +08:00
|
|
|
def os_info(self) -> str:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
@property
|
2024-02-25 12:01:36 +08:00
|
|
|
def resident_set_size(self) -> str:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
@property
|
2024-02-25 12:01:36 +08:00
|
|
|
def head_used(self) -> str:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
@property
|
2024-03-15 12:27:00 +08:00
|
|
|
def load(self) -> str:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
2024-03-16 16:58:18 +08:00
|
|
|
class IcaReplyMessage:
|
2024-02-20 20:11:25 +08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
2024-03-16 16:58:18 +08:00
|
|
|
class IcaSendMessage:
|
2024-02-24 19:26:21 +08:00
|
|
|
@property
|
|
|
|
def content(self) -> str:
|
|
|
|
...
|
|
|
|
@content.setter
|
|
|
|
def content(self, value: str) -> None:
|
|
|
|
...
|
2024-03-16 16:58:18 +08:00
|
|
|
def with_content(self, content: str) -> "IcaSendMessage":
|
2024-02-24 19:26:21 +08:00
|
|
|
"""
|
|
|
|
为了链式调用, 返回自身
|
|
|
|
"""
|
|
|
|
self.content = content
|
|
|
|
return self
|
2024-02-21 23:07:21 +08:00
|
|
|
|
|
|
|
|
2024-03-16 16:58:18 +08:00
|
|
|
class IcaDeleteMessage:
|
2024-02-25 12:01:36 +08:00
|
|
|
def __str__(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2024-03-16 16:58:18 +08:00
|
|
|
class IcaNewMessage:
|
2024-03-18 04:18:37 +08:00
|
|
|
"""
|
|
|
|
Icalingua 接收到新消息
|
|
|
|
"""
|
2024-03-16 16:58:18 +08:00
|
|
|
def reply_with(self, message: str) -> IcaSendMessage:
|
2024-03-18 04:18:37 +08:00
|
|
|
"""回复这条消息"""
|
2024-03-16 16:58:18 +08:00
|
|
|
def as_deleted(self) -> IcaDeleteMessage:
|
2024-02-25 12:01:36 +08:00
|
|
|
...
|
2024-02-22 12:47:20 +08:00
|
|
|
def __str__(self) -> str:
|
|
|
|
...
|
|
|
|
@property
|
2024-02-24 23:07:31 +08:00
|
|
|
def id(self) -> MessageId:
|
|
|
|
...
|
|
|
|
@property
|
2024-02-22 12:47:20 +08:00
|
|
|
def content(self) -> str:
|
|
|
|
...
|
|
|
|
@property
|
2024-02-24 23:07:31 +08:00
|
|
|
def sender_id(self) -> UserId:
|
2024-02-22 12:47:20 +08:00
|
|
|
...
|
|
|
|
@property
|
|
|
|
def is_from_self(self) -> bool:
|
|
|
|
...
|
2024-02-22 14:30:56 +08:00
|
|
|
@property
|
|
|
|
def is_reply(self) -> bool:
|
|
|
|
...
|
2024-03-16 16:58:18 +08:00
|
|
|
@property
|
|
|
|
def is_room_msg(self) -> bool:
|
2024-03-18 04:18:37 +08:00
|
|
|
"""是否是群聊消息"""
|
2024-03-16 16:58:18 +08:00
|
|
|
@property
|
|
|
|
def is_chat_msg(self) -> bool:
|
2024-03-18 04:18:37 +08:00
|
|
|
"""是否是私聊消息"""
|
2024-03-16 16:58:18 +08:00
|
|
|
@property
|
|
|
|
def room_id(self) -> RoomId:
|
2024-03-18 04:18:37 +08:00
|
|
|
"""
|
|
|
|
如果是群聊消息, 返回 (-群号)
|
|
|
|
如果是私聊消息, 返回 对面qq
|
|
|
|
"""
|
2024-02-22 02:40:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
class IcaClient:
|
2024-03-18 04:18:37 +08:00
|
|
|
"""
|
|
|
|
Icalingua 的客户端
|
|
|
|
"""
|
2024-03-12 22:11:59 +08:00
|
|
|
# @staticmethod
|
|
|
|
# async def send_message_a(client: "IcaClient", message: SendMessage) -> bool:
|
|
|
|
# """
|
|
|
|
# 仅作占位, 不能使用
|
|
|
|
# (因为目前来说, rust调用 Python端没法启动一个异步运行时
|
|
|
|
# 所以只能 tokio::task::block_in_place 转换成同步调用)
|
|
|
|
# """
|
2024-03-16 16:58:18 +08:00
|
|
|
def send_message(self, message: IcaSendMessage) -> bool:
|
2024-02-22 02:40:39 +08:00
|
|
|
...
|
2024-03-16 16:58:18 +08:00
|
|
|
def send_and_warn(self, message: IcaSendMessage) -> bool:
|
2024-02-25 18:49:39 +08:00
|
|
|
"""发送消息, 并在日志中输出警告信息"""
|
|
|
|
self.warn(message.content)
|
|
|
|
return self.send_message(message)
|
2024-03-16 16:58:18 +08:00
|
|
|
def delete_message(self, message: IcaDeleteMessage) -> bool:
|
2024-02-25 12:01:36 +08:00
|
|
|
...
|
2024-02-25 00:22:09 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def status() -> IcaStatus:
|
|
|
|
...
|
2024-02-25 21:33:11 +08:00
|
|
|
@property
|
|
|
|
def version() -> str:
|
|
|
|
...
|
2024-03-15 12:27:00 +08:00
|
|
|
@property
|
|
|
|
def ica_version() -> str:
|
|
|
|
"""shenbot ica 的版本号"""
|
2024-02-25 00:22:09 +08:00
|
|
|
|
2024-02-22 13:06:30 +08:00
|
|
|
def debug(self, message: str) -> None:
|
2024-02-24 23:07:31 +08:00
|
|
|
"""向日志中输出调试信息"""
|
2024-02-22 13:06:30 +08:00
|
|
|
def info(self, message: str) -> None:
|
2024-02-24 23:07:31 +08:00
|
|
|
"""向日志中输出信息"""
|
2024-02-22 13:06:30 +08:00
|
|
|
def warn(self, message: str) -> None:
|
2024-02-24 23:07:31 +08:00
|
|
|
"""向日志中输出警告信息"""
|
2024-02-22 12:06:43 +08:00
|
|
|
|
|
|
|
|
2024-03-18 04:18:37 +08:00
|
|
|
class MatrixClient:
|
|
|
|
"""
|
|
|
|
Matrix 的客户端
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2024-02-25 17:27:02 +08:00
|
|
|
class ConfigData:
|
|
|
|
def __getitem__(self, key: str):
|
|
|
|
...
|
|
|
|
def have_key(self, key: str) -> bool:
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2024-02-24 23:07:31 +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]
|
2024-02-24 23:07:31 +08:00
|
|
|
# def on_message(msg: NewMessage, client: IcaClient) -> None:
|
|
|
|
# ...
|
|
|
|
|
2024-03-16 16:58:18 +08:00
|
|
|
on_ica_delete_message = Callable[[MessageId, IcaClient], None]
|
2024-02-24 23:56:36 +08:00
|
|
|
# def on_delete_message(msg_id: MessageId, client: IcaClient) -> None:
|
|
|
|
# ...
|
2024-02-25 17:27:02 +08:00
|
|
|
|
2024-03-12 00:16:12 +08:00
|
|
|
# TODO: Matrix adapter
|
2024-03-18 04:18:37 +08:00
|
|
|
on_matrix_message = Callable[[], 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-02-25 17:27:02 +08:00
|
|
|
|
|
|
|
CONFIG_DATA: ConfigData = ConfigData()
|