Skip to content

Commit

Permalink
支持按身份组返回成员列表 (merge request !59)
Browse files Browse the repository at this point in the history
Squash merge branch 'feature_20220613_juggyaoli_roleapi_story_873895489' into 'master'
新增接口:支持按身份组返回成员列表

TAPD: --story=873895489
  • Loading branch information
juggyaoli committed Jun 14, 2022
1 parent d7c8242 commit fbfd411
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dto/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ func (g *GuildMembersPager) QueryParams() map[string]string {
return query
}

// GuildRoleMembersPager 分页器
type GuildRoleMembersPager struct {
StartIndex string `json:"start_index"`
Limit string `json:"limit"`
}

// QueryParams 转换为 query 参数
func (g *GuildRoleMembersPager) QueryParams() map[string]string {
query := make(map[string]string)
if g.Limit != "" {
query["limit"] = g.Limit
}
if g.StartIndex != "" {
query["start_index"] = g.StartIndex
}
return query
}

// GuildPager 分页器
type GuildPager struct {
Before string `json:"before"` // 读此id之前的数据
Expand Down
2 changes: 2 additions & 0 deletions openapi/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type GuildAPI interface {
Guild(ctx context.Context, guildID string) (*dto.Guild, error)
GuildMember(ctx context.Context, guildID, userID string) (*dto.Member, error)
GuildMembers(ctx context.Context, guildID string, pager *dto.GuildMembersPager) ([]*dto.Member, error)
GuildRoleMembers(ctx context.Context, guildID string, roleID string, pager *dto.GuildRoleMembersPager) (
[]*dto.Member, string, error)
DeleteGuildMember(ctx context.Context, guildID, userID string, opts ...dto.MemberDeleteOption) error
// 频道禁言
GuildMute(ctx context.Context, guildID string, mute *dto.UpdateGuildMute) error
Expand Down
28 changes: 28 additions & 0 deletions openapi/v1/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@ func (o *openAPI) GuildMembers(
return members, nil
}

// GuildRoleMembers 分页拉取频道内身份组成员列表
func (o *openAPI) GuildRoleMembers(
ctx context.Context, guildID string, roleID string, pager *dto.GuildRoleMembersPager,
) ([]*dto.Member, string, error) {
if pager == nil {
return nil, "", errs.ErrPagerIsNil
}
resp, err := o.request(ctx).
SetPathParam("guild_id", guildID).
SetPathParam("role_id", roleID).
SetQueryParams(pager.QueryParams()).
Get(o.getURL(guildRoleMemberURI))
if err != nil {
return nil, "", err
}

type res struct {
Data []*dto.Member `json:"data"`
Next string `json:"next"`
}
var roleMembersRsp res
if err := json.Unmarshal(resp.Body(), &roleMembersRsp); err != nil {
return nil, "", err
}

return roleMembersRsp.Data, roleMembersRsp.Next, nil
}

// DeleteGuildMember 将指定成员踢出频道
func (o *openAPI) DeleteGuildMember(ctx context.Context, guildID, userID string, opts ...dto.MemberDeleteOption) error {
opt := &dto.MemberDeleteOpts{}
Expand Down
1 change: 1 addition & 0 deletions openapi/v1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
guildURI uri = "/guilds/{guild_id}"
guildMembersURI uri = "/guilds/{guild_id}/members"
guildMemberURI uri = "/guilds/{guild_id}/members/{user_id}"
guildRoleMemberURI uri = "/guilds/{guild_id}/roles/{role_id}/members"
guildMuteURI uri = "/guilds/{guild_id}/mute" // 频道禁言
guildMembersMuteURI uri = "/guilds/{guild_id}/members/{user_id}/mute" // 频道指定成员禁言

Expand Down

0 comments on commit fbfd411

Please sign in to comment.