1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-06-06 23:49:42 +08:00
This commit is contained in:
Mrs4s 2020-10-27 18:23:31 +08:00
parent d32f427328
commit 151e44628c
2 changed files with 38 additions and 26 deletions

View File

@ -384,29 +384,43 @@ func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%EF%BC%8F%E9%82%80%E8%AF%B7
func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) MSG {
msgs, err := bot.Client.GetGroupSystemMessages()
if err != nil {
log.Errorf("获取群系统消息失败: %v", err)
return Failed(100)
}
if subType == "add" {
req, ok := bot.joinReqCache.Load(flag)
if !ok {
return Failed(100)
for _, req := range msgs.JoinRequests {
if strconv.FormatInt(req.RequestId, 10) == flag {
if req.Checked {
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
return Failed(100)
}
if approve {
req.Accept()
} else {
req.Reject(false, reason)
}
return OK(nil)
}
}
bot.joinReqCache.Delete(flag)
if approve {
req.(*client.UserJoinGroupRequest).Accept()
} else {
req.(*client.UserJoinGroupRequest).Reject(false, reason)
} else {
for _, req := range msgs.InvitedRequests {
if strconv.FormatInt(req.RequestId, 10) == flag {
if req.Checked {
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
return Failed(100)
}
if approve {
req.Accept()
} else {
req.Reject(false, reason)
}
return OK(nil)
}
}
return OK(nil)
}
req, ok := bot.invitedReqCache.Load(flag)
if ok {
bot.invitedReqCache.Delete(flag)
if approve {
req.(*client.GroupInvitedRequest).Accept()
} else {
req.(*client.GroupInvitedRequest).Reject(false, reason)
}
return OK(nil)
}
log.Errorf("处理群系统消息失败: 消息 %v 不存在.", flag)
return Failed(100)
}

View File

@ -23,13 +23,11 @@ import (
type CQBot struct {
Client *client.QQClient
events []func(MSG)
db *leveldb.DB
friendReqCache sync.Map
invitedReqCache sync.Map
joinReqCache sync.Map
tempMsgCache sync.Map
oneWayMsgCache sync.Map
events []func(MSG)
db *leveldb.DB
friendReqCache sync.Map
tempMsgCache sync.Map
oneWayMsgCache sync.Map
}
type MSG map[string]interface{}