Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox_Bot into dev
This commit is contained in:
@@ -4,9 +4,8 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
from typing import Dict, Callable, Any, Optional
|
from typing import Dict, Callable, Any, Optional
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import orjson
|
|
||||||
import re
|
|
||||||
from typing import TYPE_CHECKING, Dict, Any
|
from typing import TYPE_CHECKING, Dict, Any
|
||||||
|
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
@@ -12,7 +10,6 @@ from src.plugin_system.apis import generator_api
|
|||||||
from src.plugin_system.apis.generator_api import process_human_text
|
from src.plugin_system.apis.generator_api import process_human_text
|
||||||
from src.schedule.schedule_manager import schedule_manager
|
from src.schedule.schedule_manager import schedule_manager
|
||||||
from src.plugin_system import tool_api
|
from src.plugin_system import tool_api
|
||||||
from src.plugin_system.base.component_types import ComponentType
|
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
from src.chat.utils.chat_message_builder import get_raw_msg_before_timestamp_with_chat, build_readable_messages_with_id
|
from src.chat.utils.chat_message_builder import get_raw_msg_before_timestamp_with_chat, build_readable_messages_with_id
|
||||||
from src.mood.mood_manager import mood_manager
|
from src.mood.mood_manager import mood_manager
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import time
|
import time
|
||||||
import orjson
|
|
||||||
import random
|
import random
|
||||||
from typing import Dict, Any, Tuple
|
from typing import Dict, Any, Tuple
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from ..hfc_context import HfcContext
|
from ..hfc_context import HfcContext
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
from datetime import datetime, timedelta, date
|
from datetime import datetime, timedelta, date
|
||||||
from typing import Optional, TYPE_CHECKING, List, Dict, Any
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class FrequencyBasedTrigger:
|
|||||||
# 6. 直接调用 proactive_thinker
|
# 6. 直接调用 proactive_thinker
|
||||||
event = ProactiveTriggerEvent(
|
event = ProactiveTriggerEvent(
|
||||||
source="frequency_analyzer",
|
source="frequency_analyzer",
|
||||||
reason=f"User is in a high-frequency chat period."
|
reason="User is in a high-frequency chat period."
|
||||||
)
|
)
|
||||||
await sub_heartflow.heart_fc_instance.proactive_thinker.think(event)
|
await sub_heartflow.heart_fc_instance.proactive_thinker.think(event)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ from src.chat.utils.chat_message_builder import replace_user_references_sync
|
|||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.person_info.relationship_manager import get_relationship_manager
|
from src.person_info.relationship_manager import get_relationship_manager
|
||||||
from src.mood.mood_manager import mood_manager
|
from src.mood.mood_manager import mood_manager
|
||||||
from src.chat.message_receive.chat_stream import get_chat_manager
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from src.chat.heart_flow.sub_heartflow import SubHeartflow
|
from src.chat.heart_flow.sub_heartflow import SubHeartflow
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import orjson
|
import orjson
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import asyncio
|
|
||||||
import math
|
|
||||||
import random
|
import random
|
||||||
import json
|
|
||||||
from typing import Dict, Any, Optional, Tuple, List, TYPE_CHECKING
|
from typing import Dict, Any, Optional, Tuple, List, TYPE_CHECKING
|
||||||
from rich.traceback import install
|
from rich.traceback import install
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -27,7 +24,6 @@ from src.plugin_system.base.component_types import (
|
|||||||
ActionInfo,
|
ActionInfo,
|
||||||
ChatMode,
|
ChatMode,
|
||||||
ComponentType,
|
ComponentType,
|
||||||
ActionActivationType,
|
|
||||||
)
|
)
|
||||||
from src.plugin_system.core.component_registry import component_registry
|
from src.plugin_system.core.component_registry import component_registry
|
||||||
from src.schedule.schedule_manager import schedule_manager
|
from src.schedule.schedule_manager import schedule_manager
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from src.common.server import get_global_server
|
from src.common.server import get_global_server
|
||||||
import os
|
|
||||||
import importlib.metadata
|
import importlib.metadata
|
||||||
from maim_message import MessageServer
|
from maim_message import MessageServer
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
|
|||||||
@@ -662,9 +662,6 @@ class SleepSystemConfig(ValidatedConfigBase):
|
|||||||
)
|
)
|
||||||
max_sleep_delay_minutes: int = Field(default=60, description="单日最大延迟入睡分钟数")
|
max_sleep_delay_minutes: int = Field(default=60, description="单日最大延迟入睡分钟数")
|
||||||
enable_pre_sleep_notification: bool = Field(default=True, description="是否启用睡前消息")
|
enable_pre_sleep_notification: bool = Field(default=True, description="是否启用睡前消息")
|
||||||
pre_sleep_notification_groups: List[str] = Field(
|
|
||||||
default_factory=list, description='接收睡前消息的群号列表, 格式: ["platform:group_id1", "platform:group_id2"]'
|
|
||||||
)
|
|
||||||
pre_sleep_prompt: str = Field(
|
pre_sleep_prompt: str = Field(
|
||||||
default="我准备睡觉了,请生成一句简短自然的晚安问候。", description="用于生成睡前消息的提示"
|
default="我准备睡觉了,请生成一句简短自然的晚安问候。", description="用于生成睡前消息的提示"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from src.common.logger import get_logger
|
|||||||
from src.chat.message_receive.chat_stream import ChatStream
|
from src.chat.message_receive.chat_stream import ChatStream
|
||||||
from src.plugin_system.base.component_types import ActionActivationType, ChatMode, ActionInfo, ComponentType, ChatType
|
from src.plugin_system.base.component_types import ActionActivationType, ChatMode, ActionInfo, ComponentType, ChatType
|
||||||
from src.plugin_system.apis import send_api, database_api, message_api
|
from src.plugin_system.apis import send_api, database_api, message_api
|
||||||
|
from src.plugin_system.core.component_registry import component_registry
|
||||||
|
|
||||||
|
|
||||||
logger = get_logger("base_action")
|
logger = get_logger("base_action")
|
||||||
@@ -381,6 +382,60 @@ class BaseAction(ABC):
|
|||||||
logger.error(f"{self.log_prefix} 发送命令时出错: {e}")
|
logger.error(f"{self.log_prefix} 发送命令时出错: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def call_action(self, action_name: str, action_data: Optional[dict] = None) -> Tuple[bool, str]:
|
||||||
|
"""
|
||||||
|
在当前Action中调用另一个Action。
|
||||||
|
|
||||||
|
Args:
|
||||||
|
action_name (str): 要调用的Action的名称。
|
||||||
|
action_data (Optional[dict], optional): 传递给被调用Action的动作数据。如果为None,则使用当前Action的action_data。
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[bool, str]: 被调用Action的执行结果 (is_success, message)。
|
||||||
|
"""
|
||||||
|
log_prefix = f"{self.log_prefix} [call_action -> {action_name}]"
|
||||||
|
logger.info(f"{log_prefix} 尝试调用Action: {action_name}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 1. 从注册中心获取Action类
|
||||||
|
action_class = component_registry.get_component_class(action_name, ComponentType.ACTION)
|
||||||
|
if not action_class:
|
||||||
|
logger.error(f"{log_prefix} 未找到Action: {action_name}")
|
||||||
|
return False, f"未找到Action: {action_name}"
|
||||||
|
|
||||||
|
# 2. 准备实例化参数
|
||||||
|
# 复用当前Action的大部分上下文信息
|
||||||
|
called_action_data = action_data if action_data is not None else self.action_data
|
||||||
|
|
||||||
|
component_info = component_registry.get_component_info(action_name, ComponentType.ACTION)
|
||||||
|
if not component_info:
|
||||||
|
logger.warning(f"{log_prefix} 未找到Action组件信息: {action_name}")
|
||||||
|
return False, f"未找到Action组件信息: {action_name}"
|
||||||
|
|
||||||
|
plugin_config = component_registry.get_plugin_config(component_info.plugin_name)
|
||||||
|
|
||||||
|
# 3. 实例化被调用的Action
|
||||||
|
action_instance = action_class(
|
||||||
|
action_data=called_action_data,
|
||||||
|
reasoning=f"Called by {self.action_name}",
|
||||||
|
cycle_timers=self.cycle_timers,
|
||||||
|
thinking_id=self.thinking_id,
|
||||||
|
chat_stream=self.chat_stream,
|
||||||
|
log_prefix=log_prefix,
|
||||||
|
plugin_config=plugin_config,
|
||||||
|
action_message=self.action_message,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 4. 执行Action
|
||||||
|
logger.debug(f"{log_prefix} 开始执行...")
|
||||||
|
result = await action_instance.execute()
|
||||||
|
logger.info(f"{log_prefix} 执行完成,结果: {result}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"{log_prefix} 调用时发生错误: {e}", exc_info=True)
|
||||||
|
return False, f"调用Action '{action_name}' 时发生错误: {e}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_action_info(cls) -> "ActionInfo":
|
def get_action_info(cls) -> "ActionInfo":
|
||||||
"""从类属性生成ActionInfo
|
"""从类属性生成ActionInfo
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ from src.plugin_system import (
|
|||||||
ActionInfo,
|
ActionInfo,
|
||||||
ActionActivationType,
|
ActionActivationType,
|
||||||
)
|
)
|
||||||
from src.person_info.person_info import get_person_info_manager
|
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.plugin_system.base.component_types import ChatType
|
from src.plugin_system.base.component_types import ChatType
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import orjson
|
|
||||||
|
|
||||||
from src.plugin_system import BaseEventHandler
|
from src.plugin_system import BaseEventHandler
|
||||||
from src.plugin_system.base.base_event import HandlerResult
|
from src.plugin_system.base.base_event import HandlerResult
|
||||||
|
|||||||
@@ -484,8 +484,6 @@ max_sleep_delay_minutes = 60
|
|||||||
|
|
||||||
# 是否在进入“准备入睡”状态时发送一条消息通知。
|
# 是否在进入“准备入睡”状态时发送一条消息通知。
|
||||||
enable_pre_sleep_notification = false
|
enable_pre_sleep_notification = false
|
||||||
# 接收睡前消息的群组列表。格式为: ["platform:group_id1", "platform:group_id2"],例如 ["qq:12345678"]
|
|
||||||
pre_sleep_notification_groups = []
|
|
||||||
# 用于生成睡前消息的提示。AI会根据这个提示生成一句晚安问候。
|
# 用于生成睡前消息的提示。AI会根据这个提示生成一句晚安问候。
|
||||||
pre_sleep_prompt = "我准备睡觉了,请生成一句简短自然的晚安问候。"
|
pre_sleep_prompt = "我准备睡觉了,请生成一句简短自然的晚安问候。"
|
||||||
insomnia_duration_minutes = [30, 60] # 单次失眠状态的持续时间范围(分钟)
|
insomnia_duration_minutes = [30, 60] # 单次失眠状态的持续时间范围(分钟)
|
||||||
@@ -495,7 +493,7 @@ insomnia_trigger_delay_minutes = [15, 45]
|
|||||||
|
|
||||||
[server]
|
[server]
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
port = 8080
|
port = 8000
|
||||||
|
|
||||||
[cross_context] # 跨群聊/私聊上下文共享配置
|
[cross_context] # 跨群聊/私聊上下文共享配置
|
||||||
# 这是总开关,用于一键启用或禁用此功能
|
# 这是总开关,用于一键启用或禁用此功能
|
||||||
|
|||||||
Reference in New Issue
Block a user