From 6101c4d8a95ce6ca424203918f2b1ca7e5e4fbc0 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 20:16:01 +0800 Subject: [PATCH 01/18] add: honor changed event. --- coolq/event.go | 23 +++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/coolq/event.go b/coolq/event.go index a7fa0fa..63b1f07 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -238,6 +238,29 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven "lucky_king_id": notify.LuckyKing, "time": time.Now().Unix(), }) + case *client.MemberHonorChangedNotifyEvent: + log.Info(notify.Content()) + bot.dispatchEventMessage(MSG{ + "post_type": "notice", + "group_id": group.Code, + "notice_type": "notify", + "notify_type": "honor", + "self_id": c.Uin, + "user_id": notify.Uin, + "time": time.Now().Unix(), + "honor_type": func() string { + switch notify.Honor { + case client.Talkative: + return "talkative" + case client.Performer: + return "performer" + case client.Emotion: + return "emotion" + default: + return "ERROR" + } + }(), + }) } } diff --git a/go.mod b/go.mod index 56ddcdf..8fa039b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200912123655-d92d61c5998e + github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect diff --git a/go.sum b/go.sum index cb98193..2e7ce8b 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Mrs4s/MiraiGo v0.0.0-20200912123655-d92d61c5998e h1:wiaXXMPnYCfA+rX1wy9SNrDyW3O43wfun5dIYKKK3BI= -github.com/Mrs4s/MiraiGo v0.0.0-20200912123655-d92d61c5998e/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= +github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09 h1:zTe9IBmO+z6icSwjT2PgI9aMIIwlfWc00cFEz2+j9rc= +github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09/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= From 6f251e3decabafa6c23a69ec28a7434af3c85706 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 20:51:57 +0800 Subject: [PATCH 02/18] fix typo. --- coolq/api.go | 12 ++++++++++++ coolq/event.go | 24 ++++++++++++------------ docs/cqhttp.md | 22 ++++++++++++++++++---- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 486c069..258d923 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -655,6 +655,18 @@ func (bot *CQBot) CQGetVersionInfo() MSG { "runtime_version": runtime.Version(), "runtime_os": runtime.GOOS, "version": Version, + "protocol": func() int { + switch client.SystemDeviceInfo.Protocol { + case client.AndroidPad: + return 0 + case client.AndroidPhone: + return 1 + case client.AndroidWatch: + return 2 + default: + return -1 + } + }(), }) } diff --git a/coolq/event.go b/coolq/event.go index 63b1f07..d03a8a4 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -216,11 +216,11 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven "post_type": "notice", "group_id": group.Code, "notice_type": "notify", - "notify_type": "poke", + "sub_type": "poke", "self_id": c.Uin, "user_id": notify.Sender, "sender_id": notify.Sender, - "receiver_id": notify.Receiver, + "target_id": notify.Receiver, "time": time.Now().Unix(), }) case *client.GroupRedBagLuckyKingNotifyEvent: @@ -228,15 +228,15 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven luckyKing := group.FindMember(notify.LuckyKing) log.Infof("群 %v 内 %v 的红包被抢完, %v 是运气王", formatGroupName(group), formatMemberName(sender), formatMemberName(luckyKing)) bot.dispatchEventMessage(MSG{ - "post_type": "notice", - "group_id": group.Code, - "notice_type": "notify", - "notify_type": "lucky_king", - "self_id": c.Uin, - "user_id": notify.Sender, - "sender_id": notify.Sender, - "lucky_king_id": notify.LuckyKing, - "time": time.Now().Unix(), + "post_type": "notice", + "group_id": group.Code, + "notice_type": "notify", + "sub_type": "lucky_king", + "self_id": c.Uin, + "user_id": notify.Sender, + "sender_id": notify.Sender, + "target_id": notify.LuckyKing, + "time": time.Now().Unix(), }) case *client.MemberHonorChangedNotifyEvent: log.Info(notify.Content()) @@ -244,7 +244,7 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven "post_type": "notice", "group_id": group.Code, "notice_type": "notify", - "notify_type": "honor", + "sub_type": "honor", "self_id": c.Uin, "user_id": notify.Uin, "time": time.Now().Unix(), diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 3ef1681..7ce7a33 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -386,9 +386,9 @@ Type: `cardimage` | ------------- | ------ | -------------- | -------------- | | `post_type` | string | `notice` | 上报类型 | | `notice_type` | string | `notify` | 消息类型 | -| `notify_type` | string | `poke` | 提示类型 | +| `sub_type` | string | `poke` | 提示类型 | | `user_id` | int64 | | 发送者id | -| `receiver_id` | int64 | | 被戳者id | +| `target_id` | int64 | | 被戳者id | #### 群红包运气王提示 @@ -400,6 +400,20 @@ Type: `cardimage` | ------------- | ------ | -------------- | -------------- | | `post_type` | string | `notice` | 上报类型 | | `notice_type` | string | `notify` | 消息类型 | -| `notify_type` | string | `lucky_king` | 提示类型 | +| `sub_type` | string | `lucky_king` | 提示类型 | | `user_id` | int64 | | 红包发送者id | -| `lucky_king_id` | int64 | | 运气王id | +| `target_id` | int64 | | 运气王id | + +#### 群成员荣誉变更提示 + +> 注意:此事件无法在平板和手表协议上触发 + +**上报数据** + +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | -------------- | -------------- | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `notify` | 消息类型 | +| `sub_type` | string | `honor` | 提示类型 | +| `user_id` | int64 | | 成员id | +| `honor_type` | int64 | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | \ No newline at end of file From a4c6c6d7f31b36cc2b0f2b7672e8111ba3dba002 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 20:53:44 +0800 Subject: [PATCH 03/18] fix typo. --- docs/cqhttp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 7ce7a33..2ca2809 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -416,4 +416,4 @@ Type: `cardimage` | `notice_type` | string | `notify` | 消息类型 | | `sub_type` | string | `honor` | 提示类型 | | `user_id` | int64 | | 成员id | -| `honor_type` | int64 | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | \ No newline at end of file +| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | \ No newline at end of file From 69cadad155ae97e52fb95ed91e636ce8d3f28b53 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 20:56:15 +0800 Subject: [PATCH 04/18] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f39931..f7aef0b 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ | [群消息](https://cqhttp.cc/docs/4.15/#/Post?id=群消息) | | [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) | | [好友消息撤回(拓展Event)](docs/cqhttp.md#好友消息撤回) | -| 群内提示事件(拓展Event)(docs/cqhttp.md#群内戳一戳) | +| [群内提示事件(拓展Event)(龙王等事件)](docs/cqhttp.md#群内戳一戳) | | [群管理员变动](https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动) | | [群成员减少](https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少) | | [群成员增加](https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加) | From 2005cbccb07684631a3a951d0ed010a376becf3c Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 20:58:41 +0800 Subject: [PATCH 05/18] fix #276. --- coolq/cqcode.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 670a5df..b67674a 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -50,6 +50,8 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M "type": "text", "data": map[string]string{"text": o.Content}, } + case *message.ReplyElement: + continue case *message.LightAppElement: //m = MSG{ // "type": "text", From 50bfc08974e43ef3762ed0aa347702f18f425a8a Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 21:02:04 +0800 Subject: [PATCH 06/18] fix typo. --- docs/cqhttp.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 2ca2809..56bef0b 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -386,6 +386,7 @@ Type: `cardimage` | ------------- | ------ | -------------- | -------------- | | `post_type` | string | `notice` | 上报类型 | | `notice_type` | string | `notify` | 消息类型 | +| `group_id` | int64 | | 群号 | | `sub_type` | string | `poke` | 提示类型 | | `user_id` | int64 | | 发送者id | | `target_id` | int64 | | 被戳者id | @@ -400,6 +401,7 @@ Type: `cardimage` | ------------- | ------ | -------------- | -------------- | | `post_type` | string | `notice` | 上报类型 | | `notice_type` | string | `notify` | 消息类型 | +| `group_id` | int64 | | 群号 | | `sub_type` | string | `lucky_king` | 提示类型 | | `user_id` | int64 | | 红包发送者id | | `target_id` | int64 | | 运气王id | @@ -414,6 +416,7 @@ Type: `cardimage` | ------------- | ------ | -------------- | -------------- | | `post_type` | string | `notice` | 上报类型 | | `notice_type` | string | `notify` | 消息类型 | +| `group_id` | int64 | | 群号 | | `sub_type` | string | `honor` | 提示类型 | | `user_id` | int64 | | 成员id | | `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | \ No newline at end of file From fef9395890653c1a655969dc5fd3a492523b8855 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 21:33:01 +0800 Subject: [PATCH 07/18] update MiraiGo. --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8fa039b..4586aed 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09 + github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect diff --git a/go.sum b/go.sum index 2e7ce8b..5120903 100644 --- a/go.sum +++ b/go.sum @@ -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-20200913112343-ad5531c3db09 h1:zTe9IBmO+z6icSwjT2PgI9aMIIwlfWc00cFEz2+j9rc= github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= +github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2 h1:otRnJmFOuRfK2ts5x6eOqc/vTIhUN4IYKcldjhN/IQY= +github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2/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= From 741a91cf7065f4456aab2c7a539c244ad2d8995b Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 22:07:45 +0800 Subject: [PATCH 08/18] add: poke sending. --- coolq/bot.go | 8 ++++++++ coolq/cqcode.go | 14 ++++++++++++++ docs/cqhttp.md | 14 ++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/coolq/bot.go b/coolq/bot.go index 3083d13..dda64e9 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -139,6 +139,14 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int newElem = append(newElem, gv) continue } + if i, ok := elem.(*PokeElement); ok { + if group := bot.Client.FindGroup(groupId); group != nil { + if mem := group.FindMember(i.Target); mem != nil { + mem.Poke() + return 0 + } + } + } newElem = append(newElem, elem) } m.Elements = newElem diff --git a/coolq/cqcode.go b/coolq/cqcode.go index b67674a..c5a74f2 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -26,6 +26,14 @@ var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`) var IgnoreInvalidCQCode = false +type PokeElement struct { + Target int64 +} + +func (e *PokeElement) Type() message.ElementType { + return message.At +} + func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []MSG) { ur := false if len(raw) != 0 { @@ -319,6 +327,12 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. return message.NewText(d["text"]), nil case "image": return bot.makeImageElem(t, d, group) + case "poke": + if !group { + return nil, errors.New("todo") // TODO: private poke + } + t, _ := strconv.ParseInt(d["qq"], 10, 64) + return &PokeElement{Target: t}, nil case "record": if !group { return nil, errors.New("private voice unsupported now") diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 56bef0b..3b5a995 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -32,6 +32,20 @@ Type: `redbag` 示例: `[CQ:redbag,title=恭喜发财]` +### 戳一戳 + +Type: `poke` + +范围: **发送(仅群聊)** + +参数: + +| 参数名 | 类型 | 说明 | +| ------ | ------ | ----------- | +| qq | int64 | 需要戳的成员 | + +示例: `[CQ:poke,qq=123456]` + ### 合并转发 Type: `forward` From 1d1925208b9e9668f83a87232e068b46c32a6e8c Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 13 Sep 2020 22:11:28 +0800 Subject: [PATCH 09/18] update doc. --- docs/cqhttp.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 3b5a995..3b8fec4 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -34,6 +34,8 @@ Type: `redbag` ### 戳一戳 +> 注意:发送戳一戳消息无法撤回,返回的 `message id` 恒定为 `0` + Type: `poke` 范围: **发送(仅群聊)** From c4e54446c5746b9665eccb7a8da6ed646a4a6f75 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Thu, 17 Sep 2020 08:48:09 +0800 Subject: [PATCH 10/18] update MiraiGo. fix #283 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 4586aed..8030313 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2 + github.com/Mrs4s/MiraiGo v0.0.0-20200915071055-1607cdf2bff8 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect diff --git a/go.sum b/go.sum index 5120903..8d71051 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09 h1:zTe9IBmO+z6icSwjT github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2 h1:otRnJmFOuRfK2ts5x6eOqc/vTIhUN4IYKcldjhN/IQY= github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= +github.com/Mrs4s/MiraiGo v0.0.0-20200915071055-1607cdf2bff8 h1:plwKkvIVzntjTS5tz96Hf+46Hxaf0Bv/Pp9nIADD/i4= +github.com/Mrs4s/MiraiGo v0.0.0-20200915071055-1607cdf2bff8/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= From d67621487d25e17735746c51bf88f297f107a97e Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sat, 19 Sep 2020 16:46:19 +0800 Subject: [PATCH 11/18] update MiraiGo. fix #278 --- go.mod | 2 +- go.sum | 8 ++------ main.go | 12 +++++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 8030313..024148e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200915071055-1607cdf2bff8 + github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect diff --git a/go.sum b/go.sum index 8d71051..6776956 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09 h1:zTe9IBmO+z6icSwjT2PgI9aMIIwlfWc00cFEz2+j9rc= -github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= -github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2 h1:otRnJmFOuRfK2ts5x6eOqc/vTIhUN4IYKcldjhN/IQY= -github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= -github.com/Mrs4s/MiraiGo v0.0.0-20200915071055-1607cdf2bff8 h1:plwKkvIVzntjTS5tz96Hf+46Hxaf0Bv/Pp9nIADD/i4= -github.com/Mrs4s/MiraiGo v0.0.0-20200915071055-1607cdf2bff8/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= +github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tvkTB9bPc0DiOErCNN+wWXUMyvX0= +github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/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= diff --git a/main.go b/main.go index 71344e7..b116fef 100644 --- a/main.go +++ b/main.go @@ -237,7 +237,7 @@ func main() { } }) cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) { - log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 服务器地址: %v:%v 服务器位置: %v", e.Servers[0].Server, e.Servers[0].Port, e.Servers[0].Location) + log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 地址信息已储存到 servers.bin 文件") _ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) { w.WriteUInt16(uint16(len(e.Servers))) for _, s := range e.Servers { @@ -251,10 +251,12 @@ func main() { if global.PathExists("servers.bin") { if data, err := ioutil.ReadFile("servers.bin"); err == nil { r := binary.NewReader(data) - r.ReadUInt16() - cli.CustomServer = &net.TCPAddr{ - IP: net.ParseIP(r.ReadString()), - Port: int(r.ReadUInt16()), + var addr []*net.TCPAddr + for i := 0; i < int(r.ReadUInt16()); i++ { + addr = append(addr, &net.TCPAddr{ + IP: net.ParseIP(r.ReadString()), + Port: int(r.ReadUInt16()), + }) } } } From ea65e545add6e6a46eff4d8dcff99285b9ebca39 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sat, 19 Sep 2020 17:02:21 +0800 Subject: [PATCH 12/18] supported: get_stranger_info. --- coolq/api.go | 21 +++++++++++++++++++++ server/http.go | 8 ++++++++ server/websocket.go | 3 +++ 3 files changed, 32 insertions(+) diff --git a/coolq/api.go b/coolq/api.go index 258d923..83bfc97 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -497,6 +497,27 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG { return OK(msg) } +// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF +func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG { + info, err := bot.Client.GetSummaryInfo(userId) + if err != nil { + return Failed(100) + } + return OK(MSG{ + "user_id": info.Uin, + "nickname": info.Nickname, + "sex": func() string { + if info.Sex == 1 { + return "female" + } + return "male" + }(), + "age": info.Age, + "level": info.Level, + "login_days": info.LoginDays, + }) +} + // https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C // https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376 func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG { diff --git a/server/http.go b/server/http.go index 9b10904..afd2685 100644 --- a/server/http.go +++ b/server/http.go @@ -333,6 +333,11 @@ func (s *httpServer) GetVipInfo(c *gin.Context) { c.JSON(200, s.bot.CQGetVipInfo(uid)) } +func (s *httpServer) GetStrangerInfo(c *gin.Context) { + uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64) + c.JSON(200, s.bot.CQGetStrangerInfo(uid)) +} + func (s *httpServer) HandleQuickOperation(c *gin.Context) { if c.Request.Method != "POST" { c.AbortWithStatus(404) @@ -486,6 +491,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){ "_get_vip_info": func(s *httpServer, c *gin.Context) { s.GetVipInfo(c) }, + "get_stranger_info": func(s *httpServer, c *gin.Context) { + s.GetStrangerInfo(c) + }, "reload_event_filter": func(s *httpServer, c *gin.Context) { s.ReloadEventFilter(c) }, diff --git a/server/websocket.go b/server/websocket.go index ecad98a..5b43395 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -486,6 +486,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ "can_send_record": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQCanSendRecord() }, + "get_stranger_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { + return bot.CQGetStrangerInfo(p.Get("user_id").Int()) + }, "get_status": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQGetStatus() }, From 4662f1e1709bf4c2ba2419869d27fd6922587eea Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sat, 19 Sep 2020 23:37:40 +0800 Subject: [PATCH 13/18] update MiraiGo. fix #288 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 024148e..cdc0925 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d + github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect diff --git a/go.sum b/go.sum index 6776956..17e3745 100644 --- a/go.sum +++ b/go.sum @@ -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-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tvkTB9bPc0DiOErCNN+wWXUMyvX0= github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= +github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d h1:nGJSE9xQBeDiugBKKX0vUOq51MqlUEm/y2FMfZFH/w4= +github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d/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= From b5b6117487bf8dfebd6316cd260f109a034097f0 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 20 Sep 2020 00:00:53 +0800 Subject: [PATCH 14/18] fix server. --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b116fef..09a790e 100644 --- a/main.go +++ b/main.go @@ -252,12 +252,16 @@ func main() { if data, err := ioutil.ReadFile("servers.bin"); err == nil { r := binary.NewReader(data) var addr []*net.TCPAddr - for i := 0; i < int(r.ReadUInt16()); i++ { + l := r.ReadUInt16() + for i := 0; i < int(l); i++ { addr = append(addr, &net.TCPAddr{ IP: net.ParseIP(r.ReadString()), Port: int(r.ReadUInt16()), }) } + if len(addr) > 0 { + cli.SetCustomServer(addr) + } } } rsp, err := cli.Login() From c31169b99b310b229e719969844a1fb6e85b809e Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sun, 20 Sep 2020 00:29:50 +0800 Subject: [PATCH 15/18] fix #298. --- main.go | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 09a790e..75207f6 100644 --- a/main.go +++ b/main.go @@ -239,7 +239,14 @@ func main() { cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) { log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 地址信息已储存到 servers.bin 文件") _ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) { - w.WriteUInt16(uint16(len(e.Servers))) + w.WriteUInt16(func() (c uint16) { + for _, s := range e.Servers { + if !strings.Contains(s.Server, "com") { + c++ + } + } + return + }()) for _, s := range e.Servers { if !strings.Contains(s.Server, "com") { w.WriteString(s.Server) @@ -250,18 +257,25 @@ func main() { }) if global.PathExists("servers.bin") { if data, err := ioutil.ReadFile("servers.bin"); err == nil { - r := binary.NewReader(data) - var addr []*net.TCPAddr - l := r.ReadUInt16() - for i := 0; i < int(l); i++ { - addr = append(addr, &net.TCPAddr{ - IP: net.ParseIP(r.ReadString()), - Port: int(r.ReadUInt16()), - }) - } - if len(addr) > 0 { - cli.SetCustomServer(addr) - } + func() { + defer func() { + if pan := recover(); pan != nil { + log.Error("读取服务器地址时出现错误: %v", pan) + } + }() + r := binary.NewReader(data) + var addr []*net.TCPAddr + l := r.ReadUInt16() + for i := 0; i < int(l); i++ { + addr = append(addr, &net.TCPAddr{ + IP: net.ParseIP(r.ReadString()), + Port: int(r.ReadUInt16()), + }) + } + if len(addr) > 0 { + cli.SetCustomServer(addr) + } + }() } } rsp, err := cli.Login() From 01dd760b5c9b4445793a9f75244b183c3357b956 Mon Sep 17 00:00:00 2001 From: NovaNoir <68760718+the-25th-Nova@users.noreply.github.com> Date: Sun, 20 Sep 2020 11:58:37 +0800 Subject: [PATCH 16/18] Fix Markdown --- docs/cqhttp.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 3b8fec4..5614553 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -164,9 +164,9 @@ Type: `xml` 示例: `[CQ:xml,data=xxxx]` -####一些xml样例 +#### 一些xml样例 -####ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中 +#### ps:重要:xml中的value部分,记得html实体化处理后,再打加入到cq码中 #### qq音乐 @@ -435,4 +435,4 @@ Type: `cardimage` | `group_id` | int64 | | 群号 | | `sub_type` | string | `honor` | 提示类型 | | `user_id` | int64 | | 成员id | -| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | \ No newline at end of file +| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | From 387d33a01b4d7727b0e55188986c06dc03429767 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Mon, 21 Sep 2020 21:55:54 +0800 Subject: [PATCH 17/18] update MiraiGo. fix #307 #306 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index cdc0925..92b5dd3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d + github.com/Mrs4s/MiraiGo v0.0.0-20200921134646-b16719557421 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect diff --git a/go.sum b/go.sum index 17e3745..65fbc4c 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tv github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d h1:nGJSE9xQBeDiugBKKX0vUOq51MqlUEm/y2FMfZFH/w4= github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= +github.com/Mrs4s/MiraiGo v0.0.0-20200921134646-b16719557421 h1:64KSlIHas2kUc6wc1N5QnkBrUAQpW78f++sqZOe1zAk= +github.com/Mrs4s/MiraiGo v0.0.0-20200921134646-b16719557421/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= From 72d62ad7c33102bb68156b775cdca60b1abb28aa Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Mon, 21 Sep 2020 22:28:34 +0800 Subject: [PATCH 18/18] update MiraiGo. --- coolq/api.go | 14 ++++++++++++++ go.mod | 2 +- go.sum | 8 ++------ server/http.go | 8 ++++++++ server/websocket.go | 3 +++ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 83bfc97..dedaadd 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -648,6 +648,20 @@ func (bot *CQBot) CQCanSendRecord() MSG { return OK(MSG{"yes": true}) } +func (bot *CQBot) CQOcrImage(imageId string) MSG { + img, err := bot.makeImageElem("image", map[string]string{"file": imageId}, true) + if err != nil { + log.Warnf("load image error: %v", err) + return Failed(100) + } + rsp, err := bot.Client.ImageOcr(img) + if err != nil { + log.Warnf("ocr image error: %v", err) + return Failed(100) + } + return OK(rsp) +} + func (bot *CQBot) CQReloadEventFilter() MSG { global.BootFilter() return OK(nil) diff --git a/go.mod b/go.mod index 92b5dd3..8a9524b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200921134646-b16719557421 + github.com/Mrs4s/MiraiGo v0.0.0-20200921142226-9a449519db5c github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect diff --git a/go.sum b/go.sum index 65fbc4c..37daeee 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tvkTB9bPc0DiOErCNN+wWXUMyvX0= -github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= -github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d h1:nGJSE9xQBeDiugBKKX0vUOq51MqlUEm/y2FMfZFH/w4= -github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= -github.com/Mrs4s/MiraiGo v0.0.0-20200921134646-b16719557421 h1:64KSlIHas2kUc6wc1N5QnkBrUAQpW78f++sqZOe1zAk= -github.com/Mrs4s/MiraiGo v0.0.0-20200921134646-b16719557421/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= +github.com/Mrs4s/MiraiGo v0.0.0-20200921142226-9a449519db5c h1:TpGiSjI8Pe0YLEQPAVkOV37OFLeJnQ6jxvcDSb/LESY= +github.com/Mrs4s/MiraiGo v0.0.0-20200921142226-9a449519db5c/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= diff --git a/server/http.go b/server/http.go index afd2685..743c040 100644 --- a/server/http.go +++ b/server/http.go @@ -349,6 +349,11 @@ func (s *httpServer) HandleQuickOperation(c *gin.Context) { } } +func (s *httpServer) OcrImage(c *gin.Context) { + img := getParam(c, "image") + c.JSON(200, s.bot.CQOcrImage(img)) +} + func getParamOrDefault(c *gin.Context, k, def string) string { r := getParam(c, k) if r != "" { @@ -500,4 +505,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){ ".handle_quick_operation": func(s *httpServer, c *gin.Context) { s.HandleQuickOperation(c) }, + ".ocr_image": func(s *httpServer, c *gin.Context) { + s.OcrImage(c) + }, } diff --git a/server/websocket.go b/server/websocket.go index 5b43395..3a28559 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -501,6 +501,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ "reload_event_filter": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQReloadEventFilter() }, + ".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { + return bot.CQOcrImage(p.Get("image").Str) + }, ".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation")) },