forked from fumiama/NanoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi_member.go
66 lines (59 loc) · 2.61 KB
/
openapi_member.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package nano
import "time"
// Member 成员对象 Member and MemberWithGuildID
//
// https://bot.q.qq.com/wiki/develop/api/openapi/member/model.html
type Member struct {
GuildID string `json:"guild_id"` // MemberWithGuildID only
User *User `json:"user"`
Nick string `json:"nick"`
Roles []string `json:"roles"`
JoinedAt time.Time `json:"joined_at"`
Deaf bool `json:"deaf"`
Mute bool `json:"mute"`
Pending bool `json:"pending"`
OpUserID string `json:"op_user_id"` // https://bot.q.qq.com/wiki/develop/api/gateway/guild_member.html#%E5%86%85%E5%AE%B9
}
// GetGuildMembersIn 获取 guild_id 指定的频道中所有成员的详情列表,支持分页
//
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_members.html
func (bot *Bot) GetGuildMembersIn(id, after string, limit uint32) (members []Member, err error) {
err = bot.GetOpenAPI(WriteHTTPQueryIfNotNil("/guilds/"+id+"/members",
"after", after,
"limit", limit,
), "", &members)
return
}
// RoleMembers 频道身份组成员列表
//
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html#%E8%BF%94%E5%9B%9E
type RoleMembers struct {
Data []Member `json:"data"`
Next string `json:"next"`
}
// GetRoleMembersOf 获取 guild_id 频道中指定role_id身份组下所有成员的详情列表,支持分页
//
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_role_members.html
func (bot *Bot) GetRoleMembersOf(guildid, roleid, startindex string, limit uint32) (*RoleMembers, error) {
return bot.getOpenAPIofRoleMembers(WriteHTTPQueryIfNotNil("/guilds/"+guildid+"/roles/"+roleid+"/members",
"start_index", startindex,
"limit", limit,
))
}
// GetGuildMemberOf 获取 guild_id 指定的频道中 user_id 对应成员的详细信息
//
// https://bot.q.qq.com/wiki/develop/api/openapi/member/get_member.html
func (bot *Bot) GetGuildMemberOf(guildid, userid string) (*Member, error) {
return bot.getOpenAPIofMember("/guilds/" + guildid + "/members/" + userid)
}
// DeleteGuildMemberOf 删除 guild_id 指定的频道下的成员 user_id
//
// https://bot.q.qq.com/wiki/develop/api/openapi/member/delete_member.html
//
// - delhistmsgdays: 消息撤回时间范围仅支持固定的天数:3,7,15,30。 特殊的时间范围:-1: 撤回全部消息。默认值为0不撤回任何消息。
func (bot *Bot) DeleteGuildMemberOf(guildid, userid string, addblklst bool, delhistmsgdays int) error {
return bot.DeleteOpenAPI("/guilds/"+guildid+"/members/"+userid, "", WriteBodyFromJSON(&struct {
A bool `json:"add_blacklist"`
D int `json:"delete_history_msg_days"`
}{addblklst, delhistmsgdays}))
}