mirror of https://github.com/Mai-with-u/MaiBot.git
Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into groupnickname
commit
d698256397
|
|
@ -0,0 +1,51 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# ==============================================
|
||||||
|
# Environment Initialization
|
||||||
|
# ==============================================
|
||||||
|
|
||||||
|
# Step 1: Locate project root directory
|
||||||
|
SCRIPTS_DIR="scripts"
|
||||||
|
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||||
|
PROJECT_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
|
||||||
|
|
||||||
|
# Step 2: Verify scripts directory exists
|
||||||
|
if [ ! -d "$PROJECT_ROOT/$SCRIPTS_DIR" ]; then
|
||||||
|
echo "❌ Error: scripts directory not found in project root" >&2
|
||||||
|
echo "Current path: $PROJECT_ROOT" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Step 3: Set up Python environment
|
||||||
|
export PYTHONPATH="$PROJECT_ROOT:$PYTHONPATH"
|
||||||
|
cd "$PROJECT_ROOT" || {
|
||||||
|
echo "❌ Failed to cd to project root: $PROJECT_ROOT" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Debug info
|
||||||
|
echo "============================"
|
||||||
|
echo "Project Root: $PROJECT_ROOT"
|
||||||
|
echo "Python Path: $PYTHONPATH"
|
||||||
|
echo "Working Dir: $(pwd)"
|
||||||
|
echo "============================"
|
||||||
|
|
||||||
|
# ==============================================
|
||||||
|
# Python Script Execution
|
||||||
|
# ==============================================
|
||||||
|
|
||||||
|
run_python_script() {
|
||||||
|
local script_name=$1
|
||||||
|
echo "🔄 Running $script_name"
|
||||||
|
if ! python3 "$SCRIPTS_DIR/$script_name"; then
|
||||||
|
echo "❌ $script_name failed" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execute scripts in order
|
||||||
|
run_python_script "raw_data_preprocessor.py"
|
||||||
|
run_python_script "info_extraction.py"
|
||||||
|
run_python_script "import_openie.py"
|
||||||
|
|
||||||
|
echo "✅ All scripts completed successfully"
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# src/plugins/chat/message_sender.py
|
# src/plugins/chat/message_sender.py
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
|
from asyncio import Task
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
# from ...common.database import db # 数据库依赖似乎不需要了,注释掉
|
# from ...common.database import db # 数据库依赖似乎不需要了,注释掉
|
||||||
|
|
@ -146,6 +147,7 @@ class MessageManager:
|
||||||
"""管理所有聊天流的消息容器 (不再是单例)"""
|
"""管理所有聊天流的消息容器 (不再是单例)"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self._processor_task: Task | None = None
|
||||||
self.containers: dict[str, MessageContainer] = {}
|
self.containers: dict[str, MessageContainer] = {}
|
||||||
self.storage = MessageStorage() # 添加 storage 实例
|
self.storage = MessageStorage() # 添加 storage 实例
|
||||||
self._running = True # 处理器运行状态
|
self._running = True # 处理器运行状态
|
||||||
|
|
@ -155,7 +157,7 @@ class MessageManager:
|
||||||
async def start(self):
|
async def start(self):
|
||||||
"""启动后台处理器任务。"""
|
"""启动后台处理器任务。"""
|
||||||
# 检查是否已有任务在运行,避免重复启动
|
# 检查是否已有任务在运行,避免重复启动
|
||||||
if hasattr(self, "_processor_task") and not self._processor_task.done():
|
if self._processor_task is not None and not self._processor_task.done():
|
||||||
logger.warning("Processor task already running.")
|
logger.warning("Processor task already running.")
|
||||||
return
|
return
|
||||||
self._processor_task = asyncio.create_task(self._start_processor_loop())
|
self._processor_task = asyncio.create_task(self._start_processor_loop())
|
||||||
|
|
@ -164,7 +166,7 @@ class MessageManager:
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""停止后台处理器任务。"""
|
"""停止后台处理器任务。"""
|
||||||
self._running = False
|
self._running = False
|
||||||
if hasattr(self, "_processor_task") and not self._processor_task.done():
|
if self._processor_task is not None and not self._processor_task.done():
|
||||||
self._processor_task.cancel()
|
self._processor_task.cancel()
|
||||||
logger.debug("MessageManager processor task stopping.")
|
logger.debug("MessageManager processor task stopping.")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import asyncio # 重新导入 asyncio
|
import asyncio # 重新导入 asyncio
|
||||||
from typing import Dict, Optional # 重新导入类型
|
from typing import Dict, Optional # 重新导入类型
|
||||||
from ..chat.message import MessageSending, MessageThinking # 只保留 MessageSending 和 MessageThinking
|
from ..chat.message import MessageSending, MessageThinking # 只保留 MessageSending 和 MessageThinking
|
||||||
|
from ..message import global_api
|
||||||
from ..storage.storage import MessageStorage
|
from ..storage.storage import MessageStorage
|
||||||
from ..chat.utils import truncate_message
|
from ..chat.utils import truncate_message
|
||||||
from src.common.logger_manager import get_logger
|
from src.common.logger_manager import get_logger
|
||||||
|
|
@ -17,7 +18,7 @@ async def send_message(message: MessageSending) -> None:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 直接调用API发送消息
|
# 直接调用API发送消息
|
||||||
await send_message(message)
|
await global_api.send_message(message)
|
||||||
logger.success(f"发送消息 '{message_preview}' 成功")
|
logger.success(f"发送消息 '{message_preview}' 成功")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue