1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

feat: GuildChannelCreatedEvent

This commit is contained in:
Mrs4s 2021-11-14 04:33:02 +08:00
parent d3a21e577b
commit c149f28fb8
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
3 changed files with 44 additions and 0 deletions

View File

@ -238,6 +238,12 @@ type (
NewChannelInfo *ChannelInfo
}
GuildChannelCreatedEvent struct {
OperatorId uint64
GuildId uint64
ChannelInfo *ChannelInfo
}
OcrResponse struct {
Texts []*TextDetection `json:"texts"`
Language string `json:"language"`

View File

@ -17,6 +17,7 @@ type eventHandlers struct {
guildChannelMessageHandlers []func(*QQClient, *message.GuildChannelMessage)
guildMessageReactionsUpdatedHandlers []func(*QQClient, *GuildMessageReactionsUpdatedEvent)
guildChannelUpdatedHandlers []func(*QQClient, *GuildChannelUpdatedEvent)
guildChannelCreatedHandlers []func(*QQClient, *GuildChannelCreatedEvent)
groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent)
groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent)
friendRecalledHandlers []func(*QQClient, *FriendMessageRecalledEvent)
@ -83,6 +84,10 @@ func (s *GuildService) OnGuildChannelUpdated(f func(*QQClient, *GuildChannelUpda
s.c.eventHandlers.guildChannelUpdatedHandlers = append(s.c.eventHandlers.guildChannelUpdatedHandlers, f)
}
func (s *GuildService) OnGuildChannelCreated(f func(*QQClient, *GuildChannelCreatedEvent)) {
s.c.eventHandlers.guildChannelCreatedHandlers = append(s.c.eventHandlers.guildChannelCreatedHandlers, f)
}
func (c *QQClient) OnGroupMuted(f func(*QQClient, *GroupMuteEvent)) {
c.eventHandlers.groupMuteEventHandlers = append(c.eventHandlers.groupMuteEventHandlers, f)
}
@ -278,6 +283,17 @@ func (c *QQClient) dispatchGuildChannelUpdatedEvent(e *GuildChannelUpdatedEvent)
}
}
func (c *QQClient) dispatchGuildChannelCreatedEvent(e *GuildChannelCreatedEvent) {
if e == nil {
return
}
for _, f := range c.eventHandlers.guildChannelCreatedHandlers {
cover(func() {
f(c, e)
})
}
}
func (c *QQClient) dispatchGroupMuteEvent(e *GroupMuteEvent) {
if e == nil {
return

View File

@ -78,6 +78,28 @@ func decodeGuildEventFlowPacket(c *QQClient, _ *incomingPacketInfo, payload []by
func (c *QQClient) processGuildEventBody(m *channel.ChannelMsgContent, eventBody *channel.EventBody) {
switch {
case eventBody.CreateChan != nil:
guild := c.GuildService.FindGuild(m.Head.RoutingHead.GetGuildId())
if guild == nil {
c.Warning("process create channel event error: guild not found.")
return
}
for _, chanId := range eventBody.CreateChan.CreateId {
if guild.FindChannel(chanId.GetChanId()) != nil {
continue
}
channelInfo, err := c.GuildService.FetchChannelInfo(guild.GuildId, chanId.GetChanId())
if err != nil {
c.Warning("process create channel event error: fetch channel info error: %v", err)
continue
}
guild.Channels = append(guild.Channels, channelInfo)
c.dispatchGuildChannelCreatedEvent(&GuildChannelCreatedEvent{
OperatorId: m.Head.RoutingHead.GetFromTinyid(),
GuildId: m.Head.RoutingHead.GetGuildId(),
ChannelInfo: channelInfo,
})
}
case eventBody.ChangeChanInfo != nil:
updateChanLock.Lock()
defer updateChanLock.Unlock()