diff --git a/coolq/api.go b/coolq/api.go index 4ba94648d..112132bd9 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -2137,6 +2137,22 @@ func (bot *CQBot) CQGetSupportedActions(spec *onebot.Spec) global.MSG { return OK(spec.SupportedActions) } +// CQGetRkey 获取Rkey +// +// @route(get_rkey) +func (bot *CQBot) CQGetRkey() global.MSG { + rkeys, err := bot.Client.FetchRkey() + if err != nil || len(rkeys) < 2 { + return Failed(100, "GET_RKEY_ERROR", err.Error()) + } + return OK(global.MSG{ + "private_rkey": rkeys[10].RKey, + "group_rkey": rkeys[20].RKey, + "create_time": rkeys[10].CreateTime, + "expire_time": rkeys[10].ExpireTime, + }) +} + // OK 生成成功返回值 func OK(data any) global.MSG { return global.MSG{"data": data, "retcode": 0, "status": "ok", "message": ""} diff --git a/modules/api/api.go b/modules/api/api.go index 71464ae00..8203f0805 100644 --- a/modules/api/api.go +++ b/modules/api/api.go @@ -375,6 +375,8 @@ func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG { p1 := p.Get("file").String() p2 := p.Get("name").String() return c.bot.CQUploadPrivateFile(p0, p1, p2) + case "get_rkey": + return c.bot.CQGetRkey() } return coolq.Failed(404, "API_NOT_FOUND", "API不存在") } diff --git a/pkg/onebot/supported.go b/pkg/onebot/supported.go index d5357d7cf..c94a596f5 100644 --- a/pkg/onebot/supported.go +++ b/pkg/onebot/supported.go @@ -88,6 +88,7 @@ var supportedV11 = []string{ "update_guild_role", "upload_group_file", "upload_private_file", + "get_rkey", } var supportedV12 = []string{ @@ -166,4 +167,5 @@ var supportedV12 = []string{ "update_guild_role", "upload_group_file", "upload_private_file", + "get_rkey", }