mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
feature: set_group_admin.
This commit is contained in:
parent
b1fccbc0a3
commit
8c63a420a3
20
coolq/api.go
20
coolq/api.go
@ -404,6 +404,26 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
||||
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 {
|
||||
msg := MSG{}
|
||||
vip, err := bot.Client.GetVipInfo(userId)
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20200909095006-dde8bded28d1
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20200909103204-808a63a78efe
|
||||
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
github.com/go-playground/validator/v10 v10.3.0 // indirect
|
||||
|
2
go.sum
2
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-20200909095006-dde8bded28d1 h1:3cmUqA5RaikLx+59SODlBA7tjORQoh4t1w5CzH5bIH8=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20200909095006-dde8bded28d1/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20200909103204-808a63a78efe h1:O2BW87BwpwZDsn7YFHLfRGFGvTS4OUZsG2UiA13OxcQ=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20200909103204-808a63a78efe/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
|
||||
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=
|
||||
|
@ -282,6 +282,12 @@ func (s *httpServer) SetGroupName(c *gin.Context) {
|
||||
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) {
|
||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||
c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content")))
|
||||
@ -440,6 +446,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
||||
"set_group_name": func(s *httpServer, c *gin.Context) {
|
||||
s.SetGroupName(c)
|
||||
},
|
||||
"set_group_admin": func(s *httpServer, c *gin.Context) {
|
||||
s.SetGroupAdmin(c)
|
||||
},
|
||||
"_send_group_notice": func(s *httpServer, c *gin.Context) {
|
||||
s.SendGroupNotice(c)
|
||||
},
|
||||
|
@ -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 {
|
||||
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 {
|
||||
return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str)
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user