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

feat: guild channel updated event

This commit is contained in:
Mrs4s 2021-11-12 03:04:11 +08:00
parent f0ca636c54
commit 9f9db54192
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
4 changed files with 102 additions and 73 deletions

View File

@ -123,28 +123,7 @@ func (bot *CQBot) CQGetGuildChannelList(guildID uint64, noCache bool) global.MSG
}
channels := make([]global.MSG, 0, len(guild.Channels))
for _, c := range guild.Channels {
slowModes := make([]global.MSG, 0, len(c.Meta.SlowModes))
for _, mode := range c.Meta.SlowModes {
slowModes = append(slowModes, global.MSG{
"slow_mode_key": mode.SlowModeKey,
"slow_mode_text": mode.SlowModeText,
"speak_frequency": mode.SpeakFrequency,
"slow_mode_circle": mode.SlowModeCircle,
})
}
channels = append(channels, global.MSG{
"channel_id": c.ChannelId,
"channel_type": c.ChannelType,
"channel_name": c.ChannelName,
"owner_guild_id": c.Meta.GuildId,
"creator_id": c.Meta.CreatorUin,
"creator_tiny_id": c.Meta.CreatorTinyId,
"create_time": c.Meta.CreateTime,
"current_slow_mode": c.Meta.CurrentSlowMode,
"talk_permission": c.Meta.TalkPermission,
"visible_type": c.Meta.VisibleType,
"slow_modes": slowModes,
})
channels = append(channels, convertChannelInfo(c))
}
return OK(channels)
}
@ -1712,55 +1691,6 @@ func Failed(code int, msg ...string) global.MSG {
return global.MSG{"data": nil, "retcode": code, "msg": m, "wording": w, "status": "failed"}
}
func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) global.MSG {
return global.MSG{
"group_id": groupID,
"user_id": m.Uin,
"nickname": m.Nickname,
"card": m.CardName,
"sex": func() string {
if m.Gender == 1 {
return "female"
} else if m.Gender == 0 {
return "male"
}
// unknown = 0xff
return "unknown"
}(),
"age": 0,
"area": "",
"join_time": m.JoinTime,
"last_sent_time": m.LastSpeakTime,
"shut_up_timestamp": m.ShutUpTimestamp,
"level": strconv.FormatInt(int64(m.Level), 10),
"role": func() string {
switch m.Permission {
case client.Owner:
return "owner"
case client.Administrator:
return "admin"
case client.Member:
return "member"
default:
return "member"
}
}(),
"unfriendly": false,
"title": m.SpecialTitle,
"title_expire_time": m.SpecialTitleExpireTime,
"card_changeable": false,
}
}
func convertGuildMemberInfo(m *client.GuildMemberInfo) global.MSG {
return global.MSG{
"tiny_id": m.TinyId,
"title": m.Title,
"nickname": m.Nickname,
"role": m.Role,
}
}
func limitedString(str string) string {
limited := [14]rune{10: ' ', 11: '.', 12: '.', 13: '.'}
i := 0

View File

@ -77,7 +77,8 @@ func NewQQBot(cli *client.QQClient) *CQBot {
}
bot.Client.OnTempMessage(bot.tempMessageEvent)
bot.Client.GuildService.OnGuildChannelMessage(bot.guildChannelMessageEvent)
bot.Client.GuildService.OnGuildMessageReactionsUpdated(bot.guildMessageReactionsUpdated)
bot.Client.GuildService.OnGuildMessageReactionsUpdated(bot.guildMessageReactionsUpdatedEvent)
bot.Client.GuildService.OnGuildChannelUpdated(bot.guildChannelUpdatedEvent)
bot.Client.OnGroupMuted(bot.groupMutedEvent)
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
bot.Client.OnGroupNotify(bot.groupNotifyEvent)

81
coolq/converter.go Normal file
View File

@ -0,0 +1,81 @@
package coolq
import (
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/go-cqhttp/global"
"strconv"
)
func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) global.MSG {
return global.MSG{
"group_id": groupID,
"user_id": m.Uin,
"nickname": m.Nickname,
"card": m.CardName,
"sex": func() string {
if m.Gender == 1 {
return "female"
} else if m.Gender == 0 {
return "male"
}
// unknown = 0xff
return "unknown"
}(),
"age": 0,
"area": "",
"join_time": m.JoinTime,
"last_sent_time": m.LastSpeakTime,
"shut_up_timestamp": m.ShutUpTimestamp,
"level": strconv.FormatInt(int64(m.Level), 10),
"role": func() string {
switch m.Permission {
case client.Owner:
return "owner"
case client.Administrator:
return "admin"
case client.Member:
return "member"
default:
return "member"
}
}(),
"unfriendly": false,
"title": m.SpecialTitle,
"title_expire_time": m.SpecialTitleExpireTime,
"card_changeable": false,
}
}
func convertGuildMemberInfo(m *client.GuildMemberInfo) global.MSG {
return global.MSG{
"tiny_id": m.TinyId,
"title": m.Title,
"nickname": m.Nickname,
"role": m.Role,
}
}
func convertChannelInfo(c *client.ChannelInfo) global.MSG {
slowModes := make([]global.MSG, 0, len(c.Meta.SlowModes))
for _, mode := range c.Meta.SlowModes {
slowModes = append(slowModes, global.MSG{
"slow_mode_key": mode.SlowModeKey,
"slow_mode_text": mode.SlowModeText,
"speak_frequency": mode.SpeakFrequency,
"slow_mode_circle": mode.SlowModeCircle,
})
}
return global.MSG{
"channel_id": c.ChannelId,
"channel_type": c.ChannelType,
"channel_name": c.ChannelName,
"owner_guild_id": c.Meta.GuildId,
"creator_id": c.Meta.CreatorUin,
"creator_tiny_id": c.Meta.CreatorTinyId,
"create_time": c.Meta.CreateTime,
"current_slow_mode": c.Meta.CurrentSlowMode,
"talk_permission": c.Meta.TalkPermission,
"visible_type": c.Meta.VisibleType,
"slow_modes": slowModes,
}
}

View File

@ -164,7 +164,7 @@ func (bot *CQBot) guildChannelMessageEvent(c *client.QQClient, m *message.GuildC
})
}
func (bot *CQBot) guildMessageReactionsUpdated(c *client.QQClient, e *client.GuildMessageReactionsUpdatedEvent) {
func (bot *CQBot) guildMessageReactionsUpdatedEvent(c *client.QQClient, e *client.GuildMessageReactionsUpdatedEvent) {
guild := c.GuildService.FindGuild(e.GuildId)
if guild == nil {
return
@ -198,6 +198,23 @@ func (bot *CQBot) guildMessageReactionsUpdated(c *client.QQClient, e *client.Gui
})
}
func (bot *CQBot) guildChannelUpdatedEvent(c *client.QQClient, e *client.GuildChannelUpdatedEvent) {
guild := c.GuildService.FindGuild(e.GuildId)
if guild == nil {
return
}
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,
"old_info": convertChannelInfo(e.OldChannelInfo),
"new_info": convertChannelInfo(e.NewChannelInfo),
})
}
func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent) {
g := c.FindGroup(e.GroupCode)
if e.TargetUin == 0 {