mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-12-04 02:54:49 +08:00
Support multiple nicknames
This commit is contained in:
parent
030a31e63f
commit
b00e31ad84
@ -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():]
|
||||
|
@ -6,6 +6,6 @@ HOST = '0.0.0.0'
|
||||
SECRET = 'abc'
|
||||
|
||||
SUPERUSERS = {1002647525}
|
||||
NICKNAME = '奶茶'
|
||||
NICKNAME = {'奶茶', '小奶茶'}
|
||||
COMMAND_START = {'', '/', '!', '/', '!', re.compile(r'^>+\s*')}
|
||||
COMMAND_SEP = {'/', '.', re.compile(r'#|::?')}
|
||||
|
Loading…
Reference in New Issue
Block a user