mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
feat: GuildChannelUpdatedEvent
This commit is contained in:
parent
e02a9ece6e
commit
e3411adb3d
@ -230,6 +230,14 @@ type (
|
||||
CurrentReactions []*message.GuildMessageEmojiReaction
|
||||
}
|
||||
|
||||
GuildChannelUpdatedEvent struct {
|
||||
OperatorId uint64
|
||||
GuildId uint64
|
||||
ChannelId uint64
|
||||
OldChannelInfo *ChannelInfo
|
||||
NewChannelInfo *ChannelInfo
|
||||
}
|
||||
|
||||
OcrResponse struct {
|
||||
Texts []*TextDetection `json:"texts"`
|
||||
Language string `json:"language"`
|
||||
|
@ -16,6 +16,7 @@ type eventHandlers struct {
|
||||
selfGroupMessageHandlers []func(*QQClient, *message.GroupMessage)
|
||||
guildChannelMessageHandlers []func(*QQClient, *message.GuildChannelMessage)
|
||||
guildMessageReactionsUpdatedHandlers []func(*QQClient, *GuildMessageReactionsUpdatedEvent)
|
||||
guildChannelUpdatedHandlers []func(*QQClient, *GuildChannelUpdatedEvent)
|
||||
groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent)
|
||||
groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent)
|
||||
friendRecalledHandlers []func(*QQClient, *FriendMessageRecalledEvent)
|
||||
@ -78,6 +79,10 @@ func (s *GuildService) OnGuildMessageReactionsUpdated(f func(*QQClient, *GuildMe
|
||||
s.c.eventHandlers.guildMessageReactionsUpdatedHandlers = append(s.c.eventHandlers.guildMessageReactionsUpdatedHandlers, f)
|
||||
}
|
||||
|
||||
func (s *GuildService) OnGuildChannelUpdated(f func(*QQClient, *GuildChannelUpdatedEvent)) {
|
||||
s.c.eventHandlers.guildChannelUpdatedHandlers = append(s.c.eventHandlers.guildChannelUpdatedHandlers, f)
|
||||
}
|
||||
|
||||
func (c *QQClient) OnGroupMuted(f func(*QQClient, *GroupMuteEvent)) {
|
||||
c.eventHandlers.groupMuteEventHandlers = append(c.eventHandlers.groupMuteEventHandlers, f)
|
||||
}
|
||||
@ -262,6 +267,17 @@ func (c *QQClient) dispatchGuildMessageReactionsUpdatedEvent(e *GuildMessageReac
|
||||
}
|
||||
}
|
||||
|
||||
func (c *QQClient) dispatchGuildChannelUpdatedEvent(e *GuildChannelUpdatedEvent) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
for _, f := range c.eventHandlers.guildChannelUpdatedHandlers {
|
||||
cover(func() {
|
||||
f(c, e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *QQClient) dispatchGroupMuteEvent(e *GroupMuteEvent) {
|
||||
if e == nil {
|
||||
return
|
||||
|
@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/channel"
|
||||
@ -76,6 +77,8 @@ type (
|
||||
ChannelType ChannelType
|
||||
AtAllSeq uint64
|
||||
Meta *ChannelMeta
|
||||
|
||||
fetchTime int64
|
||||
}
|
||||
|
||||
ChannelMeta struct {
|
||||
@ -381,6 +384,7 @@ func convertChannelInfo(info *channel.GuildChannelInfo) *ChannelInfo {
|
||||
NotifyType: uint32(info.GetFinalNotifyType()),
|
||||
ChannelType: ChannelType(info.GetChannelType()),
|
||||
Meta: meta,
|
||||
fetchTime: time.Now().Unix(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/channel"
|
||||
@ -14,6 +15,10 @@ func init() {
|
||||
decoders["MsgPush.PushGroupProMsg"] = decodeGuildEventFlowPacket
|
||||
}
|
||||
|
||||
var (
|
||||
updateChanLock sync.Mutex
|
||||
)
|
||||
|
||||
func decodeGuildEventFlowPacket(c *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) {
|
||||
push := new(channel.MsgOnlinePush)
|
||||
if err := proto.Unmarshal(payload, push); err != nil {
|
||||
@ -59,6 +64,34 @@ func decodeGuildEventFlowPacket(c *QQClient, _ *incomingPacketInfo, payload []by
|
||||
c.Error("failed to unmarshal guild channel event body: %v", err)
|
||||
continue
|
||||
}
|
||||
if eventBody.ChangeChanInfo != nil {
|
||||
updateChanLock.Lock()
|
||||
defer updateChanLock.Unlock()
|
||||
guild := c.GuildService.FindGuild(m.Head.RoutingHead.GetGuildId())
|
||||
oldInfo := guild.FindChannel(eventBody.ChangeChanInfo.GetChanId())
|
||||
if time.Now().Unix()-oldInfo.fetchTime <= 2 {
|
||||
continue
|
||||
}
|
||||
newInfo, err := c.GuildService.FetchChannelInfo(m.Head.RoutingHead.GetGuildId(), eventBody.ChangeChanInfo.GetChanId())
|
||||
if err != nil {
|
||||
c.Error("error to decode channel info updated event: fetch channel info failed: %v", err)
|
||||
continue
|
||||
}
|
||||
for i := range guild.Channels {
|
||||
if guild.Channels[i].ChannelId == newInfo.ChannelId {
|
||||
guild.Channels[i] = newInfo
|
||||
break
|
||||
}
|
||||
}
|
||||
c.dispatchGuildChannelUpdatedEvent(&GuildChannelUpdatedEvent{
|
||||
OperatorId: m.Head.RoutingHead.GetFromTinyid(),
|
||||
GuildId: m.Head.RoutingHead.GetGuildId(),
|
||||
ChannelId: eventBody.ChangeChanInfo.GetChanId(),
|
||||
OldChannelInfo: oldInfo,
|
||||
NewChannelInfo: newInfo,
|
||||
})
|
||||
continue
|
||||
}
|
||||
if eventBody.UpdateMsg != nil {
|
||||
if eventBody.UpdateMsg.GetEventType() == 1 || eventBody.UpdateMsg.GetEventType() == 2 { // todo: 撤回消息
|
||||
continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user