Skip to content

Commit

Permalink
feat: get_guild_member_profile api
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Dec 10, 2021
1 parent d561d4f commit 5d81267
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
29 changes: 28 additions & 1 deletion coolq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion coolq/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions coolq/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "未知"}
}
Expand All @@ -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: "未知"}
}
Expand Down
1 change: 1 addition & 0 deletions docs/guild.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions modules/api/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d81267

Please sign in to comment.