Merge branch 'dev' of https://github.com/Mai-with-u/MaiBot into dev
This commit is contained in:
@@ -6,7 +6,9 @@ logger = get_logger("frequency_api")
|
||||
|
||||
|
||||
def get_current_talk_value(chat_id: str) -> float:
|
||||
return frequency_control_manager.get_or_create_frequency_control(chat_id).get_talk_frequency_adjust() * global_config.chat.get_talk_value(chat_id)
|
||||
return frequency_control_manager.get_or_create_frequency_control(
|
||||
chat_id
|
||||
).get_talk_frequency_adjust() * global_config.chat.get_talk_value(chat_id)
|
||||
|
||||
|
||||
def set_talk_frequency_adjust(chat_id: str, talk_frequency_adjust: float) -> None:
|
||||
|
||||
@@ -109,7 +109,7 @@ def get_messages_by_time_in_chat(
|
||||
limit=limit,
|
||||
limit_mode=limit_mode,
|
||||
filter_bot=filter_mai,
|
||||
filter_command=filter_command
|
||||
filter_command=filter_command,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ logger = get_logger("tool_api")
|
||||
|
||||
def get_tool_instance(tool_name: str, chat_stream: Optional["ChatStream"] = None) -> Optional[BaseTool]:
|
||||
"""获取公开工具实例
|
||||
|
||||
|
||||
Args:
|
||||
tool_name: 工具名称
|
||||
chat_stream: 聊天流对象,用于传递聊天上下文信息
|
||||
|
||||
|
||||
Returns:
|
||||
Optional[BaseTool]: 工具实例,如果未找到则返回None
|
||||
"""
|
||||
|
||||
@@ -77,7 +77,7 @@ class BaseAction(ABC):
|
||||
self.action_require: list[str] = getattr(self.__class__, "action_require", []).copy()
|
||||
|
||||
"""NORMAL模式下的激活类型"""
|
||||
self.activation_type = getattr(self.__class__, "activation_type")
|
||||
self.activation_type = self.__class__.activation_type
|
||||
"""激活类型"""
|
||||
self.random_activation_probability: float = getattr(self.__class__, "random_activation_probability", 0.0)
|
||||
"""当激活类型为RANDOM时的概率"""
|
||||
@@ -108,21 +108,16 @@ class BaseAction(ABC):
|
||||
self.is_group = False
|
||||
self.target_id = None
|
||||
|
||||
|
||||
self.group_id = (
|
||||
str(self.action_message.chat_info.group_info.group_id)
|
||||
if self.action_message.chat_info.group_info
|
||||
else None
|
||||
str(self.action_message.chat_info.group_info.group_id) if self.action_message.chat_info.group_info else None
|
||||
)
|
||||
self.group_name = (
|
||||
self.action_message.chat_info.group_info.group_name
|
||||
if self.action_message.chat_info.group_info
|
||||
else None
|
||||
self.action_message.chat_info.group_info.group_name if self.action_message.chat_info.group_info else None
|
||||
)
|
||||
|
||||
self.user_id = str(self.action_message.user_info.user_id)
|
||||
self.user_nickname = self.action_message.user_info.user_nickname
|
||||
|
||||
|
||||
if self.group_id:
|
||||
self.is_group = True
|
||||
self.target_id = self.group_id
|
||||
@@ -132,7 +127,6 @@ class BaseAction(ABC):
|
||||
self.target_id = self.user_id
|
||||
self.log_prefix = f"[{self.user_nickname} 的 私聊]"
|
||||
|
||||
|
||||
logger.debug(
|
||||
f"{self.log_prefix} 聊天信息: 类型={'群聊' if self.is_group else '私聊'}, 平台={self.platform}, 目标={self.target_id}"
|
||||
)
|
||||
@@ -448,7 +442,6 @@ class BaseAction(ABC):
|
||||
|
||||
wait_start_time = asyncio.get_event_loop().time()
|
||||
while True:
|
||||
|
||||
# 检查新消息
|
||||
current_time = time.time()
|
||||
new_message_count = message_api.count_new_messages(
|
||||
@@ -497,7 +490,7 @@ class BaseAction(ABC):
|
||||
raise ValueError(f"Action名称 '{name}' 包含非法字符 '.',请使用下划线替代")
|
||||
# 获取focus_activation_type和normal_activation_type
|
||||
focus_activation_type = getattr(cls, "focus_activation_type", ActionActivationType.ALWAYS)
|
||||
normal_activation_type = getattr(cls, "normal_activation_type", ActionActivationType.ALWAYS)
|
||||
_normal_activation_type = getattr(cls, "normal_activation_type", ActionActivationType.ALWAYS)
|
||||
|
||||
# 处理activation_type:如果插件中声明了就用插件的值,否则默认使用focus_activation_type
|
||||
activation_type = getattr(cls, "activation_type", focus_activation_type)
|
||||
|
||||
@@ -34,17 +34,17 @@ class BaseTool(ABC):
|
||||
|
||||
def __init__(self, plugin_config: Optional[dict] = None, chat_stream: Optional["ChatStream"] = None):
|
||||
"""初始化工具基类
|
||||
|
||||
|
||||
Args:
|
||||
plugin_config: 插件配置字典
|
||||
chat_stream: 聊天流对象,用于获取聊天上下文信息
|
||||
"""
|
||||
self.plugin_config = plugin_config or {} # 直接存储插件配置字典
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 便捷属性 - 直接在初始化时获取常用聊天信息(与BaseAction保持一致)
|
||||
# =============================================================================
|
||||
|
||||
|
||||
# 获取聊天流对象
|
||||
self.chat_stream = chat_stream
|
||||
self.chat_id = self.chat_stream.stream_id if self.chat_stream else None
|
||||
|
||||
@@ -346,9 +346,7 @@ class EventsManager:
|
||||
|
||||
if not isinstance(result, tuple) or len(result) != 5:
|
||||
if isinstance(result, tuple):
|
||||
annotated = ", ".join(
|
||||
f"{name}={val!r}" for name, val in zip(expected_fields, result)
|
||||
)
|
||||
annotated = ", ".join(f"{name}={val!r}" for name, val in zip(expected_fields, result, strict=False))
|
||||
actual_desc = f"{len(result)} 个元素 ({annotated})"
|
||||
else:
|
||||
actual_desc = f"非 tuple 类型: {type(result)}"
|
||||
@@ -380,7 +378,6 @@ class EventsManager:
|
||||
logger.error(f"EventHandler {handler.handler_name} 发生异常: {e}", exc_info=True)
|
||||
return True, None # 发生异常时默认不中断其他处理
|
||||
|
||||
|
||||
def _task_done_callback(
|
||||
self,
|
||||
task: asyncio.Task[Tuple[bool, bool, str | None, CustomEventHandlerResult | None, MaiMessages | None]],
|
||||
|
||||
@@ -189,9 +189,8 @@ class ToolExecutor:
|
||||
tool_info["content"] = str(content)
|
||||
# 空内容直接跳过(空字符串、全空白字符串、空列表/空元组)
|
||||
content_check = tool_info["content"]
|
||||
if (
|
||||
(isinstance(content_check, str) and not content_check.strip())
|
||||
or (isinstance(content_check, (list, tuple)) and len(content_check) == 0)
|
||||
if (isinstance(content_check, str) and not content_check.strip()) or (
|
||||
isinstance(content_check, (list, tuple)) and len(content_check) == 0
|
||||
):
|
||||
logger.debug(f"{self.log_prefix}工具{tool_name}无有效内容,跳过展示")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user