mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 20:45:53 +08:00
feat: guild channel updated event
This commit is contained in:
parent
f0ca636c54
commit
9f9db54192
72
coolq/api.go
72
coolq/api.go
@ -123,28 +123,7 @@ func (bot *CQBot) CQGetGuildChannelList(guildID uint64, noCache bool) global.MSG
|
|||||||
}
|
}
|
||||||
channels := make([]global.MSG, 0, len(guild.Channels))
|
channels := make([]global.MSG, 0, len(guild.Channels))
|
||||||
for _, c := range guild.Channels {
|
for _, c := range guild.Channels {
|
||||||
slowModes := make([]global.MSG, 0, len(c.Meta.SlowModes))
|
channels = append(channels, convertChannelInfo(c))
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return OK(channels)
|
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"}
|
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 {
|
func limitedString(str string) string {
|
||||||
limited := [14]rune{10: ' ', 11: '.', 12: '.', 13: '.'}
|
limited := [14]rune{10: ' ', 11: '.', 12: '.', 13: '.'}
|
||||||
i := 0
|
i := 0
|
||||||
|
@ -77,7 +77,8 @@ func NewQQBot(cli *client.QQClient) *CQBot {
|
|||||||
}
|
}
|
||||||
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
||||||
bot.Client.GuildService.OnGuildChannelMessage(bot.guildChannelMessageEvent)
|
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.OnGroupMuted(bot.groupMutedEvent)
|
||||||
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
||||||
bot.Client.OnGroupNotify(bot.groupNotifyEvent)
|
bot.Client.OnGroupNotify(bot.groupNotifyEvent)
|
||||||
|
81
coolq/converter.go
Normal file
81
coolq/converter.go
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
guild := c.GuildService.FindGuild(e.GuildId)
|
||||||
if guild == nil {
|
if guild == nil {
|
||||||
return
|
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) {
|
func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent) {
|
||||||
g := c.FindGroup(e.GroupCode)
|
g := c.FindGroup(e.GroupCode)
|
||||||
if e.TargetUin == 0 {
|
if e.TargetUin == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user