From b8ec05e1c1c89403eb3bc5a8429c566ac4d0337c Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Sat, 14 Nov 2020 19:03:36 +0800 Subject: [PATCH] feature private poke. --- coolq/bot.go | 5 +++++ coolq/cqcode.go | 3 --- coolq/event.go | 20 +++++++++++++++++++- go.mod | 2 +- go.sum | 6 ++++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 628c41e..1262b07 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -56,6 +56,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot { bot.Client.OnGroupMuted(bot.groupMutedEvent) bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent) bot.Client.OnGroupNotify(bot.groupNotifyEvent) + bot.Client.OnFriendNotify(bot.friendNotifyEvent) bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent) bot.Client.OnReceivedOfflineFile(bot.offlineFileEvent) bot.Client.OnJoinGroup(bot.joinGroupEvent) @@ -235,6 +236,10 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in newElem = append(newElem, fm) continue } + if i, ok := elem.(*PokeElement); ok { + bot.Client.SendFriendPoke(i.Target) + return 0 + } if i, ok := elem.(*message.VoiceElement); ok { fv, err := bot.Client.UploadPrivatePtt(target, i.Data) if err != nil { diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 631a229..b78b9c8 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -434,9 +434,6 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf } 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 "gift": diff --git a/coolq/event.go b/coolq/event.go index 7512d80..9d2e300 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -220,7 +220,7 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec }) } -func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEvent) { +func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) { group := c.FindGroup(e.From()) switch notify := e.(type) { case *client.GroupPokeNotifyEvent: @@ -279,6 +279,24 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven } } +func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e client.INotifyEvent) { + friend := c.FindFriend(e.From()) + switch notify := e.(type) { + case *client.FriendPokeNotifyEvent: + log.Infof("好友 %v 戳了戳你.", friend.Nickname) + bot.dispatchEventMessage(MSG{ + "post_type": "notice", + "notice_type": "notify", + "sub_type": "poke", + "self_id": c.Uin, + "user_id": notify.Sender, + "sender_id": notify.Sender, + "target_id": notify.Receiver, + "time": time.Now().Unix(), + }) + } +} + func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) { f := c.FindFriend(e.FriendUin) gid := ToGlobalId(e.FriendUin, e.MessageId) diff --git a/go.mod b/go.mod index 00629da..af63556 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-20201114071121-b813765774d7 + github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9 github.com/dustin/go-humanize v1.0.0 github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect diff --git a/go.sum b/go.sum index 910b372..dc1215a 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,9 @@ 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-20201114071121-b813765774d7 h1:/vnL6vhst5buzs7YwVxEZe6NuZDdayb/e7gEZ5n+YWg= -github.com/Mrs4s/MiraiGo v0.0.0-20201114071121-b813765774d7/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= +github.com/Mrs4s/MiraiGo v0.0.0-20201114105236-1ea9f982fee4 h1:0qoqKkSLTnWBS2rZm95ey9YYbCo4sujO4Kk2frw27yY= +github.com/Mrs4s/MiraiGo v0.0.0-20201114105236-1ea9f982fee4/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= +github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9 h1:evnR9D9rXcBTUzioFf7XlXX4KbZBhc0/Urp09yV01dc= +github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= 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=