From 9007a4fc5a2f2c39d15204302f09e426e91763d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=A5=E6=B5=B7?= Date: Sat, 9 Mar 2024 09:53:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpd/wrobot/chatroom.go | 2 +- httpd/wrobot/keyword.go | 2 +- httpd/wrobot/llmodel.go | 2 +- httpd/wrobot/profile.go | 2 +- httpd/wrobot/router.go | 2 +- httpd/wrobot/setting.go | 2 +- httpd/wrobot/sundry.go | 28 +++++++++++++++-- public/swagger/swagger.json | 60 ++++++++++++++++++------------------- wclient/robot/handler.go | 12 ++++---- 9 files changed, 67 insertions(+), 45 deletions(-) diff --git a/httpd/wrobot/chatroom.go b/httpd/wrobot/chatroom.go index f995cde3..362445f3 100644 --- a/httpd/wrobot/chatroom.go +++ b/httpd/wrobot/chatroom.go @@ -13,7 +13,7 @@ type Chatroom struct{} // @Produce json // @Tags BOT::群聊配置 // @Param body body chatroom.FetchAllParam true "获取群聊配置列表参数" -// @Success 200 {object} []tables.Chatroom +// @Success 200 {array} tables.Chatroom // @Router /bot/chatroom/list [post] func (*Chatroom) list(c *gin.Context) { diff --git a/httpd/wrobot/keyword.go b/httpd/wrobot/keyword.go index b745fbea..a84c591a 100644 --- a/httpd/wrobot/keyword.go +++ b/httpd/wrobot/keyword.go @@ -13,7 +13,7 @@ type Keyword struct{} // @Produce json // @Tags BOT::关键字 // @Param body body keyword.FetchAllParam true "获取关键字列表参数" -// @Success 200 {object} []tables.Keyword +// @Success 200 {array} tables.Keyword // @Router /bot/keyword/list [post] func (*Keyword) list(c *gin.Context) { diff --git a/httpd/wrobot/llmodel.go b/httpd/wrobot/llmodel.go index 0c988922..691573fa 100644 --- a/httpd/wrobot/llmodel.go +++ b/httpd/wrobot/llmodel.go @@ -13,7 +13,7 @@ type LLModel struct{} // @Produce json // @Tags BOT::大语言模型 // @Param body body llmodel.FetchAllParam true "获取模型列表参数" -// @Success 200 {object} []tables.LLModel +// @Success 200 {array} tables.LLModel // @Router /bot/llmodel/list [post] func (*LLModel) list(c *gin.Context) { diff --git a/httpd/wrobot/profile.go b/httpd/wrobot/profile.go index 298a69ca..64b3c45d 100644 --- a/httpd/wrobot/profile.go +++ b/httpd/wrobot/profile.go @@ -13,7 +13,7 @@ type Profile struct{} // @Produce json // @Tags BOT::用户配置 // @Param body body profile.FetchAllParam true "获取用户配置列表参数" -// @Success 200 {object} []tables.Profile +// @Success 200 {array} tables.Profile // @Router /bot/profile/list [post] func (*Profile) list(c *gin.Context) { diff --git a/httpd/wrobot/router.go b/httpd/wrobot/router.go index 2f7d9ccf..2b2e1b0f 100644 --- a/httpd/wrobot/router.go +++ b/httpd/wrobot/router.go @@ -48,6 +48,6 @@ func Route() { // sundry - rg.POST("handlers", handlers) + rg.POST("handlers", robotHandlers) } diff --git a/httpd/wrobot/setting.go b/httpd/wrobot/setting.go index 9fe18785..0064a383 100644 --- a/httpd/wrobot/setting.go +++ b/httpd/wrobot/setting.go @@ -12,7 +12,7 @@ type Setting struct{} // @Produce json // @Tags BOT::全局配置 // @Param body body setting.FetchAllParam true "获取全局配置列表参数" -// @Success 200 {object} []tables.Setting +// @Success 200 {array} tables.Setting // @Router /bot/setting/list [post] func (*Setting) list(c *gin.Context) { diff --git a/httpd/wrobot/sundry.go b/httpd/wrobot/sundry.go index 2356bc5d..ffa41777 100644 --- a/httpd/wrobot/sundry.go +++ b/httpd/wrobot/sundry.go @@ -7,10 +7,32 @@ import ( // @Summary 机器人指令集 // @Tags BOT::杂项 -// @Success 200 {object} []robot.Handler +// @Success 200 {array} RobotHandler // @Router /bot/handlers [post] -func handlers(c *gin.Context) { +func robotHandlers(c *gin.Context) { - c.Set("Payload", robot.Handlers) + items := []RobotHandler{} + for _, v := range robot.Handlers { + items = append(items, RobotHandler{ + Level: v.Level, + Order: v.Order, + ChatAble: v.ChatAble, + RoomAble: v.RoomAble, + Command: v.Command, + Describe: v.Describe, + }) + } + + c.Set("Payload", items) + +} + +type RobotHandler struct { + Level int32 `json:"level"` // 0:不限制 7:群管理 9:创始人 + Order int32 `json:"order"` // 排序,越小越靠前 + ChatAble bool `json:"chat_able"` // 是否允许在私聊使用 + RoomAble bool `json:"room_able"` // 是否允许在群聊使用 + Command string `json:"command"` // 指令 + Describe string `json:"describe"` // 指令的描述信息 } diff --git a/public/swagger/swagger.json b/public/swagger/swagger.json index 132d79d9..532e0c65 100644 --- a/public/swagger/swagger.json +++ b/public/swagger/swagger.json @@ -331,7 +331,7 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/robot.Handler" + "$ref": "#/definitions/wrobot.RobotHandler" } } } @@ -2449,35 +2449,6 @@ } } }, - "robot.Handler": { - "type": "object", - "properties": { - "chat_able": { - "description": "是否允许在私聊使用", - "type": "boolean" - }, - "command": { - "description": "指令", - "type": "string" - }, - "describe": { - "description": "指令的描述信息", - "type": "string" - }, - "level": { - "description": "0:不限制 7:群管理 9:创始人", - "type": "integer" - }, - "order": { - "description": "排序,越小越靠前", - "type": "integer" - }, - "room_able": { - "description": "是否允许在群聊使用", - "type": "boolean" - } - } - }, "setting.CreateParam": { "type": "object", "required": [ @@ -3269,6 +3240,35 @@ "type": "string" } } + }, + "wrobot.RobotHandler": { + "type": "object", + "properties": { + "chat_able": { + "description": "是否允许在私聊使用", + "type": "boolean" + }, + "command": { + "description": "指令", + "type": "string" + }, + "describe": { + "description": "指令的描述信息", + "type": "string" + }, + "level": { + "description": "0:不限制 7:群管理 9:创始人", + "type": "integer" + }, + "order": { + "description": "排序,越小越靠前", + "type": "integer" + }, + "room_able": { + "description": "是否允许在群聊使用", + "type": "boolean" + } + } } } } \ No newline at end of file diff --git a/wclient/robot/handler.go b/wclient/robot/handler.go index 4d45d9bc..7f497b2b 100644 --- a/wclient/robot/handler.go +++ b/wclient/robot/handler.go @@ -14,12 +14,12 @@ var Handlers = []*Handler{} var HandlerMap = map[string]*Handler{} type Handler struct { - Level int32 `json:"level"` // 0:不限制 7:群管理 9:创始人 - Order int32 `json:"order"` // 排序,越小越靠前 - ChatAble bool `json:"chat_able"` // 是否允许在私聊使用 - RoomAble bool `json:"room_able"` // 是否允许在群聊使用 - Command string `json:"command"` // 指令 - Describe string `json:"describe"` // 指令的描述信息 + Level int32 // 0:不限制 7:群管理 9:创始人 + Order int32 // 排序,越小越靠前 + ChatAble bool // 是否允许在私聊使用 + RoomAble bool // 是否允许在群聊使用 + Command string // 指令 + Describe string // 指令的描述信息 PreCheck func(*wcferry.WxMsg) string // 前置检查,可拦截文本聊天内容 Callback func(*wcferry.WxMsg) string // 指令回调,返回回复内容 }