Support multiple nicknames

This commit is contained in:
Richard Chien
2018-07-04 09:39:50 +08:00
parent 030a31e63f
commit b00e31ad84
2 changed files with 7 additions and 3 deletions

View File

@ -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():]