From 5b57aeb1d1dfc9cb72e8de636e3e2d53dbcd6b43 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Tue, 2 Feb 2021 22:12:47 +0800 Subject: [PATCH] get group info by search --- coolq/api.go | 17 ++++++++++++++++- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 713c0ab..e55afc9 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -62,7 +62,22 @@ func (bot *CQBot) CQGetGroupList(noCache bool) MSG { func (bot *CQBot) CQGetGroupInfo(groupId int64, noCache bool) MSG { group := bot.Client.FindGroup(groupId) if group == nil { - return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") + gid := strconv.FormatInt(groupId, 10) + info, err := bot.Client.SearchGroupByKeyword(gid) + if err != nil { + return Failed(100, "GROUP_SEARCH_ERROR", "群聊搜索失败") + } + for _, g := range info { + if g.Code == groupId { + return OK(MSG{ + "group_id": g.Code, + "group_name": g.Name, + "max_member_count": 0, + "member_count": 0, + }) + } + } + return Failed(100, "GROUP_NOT_FOUND", "群聊不存在失败") } if noCache { var err error diff --git a/go.mod b/go.mod index 9359d85..ded4c99 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.15 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20210201234941-c69e578d0815 + github.com/Mrs4s/MiraiGo v0.0.0-20210202135946-553229fea92e github.com/dustin/go-humanize v1.0.0 github.com/gin-contrib/pprof v1.3.0 github.com/gin-gonic/gin v1.6.3 diff --git a/go.sum b/go.sum index 673b3be..e9741f8 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-20210201234941-c69e578d0815 h1:WW2YfA+0+LSa/0VlWVhnfrXXatcE09paHgPgfPxlIMk= github.com/Mrs4s/MiraiGo v0.0.0-20210201234941-c69e578d0815/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU= +github.com/Mrs4s/MiraiGo v0.0.0-20210202135946-553229fea92e h1:5rZXeo+KW1vNq5fM7DowITQgm8r7HuH6w9tScWJ5GQQ= +github.com/Mrs4s/MiraiGo v0.0.0-20210202135946-553229fea92e/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=