🐛 修复命令前缀包含正则元字符时的意外问题

This commit is contained in:
CMHopeSunshine 2023-01-06 19:48:01 +08:00
parent 13cdd3c10b
commit 1ebd44296b

View File

@ -9,20 +9,21 @@ except ImportError:
from . import DRIVER from . import DRIVER
need_escape = {'.', '^', '$', '*', '+', '?', '[', ']', '|', '{', '}', '(', ')', '\\'}
command_start = list(DRIVER.config.command_start) command_start = list(DRIVER.config.command_start)
if len(command_start) == 1 and command_start[0] == '': command_start_new = [(f'\\{c}' if c in need_escape else c) for c in command_start if c != '']
COMMAND_START_RE = '^' COMMAND_START_RE = (
elif '' in command_start: '^(' + '|'.join(command_start_new) + ')' if command_start_new else '^'
command_start.remove('') )
COMMAND_START_RE = '^(' + '|'.join(command_start) + ')?' if '' in command_start:
else: COMMAND_START_RE += '?'
COMMAND_START_RE = '^(' + '|'.join(command_start) + ')'
ElementType = Literal['', '', '', '', '', '', '', '物理'] ElementType = Literal['', '', '', '', '', '', '', '物理']
WeaponType = Literal['单手剑', '双手剑', '长柄武器', '', '法器'] WeaponType = Literal['单手剑', '双手剑', '长柄武器', '', '法器']
DataSourceType = Literal['mihoyo', 'enka'] DataSourceType = Literal['mihoyo', 'enka']
RegionType = Literal['蒙德', '璃月', '稻妻', '须弥', '枫丹', '纳塔', '至冬'] RegionType = Literal['蒙德', '璃月', '稻妻', '须弥', '枫丹', '纳塔', '至冬', '其它']
TalentType = Literal['name', 'level', 'icon'] TalentType = Literal['name', 'level', 'icon']
ConstellationType = Literal['name', 'icon'] ConstellationType = Literal['name', 'icon']
EquipType = Literal['name', 'value'] EquipType = Literal['name', 'value']