This commit is contained in:
tt-P607
2025-10-03 22:14:30 +08:00
6 changed files with 65 additions and 6 deletions

1
src/api/__init__.py Normal file
View File

@@ -0,0 +1 @@
# This file makes src/api a Python package.

48
src/api/message_router.py Normal file
View File

@@ -0,0 +1,48 @@
import time
from typing import Literal
from fastapi import APIRouter, HTTPException, Query
from src.config.config import global_config
from src.plugin_system.apis import message_api
router = APIRouter()
@router.get("/messages/recent")
async def get_message_stats(
days: int = Query(1, ge=1, description="指定查询过去多少天的数据"),
message_type: Literal["all", "sent", "received"] = Query("all", description="筛选消息类型: 'sent' (BOT发送的), 'received' (BOT接收的), or 'all' (全部)")
):
"""
获取BOT在指定天数内的消息统计数据。
"""
try:
end_time = time.time()
start_time = end_time - (days * 24 * 3600)
messages = await message_api.get_messages_by_time(start_time, end_time)
sent_count = 0
received_count = 0
bot_qq = str(global_config.bot.qq_account)
for msg in messages:
if msg.get("user_id") == bot_qq:
sent_count += 1
else:
received_count += 1
if message_type == "sent":
return {"days": days, "message_type": message_type, "count": sent_count}
elif message_type == "received":
return {"days": days, "message_type": message_type, "count": received_count}
else:
return {
"days": days,
"message_type": message_type,
"sent_count": sent_count,
"received_count": received_count,
"total_count": len(messages)
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

View File

@@ -511,8 +511,8 @@ class ExpressionLearnerManager:
os.path.join(base_dir, "learnt_grammar"), os.path.join(base_dir, "learnt_grammar"),
] ]
for directory in directories_to_create:
try: try:
for directory in directories_to_create:
os.makedirs(directory, exist_ok=True) os.makedirs(directory, exist_ok=True)
logger.debug(f"确保目录存在: {directory}") logger.debug(f"确保目录存在: {directory}")
except Exception as e: except Exception as e:

View File

@@ -245,6 +245,16 @@ MoFox_Bot(第三方修改版)
# start_api_server() # start_api_server()
# logger.info("API服务器启动成功") # logger.info("API服务器启动成功")
# 注册API路由
try:
from src.api.message_router import router as message_router
self.server.register_router(message_router, prefix="/api")
logger.info("API路由注册成功")
except ImportError as e:
logger.error(f"导入API路由失败: {e}")
except Exception as e:
logger.error(f"注册API路由时发生错误: {e}")
# 加载所有actions包括默认的和插件的 # 加载所有actions包括默认的和插件的
plugin_manager.load_all_plugins() plugin_manager.load_all_plugins()

View File

@@ -12,7 +12,7 @@
"host_application": { "host_application": {
"min_version": "0.10.0" "min_version": "0.10.0"
}, },
"keywords": ["emoji", "reaction", "like", "表情", "回应", "点赞"], "keywords": ["主动思考","自己发消息"],
"categories": ["Chat", "Integration"], "categories": ["Chat", "Integration"],
"default_locale": "zh-CN", "default_locale": "zh-CN",

View File

@@ -292,7 +292,7 @@ class ProactiveThinkerExecutor:
- **简单问候作为备选**: 如果上下文中没有合适的话题,可以生成一个简单、真诚的日常问候(例如“在忙吗?”,“下午好呀~”)。 - **简单问候作为备选**: 如果上下文中没有合适的话题,可以生成一个简单、真诚的日常问候(例如“在忙吗?”,“下午好呀~”)。
- **避免抽象**: 避免创造过于复杂、抽象或需要对方思考很久才能明白的话题。目标是轻松、自然地开启对话。 - **避免抽象**: 避免创造过于复杂、抽象或需要对方思考很久才能明白的话题。目标是轻松、自然地开启对话。
- **避免过于频繁**: 如果你最近(尤其是在最近的几次决策中)已经主动发起过对话,请倾向于选择“不回复”,除非有非常重要和紧急的事情。 - **避免过于频繁**: 如果你最近(尤其是在最近的几次决策中)已经主动发起过对话,请倾向于选择“不回复”,除非有非常重要和紧急的事情。
- **避免打扰**: 如果你最近(尤其是在最近的几次决策中)已经主动发起过对话,请倾向于选择“不回复”,除非有非常重要和紧急的事情。
--- ---
示例1 (基于上下文): 示例1 (基于上下文):