🐛 命令前缀转义

This commit is contained in:
CMHopeSunshine 2023-01-12 16:20:07 +08:00
parent 22d83261da
commit 06d2a1af82

View File

@ -1,3 +1,4 @@
import re
from typing import Literal, List from typing import Literal, List
from pydantic import BaseModel, parse_raw_as from pydantic import BaseModel, parse_raw_as
@ -9,10 +10,9 @@ except ImportError:
from . import DRIVER from . import DRIVER
need_escape = {'.', '^', '$', '*', '+', '?', '[', ']', '|', '{', '}', '(', ')', '\\'}
command_start = list(DRIVER.config.command_start) command_start = list(DRIVER.config.command_start)
command_start_new = [(f'\\{c}' if c in need_escape else c) for c in command_start if c != ''] command_start_new = [re.escape(c) for c in command_start if c != '']
COMMAND_START_RE = ( COMMAND_START_RE = (
'^(' + '|'.join(command_start_new) + ')' if command_start_new else '^' '^(' + '|'.join(command_start_new) + ')' if command_start_new else '^'
) )