快速开始
FoxCore 插件以动态链接库(.dll / .so)形式加载,开发时依赖 foxcore-api crate 获取所有公开接口。
环境准备
在你的插件项目 Cargo.toml 中添加:
toml
[lib]
crate-type = ["dylib"]
[dependencies]
foxcore-api = { path = "../FoxCoreApi" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["rt-multi-thread", "sync", "time"] }
toml = "0.8"
toml-example = "0.16"
async-trait = "0.1"重要
必须使用与核心相同版本的 Rust 编译器(见 rust-toolchain.toml)。
项目结构
FoxNature/
├── FoxCore/ # 核心框架(闭源)
├── FoxCoreApi/ # 公开接口(插件依赖此 crate)
├── YourPlugin/ # 你的插件项目
│ ├── Cargo.toml
│ └── src/lib.rs
└── ...部署
cargo build --release编译你的插件- 将生成的
.dll/.so文件复制到 FoxCore 的plugins/目录 - 启动 FoxCore — 首次加载时自动在
config/plugins/生成配置文件 - 编辑生成的配置文件,重启 FoxCore
运行目录结构
运行目录/
├── foxcore-app.exe # 主程序
├── plugins/
│ └── your_plugin.dll
├── config/
│ ├── config.toml # 核心配置(自动生成)
│ └── plugins/
│ └── your_plugin.toml # 插件配置(自动生成)
├── data/
│ └── foxcore.db # SQLite 数据库(自动创建)
├── logs/
│ └── 2026-04-22.log
└── error.log可用接口
foxcore-api 提供以下公开接口:
| 模块 | 说明 |
|---|---|
Config trait | 定义插件配置,自动加载/保存 TOML |
Component trait | 注册为总线组件,收发消息 |
BusContext | 广播、点对点、请求-响应、适配器桥接 |
ctx.send_message() | 通过适配器发送消息 |
ctx.call_adapter_api() | 调用平台 API(撤回、禁言等) |
TaskKind / TaskDefinition | 注册定时任务(间隔、Cron、条件触发) |
Adapter trait | 开发平台适配器(如 QQ、Discord) |
log_info! / log_warn! / ... | dylib 插件日志宏(跨 dylib 安全) |
rust
use foxcore_api::*;
use foxcore_api::{log_info, log_warn, log_error};