Skip to content

Commit

Permalink
modified: nonebot/adapters/mirai2/utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ieew committed Mar 5, 2022
1 parent 09ab1c3 commit 3ab9aa3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions nonebot/adapters/mirai2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ def process_at(bot: "Bot", event: GroupMessage) -> GroupMessage:

def process_nick(bot: "Bot", event: GroupMessage) -> GroupMessage:
plain = event.message_chain.extract_first(MessageType.PLAIN)
if plain is not None and len(bot.config.nickname):
text = str(plain)
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():]
if plain is not None:
if len(bot.config.nickname):
text = str(plain)
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():]
event.message_chain.insert(0, plain)
return event

Expand Down

0 comments on commit 3ab9aa3

Please sign in to comment.