mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
feat: GuildChannelCreatedEvent
This commit is contained in:
parent
d3a21e577b
commit
c149f28fb8
@ -238,6 +238,12 @@ type (
|
|||||||
NewChannelInfo *ChannelInfo
|
NewChannelInfo *ChannelInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GuildChannelCreatedEvent struct {
|
||||||
|
OperatorId uint64
|
||||||
|
GuildId uint64
|
||||||
|
ChannelInfo *ChannelInfo
|
||||||
|
}
|
||||||
|
|
||||||
OcrResponse struct {
|
OcrResponse struct {
|
||||||
Texts []*TextDetection `json:"texts"`
|
Texts []*TextDetection `json:"texts"`
|
||||||
Language string `json:"language"`
|
Language string `json:"language"`
|
||||||
|
@ -17,6 +17,7 @@ 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)
|
||||||
groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent)
|
groupMuteEventHandlers []func(*QQClient, *GroupMuteEvent)
|
||||||
groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent)
|
groupRecalledHandlers []func(*QQClient, *GroupMessageRecalledEvent)
|
||||||
friendRecalledHandlers []func(*QQClient, *FriendMessageRecalledEvent)
|
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)
|
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)) {
|
func (c *QQClient) OnGroupMuted(f func(*QQClient, *GroupMuteEvent)) {
|
||||||
c.eventHandlers.groupMuteEventHandlers = append(c.eventHandlers.groupMuteEventHandlers, f)
|
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) {
|
func (c *QQClient) dispatchGroupMuteEvent(e *GroupMuteEvent) {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return
|
return
|
||||||
|
@ -78,6 +78,28 @@ 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 {
|
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:
|
case eventBody.ChangeChanInfo != nil:
|
||||||
updateChanLock.Lock()
|
updateChanLock.Lock()
|
||||||
defer updateChanLock.Unlock()
|
defer updateChanLock.Unlock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user