1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-30 11:53:25 +00:00

Compare commits

..

19 Commits

Author SHA1 Message Date
cc72332455 update doc. 2020-10-25 22:13:31 +08:00
84b4889def fix issue of sending the empty message. 2020-10-25 22:06:03 +08:00
6ad0d68978 feature get_group_system_msg. 2020-10-25 22:03:14 +08:00
1b63a15bbe update MiraiGo. 2020-10-25 21:53:03 +08:00
ce0a5b0271 fix timeout. 2020-10-22 22:10:15 +08:00
f96abc5e26 update gout. 2020-10-22 20:51:29 +08:00
2cdb341db4 fix oneway recall. 2020-10-20 21:12:53 +08:00
c2fd0f1bb2 fix #372. 2020-10-20 21:05:59 +08:00
8ab874ca2b Merge pull request #371 from wdvxdr1123/dev
fix array message
2020-10-20 11:54:29 +08:00
8e61060ef0 fix array message 2020-10-20 09:44:55 +08:00
508117d30b Merge remote-tracking branch 'upstream/dev' into dev 2020-10-20 09:44:20 +08:00
1c965ab9ac Merge branch 'master' into dev 2020-10-19 12:04:21 +08:00
9db1dcc76a Merge pull request #370 from Shigma/patch-1
fix get_msg response payload
2020-10-18 23:52:22 +08:00
fffed72d44 Update api.go 2020-10-18 23:50:13 +08:00
dd5fdb0735 Merge pull request #367 from wdvxdr1123/dev
feature: support custom migu music
2020-10-18 23:07:03 +08:00
c35f46e033 update doc. 2020-10-18 22:40:41 +08:00
98b9be575e fix typo 2020-10-17 19:50:14 +08:00
b99986d112 feature: support custom migu misic 2020-10-17 19:46:24 +08:00
2302cf6263 Merge remote-tracking branch 'upstream/dev' into dev 2020-10-17 19:29:55 +08:00
10 changed files with 162 additions and 8 deletions

View File

@ -662,10 +662,19 @@ func (bot *CQBot) CQGetMessage(messageId int32) MSG {
"nickname": sender.Nickname,
},
"time": msg["time"],
"content": msg["message"],
"message": msg["message"],
})
}
func (bot *CQBot) CQGetGroupSystemMessages() MSG {
msg, err := bot.Client.GetGroupSystemMessages()
if err != nil {
log.Warnf("获取群系统消息失败: %v", err)
return Failed(100)
}
return OK(msg)
}
func (bot *CQBot) CQCanSendImage() MSG {
return OK(MSG{"yes": true})
}

View File

@ -190,8 +190,31 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
}
return bot.InsertGroupMessage(ret)
}
if i, ok := elem.(*MiguMusicElement); ok {
ret, err := bot.Client.SendGroupRichMessage(groupId, 1101053067, 1, 4, client.RichClientInfo{
Platform: 1,
SdkVersion: "0.0.0",
PackageName: "cmccwm.mobilemusic",
Signature: "6cdc72a439cef99a3418d2a78aa28c73",
}, &message.RichMessage{
Title: i.Title,
Summary: i.Summary,
Url: i.Url,
PictureUrl: i.PictureUrl,
MusicUrl: i.MusicUrl,
})
if err != nil {
log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err)
return -1
}
return bot.InsertGroupMessage(ret)
}
newElem = append(newElem, elem)
}
if len(newElem) == 0 {
log.Warnf("群消息发送失败: 消息为空.")
return -1
}
m.Elements = newElem
ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented)
if ret == nil || ret.Id == -1 {
@ -256,6 +279,21 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
})
return 0
}
if i, ok := elem.(*MiguMusicElement); ok {
bot.Client.SendFriendRichMessage(target, 1101053067, 1, 4, client.RichClientInfo{
Platform: 1,
SdkVersion: "0.0.0",
PackageName: "cmccwm.mobilemusic",
Signature: "6cdc72a439cef99a3418d2a78aa28c73",
}, &message.RichMessage{
Title: i.Title,
Summary: i.Summary,
Url: i.Url,
PictureUrl: i.PictureUrl,
MusicUrl: i.MusicUrl,
})
return 0
}
newElem = append(newElem, elem)
}
m.Elements = newElem

View File

@ -51,6 +51,10 @@ type CloudMusicElement struct {
MusicElement
}
type MiguMusicElement struct {
MusicElement
}
func (e *GiftElement) Type() message.ElementType {
return message.At
}
@ -320,7 +324,7 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
return
}
}
mid, err := strconv.Atoi(e.Get("data").Get("id").Str)
mid, err := strconv.Atoi(e.Get("data").Get("id").String())
if err == nil {
org := bot.GetMessage(int32(mid))
if org != nil {
@ -338,7 +342,7 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
}
d := make(map[string]string)
e.Get("data").ForEach(func(key, value gjson.Result) bool {
d[key.Str] = value.Str
d[key.Str] = value.String()
return true
})
elem, err := bot.ToElement(t, d, group)
@ -536,6 +540,15 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag
MusicUrl: d["purl"],
}}, nil
}
if d["subtype"] == "migu" {
return &MiguMusicElement{MusicElement{
Title: d["title"],
Summary: d["content"],
Url: d["url"],
PictureUrl: d["image"],
MusicUrl: d["purl"],
}}, nil
}
xml := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="%s" src="%s"/><title>%s</title><summary>%s</summary></item><source name="音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>`,
d["title"], d["url"], d["image"], d["audio"], d["title"], d["content"])
return &message.ServiceElement{

View File

@ -271,12 +271,16 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven
func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) {
f := c.FindFriend(e.FriendUin)
gid := ToGlobalId(e.FriendUin, e.MessageId)
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
if f != nil {
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
} else {
log.Infof("好友 %v 撤回了消息: %v", e.FriendUin, gid)
}
bot.dispatchEventMessage(MSG{
"post_type": "notice",
"notice_type": "friend_recall",
"self_id": c.Uin,
"user_id": f.Uin,
"user_id": e.FriendUin,
"time": e.Time,
"message_id": gid,
})

View File

@ -472,6 +472,74 @@ Type: `tts`
| ---------- | ----------------- | -------- |
| `slices` | string[] | 词组 |
### 图片OCR
> 注意: 目前图片OCR接口仅支持接受的图片
终结点: `/.ocr_image`
**参数**
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `image` | string | 图片ID |
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `texts` | TextDetection[] | OCR结果 |
| `language` | string | 语言 |
**TextDetection**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `text` | string | 文本 |
| `confidence`| int32 | 置信度 |
| `coordinates` | vector2 | 坐标 |
### 获取群系统消息
终结点: `/get_group_system_msg`
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `invited_requests` | InvitedRequest[] | 邀请消息列表 |
| `join_requests` | JoinRequest[] | 进群消息列表 |
> 注意: 如果列表不存在任何消息, 将返回 `null`
**InvitedRequest**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `request_id` | int64 | 请求ID |
| `invitor_uin` | int64 | 邀请者 |
| `invitor_nick` | string | 邀请者昵称 |
| `group_id` | int64 | 群号 |
| `group_name` | string | 群名 |
| `checked` | bool | 是否已被处理|
| `actor` | int64 | 处理者, 未处理为0 |
**JoinRequest**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `request_id` | int64 | 请求ID |
| `requester_uin` | int64 | 请求者ID |
| `requester_nick` | string | 请求者昵称 |
| `message` | string | 验证消息 |
| `group_id` | int64 | 群号 |
| `group_name` | string | 群名 |
| `checked` | bool | 是否已被处理|
| `actor` | int64 | 处理者, 未处理为0 |
## 事件
#### 群消息撤回

View File

@ -8,15 +8,20 @@ import (
"io/ioutil"
"net/http"
"strings"
"time"
)
var client = &http.Client{
Timeout: time.Second * 15,
}
func GetBytes(url string) ([]byte, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header["User-Agent"] = []string{"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61"}
resp, err := http.DefaultClient.Do(req)
resp, err := client.Do(req)
if err != nil {
return nil, err
}

4
go.mod
View File

@ -3,10 +3,10 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-20201017083749-517ddcd50b8d
github.com/Mrs4s/MiraiGo v0.0.0-20201025135955-5be0ad946177
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.2
github.com/guonaihong/gout v0.1.3
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lestrrat-go/strftime v1.0.3 // indirect
github.com/pkg/errors v0.9.1 // indirect

6
go.sum
View File

@ -6,6 +6,10 @@ github.com/Mrs4s/MiraiGo v0.0.0-20201016033322-0922b058ff56 h1:vcXOLG+W/c56EWOwA
github.com/Mrs4s/MiraiGo v0.0.0-20201016033322-0922b058ff56/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20201017083749-517ddcd50b8d h1:f59SuqT0RVy6T9nAg6zTNfnzkvdgLdGqkNKu/AfiPU4=
github.com/Mrs4s/MiraiGo v0.0.0-20201017083749-517ddcd50b8d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20201024092610-03d2bbf32a4d h1:g200Tv/mkCy6oSFqfOzblMfa3D50iNhyG7IUUQWkb78=
github.com/Mrs4s/MiraiGo v0.0.0-20201024092610-03d2bbf32a4d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20201025135955-5be0ad946177 h1:TcKqPWXKvOKW2O80rbswKYVLBB3Xas3+RvRInVMyBm8=
github.com/Mrs4s/MiraiGo v0.0.0-20201025135955-5be0ad946177/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=
@ -55,6 +59,8 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/guonaihong/gout v0.1.2 h1:TR2XCRopGgJdj231IayEoeavgbznFXzzzcZVdT/hG10=
github.com/guonaihong/gout v0.1.2/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
github.com/guonaihong/gout v0.1.3 h1:BIiV6nnsA+R6dIB1P33uhCM8+TVAG3zHrXGZad7hDc8=
github.com/guonaihong/gout v0.1.3/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=

View File

@ -137,6 +137,7 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
log.Warnf("上报Event数据 %v 到 %v 失败: %v", m.ToJson(), c.addr, err)
return
}
log.Debugf("上报Event数据 %v 到 %v", m.ToJson(), c.addr)
if gjson.Valid(res) {
c.bot.CQHandleQuickOperation(gjson.Parse(m.ToJson()), gjson.Parse(res))
}
@ -317,6 +318,10 @@ func (s *httpServer) GetForwardMessage(c *gin.Context) {
c.JSON(200, s.bot.CQGetForwardMessage(resId))
}
func (s *httpServer) GetGroupSystemMessage(c *gin.Context) {
c.JSON(200, s.bot.CQGetGroupSystemMessages())
}
func (s *httpServer) DeleteMessage(c *gin.Context) {
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))
@ -504,6 +509,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"get_msg": func(s *httpServer, c *gin.Context) {
s.GetMessage(c)
},
"get_group_system_msg": func(s *httpServer, c *gin.Context) {
s.GetGroupSystemMessage(c)
},
"get_group_honor_info": func(s *httpServer, c *gin.Context) {
s.GetGroupHonorInfo(c)
},

View File

@ -495,6 +495,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"get_version_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetVersionInfo()
},
"get_group_system_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupSystemMessages()
},
"_get_vip_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetVipInfo(p.Get("user_id").Int())
},