Skip to content

Commit

Permalink
feat: 临时会话和新增好友事件
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 28, 2024
1 parent 7fdb04c commit 7727819
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions coolq/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 客户端变更
Expand Down
52 changes: 24 additions & 28 deletions coolq/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 7727819

Please sign in to comment.