Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox_Bot into dev
This commit is contained in:
@@ -11,7 +11,7 @@ from src.common.logger import get_logger
|
|||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
from src.manager.async_task_manager import AsyncTask, async_task_manager
|
from src.manager.async_task_manager import AsyncTask, async_task_manager
|
||||||
from src.plugin_system import BaseEventHandler, EventType
|
from src.plugin_system import BaseEventHandler, EventType
|
||||||
from src.plugin_system.apis import chat_api, person_api
|
from src.plugin_system.apis import chat_api, message_api, person_api
|
||||||
from src.plugin_system.base.base_event import HandlerResult
|
from src.plugin_system.base.base_event import HandlerResult
|
||||||
|
|
||||||
from .proactive_thinker_executor import ProactiveThinkerExecutor
|
from .proactive_thinker_executor import ProactiveThinkerExecutor
|
||||||
@@ -160,7 +160,9 @@ class ProactiveThinkingTask(AsyncTask):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# 检查冷却时间
|
# 检查冷却时间
|
||||||
time_since_last_active = time.time() - stream.last_active_time
|
recent_messages = await message_api.get_recent_messages(chat_id=stream.stream_id, limit=1,limit_mode="latest")
|
||||||
|
last_message_time = recent_messages[0]["time"] if recent_messages else stream.create_time
|
||||||
|
time_since_last_active = time.time() - last_message_time
|
||||||
if time_since_last_active > next_interval:
|
if time_since_last_active > next_interval:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"【日常唤醒-私聊】聊天流 {stream.stream_id} 已冷却 {time_since_last_active:.2f} 秒,触发主动对话。"
|
f"【日常唤醒-私聊】聊天流 {stream.stream_id} 已冷却 {time_since_last_active:.2f} 秒,触发主动对话。"
|
||||||
@@ -184,7 +186,9 @@ class ProactiveThinkingTask(AsyncTask):
|
|||||||
# 检查群聊是否在白名单内
|
# 检查群聊是否在白名单内
|
||||||
if not enabled_groups or f"qq:{stream.group_info.group_id}" in enabled_groups:
|
if not enabled_groups or f"qq:{stream.group_info.group_id}" in enabled_groups:
|
||||||
# 检查冷却时间
|
# 检查冷却时间
|
||||||
time_since_last_active = time.time() - stream.last_active_time
|
recent_messages = await message_api.get_recent_messages(chat_id=stream.stream_id, limit=1)
|
||||||
|
last_message_time = recent_messages[0]["time"] if recent_messages else stream.create_time
|
||||||
|
time_since_last_active = time.time() - last_message_time
|
||||||
if time_since_last_active > next_interval:
|
if time_since_last_active > next_interval:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"【日常唤醒-群聊】聊天流 {stream.stream_id} 已冷却 {time_since_last_active:.2f} 秒,触发主动对话。"
|
f"【日常唤醒-群聊】聊天流 {stream.stream_id} 已冷却 {time_since_last_active:.2f} 秒,触发主动对话。"
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import orjson
|
import orjson
|
||||||
|
|
||||||
|
from src.chat.utils.chat_message_builder import build_readable_actions, get_actions_by_timestamp_with_chat
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.config.config import global_config, model_config
|
from src.config.config import global_config, model_config
|
||||||
from src.mood.mood_manager import mood_manager
|
from src.mood.mood_manager import mood_manager
|
||||||
@@ -140,23 +142,20 @@ class ProactiveThinkerExecutor:
|
|||||||
else "今天没有日程安排。"
|
else "今天没有日程安排。"
|
||||||
)
|
)
|
||||||
|
|
||||||
recent_messages = await message_api.get_recent_messages(stream.stream_id)
|
recent_messages = await message_api.get_recent_messages(stream.stream_id,limit=50,limit_mode="latest",hours=12)
|
||||||
recent_chat_history = (
|
recent_chat_history = (
|
||||||
await message_api.build_readable_messages_to_str(recent_messages) if recent_messages else "无"
|
await message_api.build_readable_messages_to_str(recent_messages) if recent_messages else "无"
|
||||||
)
|
)
|
||||||
|
|
||||||
action_history_list = await database_api.db_query(
|
action_history_list = await get_actions_by_timestamp_with_chat(
|
||||||
database_api.MODEL_MAPPING["ActionRecords"],
|
chat_id=stream.stream_id,
|
||||||
filters={"chat_id": stream_id, "action_name": "proactive_decision"},
|
timestamp_start=time.time() - 3600 * 24, #过去24小时
|
||||||
limit=3,
|
timestamp_end=time.time(),
|
||||||
order_by=["-time"],
|
limit=7,
|
||||||
)
|
|
||||||
action_history_context = (
|
|
||||||
"\n".join([f"- {a['action_data']}" for a in action_history_list if isinstance(a, dict)])
|
|
||||||
if isinstance(action_history_list, list)
|
|
||||||
else "无"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
action_history_context = build_readable_actions(actions=action_history_list)
|
||||||
|
|
||||||
# 2. 构建基础上下文
|
# 2. 构建基础上下文
|
||||||
mood_state = "暂时没有"
|
mood_state = "暂时没有"
|
||||||
if global_config.mood.enable_mood:
|
if global_config.mood.enable_mood:
|
||||||
|
|||||||
Reference in New Issue
Block a user