diff --git a/coolq/api.go b/coolq/api.go index d20bf6c..f9ecde2 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -396,6 +396,24 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG { return OK(nil) } +func (bot *CQBot) CQGetVipInfo(userId int64) MSG { + msg := MSG{} + vip, err := bot.Client.GetVipInfo(userId) + if err != nil { + return Failed(100) + } + msg = MSG{ + "user_id": vip.Uin, + "nickname": vip.Name, + "level": vip.Level, + "level_speed": vip.LevelSpeed, + "vip_level": vip.VipLevel, + "vip_growth_speed": vip.VipGrowthSpeed, + "vip_growth_total": vip.VipGrowthTotal, + } + return OK(msg) +} + // https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_honor_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E8%8D%A3%E8%AA%89%E4%BF%A1%E6%81%AF func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG { msg := MSG{"group_id": groupId} diff --git a/server/http.go b/server/http.go index 1bbac8c..aa4d591 100644 --- a/server/http.go +++ b/server/http.go @@ -154,6 +154,9 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) { s.engine.Any("/get_version_info", s.GetVersionInfo) s.engine.Any("/get_version_info_async", s.GetVersionInfo) + s.engine.Any("/_get_vip_info", s.GetVipInfo) + s.engine.Any("/_get_vip_info_async", s.GetVipInfo) + s.engine.Any("/.handle_quick_operation", s.HandleQuickOperation) go func() { @@ -381,6 +384,11 @@ func (s *httpServer) GetVersionInfo(c *gin.Context) { c.JSON(200, s.bot.CQGetVersionInfo()) } +func (s *httpServer) GetVipInfo(c *gin.Context) { + uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) + c.JSON(200, s.bot.CQGetVipInfo(uid)) +} + func (s *httpServer) HandleQuickOperation(c *gin.Context) { if c.Request.Method != "POST" { c.AbortWithStatus(404) diff --git a/server/websocket.go b/server/websocket.go index a1f241d..9f80ee4 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -506,6 +506,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ "get_version_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQGetVersionInfo() }, + "_get_vip_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { + return bot.CQGetVipInfo(p.Get("user_id").Int()) + }, ".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation")) },