1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

forward message supported.

This commit is contained in:
Mrs4s 2020-07-27 04:57:17 +08:00
parent 0a6ddb0810
commit 557400b343
8 changed files with 53 additions and 5 deletions

View File

@ -307,6 +307,28 @@ func (bot *CQBot) CQGetImage(file string) MSG {
return Failed(100)
}
func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
m := bot.Client.GetForwardMessage(resId)
if m == nil {
return Failed(100)
}
var r []MSG
for _, n := range m.Nodes {
checkImage(n.Message)
r = append(r, MSG{
"sender": MSG{
"user_id": n.SenderId,
"nick": n.SenderName,
},
"time": n.Time,
"content": ToStringMessage(n.Message, 0, false),
})
}
return OK(MSG{
"messages": r,
})
}
func (bot *CQBot) CQGetGroupMessage(messageId int32) MSG {
msg := bot.GetGroupMessage(messageId)
if msg == nil {

View File

@ -36,6 +36,8 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
r += fmt.Sprintf("[CQ:at,qq=%d]", o.Target)
case *message.ReplyElement:
r += fmt.Sprintf("[CQ:reply,id=%d]", ToGlobalId(code, o.ReplySeq))
case *message.ForwardElement:
r += fmt.Sprintf("[CQ:forward,id=%s]", o.ResId)
case *message.FaceElement:
r += fmt.Sprintf(`[CQ:face,id=%d]`, o.Index)
case *message.ImageElement:

View File

@ -25,7 +25,8 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
"http_config": {
"enabled": true,
"host": "0.0.0.0",
"port": 5700
"port": 5700,
"post_urls": []
},
"ws_config": {
"enabled": true,

View File

@ -4,9 +4,10 @@
## CQCode
| Code | 示例 | 说明 |
| ----- | -------------------- | ---------------------------------------------------------- |
| reply | [CQ:reply,id=123456] | 回复ID为 `123456`的信息. 发送时一条 `message` 仅能使用一次 |
| Code | 示例 | 说明 |
| ------- | -------------------- | ------------------------------------------------------------ |
| reply | [CQ:reply,id=123456] | 回复ID为 `123456`的信息. 发送时一条 `message` 仅能使用一次 |
| forward | [CQ:forward,id=abcd] | ID为abcd的转发消息, 暂时仅能接收. 可通过 `/get_forward_msg` API获取具体信息 |
## API
@ -55,6 +56,16 @@
| `time` | int32 | 发送时间 |
| `content` | message | 消息内容 |
`/get_forward_msg` **获取转发消息信息**
参数
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `message_id` | string | 消息id |
## 事件
#### 群消息撤回

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-20200721195252-2accd73f8b8e
github.com/Mrs4s/MiraiGo v0.0.0-20200726203306-14d741fe9383
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.1

2
go.sum
View File

@ -14,6 +14,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20200720231612-a7e460246fbc h1:elEjdwOy2u+Gfz+1U
github.com/Mrs4s/MiraiGo v0.0.0-20200720231612-a7e460246fbc/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
github.com/Mrs4s/MiraiGo v0.0.0-20200721195252-2accd73f8b8e h1:68ol9TpLBwbFQU+S6VQ0CY6nQqN2xIPxHWD/rvBZxVI=
github.com/Mrs4s/MiraiGo v0.0.0-20200721195252-2accd73f8b8e/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
github.com/Mrs4s/MiraiGo v0.0.0-20200726203306-14d741fe9383 h1:Z1z7pG9RJo5ynI1mW0r+PyK9wZ6xExY8cMS+kV0NUJ0=
github.com/Mrs4s/MiraiGo v0.0.0-20200726203306-14d741fe9383/go.mod h1:M9wh1hjd0rie3+wm27tjPZkYMbD+MBV76CGqp2G7WSU=
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=

View File

@ -127,6 +127,8 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
s.engine.Any("/get_image", s.GetImage)
s.engine.Any("/get_image_async", s.GetImage)
s.engine.Any("/get_forward_msg", s.GetForwardMessage)
s.engine.Any("/get_group_msg", s.GetGroupMessage)
s.engine.Any("/get_group_msg_async", s.GetGroupMessage)
@ -298,6 +300,11 @@ func (s *httpServer) SetGroupName(c *gin.Context) {
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "name")))
}
func (s *httpServer) GetForwardMessage(c *gin.Context) {
resId := getParam(c, "message_id")
c.JSON(200, s.bot.CQGetForwardMessage(resId))
}
func (s *httpServer) DeleteMessage(c *gin.Context) {
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))

View File

@ -380,6 +380,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"get_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetImage(p.Get("file").Str)
},
"get_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetForwardMessage(p.Get("message_id").Str)
},
"get_group_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupMessage(int32(p.Get("message_id").Int()))
},