1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-07 04:23:49 +08:00
This commit is contained in:
Mrs4s 2020-10-28 11:53:04 +08:00
commit 7b1f0d72eb
6 changed files with 44 additions and 32 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{}

View File

@ -396,7 +396,6 @@ func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent)
func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRequest) {
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
flag := strconv.FormatInt(e.RequestId, 10)
bot.invitedReqCache.Store(flag, e)
bot.dispatchEventMessage(MSG{
"post_type": "request",
"request_type": "group",
@ -413,7 +412,6 @@ func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRe
func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupRequest) {
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
flag := strconv.FormatInt(e.RequestId, 10)
bot.joinReqCache.Store(flag, e)
bot.dispatchEventMessage(MSG{
"post_type": "request",
"request_type": "group",

View File

@ -380,9 +380,9 @@ Type: `tts`
| `filename` | string | 图片文件原名 |
| `url` | string | 图片下载地址 |
### 获取消息
### 获取消息
终结点: `/get_group_msg`
终结点: `/get_msg`
参数
@ -398,7 +398,7 @@ Type: `tts`
| `real_id` | int32 | 消息真实id |
| `sender` | object | 发送者 |
| `time` | int32 | 发送时间 |
| `content` | message | 消息内容 |
| `message` | message | 消息内容 |
### 获取合并转发内容

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-20201025234014-8ece3a9dd803
github.com/Mrs4s/MiraiGo v0.0.0-20201027102621-5fa25a7f7434
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.3

2
go.sum
View File

@ -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-20201025234014-8ece3a9dd803 h1:tRXLslHbNt4bd2wV+MIU2sqQME6UJfMYolYufhSRdg0=
github.com/Mrs4s/MiraiGo v0.0.0-20201025234014-8ece3a9dd803/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20201027102621-5fa25a7f7434 h1:wb5EoWBj/ulZ30fBQA2KJ0IwVXcesu9aynCFdpRwS8M=
github.com/Mrs4s/MiraiGo v0.0.0-20201027102621-5fa25a7f7434/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=