Commit b33bb37d authored by wdvxdr1123's avatar wdvxdr1123 Committed by GitHub

Merge pull request #1 from Mrs4s/master

sync
parents 5ddb246a 50ebfe47
...@@ -404,6 +404,26 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG { ...@@ -404,6 +404,26 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
return OK(nil) return OK(nil)
} }
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_admin-%E7%BE%A4%E7%BB%84%E8%AE%BE%E7%BD%AE%E7%AE%A1%E7%90%86%E5%91%98
func (bot *CQBot) CQSetGroupAdmin(groupId, userId int64, enable bool) MSG {
group := bot.Client.FindGroup(groupId)
if group == nil || group.OwnerUin != bot.Client.Uin {
return Failed(100)
}
mem := group.FindMember(userId)
if mem == nil {
return Failed(100)
}
mem.SetAdmin(enable)
t, err := bot.Client.GetGroupMembers(group)
if err != nil {
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
return Failed(100)
}
group.Members = t
return OK(nil)
}
func (bot *CQBot) CQGetVipInfo(userId int64) MSG { func (bot *CQBot) CQGetVipInfo(userId int64) MSG {
msg := MSG{} msg := MSG{}
vip, err := bot.Client.GetVipInfo(userId) vip, err := bot.Client.GetVipInfo(userId)
......
...@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp ...@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14 go 1.14
require ( require (
github.com/Mrs4s/MiraiGo v0.0.0-20200906025848-23750bb59124 github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect github.com/go-playground/validator/v10 v10.3.0 // indirect
......
This diff is collapsed.
...@@ -282,6 +282,12 @@ func (s *httpServer) SetGroupName(c *gin.Context) { ...@@ -282,6 +282,12 @@ func (s *httpServer) SetGroupName(c *gin.Context) {
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name"))) c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name")))
} }
func (s *httpServer) SetGroupAdmin(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupAdmin(gid, uid, getParamOrDefault(c, "enable", "true") == "true"))
}
func (s *httpServer) SendGroupNotice(c *gin.Context) { func (s *httpServer) SendGroupNotice(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64) gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content"))) c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content")))
...@@ -440,6 +446,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){ ...@@ -440,6 +446,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"set_group_name": func(s *httpServer, c *gin.Context) { "set_group_name": func(s *httpServer, c *gin.Context) {
s.SetGroupName(c) s.SetGroupName(c)
}, },
"set_group_admin": func(s *httpServer, c *gin.Context) {
s.SetGroupAdmin(c)
},
"_send_group_notice": func(s *httpServer, c *gin.Context) { "_send_group_notice": func(s *httpServer, c *gin.Context) {
s.SendGroupNotice(c) s.SendGroupNotice(c)
}, },
......
...@@ -454,6 +454,14 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ ...@@ -454,6 +454,14 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"set_group_name": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { "set_group_name": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str) return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str)
}, },
"set_group_admin": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQSetGroupAdmin(p.Get("group_id").Int(), p.Get("user_id").Int(), func() bool {
if p.Get("enable").Exists() {
return p.Get("enable").Bool()
}
return true
}())
},
"_send_group_notice": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { "_send_group_notice": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str) return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str)
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment