Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -335,8 +335,6 @@ async def clean_unused_emojis(emoji_dir: str, emoji_objects: List["MaiEmoji"], r
|
||||
for file_name in os.listdir(emoji_dir):
|
||||
file_full_path = os.path.join(emoji_dir, file_name)
|
||||
|
||||
|
||||
|
||||
# 确保处理的是文件而不是子目录
|
||||
if not os.path.isfile(file_full_path):
|
||||
continue
|
||||
|
||||
@@ -298,7 +298,9 @@ class HeartFChatting:
|
||||
|
||||
# 使用异步上下文管理器处理消息
|
||||
try:
|
||||
async with global_prompt_manager.async_message_scope(self.chat_stream.context.get_template_name()):
|
||||
async with global_prompt_manager.async_message_scope(
|
||||
self.chat_stream.context.get_template_name()
|
||||
):
|
||||
# 在上下文内部检查关闭状态
|
||||
if self._shutting_down:
|
||||
logger.info(f"{self.log_prefix} 在处理上下文中检测到关闭信号,退出")
|
||||
@@ -357,7 +359,9 @@ class HeartFChatting:
|
||||
timer_strings.append(f"{name}: {formatted_time}")
|
||||
|
||||
# 新增:输出每个处理器的耗时
|
||||
processor_time_costs = self._current_cycle_detail.loop_processor_info.get("processor_time_costs", {})
|
||||
processor_time_costs = self._current_cycle_detail.loop_processor_info.get(
|
||||
"processor_time_costs", {}
|
||||
)
|
||||
processor_time_strings = []
|
||||
for pname, ptime in processor_time_costs.items():
|
||||
formatted_ptime = f"{ptime * 1000:.2f}毫秒" if ptime < 1 else f"{ptime:.2f}秒"
|
||||
|
||||
@@ -196,7 +196,9 @@ class NormalChat:
|
||||
|
||||
# 使用异步上下文管理器处理消息
|
||||
try:
|
||||
async with global_prompt_manager.async_message_scope(self.chat_stream.context.get_template_name()):
|
||||
async with global_prompt_manager.async_message_scope(
|
||||
self.chat_stream.context.get_template_name()
|
||||
):
|
||||
# 在上下文内部再次检查取消状态
|
||||
if self._disabled:
|
||||
logger.info(f"[{self.stream_name}] 在处理上下文中检测到停止信号,退出")
|
||||
|
||||
@@ -490,18 +490,19 @@ def _immediate_setup():
|
||||
# 立即执行配置
|
||||
_immediate_setup()
|
||||
|
||||
raw_logger = structlog.get_logger()
|
||||
raw_logger: structlog.stdlib.BoundLogger = structlog.get_logger()
|
||||
|
||||
binds: dict[str, Callable] = {}
|
||||
|
||||
|
||||
def get_logger(name: Optional[str]):
|
||||
def get_logger(name: Optional[str]) -> structlog.stdlib.BoundLogger:
|
||||
"""获取logger实例,支持按名称绑定"""
|
||||
if name is None:
|
||||
return raw_logger
|
||||
logger = binds.get(name)
|
||||
if logger is None:
|
||||
binds[name] = logger = structlog.get_logger(name).bind(logger_name=name)
|
||||
logger: structlog.stdlib.BoundLogger = structlog.get_logger(name).bind(logger_name=name)
|
||||
binds[name] = logger
|
||||
return logger
|
||||
|
||||
|
||||
|
||||
@@ -252,7 +252,16 @@ class ComponentRegistry:
|
||||
|
||||
def get_registry_stats(self) -> Dict[str, Any]:
|
||||
"""获取注册中心统计信息"""
|
||||
action_components: int = 0
|
||||
command_components: int = 0
|
||||
for component in self._components.values():
|
||||
if component.component_type == ComponentType.ACTION:
|
||||
action_components += 1
|
||||
elif component.component_type == ComponentType.COMMAND:
|
||||
command_components += 1
|
||||
return {
|
||||
"action_components": action_components,
|
||||
"command_components": command_components,
|
||||
"total_components": len(self._components),
|
||||
"total_plugins": len(self._plugins),
|
||||
"components_by_type": {
|
||||
|
||||
@@ -38,14 +38,20 @@ class PluginManager:
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
logger.info(f"创建插件目录: {directory}")
|
||||
if directory not in self.plugin_directories:
|
||||
self.plugin_directories.append(directory)
|
||||
logger.debug(f"已添加插件目录: {directory}")
|
||||
else:
|
||||
logger.warning(f"插件不可重复加载: {directory}")
|
||||
|
||||
def add_plugin_directory(self, directory: str):
|
||||
"""添加插件目录"""
|
||||
if os.path.exists(directory):
|
||||
if directory not in self.plugin_directories:
|
||||
self.plugin_directories.append(directory)
|
||||
logger.debug(f"已添加插件目录: {directory}")
|
||||
else:
|
||||
logger.warning(f"插件不可重复加载: {directory}")
|
||||
else:
|
||||
logger.warning(f"插件目录不存在: {directory}")
|
||||
|
||||
@@ -130,7 +136,7 @@ class PluginManager:
|
||||
if plugin_info:
|
||||
# 插件基本信息
|
||||
version_info = f"v{plugin_info.version}" if plugin_info.version else ""
|
||||
author_info = f"by {plugin_info.author}" if plugin_info.author else ""
|
||||
author_info = f"by {plugin_info.author}" if plugin_info.author else "unknown"
|
||||
info_parts = [part for part in [version_info, author_info] if part]
|
||||
extra_info = f" ({', '.join(info_parts)})" if info_parts else ""
|
||||
|
||||
@@ -342,7 +348,9 @@ class PluginManager:
|
||||
# 全局插件管理器实例
|
||||
plugin_manager = PluginManager()
|
||||
|
||||
# 注释掉以解决插件目录重复加载的情况
|
||||
# 默认插件目录
|
||||
plugin_manager.add_plugin_directory("src/plugins/built_in")
|
||||
plugin_manager.add_plugin_directory("src/plugins/examples")
|
||||
plugin_manager.add_plugin_directory("plugins") # 用户插件目录
|
||||
# plugin_manager.add_plugin_directory("src/plugins/built_in")
|
||||
# plugin_manager.add_plugin_directory("src/plugins/examples")
|
||||
# 用户插件目录
|
||||
# plugin_manager.add_plugin_directory("plugins")
|
||||
|
||||
@@ -4,12 +4,12 @@ NormalChat 启动停止测试脚本
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
import logging
|
||||
from src.common.logger import get_logger
|
||||
|
||||
logger = get_logger("test_normal_chat_stop")
|
||||
|
||||
|
||||
async def test_task_cancel_behavior():
|
||||
"""测试任务取消行为"""
|
||||
|
||||
@@ -85,6 +85,7 @@ async def test_task_cancel_behavior():
|
||||
|
||||
logger.info("=== 测试完成 ===")
|
||||
|
||||
|
||||
async def main():
|
||||
"""主函数"""
|
||||
logger.info("开始 NormalChat 停止测试")
|
||||
@@ -94,10 +95,12 @@ async def main():
|
||||
except Exception as e:
|
||||
logger.error(f"测试失败: {e}")
|
||||
import traceback
|
||||
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
logger.info("测试结束")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 设置日志级别
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
Reference in New Issue
Block a user