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

feat: get_guild_member_profile api

This commit is contained in:
Mrs4s 2021-12-11 02:57:17 +08:00
parent d561d4fd80
commit 5d81267c12
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
7 changed files with 38 additions and 7 deletions

View File

@ -187,6 +187,33 @@ func (bot *CQBot) CQGetGuildMembers(guildID uint64, nextToken string) global.MSG
return OK(res) 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 获取频道角色列表 // CQGetGuildRoles 获取频道角色列表
// @route(get_guild_roles) // @route(get_guild_roles)
func (bot *CQBot) CQGetGuildRoles(guildID uint64) global.MSG { 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) { fixAt := func(elem []message.IMessageElement) {
for _, e := range elem { for _, e := range elem {
if at, ok := e.(*message.AtElement); ok && at.Target != 0 && at.Display == "" { 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 { if mem != nil {
at.Display = "@" + mem.Nickname at.Display = "@" + mem.Nickname
} else { } else {

View File

@ -154,7 +154,6 @@ func convertChannelInfo(c *client.ChannelInfo) global.MSG {
"channel_type": c.ChannelType, "channel_type": c.ChannelType,
"channel_name": c.ChannelName, "channel_name": c.ChannelName,
"owner_guild_id": fU64(c.Meta.GuildId), "owner_guild_id": fU64(c.Meta.GuildId),
"creator_id": c.Meta.CreatorUin,
"creator_tiny_id": fU64(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,

View File

@ -239,7 +239,7 @@ func (bot *CQBot) guildChannelCreatedEvent(c *client.QQClient, e *client.GuildCh
if guild == nil { if guild == nil {
return return
} }
member, _ := c.GuildService.GetGuildMemberProfileInfo(e.GuildId, e.OperatorId) member, _ := c.GuildService.FetchGuildMemberProfileInfo(e.GuildId, e.OperatorId)
if member == nil { if member == nil {
member = &client.GuildUserProfile{Nickname: "未知"} member = &client.GuildUserProfile{Nickname: "未知"}
} }
@ -263,7 +263,7 @@ func (bot *CQBot) guildChannelDestroyedEvent(c *client.QQClient, e *client.Guild
if guild == nil { if guild == nil {
return return
} }
member, _ := c.GuildService.GetGuildMemberProfileInfo(e.GuildId, e.OperatorId) member, _ := c.GuildService.FetchGuildMemberProfileInfo(e.GuildId, e.OperatorId)
if member == nil { if member == nil {
member = &client.GuildUserProfile{Nickname: "未知"} member = &client.GuildUserProfile{Nickname: "未知"}
} }

View File

@ -31,6 +31,7 @@ API以及字段相关命名均为参考QQ官方命名或相似产品命名规则
- 遵循我们一贯的原则, 将不会支持主动加频道/主动拉人/红包相关消息类型 - 遵循我们一贯的原则, 将不会支持主动加频道/主动拉人/红包相关消息类型
- 频道相关的API仅能在 `Android Phone``iPad` 协议上使用. - 频道相关的API仅能在 `Android Phone``iPad` 协议上使用.
- 由于频道相关ID的数据类型均为 `uint64` , 为保证不超过某些语言的安全值范围, 在 `v1.0.0-beta8-fix3` 以后, 所有ID相关数据均转换为 `string` 类型, API调用两种类型均可接受. - 由于频道相关ID的数据类型均为 `uint64` , 为保证不超过某些语言的安全值范围, 在 `v1.0.0-beta8-fix3` 以后, 所有ID相关数据均转换为 `string` 类型, API调用两种类型均可接受.
- 为保证一致性, 所有频道接口返回的 `用户ID` 均命名为 `tiny_id`, 所有频道相关接口的 `用户ID` 入参均命名为 `user_id`
## API ## API

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.17
require ( require (
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
github.com/Microsoft/go-winio v0.5.1 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/dustin/go-humanize v1.0.0
github.com/fumiama/go-hide-param v0.1.4 github.com/fumiama/go-hide-param v0.1.4
github.com/gabriel-vasile/mimetype v1.4.0 github.com/gabriel-vasile/mimetype v1.4.0

4
go.sum
View File

@ -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/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 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= 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-20211210183655-416a6c17bee3 h1:IWZEA6yZOwXCEg5a4kuZkzfy3NghjsRtVIbJ4SBpzU0=
github.com/Mrs4s/MiraiGo v0.0.0-20211208132533-8cd25e02fcf3/go.mod h1:YD9gBKkxC9lPPtx3doYXRG26VBkK6YXjrS76cv01C5w= 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 h1:p4o7/eSoP39jwnGZz08N1IpH/mNzg9SdCn7kPM9A9BE=
github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE= 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= github.com/bits-and-blooms/bitset v1.2.1 h1:M+/hrU9xlMp7t4TyTDQW97d3tRPVuKFC6zBEK16QnXY=

View File

@ -144,6 +144,10 @@ func (c *Caller) call(action string, p Getter) global.MSG {
p0 := p.Get("guild_id").Uint() p0 := p.Get("guild_id").Uint()
p1 := p.Get("next_token").String() p1 := p.Get("next_token").String()
return c.bot.CQGetGuildMembers(p0, p1) 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": case "get_guild_meta_by_guest":
p0 := p.Get("guild_id").Uint() p0 := p.Get("guild_id").Uint()
return c.bot.CQGetGuildMetaByGuest(p0) return c.bot.CQGetGuildMetaByGuest(p0)