Compare commits
4 Commits
2340916570
...
31a490b40c
Author | SHA1 | Date | |
---|---|---|---|
31a490b40c | |||
aad9ab08f6 | |||
54dfb59b16 | |||
|
d249c33d58 |
@ -1,6 +1,6 @@
|
|||||||
# Python 兼容版本 3.8+
|
# Python 兼容版本 3.8+
|
||||||
|
|
||||||
from typing import Callable, Tuple, NewType, TYPE_CHECKING, TypeVar
|
from typing import Callable, Tuple, NewType, TYPE_CHECKING, TypeVar, Optional
|
||||||
|
|
||||||
"""
|
"""
|
||||||
ica.rs
|
ica.rs
|
||||||
@ -26,261 +26,255 @@ class TailchatType:
|
|||||||
UserId = NewType('UserId', str)
|
UserId = NewType('UserId', str)
|
||||||
MessageId = NewType('MessageId', str)
|
MessageId = NewType('MessageId', str)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
class IcaStatus:
|
||||||
|
"""
|
||||||
class IcaStatus:
|
ica状态信息
|
||||||
"""
|
此类并不存储信息, 所有方法都是实时获取
|
||||||
ica状态信息
|
"""
|
||||||
此类并不存储信息, 所有方法都是实时获取
|
@property
|
||||||
"""
|
def qq_login(self) -> bool:
|
||||||
@property
|
...
|
||||||
def qq_login(self) -> bool:
|
@property
|
||||||
...
|
def online(self) -> bool:
|
||||||
@property
|
...
|
||||||
def online(self) -> bool:
|
@property
|
||||||
...
|
def self_id(self) -> IcaType.UserId:
|
||||||
@property
|
...
|
||||||
def self_id(self) -> IcaType.UserId:
|
@property
|
||||||
...
|
def nick_name(self) -> str:
|
||||||
@property
|
...
|
||||||
def nick_name(self) -> str:
|
@property
|
||||||
...
|
def ica_version(self) -> str:
|
||||||
@property
|
...
|
||||||
def ica_version(self) -> str:
|
@property
|
||||||
...
|
def os_info(self) -> str:
|
||||||
@property
|
...
|
||||||
def os_info(self) -> str:
|
@property
|
||||||
...
|
def resident_set_size(self) -> str:
|
||||||
@property
|
...
|
||||||
def resident_set_size(self) -> str:
|
@property
|
||||||
...
|
def head_used(self) -> str:
|
||||||
@property
|
...
|
||||||
def head_used(self) -> str:
|
@property
|
||||||
...
|
def load(self) -> str:
|
||||||
@property
|
|
||||||
def load(self) -> str:
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
class IcaReplyMessage:
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class IcaSendMessage:
|
class IcaReplyMessage:
|
||||||
@property
|
...
|
||||||
def content(self) -> str:
|
|
||||||
...
|
|
||||||
@content.setter
|
|
||||||
def content(self, value: str) -> None:
|
|
||||||
...
|
|
||||||
def with_content(self, content: str) -> "IcaSendMessage":
|
|
||||||
"""
|
|
||||||
为了链式调用, 返回自身
|
|
||||||
"""
|
|
||||||
self.content = content
|
|
||||||
return self
|
|
||||||
def set_img(self, file: bytes, file_type: str, as_sticker: bool):
|
|
||||||
"""
|
|
||||||
设置消息的图片
|
|
||||||
@param file: 图片文件 (实际上是 vec<u8>)
|
|
||||||
@param file_type: 图片类型 (MIME) (image/png; image/jpeg)
|
|
||||||
@param as_sticker: 是否作为贴纸发送
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class IcaDeleteMessage:
|
class IcaSendMessage:
|
||||||
def __str__(self) -> str:
|
@property
|
||||||
...
|
def content(self) -> str:
|
||||||
|
...
|
||||||
|
@content.setter
|
||||||
class IcaNewMessage:
|
def content(self, value: str) -> None:
|
||||||
|
...
|
||||||
|
def with_content(self, content: str) -> "IcaSendMessage":
|
||||||
"""
|
"""
|
||||||
Icalingua 接收到新消息
|
为了链式调用, 返回自身
|
||||||
"""
|
"""
|
||||||
def reply_with(self, message: str) -> IcaSendMessage:
|
self.content = content
|
||||||
"""回复这条消息"""
|
return self
|
||||||
...
|
def set_img(self, file: bytes, file_type: str, as_sticker: bool):
|
||||||
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:
|
|
||||||
"""
|
|
||||||
如果是群聊消息, 返回 (-群号)
|
|
||||||
如果是私聊消息, 返回 对面qq
|
|
||||||
"""
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
class IcaClient:
|
|
||||||
"""
|
"""
|
||||||
Icalingua 的客户端
|
设置消息的图片
|
||||||
|
@param file: 图片文件 (实际上是 vec<u8>)
|
||||||
|
@param file_type: 图片类型 (MIME) (image/png; image/jpeg)
|
||||||
|
@param as_sticker: 是否作为贴纸发送
|
||||||
"""
|
"""
|
||||||
# @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 ica_version(self) -> str:
|
|
||||||
"""shenbot ica 的版本号"""
|
|
||||||
...
|
|
||||||
def debug(self, message: str) -> None:
|
|
||||||
"""向日志中输出调试信息"""
|
|
||||||
...
|
|
||||||
def info(self, message: str) -> None:
|
|
||||||
"""向日志中输出信息"""
|
|
||||||
...
|
|
||||||
def warn(self, message: str) -> None:
|
|
||||||
"""向日志中输出警告信息"""
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
class TailchatReciveMessage:
|
class IcaDeleteMessage:
|
||||||
"""
|
def __str__(self) -> str:
|
||||||
Tailchat 接收到的新消息
|
...
|
||||||
"""
|
|
||||||
@property
|
|
||||||
def id(self) -> TailchatType.MessageId:
|
|
||||||
...
|
|
||||||
@property
|
|
||||||
def content(self) -> str:
|
|
||||||
...
|
|
||||||
@property
|
|
||||||
def sender_id(self) -> TailchatType.UserId:
|
|
||||||
...
|
|
||||||
# @property
|
|
||||||
# def is_from_self(self) -> bool:
|
|
||||||
# ...
|
|
||||||
@property
|
|
||||||
def is_reply(self) -> bool:
|
|
||||||
...
|
|
||||||
@property
|
|
||||||
def group_id(self) -> 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:
|
class IcaNewMessage:
|
||||||
"""
|
|
||||||
Tailchat 将要发送的信息
|
|
||||||
"""
|
|
||||||
@property
|
|
||||||
def content(self) -> str:
|
|
||||||
...
|
|
||||||
@content.setter
|
|
||||||
def content(self, value: str) -> None:
|
|
||||||
...
|
|
||||||
def with_content(self, content: str) -> "TailchatSendingMessage":
|
|
||||||
"""
|
|
||||||
为了链式调用, 返回自身
|
|
||||||
"""
|
|
||||||
self.content = content
|
|
||||||
return self
|
|
||||||
# def set_img(self, file: bytes, file_type: str, as_sticker: bool):
|
|
||||||
# """
|
|
||||||
# 设置消息的图片
|
|
||||||
# @param file: 图片文件 (实际上是 vec<u8>)
|
|
||||||
# @param file_type: 图片类型 (MIME) (image/png; image/jpeg)
|
|
||||||
# @param as_sticker: 是否作为贴纸发送
|
|
||||||
# """
|
|
||||||
|
|
||||||
|
|
||||||
class TailchatClient:
|
|
||||||
"""
|
|
||||||
Tailchat 的客户端
|
|
||||||
"""
|
|
||||||
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 的版本号"""
|
|
||||||
...
|
|
||||||
def debug(self, message: str) -> None:
|
|
||||||
"""向日志中输出调试信息"""
|
|
||||||
def info(self, message: str) -> None:
|
|
||||||
"""向日志中输出信息"""
|
|
||||||
def warn(self, message: str) -> None:
|
|
||||||
"""向日志中输出警告信息"""
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigData:
|
|
||||||
def __getitem__(self, key: str):
|
|
||||||
...
|
|
||||||
def have_key(self, key: str) -> bool:
|
|
||||||
...
|
|
||||||
|
|
||||||
CONFIG_DATA: ConfigData = ConfigData()
|
|
||||||
else:
|
|
||||||
"""
|
"""
|
||||||
正常 Import 的时候使用的类型定义
|
Icalingua 接收到新消息
|
||||||
"""
|
"""
|
||||||
IcaStatus = TypeVar("IcaStatus")
|
def reply_with(self, message: str) -> IcaSendMessage:
|
||||||
IcaReplyMessage = TypeVar("IcaReplyMessage")
|
"""回复这条消息"""
|
||||||
IcaNewMessage = TypeVar("IcaNewMessage")
|
...
|
||||||
IcaSendMessage = TypeVar("IcaSendMessage")
|
def as_deleted(self) -> IcaDeleteMessage:
|
||||||
IcaDeleteMessage = TypeVar("IcaDeleteMessage")
|
...
|
||||||
IcaClient = TypeVar("IcaClient")
|
def __str__(self) -> str:
|
||||||
TailchatReciveMessage = TypeVar("TailchatReciveMessage")
|
...
|
||||||
TailchatSendingMessage = TypeVar("TailchatSendingMessage")
|
@property
|
||||||
TailchatClient = TypeVar("TailchatClient")
|
def id(self) -> IcaType.MessageId:
|
||||||
ConfigData = TypeVar("ConfigData")
|
...
|
||||||
|
@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:
|
||||||
|
"""
|
||||||
|
如果是群聊消息, 返回 (-群号)
|
||||||
|
如果是私聊消息, 返回 对面qq
|
||||||
|
"""
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
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 ica_version(self) -> str:
|
||||||
|
"""shenbot ica 的版本号"""
|
||||||
|
...
|
||||||
|
def debug(self, message: str) -> None:
|
||||||
|
"""向日志中输出调试信息"""
|
||||||
|
...
|
||||||
|
def info(self, message: str) -> None:
|
||||||
|
"""向日志中输出信息"""
|
||||||
|
...
|
||||||
|
def warn(self, message: str) -> None:
|
||||||
|
"""向日志中输出警告信息"""
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
class TailchatReciveMessage:
|
||||||
|
"""
|
||||||
|
Tailchat 接收到的新消息
|
||||||
|
"""
|
||||||
|
@property
|
||||||
|
def id(self) -> TailchatType.MessageId:
|
||||||
|
...
|
||||||
|
@property
|
||||||
|
def content(self) -> str:
|
||||||
|
...
|
||||||
|
@property
|
||||||
|
def sender_id(self) -> TailchatType.UserId:
|
||||||
|
...
|
||||||
|
# @property
|
||||||
|
# def is_from_self(self) -> bool:
|
||||||
|
# ...
|
||||||
|
@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":
|
||||||
|
"""
|
||||||
|
为了链式调用, 返回自身
|
||||||
|
"""
|
||||||
|
self.content = content
|
||||||
|
return self
|
||||||
|
# def set_img(self, file: bytes, file_type: str, as_sticker: bool):
|
||||||
|
# """
|
||||||
|
# 设置消息的图片
|
||||||
|
# @param file: 图片文件 (实际上是 vec<u8>)
|
||||||
|
# @param file_type: 图片类型 (MIME) (image/png; image/jpeg)
|
||||||
|
# @param as_sticker: 是否作为贴纸发送
|
||||||
|
# """
|
||||||
|
|
||||||
|
|
||||||
|
class TailchatClient:
|
||||||
|
"""
|
||||||
|
Tailchat 的客户端
|
||||||
|
"""
|
||||||
|
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 的版本号"""
|
||||||
|
...
|
||||||
|
def debug(self, message: str) -> None:
|
||||||
|
"""向日志中输出调试信息"""
|
||||||
|
def info(self, message: str) -> None:
|
||||||
|
"""向日志中输出信息"""
|
||||||
|
def warn(self, message: str) -> None:
|
||||||
|
"""向日志中输出警告信息"""
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigData:
|
||||||
|
def __getitem__(self, key: str):
|
||||||
|
...
|
||||||
|
def have_key(self, key: str) -> bool:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
on_load = Callable[[IcaClient], None]
|
on_load = Callable[[IcaClient], None]
|
||||||
@ -300,3 +294,5 @@ on_tailchat_message = Callable[[TailchatClient, TailchatReciveMessage], None]
|
|||||||
# ...
|
# ...
|
||||||
|
|
||||||
on_config = Callable[[None], Tuple[str, str]]
|
on_config = Callable[[None], Tuple[str, str]]
|
||||||
|
|
||||||
|
CONFIG_DATA: ConfigData = ConfigData()
|
||||||
|
@ -16,8 +16,9 @@ pub struct ReciveMessage {
|
|||||||
#[serde(rename = "author")]
|
#[serde(rename = "author")]
|
||||||
pub sender_id: UserId,
|
pub sender_id: UserId,
|
||||||
/// 服务器ID
|
/// 服务器ID
|
||||||
|
/// 在私聊中不存在
|
||||||
#[serde(rename = "groupId")]
|
#[serde(rename = "groupId")]
|
||||||
pub group_id: GroupId,
|
pub group_id: Option<GroupId>,
|
||||||
/// 会话ID
|
/// 会话ID
|
||||||
#[serde(rename = "converseId")]
|
#[serde(rename = "converseId")]
|
||||||
pub converse_id: ConverseId,
|
pub converse_id: ConverseId,
|
||||||
@ -31,13 +32,10 @@ pub struct ReciveMessage {
|
|||||||
pub reactions: Vec<JsonValue>,
|
pub reactions: Vec<JsonValue>,
|
||||||
/// 创建时间
|
/// 创建时间
|
||||||
#[serde(rename = "createdAt")]
|
#[serde(rename = "createdAt")]
|
||||||
pub created_at: JsonValue,
|
pub created_at: String,
|
||||||
/// 更新时间
|
/// 更新时间
|
||||||
#[serde(rename = "updatedAt")]
|
#[serde(rename = "updatedAt")]
|
||||||
pub updated_at: JsonValue,
|
pub updated_at: String,
|
||||||
/// 未知
|
|
||||||
#[serde(rename = "__v")]
|
|
||||||
pub v: JsonValue,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReciveMessage {
|
impl ReciveMessage {
|
||||||
@ -69,7 +67,7 @@ impl Display for ReciveMessage {
|
|||||||
// msgid|groupid-converseid|senderid|content
|
// msgid|groupid-converseid|senderid|content
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{}|{}-{}|{}|{}",
|
"{}|{:?}-{}|{}|{}",
|
||||||
self.msg_id, self.group_id, self.converse_id, self.sender_id, self.content
|
self.msg_id, self.group_id, self.converse_id, self.sender_id, self.content
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -98,7 +96,7 @@ pub struct SendingMessage {
|
|||||||
pub converse_id: ConverseId,
|
pub converse_id: ConverseId,
|
||||||
/// 服务器ID
|
/// 服务器ID
|
||||||
#[serde(rename = "groupId")]
|
#[serde(rename = "groupId")]
|
||||||
pub group_id: GroupId,
|
pub group_id: Option<GroupId>,
|
||||||
/// 消息的元数据
|
/// 消息的元数据
|
||||||
pub meta: Option<ReplyMeta>,
|
pub meta: Option<ReplyMeta>,
|
||||||
}
|
}
|
||||||
@ -107,7 +105,7 @@ impl SendingMessage {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
content: String,
|
content: String,
|
||||||
converse_id: ConverseId,
|
converse_id: ConverseId,
|
||||||
group_id: GroupId,
|
group_id: Option<GroupId>,
|
||||||
meta: Option<ReplyMeta>,
|
meta: Option<ReplyMeta>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -117,7 +115,11 @@ impl SendingMessage {
|
|||||||
meta,
|
meta,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn new_without_meta(content: String, converse_id: ConverseId, group_id: GroupId) -> Self {
|
pub fn new_without_meta(
|
||||||
|
content: String,
|
||||||
|
converse_id: ConverseId,
|
||||||
|
group_id: Option<GroupId>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
content,
|
content,
|
||||||
converse_id,
|
converse_id,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
use crate::data_struct::tailchat::UserId;
|
use crate::data_struct::tailchat::UserId;
|
||||||
|
|
||||||
@ -11,3 +12,21 @@ pub struct LoginData {
|
|||||||
pub nickname: String,
|
pub nickname: String,
|
||||||
pub avatar: String,
|
pub avatar: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub struct UpdateDMConverse {
|
||||||
|
/// 会话ID
|
||||||
|
#[serde(rename = "_id")]
|
||||||
|
pub id: String,
|
||||||
|
/// 创建时间
|
||||||
|
#[serde(rename = "createdAt")]
|
||||||
|
pub created_at: String,
|
||||||
|
/// 成员
|
||||||
|
pub members: Vec<UserId>,
|
||||||
|
/// 类型
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub converse_type: String,
|
||||||
|
/// 更新时间
|
||||||
|
#[serde(rename = "updatedAt")]
|
||||||
|
pub updated_at: String,
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@ use crate::config::IcaConfig;
|
|||||||
use crate::error::{ClientResult, IcaError};
|
use crate::error::{ClientResult, IcaError};
|
||||||
use crate::{wrap_any_callback, wrap_callback, StopGetter};
|
use crate::{wrap_any_callback, wrap_callback, StopGetter};
|
||||||
|
|
||||||
const ICA_PROTOCOL_VERSION: &str = "2.12.2";
|
const ICA_PROTOCOL_VERSION: &str = "2.12.6";
|
||||||
|
|
||||||
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
|
pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> {
|
||||||
let span = span!(Level::INFO, "Icalingua Client");
|
let span = span!(Level::INFO, "Icalingua Client");
|
||||||
|
@ -123,6 +123,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
|||||||
// 忽略的
|
// 忽略的
|
||||||
"notify",
|
"notify",
|
||||||
"closeLoading", // 发送消息/加载新聊天 有一个 loading
|
"closeLoading", // 发送消息/加载新聊天 有一个 loading
|
||||||
|
"renewMessage", // 我也不确定到底是啥事件
|
||||||
"updateRoom",
|
"updateRoom",
|
||||||
"syncRead", // 同步已读
|
"syncRead", // 同步已读
|
||||||
];
|
];
|
||||||
|
@ -86,7 +86,7 @@ impl TailchatReciveMessagePy {
|
|||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_sender_id(&self) -> UserId { self.message.sender_id.clone() }
|
pub fn get_sender_id(&self) -> UserId { self.message.sender_id.clone() }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_group_id(&self) -> GroupId { self.message.group_id.clone() }
|
pub fn get_group_id(&self) -> Option<GroupId> { self.message.group_id.clone() }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_converse_id(&self) -> ConverseId { self.message.converse_id.clone() }
|
pub fn get_converse_id(&self) -> ConverseId { self.message.converse_id.clone() }
|
||||||
/// 作为回复
|
/// 作为回复
|
||||||
@ -110,8 +110,14 @@ impl TailchatSendingMessagePy {
|
|||||||
pub fn set_content(&mut self, content: String) { self.message.content = content; }
|
pub fn set_content(&mut self, content: String) { self.message.content = content; }
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_converse_id(&self) -> ConverseId { self.message.converse_id.clone() }
|
pub fn get_converse_id(&self) -> ConverseId { self.message.converse_id.clone() }
|
||||||
|
#[setter]
|
||||||
|
pub fn set_converse_id(&mut self, converse_id: ConverseId) {
|
||||||
|
self.message.converse_id = converse_id;
|
||||||
|
}
|
||||||
#[getter]
|
#[getter]
|
||||||
pub fn get_group_id(&self) -> GroupId { self.message.group_id.clone() }
|
pub fn get_group_id(&self) -> Option<GroupId> { self.message.group_id.clone() }
|
||||||
|
#[setter]
|
||||||
|
pub fn set_group_id(&mut self, group_id: Option<GroupId>) { self.message.group_id = group_id; }
|
||||||
pub fn with_content(&mut self, content: String) -> Self {
|
pub fn with_content(&mut self, content: String) -> Self {
|
||||||
self.message.content = content;
|
self.message.content = content;
|
||||||
self.clone()
|
self.clone()
|
||||||
|
@ -5,6 +5,7 @@ use std::path::Path;
|
|||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
|
use colored::Colorize;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::PyTuple;
|
use pyo3::types::PyTuple;
|
||||||
use tracing::{debug, info, span, warn, Level};
|
use tracing::{debug, info, span, warn, Level};
|
||||||
@ -19,6 +20,18 @@ pub struct PyStatus {
|
|||||||
pub type PyPluginData = HashMap<PathBuf, PyPlugin>;
|
pub type PyPluginData = HashMap<PathBuf, PyPlugin>;
|
||||||
pub type RawPyPlugin = (PathBuf, Option<SystemTime>, String);
|
pub type RawPyPlugin = (PathBuf, Option<SystemTime>, String);
|
||||||
|
|
||||||
|
pub fn get_py_err_traceback(py_err: &PyErr) -> String {
|
||||||
|
Python::with_gil(|py| match py_err.traceback_bound(py) {
|
||||||
|
Some(traceback) => match traceback.format() {
|
||||||
|
Ok(trace) => trace,
|
||||||
|
Err(e) => format!("{:?}", e),
|
||||||
|
},
|
||||||
|
None => "".to_string(),
|
||||||
|
})
|
||||||
|
.red()
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PyPlugin {
|
pub struct PyPlugin {
|
||||||
pub file_path: PathBuf,
|
pub file_path: PathBuf,
|
||||||
@ -33,7 +46,12 @@ impl PyPlugin {
|
|||||||
Ok(raw_file) => match Self::try_from(raw_file) {
|
Ok(raw_file) => match Self::try_from(raw_file) {
|
||||||
Ok(plugin) => Some(plugin),
|
Ok(plugin) => Some(plugin),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("加载 Python 插件文件{:?}: {:?} 失败", path, e);
|
warn!(
|
||||||
|
"加载 Python 插件文件{:?}: {:?} 失败\n{}",
|
||||||
|
path,
|
||||||
|
e,
|
||||||
|
get_py_err_traceback(&e)
|
||||||
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
|
|
||||||
|
use colored::Colorize;
|
||||||
use futures_util::FutureExt;
|
use futures_util::FutureExt;
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
use reqwest::ClientBuilder as reqwest_ClientBuilder;
|
use reqwest::ClientBuilder as reqwest_ClientBuilder;
|
||||||
@ -42,6 +43,7 @@ pub async fn start_tailchat(
|
|||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
if resp.status().is_success() {
|
if resp.status().is_success() {
|
||||||
let raw_data = resp.text().await?;
|
let raw_data = resp.text().await?;
|
||||||
|
|
||||||
let json_data = serde_json::from_str::<Value>(&raw_data).unwrap();
|
let json_data = serde_json::from_str::<Value>(&raw_data).unwrap();
|
||||||
let login_data = serde_json::from_value::<LoginData>(json_data["data"].clone());
|
let login_data = serde_json::from_value::<LoginData>(json_data["data"].clone());
|
||||||
match login_data {
|
match login_data {
|
||||||
@ -64,20 +66,24 @@ pub async fn start_tailchat(
|
|||||||
.on_any(wrap_any_callback!(events::any_event))
|
.on_any(wrap_any_callback!(events::any_event))
|
||||||
.on("notify:chat.message.add", wrap_callback!(events::on_message))
|
.on("notify:chat.message.add", wrap_callback!(events::on_message))
|
||||||
.on("notify:chat.message.delete", wrap_callback!(events::on_msg_delete))
|
.on("notify:chat.message.delete", wrap_callback!(events::on_msg_delete))
|
||||||
|
.on(
|
||||||
|
"notify:chat.converse.updateDMConverse",
|
||||||
|
wrap_callback!(events::on_converse_update),
|
||||||
|
)
|
||||||
// .on("notify:chat.message.update", wrap_callback!(events::on_message))
|
// .on("notify:chat.message.update", wrap_callback!(events::on_message))
|
||||||
// .on("notify:chat.message.addReaction", wrap_callback!(events::on_msg_update))
|
// .on("notify:chat.message.addReaction", wrap_callback!(events::on_msg_update))
|
||||||
.connect()
|
.connect()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
event!(Level::INFO, "tailchat connected");
|
event!(Level::INFO, "{}", "已经连接到 tailchat!".green());
|
||||||
|
|
||||||
// sleep for 500ms to wait for the connection to be established
|
// sleep for 500ms to wait for the connection to be established
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||||
|
|
||||||
socket.emit("chat.converse.findAndJoinRoom", json!([])).await.unwrap();
|
socket.emit("chat.converse.findAndJoinRoom", json!([])).await.unwrap();
|
||||||
|
|
||||||
event!(Level::INFO, "tailchat joined room");
|
event!(Level::INFO, "{}", "tailchat 已经加入房间".green());
|
||||||
|
|
||||||
stop_reciver.await.ok();
|
stop_reciver.await.ok();
|
||||||
event!(Level::INFO, "socketio client stopping");
|
event!(Level::INFO, "socketio client stopping");
|
||||||
|
@ -4,8 +4,8 @@ use crate::data_struct::tailchat::messages::SendingMessage;
|
|||||||
use rust_socketio::asynchronous::Client;
|
use rust_socketio::asynchronous::Client;
|
||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use serde_json::Value;
|
use serde_json::{json, Value};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
|
pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
|
||||||
let value: Value = message.as_value();
|
let value: Value = message.as_value();
|
||||||
@ -20,3 +20,16 @@ pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn emit_join_room(client: &Client) -> bool {
|
||||||
|
match client.emit("chat.converse.findAndJoinRoom", json!([])).await {
|
||||||
|
Ok(_) => {
|
||||||
|
info!("emiting join room");
|
||||||
|
true
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("emit_join_room faild:{}", format!("{:#?}", e).red());
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
|||||||
// 真正处理过的
|
// 真正处理过的
|
||||||
"notify:chat.message.add",
|
"notify:chat.message.add",
|
||||||
"notify:chat.message.delete",
|
"notify:chat.message.delete",
|
||||||
|
"notify:chat.converse.updateDMConverse",
|
||||||
// 也许以后会用到
|
// 也许以后会用到
|
||||||
"notify:chat.message.update",
|
"notify:chat.message.update",
|
||||||
"notify:chat.message.addReaction",
|
"notify:chat.message.addReaction",
|
||||||
@ -60,7 +61,14 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
|
|||||||
pub async fn on_message(payload: Payload, client: Client) {
|
pub async fn on_message(payload: Payload, client: Client) {
|
||||||
if let Payload::Text(values) = payload {
|
if let Payload::Text(values) = payload {
|
||||||
if let Some(value) = values.first() {
|
if let Some(value) = values.first() {
|
||||||
let message: ReciveMessage = serde_json::from_value(value.clone()).unwrap();
|
let message: ReciveMessage = match serde_json::from_value(value.clone()) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => {
|
||||||
|
info!("tailchat_msg {}", value.to_string().red());
|
||||||
|
info!("tailchat_msg {}", format!("{:?}", e).red());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
info!("tailchat_msg {}", message.to_string().cyan());
|
info!("tailchat_msg {}", message.to_string().cyan());
|
||||||
|
|
||||||
if !message.is_reply() {
|
if !message.is_reply() {
|
||||||
@ -84,3 +92,11 @@ pub async fn on_msg_delete(payload: Payload, _client: Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn on_converse_update(payload: Payload, _client: Client) {
|
||||||
|
if let Payload::Text(values) = payload {
|
||||||
|
if let Some(value) = values.first() {
|
||||||
|
info!("更新会话 {}", value.to_string().green());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
15
news.md
15
news.md
@ -1,5 +1,20 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
## 0.6.7
|
||||||
|
|
||||||
|
游学回来啦
|
||||||
|
|
||||||
|
- 处理了一些 tailchat 的特殊情况
|
||||||
|
- 比如 message 里面的 `GroupId` 实际上是可选的, 在私聊中没有这一项
|
||||||
|
- 忽略了所有的 `__v` (用于数据库记录信息的, bot不需要管)
|
||||||
|
- 作者原话 `不用管。数据库记录版本`
|
||||||
|
- 修复了如果没法解析新的信息, 会 panic 的问题
|
||||||
|
- `ica_typing.py`
|
||||||
|
- 补充了 `TailchatSendingMessage` 的 `group_id` 和 `converse_id` 字段
|
||||||
|
- 把 `group_id` 的设置和返回都改成了 `Optional[GroupId]`
|
||||||
|
- tailchat 的 API 也差点意思就是了(逃)
|
||||||
|
- 处理了 icalingua 的 `renewMessage` 事件 (其实就是直接忽略掉了)
|
||||||
|
|
||||||
## 0.6.6
|
## 0.6.6
|
||||||
|
|
||||||
游学之前最后一次更新
|
游学之前最后一次更新
|
||||||
|
@ -16,7 +16,7 @@ python -m pip install -r requirement.txt
|
|||||||
> 如果你想使用虚拟环境 \
|
> 如果你想使用虚拟环境 \
|
||||||
> 可以使用 `python -m venv venv` 创建虚拟环境 \
|
> 可以使用 `python -m venv venv` 创建虚拟环境 \
|
||||||
> 然后使用 `venv\Scripts\activate` 激活虚拟环境 \
|
> 然后使用 `venv\Scripts\activate` 激活虚拟环境 \
|
||||||
> 最后使用 `python -m pip install -r requirement.txt` 安装依赖
|
> 最后使用 `python -m pip install -r requirements.txt` 安装依赖
|
||||||
|
|
||||||
- 修改配置文件
|
- 修改配置文件
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user