修复指令解析错误

This commit is contained in:
2025-10-30 11:05:08 +08:00
parent a893e54166
commit 0a60a7fc4b

View File

@@ -94,11 +94,20 @@ class CommandParser:
if at_match: if at_match:
content = at_match.group(1).strip() content = at_match.group(1).strip()
# 检查是否以指令开头 # 拦截全角空格与全角标点(不允许)
for cmd_prefix, game_type in cls.COMMAND_MAP.items(): # 范围包含:全角空格\u3000、全角标点\uFF01-\uFF60、兼容区\uFFE0-\uFFEE
if content == cmd_prefix: if re.search(r"[\u3000\uFF01-\uFF60\uFFE0-\uFFEE]", content):
# 返回游戏类型和完整指令 logger.debug(f"包含全角字符,忽略: {content}")
return game_type, content return None
# 大小写不敏感匹配(仅用于匹配,不改变返回的原始内容)
content_lower = content.lower()
# 使用最长前缀优先,避免 .r 误匹配 .roll 等更长前缀
command_keys_sorted = sorted(cls.COMMAND_MAP.keys(), key=len, reverse=True)
for cmd_prefix in command_keys_sorted:
if content_lower.startswith(cmd_prefix.lower()):
return cls.COMMAND_MAP[cmd_prefix], content
# 没有匹配的指令 # 没有匹配的指令
logger.debug(f"未识别的指令: {content}") logger.debug(f"未识别的指令: {content}")