2021-12-31 14:44:34 +00:00
|
|
|
|
from typing import List, Union
|
2021-11-02 14:58:42 +00:00
|
|
|
|
|
2021-08-30 18:53:39 +00:00
|
|
|
|
|
2021-07-15 14:59:32 +00:00
|
|
|
|
class MsgInfo:
|
2021-07-26 12:43:51 +00:00
|
|
|
|
__slots__ = ["targetId", "senderId", "senderName", "targetFrom", "senderInfo", "senderFrom"]
|
2021-07-24 08:59:15 +00:00
|
|
|
|
|
2021-07-11 14:20:24 +00:00
|
|
|
|
def __init__(self,
|
2021-07-24 08:59:15 +00:00
|
|
|
|
targetId: [int, str],
|
|
|
|
|
senderId: [int, str],
|
|
|
|
|
senderName: str,
|
2021-07-26 12:43:51 +00:00
|
|
|
|
targetFrom: str,
|
|
|
|
|
senderFrom: str
|
2021-07-16 15:50:25 +00:00
|
|
|
|
):
|
|
|
|
|
self.targetId = targetId
|
2021-07-11 14:20:24 +00:00
|
|
|
|
self.senderId = senderId
|
|
|
|
|
self.senderName = senderName
|
2021-07-26 12:43:51 +00:00
|
|
|
|
self.targetFrom = targetFrom
|
|
|
|
|
self.senderFrom = senderFrom
|
2021-07-11 14:20:24 +00:00
|
|
|
|
|
|
|
|
|
|
2021-07-24 08:59:15 +00:00
|
|
|
|
class Session:
|
|
|
|
|
def __init__(self, message, target, sender):
|
|
|
|
|
self.message = message
|
|
|
|
|
self.target = target
|
|
|
|
|
self.sender = sender
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MessageSession:
|
2021-08-07 07:56:48 +00:00
|
|
|
|
"""
|
|
|
|
|
消息会话,囊括了处理一条消息所需要的东西。
|
|
|
|
|
"""
|
2021-10-13 15:22:11 +00:00
|
|
|
|
__slots__ = ("target", "session", "trigger_msg", "parsed_msg", "matched_msg",)
|
2021-07-24 08:59:15 +00:00
|
|
|
|
|
2021-07-11 14:20:24 +00:00
|
|
|
|
def __init__(self,
|
2021-07-24 08:59:15 +00:00
|
|
|
|
target: MsgInfo,
|
|
|
|
|
session: Session):
|
2021-07-11 14:20:24 +00:00
|
|
|
|
self.target = target
|
2021-07-24 08:59:15 +00:00
|
|
|
|
self.session = session
|
2021-07-12 13:31:11 +00:00
|
|
|
|
|
2022-01-08 08:08:25 +00:00
|
|
|
|
async def sendMessage(self, msgchain, quote=True, disable_secret_check=False):
|
2021-08-06 14:10:48 +00:00
|
|
|
|
"""
|
|
|
|
|
用于向消息发送者回复消息。
|
|
|
|
|
:param msgchain: 消息链,若传入str则自动创建一条带有Plain元素的消息链
|
2021-09-10 18:05:27 +00:00
|
|
|
|
:param quote: 是否引用传入dict中的消息(默认为True)
|
2022-01-08 08:08:25 +00:00
|
|
|
|
:param disable_secret_check: 是否禁用消息检查(默认为False)
|
2021-08-06 14:10:48 +00:00
|
|
|
|
:return: 被发送的消息链
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-07-12 13:31:11 +00:00
|
|
|
|
|
2021-09-10 18:05:27 +00:00
|
|
|
|
async def waitConfirm(self, msgchain=None, quote=True):
|
2021-08-06 14:10:48 +00:00
|
|
|
|
"""
|
|
|
|
|
一次性模板,用于等待触发对象确认。
|
2021-09-10 18:05:27 +00:00
|
|
|
|
:param msgchain: 需要发送的确认消息,可不填
|
|
|
|
|
:param quote: 是否引用传入dict中的消息(默认为True)
|
2021-08-06 14:10:48 +00:00
|
|
|
|
:return: 若对象发送confirm_command中的其一文本时返回True,反之则返回False
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-07-16 15:50:25 +00:00
|
|
|
|
|
2021-08-06 14:10:48 +00:00
|
|
|
|
def asDisplay(self):
|
|
|
|
|
"""
|
|
|
|
|
用于将消息转换为一般文本格式。
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-07-16 15:50:25 +00:00
|
|
|
|
|
2021-08-06 14:10:48 +00:00
|
|
|
|
async def delete(self):
|
|
|
|
|
"""
|
|
|
|
|
用于删除这条消息。
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-08-01 14:54:25 +00:00
|
|
|
|
|
2021-08-14 15:26:10 +00:00
|
|
|
|
async def checkPermission(self):
|
2021-08-06 14:10:48 +00:00
|
|
|
|
"""
|
|
|
|
|
用于检查消息发送者在对象内的权限。
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-08-01 14:54:25 +00:00
|
|
|
|
|
2022-01-08 08:37:03 +00:00
|
|
|
|
async def checkNativePermission(self):
|
|
|
|
|
"""
|
|
|
|
|
用于检查消息发送者原本在聊天平台中是否具有管理员权限。
|
|
|
|
|
"""
|
|
|
|
|
...
|
|
|
|
|
|
2021-10-11 14:45:28 +00:00
|
|
|
|
async def fake_forward_msg(self, nodelist):
|
|
|
|
|
"""
|
|
|
|
|
用于发送假转发消息(QQ)。
|
|
|
|
|
"""
|
|
|
|
|
...
|
|
|
|
|
|
2021-11-19 16:33:53 +00:00
|
|
|
|
async def get_text_channel_list(self):
|
|
|
|
|
"""
|
|
|
|
|
用于获取子文字频道列表(QQ)。
|
|
|
|
|
"""
|
|
|
|
|
...
|
|
|
|
|
|
2021-08-01 14:54:25 +00:00
|
|
|
|
class Typing:
|
2021-08-06 14:10:48 +00:00
|
|
|
|
def __init__(self, msg):
|
|
|
|
|
"""
|
|
|
|
|
:param msg: 本条消息,由于此class需要被一同传入下游方便调用,所以作为子class存在,将来可能会有其他的解决办法。
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-08-01 14:54:25 +00:00
|
|
|
|
|
2021-08-06 14:10:48 +00:00
|
|
|
|
def checkSuperUser(self):
|
|
|
|
|
"""
|
|
|
|
|
用于检查消息发送者是否为超级用户。
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-08-01 14:54:25 +00:00
|
|
|
|
|
2021-10-24 10:55:45 +00:00
|
|
|
|
async def sleep(self, s):
|
|
|
|
|
...
|
|
|
|
|
|
2021-08-01 14:54:25 +00:00
|
|
|
|
class Feature:
|
2021-08-06 14:10:48 +00:00
|
|
|
|
"""
|
|
|
|
|
此消息来自的客户端所支持的消息特性一览,用于不同平台适用特性判断(如QQ支持消息类型的语音而Discord不支持)
|
|
|
|
|
"""
|
2021-08-01 14:54:25 +00:00
|
|
|
|
image = ...
|
|
|
|
|
voice = ...
|
2021-10-11 14:45:28 +00:00
|
|
|
|
forward = ...
|
2021-11-16 14:19:48 +00:00
|
|
|
|
delete = ...
|
2021-08-07 07:56:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FetchTarget:
|
2022-01-05 11:14:45 +00:00
|
|
|
|
name = ''
|
|
|
|
|
|
2021-08-07 07:56:48 +00:00
|
|
|
|
@staticmethod
|
2021-08-20 16:32:46 +00:00
|
|
|
|
async def fetch_target(targetId) -> MessageSession:
|
2021-08-07 07:56:48 +00:00
|
|
|
|
"""
|
|
|
|
|
尝试从数据库记录的对象ID中取得对象消息会话,实际此会话中的消息文本会被设为False(因为本来就没有)。
|
|
|
|
|
"""
|
|
|
|
|
...
|
2021-08-23 12:44:31 +00:00
|
|
|
|
|
2021-10-08 11:54:27 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
async def fetch_target_list(targetList: list) -> List[MessageSession]:
|
|
|
|
|
"""
|
|
|
|
|
尝试从数据库记录的对象ID中取得对象消息会话,实际此会话中的消息文本会被设为False(因为本来就没有)。
|
|
|
|
|
"""
|
|
|
|
|
...
|
|
|
|
|
|
2021-08-30 18:53:39 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
async def post_message(module_name, message, user_list: List[MessageSession] = None):
|
|
|
|
|
"""
|
|
|
|
|
尝试向开启此模块的对象发送一条消息。
|
|
|
|
|
"""
|
|
|
|
|
|
2021-08-23 12:44:31 +00:00
|
|
|
|
|
|
|
|
|
__all__ = ["FetchTarget", "MsgInfo", "MessageSession", "Session"]
|