Fix nickname matching bug

This commit is contained in:
Richard Chien 2018-12-24 11:59:28 +08:00
parent 89f49bde41
commit ecb48c8ffa

View File

@ -95,10 +95,11 @@ async def handle_natural_language(bot: NoneBot, ctx: Context_T) -> bool:
nicknames = (bot.config.NICKNAME,) nicknames = (bot.config.NICKNAME,)
else: else:
nicknames = filter(lambda n: n, bot.config.NICKNAME) nicknames = filter(lambda n: n, bot.config.NICKNAME)
m = re.search(rf'^{"|".join(nicknames)}([\s,]|$)', nickname_regex = '|'.join(nicknames)
msg, re.IGNORECASE) m = re.search(rf'^({nickname_regex})([\s,]|$)', msg, re.IGNORECASE)
if m: if m:
logger.debug(f'User is calling me {m.group(1)}') nickname = m.group(1)
logger.debug(f'User is calling me {nickname}')
ctx['to_me'] = True ctx['to_me'] = True
msg = msg[m.end():] msg = msg[m.end():]