mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-31 15:41:34 +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.'
|
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)
|
@overrides(BaseMessage)
|
||||||
def _construct(
|
def _construct(
|
||||||
self, message: Union[List[Dict[str, Any]], Iterable[MessageSegment]]
|
self, message: Union[List[Dict[str, Any]], Iterable[MessageSegment]]
|
||||||
@ -310,6 +323,15 @@ class MessageChain(BaseMessage):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def extract_first(self, *type: MessageType) -> Optional[MessageSegment]:
|
def extract_first(self, *type: MessageType) -> Optional[MessageSegment]:
|
||||||
|
"""
|
||||||
|
:说明:
|
||||||
|
|
||||||
|
弹出该消息链的第一个消息
|
||||||
|
|
||||||
|
:参数:
|
||||||
|
|
||||||
|
* `*type: MessageType`: 指定的消息类型, 当指定后如类型不匹配不弹出
|
||||||
|
"""
|
||||||
if not len(self):
|
if not len(self):
|
||||||
return None
|
return None
|
||||||
first: MessageSegment = self[0]
|
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:
|
async def process_event(bot: "Bot", event: Event) -> None:
|
||||||
if isinstance(event, MessageEvent):
|
if isinstance(event, MessageEvent):
|
||||||
|
event.message_chain.reduce()
|
||||||
Log.debug(event.message_chain)
|
Log.debug(event.message_chain)
|
||||||
event = process_source(bot, event)
|
event = process_source(bot, event)
|
||||||
if isinstance(event, GroupMessage):
|
if isinstance(event, GroupMessage):
|
||||||
event = process_nick(bot, event)
|
event = process_nick(bot, event)
|
||||||
event = process_reply(bot, event)
|
|
||||||
event = process_at(bot, event)
|
event = process_at(bot, event)
|
||||||
|
event = process_reply(bot, event)
|
||||||
await handle_event(bot, event)
|
await handle_event(bot, event)
|
Loading…
x
Reference in New Issue
Block a user