From 7727819c92aeceb19162a078797e128d56eba573 Mon Sep 17 00:00:00 2001 From: Redmomn <109732988+Redmomn@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:32:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=B4=E6=97=B6=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=92=8C=E6=96=B0=E5=A2=9E=E5=A5=BD=E5=8F=8B=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/bot.go | 4 ++-- coolq/event.go | 52 +++++++++++++++++++++++--------------------------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 25f849165..2a26286b7 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -85,7 +85,7 @@ func NewQQBot(cli *client.QQClient) *CQBot { bot.Client.SelfPrivateMessageEvent.Subscribe(bot.privateMessageEvent) bot.Client.SelfGroupMessageEvent.Subscribe(bot.groupMessageEvent) } - //bot.Client.TempMessageEvent.Subscribe(bot.tempMessageEvent) + bot.Client.TempMessageEvent.Subscribe(bot.tempMessageEvent) bot.Client.GroupMuteEvent.Subscribe(bot.groupMutedEvent) bot.Client.GroupRecallEvent.Subscribe(bot.groupRecallEvent) bot.Client.GroupNotifyEvent.Subscribe(bot.groupNotifyEvent) @@ -103,7 +103,7 @@ func NewQQBot(cli *client.QQClient) *CQBot { //bot.Client.MemberCardUpdatedEvent.Subscribe(bot.memberCardUpdatedEvent) bot.Client.NewFriendRequestEvent.Subscribe(bot.friendRequestEvent) // TODO 成为好友 - //bot.Client.NewFriendEvent.Subscribe(bot.friendAddedEvent) + bot.Client.NewFriendEvent.Subscribe(bot.friendAddedEvent) bot.Client.GroupInvitedEvent.Subscribe(bot.groupInvitedEvent) bot.Client.GroupMemberJoinRequestEvent.Subscribe(bot.groupJoinReqEvent) // TODO 客户端变更 diff --git a/coolq/event.go b/coolq/event.go index 99045e3e3..6f7a8d0da 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -140,43 +140,41 @@ func (bot *CQBot) groupMessageEvent(_ *client.QQClient, m *message.GroupMessage) bot.dispatch(gm) } -// TODO 暂不支持临时会话 -/* -func (bot *CQBot) tempMessageEvent(_ *client.QQClient, e *client.TempMessageEvent) { - m := e.Message - bot.checkMedia(m.Elements, m.Sender.Uin) +func (bot *CQBot) tempMessageEvent(_ *client.QQClient, e *message.TempMessage) { source := message.Source{ SourceType: message.SourcePrivate, - PrimaryID: e.Session.Sender, - } - cqm := toStringMessage(m.Elements, source) - if base.AllowTempSession { - bot.tempSessionCache.Store(m.Sender.Uin, e.Session) + PrimaryID: int64(e.Sender.Uin), } + bot.checkMedia(e.Elements, source) + + cqm := toStringMessage(e.Elements, source) + //if base.AllowTempSession { + // bot.tempSessionCache.Store(e.Sender.Uin, e.Session) + //} - id := m.Id + id := e.ID // todo(Mrs4s) // if bot.db != nil { // nolint // id = bot.InsertTempMessage(m.Sender.Uin, m) // } - log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm) + log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", e.GroupName, e.GroupName, e.Sender.Nickname, e.Sender.Uin, cqm) tm := global.MSG{ - "temp_source": e.Session.Source, + //"temp_source": e.Session.Source, "message_id": id, - "user_id": m.Sender.Uin, - "message": ToFormattedMessage(m.Elements, source), + "user_id": e.Sender.Uin, + "message": ToFormattedMessage(e.Elements, source), "raw_message": cqm, "font": 0, "sender": global.MSG{ - "user_id": m.Sender.Uin, - "group_id": m.GroupCode, - "nickname": m.Sender.Nickname, + "user_id": e.Sender.Uin, + "group_id": e.GroupUin, + "nickname": e.Sender.Nickname, "sex": "unknown", "age": 0, }, } bot.dispatchEvent("message/private/group", tm) -}*/ +} func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *event2.GroupMute) { g := c.GetCachedGroupInfo(e.GroupUin) @@ -235,8 +233,6 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *event2.GroupRecall) { bot.dispatch(ev) } -//TODO 群通知 - func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e event2.INotifyEvent) { group := c.GetCachedGroupInfo(e.From()) // TODO more event @@ -413,13 +409,13 @@ func (bot *CQBot) friendRequestEvent(_ *client.QQClient, e *event2.NewFriendRequ }) } -//func (bot *CQBot) friendAddedEvent(_ *client.QQClient, e *client.NewFriendEvent) { -// log.Infof("添加了新好友: %v(%v)", e.Friend.Nickname, e.Friend.Uin) -// bot.tempSessionCache.Delete(e.Friend.Uin) -// bot.dispatchEvent("notice/friend_add", global.MSG{ -// "user_id": e.Friend.Uin, -// }) -//} +func (bot *CQBot) friendAddedEvent(_ *client.QQClient, e *event2.NewFriend) { + log.Infof("添加了新好友: %v(%v)", e.FromNick, e.FromUin) + //bot.tempSessionCache.Delete(e.Friend.Uin) + bot.dispatchEvent("notice/friend_add", global.MSG{ + "user_id": e.FromUin, + }) +} func (bot *CQBot) groupInvitedEvent(_ *client.QQClient, e *event2.GroupInvite) { log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupUin, e.InvitorNick, e.InvitorUin) diff --git a/go.mod b/go.mod index 2ac65d21b..17c20cfcb 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/FloatTech/sqlite v1.6.3 - github.com/LagrangeDev/LagrangeGo v0.1.2 + github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241128062531-bea32754985f github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 diff --git a/go.sum b/go.sum index 3a92f1a3d..aece5f857 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4 github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY= github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1 h1:g4pTnDJUW4VbJ9NvoRfUvdjDrHz/6QhfN/LoIIpICbo= github.com/FloatTech/ttl v0.0.0-20230307105452-d6f7b2b647d1/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= -github.com/LagrangeDev/LagrangeGo v0.1.2 h1:owH3gSZRTmW1qRuLsdkZsaBjyijKQUaJnLoui5XaTq0= -github.com/LagrangeDev/LagrangeGo v0.1.2/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA= +github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241128062531-bea32754985f h1:arXQxi9PrzbK3d2dw9xvRFkn9jMqqd0dwziwO24dMhg= +github.com/LagrangeDev/LagrangeGo v0.1.3-0.20241128062531-bea32754985f/go.mod h1:m7ydyvA8DKOg5c6iTFDfNtfIK9uhqXVJKRXl4mlGkTA= github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU= github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o= github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=