1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

feat get group info no cache

This commit is contained in:
wdvxdr 2020-12-03 23:04:27 +08:00
parent dfeadef1a2
commit 12ac895b21
3 changed files with 11 additions and 3 deletions

View File

@ -55,11 +55,18 @@ func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
}
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF
func (bot *CQBot) CQGetGroupInfo(groupId int64) MSG {
func (bot *CQBot) CQGetGroupInfo(groupId int64, noCache bool) MSG {
group := bot.Client.FindGroup(groupId)
if group == nil {
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
}
if noCache {
var err error
group, err = bot.Client.GetGroupInfo(groupId)
if err != nil {
return Failed(100, "GET_GROUP_INFO_API_ERROR", err.Error())
}
}
return OK(MSG{
"group_id": group.Code,
"group_name": group.Name,

View File

@ -177,7 +177,8 @@ func GetGroupList(s *httpServer, c *gin.Context) {
func GetGroupInfo(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupInfo(gid))
nc := getParamOrDefault(c, "no_cache", "false")
c.JSON(200, s.bot.CQGetGroupInfo(gid, nc == "true"))
}
func GetGroupMemberList(s *httpServer, c *gin.Context) {

View File

@ -370,7 +370,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
return bot.CQGetGroupList(p.Get("no_cache").Bool())
},
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupInfo(p.Get("group_id").Int())
return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
},
"get_group_member_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())