feat: 添加Docker沙箱代码执行功能

- 新增Docker沙箱执行环境,提供安全隔离的代码执行能力
- 重构code_py插件,使用Docker容器替代子进程执行
- 添加docker配置项和权限检查功能
- 实现代码执行队列和并发控制
- 新增广播插件,仅限管理员使用
This commit is contained in:
2026-01-06 22:56:00 +08:00
parent 839add3cb9
commit 54f74d0e73
12 changed files with 477 additions and 182 deletions

15
main.py
View File

@@ -108,6 +108,21 @@ async def main():
try:
bot = WS()
# 初始化代码执行器
from core.config_loader import global_config as config
from core.executor import initialize_executor
code_executor = initialize_executor(bot, config)
bot.bot.code_executor = code_executor # 将执行器实例附加到 bot.bot 对象上
# 启动代码执行器的后台 worker
logger.debug("[Main] 检查是否需要启动代码执行 Worker...")
if code_executor and code_executor.docker_client:
logger.info("[Main] Docker 连接成功,正在启动代码执行 Worker...")
asyncio.create_task(code_executor.worker())
else:
logger.warning("[Main] 未启动代码执行 Worker因为 Docker 客户端未初始化或连接失败。")
await bot.connect()
finally:
if observer.is_alive():