diff --git a/coolq/api.go b/coolq/api.go index 7836eca..02dca95 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -187,6 +187,33 @@ func (bot *CQBot) CQGetGuildMembers(guildID uint64, nextToken string) global.MSG return OK(res) } +// CQGetGuildMemberProfile 获取频道成员资料 +// @route(get_guild_member_profile) +func (bot *CQBot) CQGetGuildMemberProfile(guildID, userID uint64) global.MSG { + if bot.Client.GuildService.FindGuild(guildID) == nil { + return Failed(100, "GUILD_NOT_FOUND") + } + profile, err := bot.Client.GuildService.FetchGuildMemberProfileInfo(guildID, userID) + if err != nil { + log.Errorf("获取频道 %v 成员 %v 资料时出现错误: %v", guildID, userID, err) + return Failed(100, "API_ERROR", err.Error()) + } + roles := make([]global.MSG, 0, len(profile.Roles)) + for _, role := range profile.Roles { + roles = append(roles, global.MSG{ + "role_id": fU64(role.RoleId), + "role_name": role.RoleName, + }) + } + return OK(global.MSG{ + "tiny_id": fU64(profile.TinyId), + "nickname": profile.Nickname, + "avatar_url": profile.AvatarUrl, + "join_time": profile.JoinTime, + "roles": roles, + }) +} + // CQGetGuildRoles 获取频道角色列表 // @route(get_guild_roles) func (bot *CQBot) CQGetGuildRoles(guildID uint64) global.MSG { @@ -725,7 +752,7 @@ func (bot *CQBot) CQSendGuildChannelMessage(guildID, channelID uint64, m gjson.R fixAt := func(elem []message.IMessageElement) { for _, e := range elem { if at, ok := e.(*message.AtElement); ok && at.Target != 0 && at.Display == "" { - mem, _ := bot.Client.GuildService.GetGuildMemberProfileInfo(guildID, uint64(at.Target)) + mem, _ := bot.Client.GuildService.FetchGuildMemberProfileInfo(guildID, uint64(at.Target)) if mem != nil { at.Display = "@" + mem.Nickname } else { diff --git a/coolq/converter.go b/coolq/converter.go index e025384..a62bce8 100644 --- a/coolq/converter.go +++ b/coolq/converter.go @@ -154,7 +154,6 @@ func convertChannelInfo(c *client.ChannelInfo) global.MSG { "channel_type": c.ChannelType, "channel_name": c.ChannelName, "owner_guild_id": fU64(c.Meta.GuildId), - "creator_id": c.Meta.CreatorUin, "creator_tiny_id": fU64(c.Meta.CreatorTinyId), "create_time": c.Meta.CreateTime, "current_slow_mode": c.Meta.CurrentSlowMode, diff --git a/coolq/event.go b/coolq/event.go index 82a6fe1..9c9ec87 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -239,7 +239,7 @@ func (bot *CQBot) guildChannelCreatedEvent(c *client.QQClient, e *client.GuildCh if guild == nil { return } - member, _ := c.GuildService.GetGuildMemberProfileInfo(e.GuildId, e.OperatorId) + member, _ := c.GuildService.FetchGuildMemberProfileInfo(e.GuildId, e.OperatorId) if member == nil { member = &client.GuildUserProfile{Nickname: "未知"} } @@ -263,7 +263,7 @@ func (bot *CQBot) guildChannelDestroyedEvent(c *client.QQClient, e *client.Guild if guild == nil { return } - member, _ := c.GuildService.GetGuildMemberProfileInfo(e.GuildId, e.OperatorId) + member, _ := c.GuildService.FetchGuildMemberProfileInfo(e.GuildId, e.OperatorId) if member == nil { member = &client.GuildUserProfile{Nickname: "未知"} } diff --git a/docs/guild.md b/docs/guild.md index 6d7a70d..69c6f0d 100644 --- a/docs/guild.md +++ b/docs/guild.md @@ -31,6 +31,7 @@ API以及字段相关命名均为参考QQ官方命名或相似产品命名规则 - 遵循我们一贯的原则, 将不会支持主动加频道/主动拉人/红包相关消息类型 - 频道相关的API仅能在 `Android Phone` 和 `iPad` 协议上使用. - 由于频道相关ID的数据类型均为 `uint64` , 为保证不超过某些语言的安全值范围, 在 `v1.0.0-beta8-fix3` 以后, 所有ID相关数据均转换为 `string` 类型, API调用两种类型均可接受. +- 为保证一致性, 所有频道接口返回的 `用户ID` 均命名为 `tiny_id`, 所有频道相关接口的 `用户ID` 入参均命名为 `user_id` ## API diff --git a/go.mod b/go.mod index ebcd477..d0a41dc 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.17 require ( github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f github.com/Microsoft/go-winio v0.5.1 - github.com/Mrs4s/MiraiGo v0.0.0-20211208132533-8cd25e02fcf3 + github.com/Mrs4s/MiraiGo v0.0.0-20211210183655-416a6c17bee3 github.com/dustin/go-humanize v1.0.0 github.com/fumiama/go-hide-param v0.1.4 github.com/gabriel-vasile/mimetype v1.4.0 diff --git a/go.sum b/go.sum index 15b2bbb..9b2b005 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/g github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= -github.com/Mrs4s/MiraiGo v0.0.0-20211208132533-8cd25e02fcf3 h1:w42Z7gE+HjBcjXDjVZ8o5rzNgAzt7nhuL84HOYpIhRE= -github.com/Mrs4s/MiraiGo v0.0.0-20211208132533-8cd25e02fcf3/go.mod h1:YD9gBKkxC9lPPtx3doYXRG26VBkK6YXjrS76cv01C5w= +github.com/Mrs4s/MiraiGo v0.0.0-20211210183655-416a6c17bee3 h1:IWZEA6yZOwXCEg5a4kuZkzfy3NghjsRtVIbJ4SBpzU0= +github.com/Mrs4s/MiraiGo v0.0.0-20211210183655-416a6c17bee3/go.mod h1:YD9gBKkxC9lPPtx3doYXRG26VBkK6YXjrS76cv01C5w= github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737 h1:p4o7/eSoP39jwnGZz08N1IpH/mNzg9SdCn7kPM9A9BE= github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE= github.com/bits-and-blooms/bitset v1.2.1 h1:M+/hrU9xlMp7t4TyTDQW97d3tRPVuKFC6zBEK16QnXY= diff --git a/modules/api/api.go b/modules/api/api.go index 490f2b1..0d45729 100644 --- a/modules/api/api.go +++ b/modules/api/api.go @@ -144,6 +144,10 @@ func (c *Caller) call(action string, p Getter) global.MSG { p0 := p.Get("guild_id").Uint() p1 := p.Get("next_token").String() return c.bot.CQGetGuildMembers(p0, p1) + case "get_guild_member_profile": + p0 := p.Get("guild_id").Uint() + p1 := p.Get("user_id").Uint() + return c.bot.CQGetGuildMemberProfile(p0, p1) case "get_guild_meta_by_guest": p0 := p.Get("guild_id").Uint() return c.bot.CQGetGuildMetaByGuest(p0)