mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 09:38:21 +08:00
🐛 fix bug founded during test in mirai adapter
This commit is contained in:
parent
49010bf5b7
commit
85aba9e36f
@ -253,10 +253,9 @@ class Bot(BaseBot):
|
||||
* ``message: Union[MessageChain, MessageSegment, str]``: 要发送的消息
|
||||
* ``at_sender: bool``: 是否 @ 事件主体
|
||||
"""
|
||||
if isinstance(message, MessageSegment):
|
||||
print(event, message, at_sender)
|
||||
if not isinstance(message, MessageChain):
|
||||
message = MessageChain(message)
|
||||
elif isinstance(message, str):
|
||||
message = MessageChain(MessageSegment.plain(message))
|
||||
if isinstance(event, FriendMessage):
|
||||
return await self.send_friend_message(target=event.sender.id,
|
||||
message_chain=message)
|
||||
|
@ -273,12 +273,14 @@ class MessageChain(BaseMessage):
|
||||
"""
|
||||
|
||||
@overrides(BaseMessage)
|
||||
def __init__(self, message: Union[List[Dict[str, Any]],
|
||||
Iterable[MessageSegment], MessageSegment],
|
||||
**kwargs):
|
||||
def __init__(self, message: Union[List[Dict[str,
|
||||
Any]], Iterable[MessageSegment],
|
||||
MessageSegment, str], **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
if isinstance(message, MessageSegment):
|
||||
self.append(message)
|
||||
elif isinstance(message, str):
|
||||
self.append(MessageSegment.plain(text=message))
|
||||
elif isinstance(message, Iterable):
|
||||
self.extend(self._construct(message))
|
||||
else:
|
||||
|
@ -149,6 +149,7 @@ def process_nick(bot: "Bot", event: GroupMessage) -> GroupMessage:
|
||||
nick_regex = '|'.join(filter(lambda x: x, bot.config.nickname))
|
||||
matched = re.search(rf"^({nick_regex})([\s,,]*|$)", text, re.IGNORECASE)
|
||||
if matched is not None:
|
||||
event.to_me = True
|
||||
nickname = matched.group(1)
|
||||
Log.info(f'User is calling me {nickname}')
|
||||
plain.data['text'] = text[matched.end():]
|
||||
@ -159,7 +160,7 @@ def process_nick(bot: "Bot", event: GroupMessage) -> GroupMessage:
|
||||
def process_reply(bot: "Bot", event: GroupMessage) -> GroupMessage:
|
||||
reply = event.message_chain.extract_first(MessageType.QUOTE)
|
||||
if reply is not None:
|
||||
if reply.data['sender_id'] == event.self_id:
|
||||
if reply.data['senderId'] == event.self_id:
|
||||
event.to_me = True
|
||||
else:
|
||||
event.message_chain.insert(0, reply)
|
||||
|
Loading…
Reference in New Issue
Block a user