Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -46,7 +46,7 @@ TEMPLATE_DIR = "template"
|
||||
|
||||
# 考虑到,实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码
|
||||
# 对该字段的更新,请严格参照语义化版本规范:https://semver.org/lang/zh-CN/
|
||||
MMC_VERSION = "0.7.0"
|
||||
MMC_VERSION = "0.7.1-snapshot.1"
|
||||
|
||||
|
||||
def update_config():
|
||||
|
||||
@@ -78,6 +78,9 @@ class ConfigBase:
|
||||
raise TypeError(f"Expected an list for {field_type.__name__}, got {type(value).__name__}")
|
||||
|
||||
if field_origin_type is list:
|
||||
# 如果列表元素类型是ConfigBase的子类,则对每个元素调用from_dict
|
||||
if field_type_args and isinstance(field_type_args[0], type) and issubclass(field_type_args[0], ConfigBase):
|
||||
return [field_type_args[0].from_dict(item) for item in value]
|
||||
return [cls._convert_field(item, field_type_args[0]) for item in value]
|
||||
elif field_origin_type is set:
|
||||
return {cls._convert_field(item, field_type_args[0]) for item in value}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any, Literal
|
||||
import re
|
||||
|
||||
from src.config.config_base import ConfigBase
|
||||
|
||||
@@ -156,6 +157,9 @@ class FocusChatConfig(ConfigBase):
|
||||
processor_max_time: int = 25
|
||||
"""处理器最大时间,单位秒,如果超过这个时间,处理器会自动停止"""
|
||||
|
||||
planner_type: str = "simple"
|
||||
"""规划器类型,可选值:default(默认规划器), simple(简单规划器)"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class FocusChatProcessorConfig(ConfigBase):
|
||||
@@ -289,9 +293,6 @@ class MoodConfig(ConfigBase):
|
||||
class KeywordRuleConfig(ConfigBase):
|
||||
"""关键词规则配置类"""
|
||||
|
||||
enable: bool = True
|
||||
"""是否启用关键词规则"""
|
||||
|
||||
keywords: list[str] = field(default_factory=lambda: [])
|
||||
"""关键词列表"""
|
||||
|
||||
@@ -301,16 +302,38 @@ class KeywordRuleConfig(ConfigBase):
|
||||
reaction: str = ""
|
||||
"""关键词触发的反应"""
|
||||
|
||||
def __post_init__(self):
|
||||
"""验证配置"""
|
||||
if not self.keywords and not self.regex:
|
||||
raise ValueError("关键词规则必须至少包含keywords或regex中的一个")
|
||||
|
||||
if not self.reaction:
|
||||
raise ValueError("关键词规则必须包含reaction")
|
||||
|
||||
# 验证正则表达式
|
||||
for pattern in self.regex:
|
||||
try:
|
||||
re.compile(pattern)
|
||||
except re.error as e:
|
||||
raise ValueError(f"无效的正则表达式 '{pattern}': {str(e)}")
|
||||
|
||||
|
||||
@dataclass
|
||||
class KeywordReactionConfig(ConfigBase):
|
||||
"""关键词配置类"""
|
||||
|
||||
enable: bool = True
|
||||
"""是否启用关键词反应"""
|
||||
keyword_rules: list[KeywordRuleConfig] = field(default_factory=lambda: [])
|
||||
"""关键词规则列表"""
|
||||
|
||||
rules: list[KeywordRuleConfig] = field(default_factory=lambda: [])
|
||||
"""关键词反应规则列表"""
|
||||
regex_rules: list[KeywordRuleConfig] = field(default_factory=lambda: [])
|
||||
"""正则表达式规则列表"""
|
||||
|
||||
def __post_init__(self):
|
||||
"""验证配置"""
|
||||
# 验证所有规则
|
||||
for rule in self.keyword_rules + self.regex_rules:
|
||||
if not isinstance(rule, KeywordRuleConfig):
|
||||
raise ValueError(f"规则必须是KeywordRuleConfig类型,而不是{type(rule).__name__}")
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user