mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
feat: GuildChannelDestroyedEvent
This commit is contained in:
parent
c149f28fb8
commit
849be61d5a
@ -238,7 +238,7 @@ type (
|
|||||||
NewChannelInfo *ChannelInfo
|
NewChannelInfo *ChannelInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
GuildChannelCreatedEvent struct {
|
GuildChannelOperationEvent struct {
|
||||||
OperatorId uint64
|
OperatorId uint64
|
||||||
GuildId uint64
|
GuildId uint64
|
||||||
ChannelInfo *ChannelInfo
|
ChannelInfo *ChannelInfo
|
||||||
|
@ -17,7 +17,8 @@ type eventHandlers struct {
|
|||||||
guildChannelMessageHandlers []func(*QQClient, *message.GuildChannelMessage)
|
guildChannelMessageHandlers []func(*QQClient, *message.GuildChannelMessage)
|
||||||
guildMessageReactionsUpdatedHandlers []func(*QQClient, *GuildMessageReactionsUpdatedEvent)
|
guildMessageReactionsUpdatedHandlers []func(*QQClient, *GuildMessageReactionsUpdatedEvent)
|
||||||
guildChannelUpdatedHandlers []func(*QQClient, *GuildChannelUpdatedEvent)
|
guildChannelUpdatedHandlers []func(*QQClient, *GuildChannelUpdatedEvent)
|
||||||
guildChannelCreatedHandlers []func(*QQClient, *GuildChannelCreatedEvent)
|
guildChannelCreatedHandlers []func(*QQClient, *GuildChannelOperationEvent)
|
||||||
|
guildChannelDestroyedHandlers []func(*QQClient, *GuildChannelOperationEvent)
|
||||||
groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent)
|
groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent)
|
||||||
groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent)
|
groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent)
|
||||||
friendRecalledHandlers []func(*QQClient, *FriendMessageRecalledEvent)
|
friendRecalledHandlers []func(*QQClient, *FriendMessageRecalledEvent)
|
||||||
@ -84,10 +85,14 @@ func (s *GuildService) OnGuildChannelUpdated(f func(*QQClient, *GuildChannelUpda
|
|||||||
s.c.eventHandlers.guildChannelUpdatedHandlers = append(s.c.eventHandlers.guildChannelUpdatedHandlers, f)
|
s.c.eventHandlers.guildChannelUpdatedHandlers = append(s.c.eventHandlers.guildChannelUpdatedHandlers, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GuildService) OnGuildChannelCreated(f func(*QQClient, *GuildChannelCreatedEvent)) {
|
func (s *GuildService) OnGuildChannelCreated(f func(*QQClient, *GuildChannelOperationEvent)) {
|
||||||
s.c.eventHandlers.guildChannelCreatedHandlers = append(s.c.eventHandlers.guildChannelCreatedHandlers, f)
|
s.c.eventHandlers.guildChannelCreatedHandlers = append(s.c.eventHandlers.guildChannelCreatedHandlers, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GuildService) OnGuildChannelDestroyed(f func(*QQClient, *GuildChannelOperationEvent)) {
|
||||||
|
s.c.eventHandlers.guildChannelDestroyedHandlers = append(s.c.eventHandlers.guildChannelDestroyedHandlers, f)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *QQClient) OnGroupMuted(f func(*QQClient, *GroupMuteEvent)) {
|
func (c *QQClient) OnGroupMuted(f func(*QQClient, *GroupMuteEvent)) {
|
||||||
c.eventHandlers.groupMuteEventHandlers = append(c.eventHandlers.groupMuteEventHandlers, f)
|
c.eventHandlers.groupMuteEventHandlers = append(c.eventHandlers.groupMuteEventHandlers, f)
|
||||||
}
|
}
|
||||||
@ -283,7 +288,7 @@ func (c *QQClient) dispatchGuildChannelUpdatedEvent(e *GuildChannelUpdatedEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *QQClient) dispatchGuildChannelCreatedEvent(e *GuildChannelCreatedEvent) {
|
func (c *QQClient) dispatchGuildChannelCreatedEvent(e *GuildChannelOperationEvent) {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -294,6 +299,17 @@ func (c *QQClient) dispatchGuildChannelCreatedEvent(e *GuildChannelCreatedEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *QQClient) dispatchGuildChannelDestroyedEvent(e *GuildChannelOperationEvent) {
|
||||||
|
if e == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, f := range c.eventHandlers.guildChannelDestroyedHandlers {
|
||||||
|
cover(func() {
|
||||||
|
f(c, e)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *QQClient) dispatchGroupMuteEvent(e *GroupMuteEvent) {
|
func (c *QQClient) dispatchGroupMuteEvent(e *GroupMuteEvent) {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -153,6 +154,16 @@ func (g *GuildInfo) FindChannel(channelId uint64) *ChannelInfo {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GuildInfo) removeChannel(id uint64) {
|
||||||
|
i := sort.Search(len(g.Channels), func(i int) bool {
|
||||||
|
return g.Channels[i].ChannelId >= id
|
||||||
|
})
|
||||||
|
if i >= len(g.Channels) || g.Channels[i].ChannelId != id {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
g.Channels = append(g.Channels[:i], g.Channels[i+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *GuildService) GetUserProfile(tinyId uint64) (*GuildUserProfile, error) {
|
func (s *GuildService) GetUserProfile(tinyId uint64) (*GuildUserProfile, error) {
|
||||||
seq := s.c.nextSeq()
|
seq := s.c.nextSeq()
|
||||||
flags := binary.DynamicProtoMessage{}
|
flags := binary.DynamicProtoMessage{}
|
||||||
|
@ -77,13 +77,15 @@ func decodeGuildEventFlowPacket(c *QQClient, _ *incomingPacketInfo, payload []by
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *QQClient) processGuildEventBody(m *channel.ChannelMsgContent, eventBody *channel.EventBody) {
|
func (c *QQClient) processGuildEventBody(m *channel.ChannelMsgContent, eventBody *channel.EventBody) {
|
||||||
switch {
|
var guild *GuildInfo
|
||||||
case eventBody.CreateChan != nil:
|
if m.Head.RoutingHead.GetGuildId() != 0 {
|
||||||
guild := c.GuildService.FindGuild(m.Head.RoutingHead.GetGuildId())
|
if guild = c.GuildService.FindGuild(m.Head.RoutingHead.GetGuildId()); guild == nil {
|
||||||
if guild == nil {
|
c.Warning("process channel event error: guild not found.")
|
||||||
c.Warning("process create channel event error: guild not found.")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case eventBody.CreateChan != nil:
|
||||||
for _, chanId := range eventBody.CreateChan.CreateId {
|
for _, chanId := range eventBody.CreateChan.CreateId {
|
||||||
if guild.FindChannel(chanId.GetChanId()) != nil {
|
if guild.FindChannel(chanId.GetChanId()) != nil {
|
||||||
continue
|
continue
|
||||||
@ -94,16 +96,28 @@ func (c *QQClient) processGuildEventBody(m *channel.ChannelMsgContent, eventBody
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
guild.Channels = append(guild.Channels, channelInfo)
|
guild.Channels = append(guild.Channels, channelInfo)
|
||||||
c.dispatchGuildChannelCreatedEvent(&GuildChannelCreatedEvent{
|
c.dispatchGuildChannelCreatedEvent(&GuildChannelOperationEvent{
|
||||||
OperatorId: m.Head.RoutingHead.GetFromTinyid(),
|
OperatorId: m.Head.RoutingHead.GetFromTinyid(),
|
||||||
GuildId: m.Head.RoutingHead.GetGuildId(),
|
GuildId: m.Head.RoutingHead.GetGuildId(),
|
||||||
ChannelInfo: channelInfo,
|
ChannelInfo: channelInfo,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
case eventBody.DestroyChan != nil:
|
||||||
|
for _, chanId := range eventBody.DestroyChan.DeleteId {
|
||||||
|
channelInfo := guild.FindChannel(chanId.GetChanId())
|
||||||
|
if channelInfo == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
guild.removeChannel(chanId.GetChanId())
|
||||||
|
c.dispatchGuildChannelDestroyedEvent(&GuildChannelOperationEvent{
|
||||||
|
OperatorId: m.Head.RoutingHead.GetFromTinyid(),
|
||||||
|
GuildId: guild.GuildId,
|
||||||
|
ChannelInfo: channelInfo,
|
||||||
|
})
|
||||||
|
}
|
||||||
case eventBody.ChangeChanInfo != nil:
|
case eventBody.ChangeChanInfo != nil:
|
||||||
updateChanLock.Lock()
|
updateChanLock.Lock()
|
||||||
defer updateChanLock.Unlock()
|
defer updateChanLock.Unlock()
|
||||||
guild := c.GuildService.FindGuild(m.Head.RoutingHead.GetGuildId())
|
|
||||||
oldInfo := guild.FindChannel(eventBody.ChangeChanInfo.GetChanId())
|
oldInfo := guild.FindChannel(eventBody.ChangeChanInfo.GetChanId())
|
||||||
if time.Now().Unix()-oldInfo.fetchTime <= 2 {
|
if time.Now().Unix()-oldInfo.fetchTime <= 2 {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user