mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
feature set_group_anonymous_ban.
This commit is contained in:
parent
fc2fc3494e
commit
20f2290ba4
20
coolq/api.go
20
coolq/api.go
@ -840,6 +840,26 @@ func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) CQSetGroupAnonymousBan(groupId int64, flag string, duration int32) MSG {
|
||||||
|
if flag == "" {
|
||||||
|
return Failed(100, "INVALID_FLAG", "无效的flag")
|
||||||
|
}
|
||||||
|
if g := bot.Client.FindGroup(groupId); g != nil {
|
||||||
|
s := strings.SplitN(flag, "|", 2)
|
||||||
|
if len(s) != 2 {
|
||||||
|
return Failed(100, "INVALID_FLAG", "无效的flag")
|
||||||
|
}
|
||||||
|
id := s[0]
|
||||||
|
nick := s[1]
|
||||||
|
if err := g.MuteAnonymous(id, nick, duration); err != nil {
|
||||||
|
log.Warnf("anonymous ban error: %v", err)
|
||||||
|
return Failed(100, "CALL_API_ERROR", err.Error())
|
||||||
|
}
|
||||||
|
return OK(nil)
|
||||||
|
}
|
||||||
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81
|
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81
|
||||||
func (bot *CQBot) CQGetStatus() MSG {
|
func (bot *CQBot) CQGetStatus() MSG {
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
|
@ -114,9 +114,9 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
|||||||
}
|
}
|
||||||
if m.Sender.IsAnonymous() {
|
if m.Sender.IsAnonymous() {
|
||||||
gm["anonymous"] = MSG{
|
gm["anonymous"] = MSG{
|
||||||
"flag": "",
|
"flag": m.Sender.AnonymousInfo.AnonymousId + "|" + m.Sender.AnonymousInfo.AnonymousNick,
|
||||||
"id": 0,
|
"id": m.Sender.Uin,
|
||||||
"name": m.Sender.Nickname,
|
"name": m.Sender.AnonymousInfo.AnonymousNick,
|
||||||
}
|
}
|
||||||
gm["sender"].(MSG)["nickname"] = "匿名消息"
|
gm["sender"].(MSG)["nickname"] = "匿名消息"
|
||||||
gm["sub_type"] = "anonymous"
|
gm["sub_type"] = "anonymous"
|
||||||
|
@ -399,6 +399,20 @@ func GetGroupAtAllRemain(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQGetAtAllRemain(gid))
|
c.JSON(200, s.bot.CQGetAtAllRemain(gid))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetGroupAnonymousBan(s *httpServer, c *gin.Context) {
|
||||||
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
|
d, _ := strconv.ParseInt(getParam(c, "duration"), 10, 64)
|
||||||
|
flag := getParam(c, "flag")
|
||||||
|
if flag == "" {
|
||||||
|
flag = getParam(c, "anonymous_flag")
|
||||||
|
}
|
||||||
|
if flag == "" {
|
||||||
|
o := gjson.Parse(getParam(c, "anonymous"))
|
||||||
|
flag = o.Get("flag").String()
|
||||||
|
}
|
||||||
|
c.JSON(200, s.bot.CQSetGroupAnonymousBan(gid, flag, int32(d)))
|
||||||
|
}
|
||||||
|
|
||||||
func HandleQuickOperation(s *httpServer, c *gin.Context) {
|
func HandleQuickOperation(s *httpServer, c *gin.Context) {
|
||||||
if c.Request.Method != "POST" {
|
if c.Request.Method != "POST" {
|
||||||
c.AbortWithStatus(404)
|
c.AbortWithStatus(404)
|
||||||
@ -516,6 +530,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
|||||||
"get_stranger_info": GetStrangerInfo,
|
"get_stranger_info": GetStrangerInfo,
|
||||||
"reload_event_filter": ReloadEventFilter,
|
"reload_event_filter": ReloadEventFilter,
|
||||||
"set_group_portrait": SetGroupPortrait,
|
"set_group_portrait": SetGroupPortrait,
|
||||||
|
"set_group_anonymous_ban": SetGroupAnonymousBan,
|
||||||
".handle_quick_operation": HandleQuickOperation,
|
".handle_quick_operation": HandleQuickOperation,
|
||||||
".ocr_image": OcrImage,
|
".ocr_image": OcrImage,
|
||||||
"ocr_image": OcrImage,
|
"ocr_image": OcrImage,
|
||||||
|
@ -553,6 +553,20 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
||||||
},
|
},
|
||||||
|
"set_group_anonymous_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
obj := p.Get("anonymous")
|
||||||
|
flag := p.Get("anonymous_flag")
|
||||||
|
if !flag.Exists() {
|
||||||
|
flag = p.Get("flag")
|
||||||
|
}
|
||||||
|
if !flag.Exists() && !obj.Exists() {
|
||||||
|
return coolq.Failed(100, "FLAG_NOT_FOUND", "flag未找到")
|
||||||
|
}
|
||||||
|
if !flag.Exists() {
|
||||||
|
flag = obj.Get("flag")
|
||||||
|
}
|
||||||
|
return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
|
||||||
|
},
|
||||||
".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user