From 8c71dbff68631c9345af8a87bc6cc76d1c2c337f Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Wed, 19 Aug 2020 16:04:30 +0800 Subject: [PATCH] honor api supported. --- coolq/api.go | 55 +++++++++++++++++++++++++++++++++++++++++++++ coolq/bot.go | 4 ++++ go.mod | 2 +- go.sum | 2 ++ server/http.go | 9 ++++++-- server/websocket.go | 3 +++ 6 files changed, 72 insertions(+), 3 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 33d9dab..fe64af5 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -376,6 +376,61 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG { return OK(nil) } +// 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} + convertMem := func(memList []client.HonorMemberInfo) (ret []MSG) { + for _, mem := range memList { + ret = append(ret, MSG{ + "user_id": mem.Uin, + "nickname": mem.Name, + "avatar": mem.Avatar, + "description": mem.Desc, + }) + } + return + } + if t == "talkative" || t == "all" { + if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Talkative); err == nil { + if honor.CurrentTalkative.Uin != 0 { + msg["current_talkative"] = MSG{ + "user_id": honor.CurrentTalkative.Uin, + "nickname": honor.CurrentTalkative.Name, + "avatar": honor.CurrentTalkative.Avatar, + "day_count": honor.CurrentTalkative.DayCount, + } + } + msg["talkative_list"] = convertMem(honor.TalkativeList) + } + } + + if t == "performer" || t == "all" { + if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Performer); err == nil { + msg["performer_lis"] = convertMem(honor.ActorList) + } + } + + if t == "legend" || t == "all" { + if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Legend); err == nil { + msg["legend_list"] = convertMem(honor.LegendList) + } + } + + if t == "strong_newbie" || t == "all" { + if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.StrongNewbie); err == nil { + msg["strong_newbie_list"] = convertMem(honor.StrongNewbieList) + } + } + + if t == "emotion" || t == "all" { + if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Emotion); err == nil { + msg["emotion_list"] = convertMem(honor.EmotionList) + } + } + + return OK(msg) +} + // 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/coolq/bot.go b/coolq/bot.go index c095bf7..70c13bc 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -117,6 +117,10 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int } m.Elements = newElem ret := bot.Client.SendGroupMessage(groupId, m) + if ret.Id == -1 { + log.Warnf("警告: 群 %v 消息发送失败, 账号可能被风控.", groupId) + return -1 + } return bot.InsertGroupMessage(ret) } diff --git a/go.mod b/go.mod index b9813dc..45ed455 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200817175311-ac7fc7ad2847 + github.com/Mrs4s/MiraiGo v0.0.0-20200819041545-3561e5f156ce github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 github.com/guonaihong/gout v0.1.1 diff --git a/go.sum b/go.sum index eec3b22..77e375c 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Mrs4s/MiraiGo v0.0.0-20200817175311-ac7fc7ad2847 h1:ZnCHrRSLvN+a7ndOFPJF/FIg80JM6WxiOGC1TPTarEk= github.com/Mrs4s/MiraiGo v0.0.0-20200817175311-ac7fc7ad2847/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= +github.com/Mrs4s/MiraiGo v0.0.0-20200819041545-3561e5f156ce h1:rqefWaA8Xrk6qxFBbEQaySOUXH614DIR7cFmU5jVAQY= +github.com/Mrs4s/MiraiGo v0.0.0-20200819041545-3561e5f156ce/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/server/http.go b/server/http.go index 2e81d52..6bac8bf 100644 --- a/server/http.go +++ b/server/http.go @@ -134,12 +134,12 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) { s.engine.Any("/set_group_leave_async", s.SetGroupLeave) s.engine.Any("/get_image", s.GetImage) - s.engine.Any("/get_image_async", s.GetImage) s.engine.Any("/get_forward_msg", s.GetForwardMessage) s.engine.Any("/get_group_msg", s.GetGroupMessage) - s.engine.Any("/get_group_msg_async", s.GetGroupMessage) + + s.engine.Any("/get_group_honor_info", s.GetGroupHonorInfo) s.engine.Any("/can_send_image", s.CanSendImage) s.engine.Any("/can_send_image_async", s.CanSendImage) @@ -285,6 +285,11 @@ func (s *httpServer) GetGroupMessage(c *gin.Context) { c.JSON(200, s.bot.CQGetGroupMessage(int32(mid))) } +func (s *httpServer) GetGroupHonorInfo(c *gin.Context) { + gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) + c.JSON(200, s.bot.CQGetGroupHonorInfo(gid, getParam(c, "type"))) +} + func (s *httpServer) ProcessFriendRequest(c *gin.Context) { flag := getParam(c, "flag") approve := getParamOrDefault(c, "approve", "true") diff --git a/server/websocket.go b/server/websocket.go index 18ba3e7..4668d9f 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -422,6 +422,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ "get_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQGetGroupMessage(int32(p.Get("message_id").Int())) }, + "get_group_honor_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { + return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str) + }, "can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQCanSendImage() },