1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

feat: GuildMessageRecalledEvent

This commit is contained in:
Mrs4s 2021-12-13 01:34:54 +08:00
parent abe1fe7770
commit 06bc0bba17
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
3 changed files with 32 additions and 1 deletions

View File

@ -238,6 +238,14 @@ type (
NewChannelInfo *ChannelInfo
}
GuildMessageRecalledEvent struct {
OperatorId uint64
GuildId uint64
ChannelId uint64
MessageId uint64
RecallTime int64
}
GuildChannelOperationEvent struct {
OperatorId uint64
GuildId uint64

View File

@ -16,6 +16,7 @@ type eventHandlers struct {
selfGroupMessageHandlers []func(*QQClient, *message.GroupMessage)
guildChannelMessageHandlers []func(*QQClient, *message.GuildChannelMessage)
guildMessageReactionsUpdatedHandlers []func(*QQClient, *GuildMessageReactionsUpdatedEvent)
guildMessageRecalledHandlers []func(*QQClient, *GuildMessageRecalledEvent)
guildChannelUpdatedHandlers []func(*QQClient, *GuildChannelUpdatedEvent)
guildChannelCreatedHandlers []func(*QQClient, *GuildChannelOperationEvent)
guildChannelDestroyedHandlers []func(*QQClient, *GuildChannelOperationEvent)
@ -82,6 +83,10 @@ func (s *GuildService) OnGuildMessageReactionsUpdated(f func(*QQClient, *GuildMe
s.c.eventHandlers.guildMessageReactionsUpdatedHandlers = append(s.c.eventHandlers.guildMessageReactionsUpdatedHandlers, f)
}
func (s *GuildService) OnGuildMessageRecalled(f func(*QQClient, *GuildMessageRecalledEvent)) {
s.c.eventHandlers.guildMessageRecalledHandlers = append(s.c.eventHandlers.guildMessageRecalledHandlers, f)
}
func (s *GuildService) OnGuildChannelUpdated(f func(*QQClient, *GuildChannelUpdatedEvent)) {
s.c.eventHandlers.guildChannelUpdatedHandlers = append(s.c.eventHandlers.guildChannelUpdatedHandlers, f)
}
@ -282,6 +287,17 @@ func (c *QQClient) dispatchGuildMessageReactionsUpdatedEvent(e *GuildMessageReac
}
}
func (c *QQClient) dispatchGuildMessageRecalledEvent(e *GuildMessageRecalledEvent) {
if e == nil {
return
}
for _, f := range c.eventHandlers.guildMessageRecalledHandlers {
cover(func() {
f(c, e)
})
}
}
func (c *QQClient) dispatchGuildChannelUpdatedEvent(e *GuildChannelUpdatedEvent) {
if e == nil {
return

View File

@ -195,7 +195,14 @@ func (c *QQClient) processGuildEventBody(m *channel.ChannelMsgContent, eventBody
Member: info,
})
case eventBody.UpdateMsg != nil:
if eventBody.UpdateMsg.GetEventType() == 1 || eventBody.UpdateMsg.GetEventType() == 2 { // todo: 撤回消息
if eventBody.UpdateMsg.GetEventType() == 1 || eventBody.UpdateMsg.GetEventType() == 2 {
c.dispatchGuildMessageRecalledEvent(&GuildMessageRecalledEvent{
OperatorId: eventBody.UpdateMsg.GetOperatorTinyid(),
GuildId: m.Head.RoutingHead.GetGuildId(),
ChannelId: m.Head.RoutingHead.GetChannelId(),
MessageId: eventBody.UpdateMsg.GetMsgSeq(),
RecallTime: int64(m.Head.ContentHead.GetTime()),
})
return
}
if eventBody.UpdateMsg.GetEventType() == 4 { // 消息贴表情更新 (包含添加或删除)