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

fix: guild event use string-id type

This commit is contained in:
Mrs4s 2021-11-23 23:36:32 +08:00
parent 52743a8a5f
commit b4d92fcae3
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
3 changed files with 36 additions and 27 deletions

View File

@ -52,7 +52,7 @@ func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) global.MSG
func convertGuildMemberInfo(m *client.GuildMemberInfo) global.MSG { func convertGuildMemberInfo(m *client.GuildMemberInfo) global.MSG {
return global.MSG{ return global.MSG{
"tiny_id": m.TinyId, "tiny_id": fU64(m.TinyId),
"title": m.Title, "title": m.Title,
"nickname": m.Nickname, "nickname": m.Nickname,
"role": m.Role, "role": m.Role,
@ -144,12 +144,12 @@ func convertChannelInfo(c *client.ChannelInfo) global.MSG {
}) })
} }
return global.MSG{ return global.MSG{
"channel_id": c.ChannelId, "channel_id": fU64(c.ChannelId),
"channel_type": c.ChannelType, "channel_type": c.ChannelType,
"channel_name": c.ChannelName, "channel_name": c.ChannelName,
"owner_guild_id": c.Meta.GuildId, "owner_guild_id": fU64(c.Meta.GuildId),
"creator_id": c.Meta.CreatorUin, "creator_id": c.Meta.CreatorUin,
"creator_tiny_id": c.Meta.CreatorTinyId, "creator_tiny_id": fU64(c.Meta.CreatorTinyId),
"create_time": c.Meta.CreateTime, "create_time": c.Meta.CreateTime,
"current_slow_mode": c.Meta.CurrentSlowMode, "current_slow_mode": c.Meta.CurrentSlowMode,
"talk_permission": c.Meta.TalkPermission, "talk_permission": c.Meta.TalkPermission,
@ -157,3 +157,12 @@ func convertChannelInfo(c *client.ChannelInfo) global.MSG {
"slow_modes": slowModes, "slow_modes": slowModes,
} }
} }
func fU64(v uint64) string {
return strconv.FormatUint(v, 10)
}
func sU64(v string) uint64 {
r, _ := strconv.ParseUint(v, 10, 64)
return r
}

View File

@ -166,7 +166,7 @@ func ToArrayMessage(e []message.IMessageElement, source MessageSource) (r []glob
} else { } else {
m = global.MSG{ m = global.MSG{
"type": "at", "type": "at",
"data": map[string]string{"qq": strconv.FormatInt(o.Target, 10)}, "data": map[string]string{"qq": strconv.FormatUint(uint64(o.Target), 10)},
} }
} }
case *message.RedBagElement: case *message.RedBagElement:
@ -310,7 +310,7 @@ func ToStringMessage(e []message.IMessageElement, source MessageSource, isRaw ..
write("[CQ:at,qq=all]") write("[CQ:at,qq=all]")
continue continue
} }
write("[CQ:at,qq=%d]", o.Target) write("[CQ:at,qq=%d]", uint64(o.Target))
case *message.RedBagElement: case *message.RedBagElement:
write("[CQ:redbag,title=%s]", o.Title) write("[CQ:redbag,title=%s]", o.Title)
case *message.ForwardElement: case *message.ForwardElement:

View File

@ -165,16 +165,16 @@ func (bot *CQBot) guildChannelMessageEvent(c *client.QQClient, m *message.GuildC
"post_type": "message", "post_type": "message",
"message_type": "guild", "message_type": "guild",
"sub_type": "channel", "sub_type": "channel",
"guild_id": m.GuildId, "guild_id": fU64(m.GuildId),
"channel_id": m.ChannelId, "channel_id": fU64(m.ChannelId),
"message_id": fmt.Sprintf("%v-%v", m.Id, m.InternalId), "message_id": fmt.Sprintf("%v-%v", m.Id, m.InternalId),
"user_id": m.Sender.TinyId, "user_id": fU64(m.Sender.TinyId),
"message": ToFormattedMessage(m.Elements, source, false), // todo: 增加对频道消息 Reply 的支持 "message": ToFormattedMessage(m.Elements, source, false), // todo: 增加对频道消息 Reply 的支持
"self_id": bot.Client.Uin, "self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId, "self_tiny_id": fU64(bot.Client.GuildService.TinyId),
"time": m.Time, "time": m.Time,
"sender": global.MSG{ "sender": global.MSG{
"user_id": m.Sender.TinyId, "user_id": fU64(m.Sender.TinyId),
"nickname": m.Sender.Nickname, "nickname": m.Sender.Nickname,
}, },
}) })
@ -206,14 +206,14 @@ func (bot *CQBot) guildMessageReactionsUpdatedEvent(c *client.QQClient, e *clien
"post_type": "notice", "post_type": "notice",
"notice_type": "message_reactions_updated", "notice_type": "message_reactions_updated",
"message_sender_uin": e.MessageSenderUin, "message_sender_uin": e.MessageSenderUin,
"guild_id": e.GuildId, "guild_id": fU64(e.GuildId),
"channel_id": e.ChannelId, "channel_id": fU64(e.ChannelId),
"message_id": fmt.Sprint(e.MessageId), // todo: 支持数据库后转换为数据库id "message_id": fmt.Sprint(e.MessageId), // todo: 支持数据库后转换为数据库id
"operator_id": e.OperatorId, "operator_id": fU64(e.OperatorId),
"current_reactions": currentReactions, "current_reactions": currentReactions,
"time": time.Now().Unix(), "time": time.Now().Unix(),
"self_id": bot.Client.Uin, "self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId, "self_tiny_id": fU64(bot.Client.GuildService.TinyId),
"user_id": e.OperatorId, "user_id": e.OperatorId,
}) })
} }
@ -227,12 +227,12 @@ func (bot *CQBot) guildChannelUpdatedEvent(c *client.QQClient, e *client.GuildCh
bot.dispatchEventMessage(global.MSG{ bot.dispatchEventMessage(global.MSG{
"post_type": "notice", "post_type": "notice",
"notice_type": "channel_updated", "notice_type": "channel_updated",
"guild_id": e.GuildId, "guild_id": fU64(e.GuildId),
"channel_id": e.ChannelId, "channel_id": fU64(e.ChannelId),
"operator_id": e.OperatorId, "operator_id": fU64(e.OperatorId),
"time": time.Now().Unix(), "time": time.Now().Unix(),
"self_id": bot.Client.Uin, "self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId, "self_tiny_id": fU64(bot.Client.GuildService.TinyId),
"user_id": e.OperatorId, "user_id": e.OperatorId,
"old_info": convertChannelInfo(e.OldChannelInfo), "old_info": convertChannelInfo(e.OldChannelInfo),
"new_info": convertChannelInfo(e.NewChannelInfo), "new_info": convertChannelInfo(e.NewChannelInfo),
@ -252,11 +252,11 @@ func (bot *CQBot) guildChannelCreatedEvent(c *client.QQClient, e *client.GuildCh
bot.dispatchEventMessage(global.MSG{ bot.dispatchEventMessage(global.MSG{
"post_type": "notice", "post_type": "notice",
"notice_type": "channel_created", "notice_type": "channel_created",
"guild_id": e.GuildId, "guild_id": fU64(e.GuildId),
"channel_id": e.ChannelInfo.ChannelId, "channel_id": fU64(e.ChannelInfo.ChannelId),
"operator_id": e.OperatorId, "operator_id": fU64(e.OperatorId),
"self_id": bot.Client.Uin, "self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId, "self_tiny_id": fU64(bot.Client.GuildService.TinyId),
"user_id": e.OperatorId, "user_id": e.OperatorId,
"time": time.Now().Unix(), "time": time.Now().Unix(),
"channel_info": convertChannelInfo(e.ChannelInfo), "channel_info": convertChannelInfo(e.ChannelInfo),
@ -276,11 +276,11 @@ func (bot *CQBot) guildChannelDestroyedEvent(c *client.QQClient, e *client.Guild
bot.dispatchEventMessage(global.MSG{ bot.dispatchEventMessage(global.MSG{
"post_type": "notice", "post_type": "notice",
"notice_type": "channel_destroyed", "notice_type": "channel_destroyed",
"guild_id": e.GuildId, "guild_id": fU64(e.GuildId),
"channel_id": e.ChannelInfo.ChannelId, "channel_id": fU64(e.ChannelInfo.ChannelId),
"operator_id": e.OperatorId, "operator_id": fU64(e.OperatorId),
"self_id": bot.Client.Uin, "self_id": bot.Client.Uin,
"self_tiny_id": bot.Client.GuildService.TinyId, "self_tiny_id": fU64(bot.Client.GuildService.TinyId),
"user_id": e.OperatorId, "user_id": e.OperatorId,
"time": time.Now().Unix(), "time": time.Now().Unix(),
"channel_info": convertChannelInfo(e.ChannelInfo), "channel_info": convertChannelInfo(e.ChannelInfo),