This commit is contained in:
bridge
2025-10-08 21:31:24 +08:00
parent 004e6d34c5
commit a7e2de6783
5 changed files with 96 additions and 2 deletions

View File

@@ -31,6 +31,21 @@ class Alignment(Enum):
return other == self.value or other == str(self)
return False
@staticmethod
def from_str(text: str) -> "Alignment":
"""
将字符串解析为 Alignment支持中文与英文别名。
未识别时返回中立。
"""
t = str(text).strip().lower()
if t in {"", "righteous", "right"}:
return Alignment.RIGHTEOUS
if t in {"", "neutral", "middle", "center"}:
return Alignment.NEUTRAL
if t in {"", "evil"}:
return Alignment.EVIL
return Alignment.NEUTRAL
alignment_strs = {
Alignment.RIGHTEOUS: "",