Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/core/elements/message/__init__.py

184 lines
5.4 KiB
Python
Raw Normal View History

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