mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 01:18:19 +08:00
🩹 fix reply process in mirai adapter
This commit is contained in:
parent
217b1a5fac
commit
0761a60443
@ -289,6 +289,19 @@ class MessageChain(BaseMessage):
|
||||
f'Type {type(message).__name__} is not supported in mirai adapter.'
|
||||
)
|
||||
|
||||
@overrides(BaseMessage)
|
||||
def reduce(self):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
忽略为空的消息段, 合并相邻的纯文本消息段
|
||||
"""
|
||||
for index, segment in enumerate(self):
|
||||
segment: MessageSegment
|
||||
if segment.is_text() and not str(segment).strip():
|
||||
self.pop(index)
|
||||
super().reduce()
|
||||
|
||||
@overrides(BaseMessage)
|
||||
def _construct(
|
||||
self, message: Union[List[Dict[str, Any]], Iterable[MessageSegment]]
|
||||
@ -310,6 +323,15 @@ class MessageChain(BaseMessage):
|
||||
]
|
||||
|
||||
def extract_first(self, *type: MessageType) -> Optional[MessageSegment]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
弹出该消息链的第一个消息
|
||||
|
||||
:参数:
|
||||
|
||||
* `*type: MessageType`: 指定的消息类型, 当指定后如类型不匹配不弹出
|
||||
"""
|
||||
if not len(self):
|
||||
return None
|
||||
first: MessageSegment = self[0]
|
||||
|
@ -168,10 +168,11 @@ def process_reply(bot: "Bot", event: GroupMessage) -> GroupMessage:
|
||||
|
||||
async def process_event(bot: "Bot", event: Event) -> None:
|
||||
if isinstance(event, MessageEvent):
|
||||
event.message_chain.reduce()
|
||||
Log.debug(event.message_chain)
|
||||
event = process_source(bot, event)
|
||||
if isinstance(event, GroupMessage):
|
||||
event = process_nick(bot, event)
|
||||
event = process_reply(bot, event)
|
||||
event = process_at(bot, event)
|
||||
event = process_reply(bot, event)
|
||||
await handle_event(bot, event)
|
Loading…
Reference in New Issue
Block a user