mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-27 16:21:28 +00:00
Support multiple nicknames
This commit is contained in:
@ -80,8 +80,12 @@ async def handle_natural_language(bot: NoneBot, ctx: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
msg = str(ctx['message'])
|
||||
if bot.config.NICKNAME:
|
||||
# check if the user is calling to me with my nickname
|
||||
m = re.search(rf'^{bot.config.NICKNAME}[\s,,]+', msg)
|
||||
# check if the user is calling me with my nickname
|
||||
if not isinstance(bot.config.NICKNAME, Iterable):
|
||||
nicknames = (bot.config.NICKNAME,)
|
||||
else:
|
||||
nicknames = filter(lambda n: n, bot.config.NICKNAME)
|
||||
m = re.search(rf'^({"|".join(nicknames)})[\s,,]+', msg)
|
||||
if m:
|
||||
ctx['to_me'] = True
|
||||
msg = msg[m.end():]
|
||||
|
Reference in New Issue
Block a user