✨ feat(core): 初始化 Bot 命令处理服务器
- 基于 Gin 框架搭建 HTTP 服务,接收并处理 Bot 命令请求 - 实现插件化命令系统,支持通过 Plugin 接口扩展新命令 - 内置菜单、启用/禁用、时间查询等基础命令 - 新增图片生成插件,对接 OpenAI Images API - 支持管理员权限控制、命令动态启禁用 - 提供完整配置管理(.env)与 Docker 部署方案
This commit is contained in:
44
main.go
Normal file
44
main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"ncatbot-command-server/command"
|
||||
"ncatbot-command-server/config"
|
||||
|
||||
// 统一加载所有插件
|
||||
_ "ncatbot-command-server/plugins"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := config.Load(".env"); err != nil {
|
||||
log.Fatalf("load config: %v", err)
|
||||
}
|
||||
|
||||
// 注册内置命令
|
||||
command.Init()
|
||||
|
||||
// 初始化所有插件
|
||||
command.InitAll()
|
||||
|
||||
r := gin.Default()
|
||||
r.POST("/", handleCommand)
|
||||
|
||||
log.Printf("server starting on %s", config.Cfg.ServerAddr)
|
||||
if err := r.Run(config.Cfg.ServerAddr); err != nil {
|
||||
log.Fatalf("failed to start server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleCommand(c *gin.Context) {
|
||||
var req command.Req
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Printf("request: command=%s user=%s group=%s", req.Command, req.UserID, req.GroupID)
|
||||
|
||||
resp := command.Handle(&req)
|
||||
c.JSON(200, resp)
|
||||
}
|
||||
Reference in New Issue
Block a user