From ea65e545add6e6a46eff4d8dcff99285b9ebca39 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sat, 19 Sep 2020 17:02:21 +0800 Subject: [PATCH] supported: get_stranger_info. --- coolq/api.go | 21 +++++++++++++++++++++ server/http.go | 8 ++++++++ server/websocket.go | 3 +++ 3 files changed, 32 insertions(+) diff --git a/coolq/api.go b/coolq/api.go index 258d923..83bfc97 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -497,6 +497,27 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG { return OK(msg) } +// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF +func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG { + info, err := bot.Client.GetSummaryInfo(userId) + if err != nil { + return Failed(100) + } + return OK(MSG{ + "user_id": info.Uin, + "nickname": info.Nickname, + "sex": func() string { + if info.Sex == 1 { + return "female" + } + return "male" + }(), + "age": info.Age, + "level": info.Level, + "login_days": info.LoginDays, + }) +} + // https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C // https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376 func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG { diff --git a/server/http.go b/server/http.go index 9b10904..afd2685 100644 --- a/server/http.go +++ b/server/http.go @@ -333,6 +333,11 @@ func (s *httpServer) GetVipInfo(c *gin.Context) { c.JSON(200, s.bot.CQGetVipInfo(uid)) } +func (s *httpServer) GetStrangerInfo(c *gin.Context) { + uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) + c.JSON(200, s.bot.CQGetStrangerInfo(uid)) +} + func (s *httpServer) HandleQuickOperation(c *gin.Context) { if c.Request.Method != "POST" { c.AbortWithStatus(404) @@ -486,6 +491,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){ "_get_vip_info": func(s *httpServer, c *gin.Context) { s.GetVipInfo(c) }, + "get_stranger_info": func(s *httpServer, c *gin.Context) { + s.GetStrangerInfo(c) + }, "reload_event_filter": func(s *httpServer, c *gin.Context) { s.ReloadEventFilter(c) }, diff --git a/server/websocket.go b/server/websocket.go index ecad98a..5b43395 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -486,6 +486,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ "can_send_record": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQCanSendRecord() }, + "get_stranger_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { + return bot.CQGetStrangerInfo(p.Get("user_id").Int()) + }, "get_status": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQGetStatus() },