1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 03:53:50 +08:00

feat: channel_created event & channel_destroyed event support

This commit is contained in:
Mrs4s 2021-11-14 19:35:46 +08:00
parent 08e59f0394
commit cc8f2b5a7a
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
2 changed files with 63 additions and 11 deletions

View File

@ -79,6 +79,8 @@ func NewQQBot(cli *client.QQClient) *CQBot {
bot.Client.GuildService.OnGuildChannelMessage(bot.guildChannelMessageEvent)
bot.Client.GuildService.OnGuildMessageReactionsUpdated(bot.guildMessageReactionsUpdatedEvent)
bot.Client.GuildService.OnGuildChannelUpdated(bot.guildChannelUpdatedEvent)
bot.Client.GuildService.OnGuildChannelCreated(bot.guildChannelCreatedEvent)
bot.Client.GuildService.OnGuildChannelDestroyed(bot.guildChannelDestroyedEvent)
bot.Client.OnGroupMuted(bot.groupMutedEvent)
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
bot.Client.OnGroupNotify(bot.groupNotifyEvent)

View File

@ -213,7 +213,8 @@ func (bot *CQBot) guildMessageReactionsUpdatedEvent(c *client.QQClient, e *clien
"operator_id": e.OperatorId,
"current_reactions": currentReactions,
"time": time.Now().Unix(),
"self_id": c.Uin,
"self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId,
"user_id": e.OperatorId,
})
}
@ -225,16 +226,65 @@ func (bot *CQBot) guildChannelUpdatedEvent(c *client.QQClient, e *client.GuildCh
}
log.Infof("频道 %v(%v) 子频道 %v(%v) 信息已更新", guild.GuildName, guild.GuildId, e.NewChannelInfo.ChannelName, e.NewChannelInfo.ChannelId)
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "channel_updated",
"guild_id": e.GuildId,
"channel_id": e.ChannelId,
"operator_id": e.OperatorId,
"time": time.Now().Unix(),
"self_id": c.Uin,
"user_id": e.OperatorId,
"old_info": convertChannelInfo(e.OldChannelInfo),
"new_info": convertChannelInfo(e.NewChannelInfo),
"post_type": "notice",
"notice_type": "channel_updated",
"guild_id": e.GuildId,
"channel_id": e.ChannelId,
"operator_id": e.OperatorId,
"time": time.Now().Unix(),
"self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId,
"user_id": e.OperatorId,
"old_info": convertChannelInfo(e.OldChannelInfo),
"new_info": convertChannelInfo(e.NewChannelInfo),
})
}
func (bot *CQBot) guildChannelCreatedEvent(c *client.QQClient, e *client.GuildChannelOperationEvent) {
guild := c.GuildService.FindGuild(e.GuildId)
if guild == nil {
return
}
member := guild.FindMember(e.OperatorId)
if member == nil {
member = &client.GuildMemberInfo{Nickname: "未知"}
}
log.Infof("频道 %v(%v) 内用户 %v(%v) 创建了子频道 %v(%v)", guild.GuildName, guild.GuildId, member.Nickname, member.TinyId, e.ChannelInfo.ChannelName, e.ChannelInfo.ChannelId)
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "channel_created",
"guild_id": e.GuildId,
"channel_id": e.ChannelInfo.ChannelId,
"operator_id": e.OperatorId,
"self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId,
"user_id": e.OperatorId,
"time": time.Now().Unix(),
"channel_info": convertChannelInfo(e.ChannelInfo),
})
}
func (bot *CQBot) guildChannelDestroyedEvent(c *client.QQClient, e *client.GuildChannelOperationEvent) {
guild := c.GuildService.FindGuild(e.GuildId)
if guild == nil {
return
}
member := guild.FindMember(e.OperatorId)
if member == nil {
member = &client.GuildMemberInfo{Nickname: "未知"}
}
log.Infof("频道 %v(%v) 内用户 %v(%v) 删除了子频道 %v(%v)", guild.GuildName, guild.GuildId, member.Nickname, member.TinyId, e.ChannelInfo.ChannelName, e.ChannelInfo.ChannelId)
bot.dispatchEventMessage(global.MSG{
"post_type": "notice",
"notice_type": "channel_destroyed",
"guild_id": e.GuildId,
"channel_id": e.ChannelInfo.ChannelId,
"operator_id": e.OperatorId,
"self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId,
"user_id": e.OperatorId,
"time": time.Now().Unix(),
"channel_info": convertChannelInfo(e.ChannelInfo),
})
}