/
member.go
89 lines (75 loc) · 2.75 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package discord
import (
"time"
"github.com/disgoorg/disgo/json"
"github.com/disgoorg/snowflake/v2"
)
var _ Mentionable = (*Member)(nil)
// Member is a discord GuildMember
type Member struct {
User User `json:"user"`
Nick *string `json:"nick"`
Avatar *string `json:"avatar"`
RoleIDs []snowflake.ID `json:"roles,omitempty"`
JoinedAt time.Time `json:"joined_at"`
PremiumSince *time.Time `json:"premium_since,omitempty"`
Deaf bool `json:"deaf,omitempty"`
Mute bool `json:"mute,omitempty"`
Pending bool `json:"pending"`
CommunicationDisabledUntil *time.Time `json:"communication_disabled_until"`
// This field is not present everywhere in the API and often populated by disgo
GuildID snowflake.ID `json:"guild_id"`
}
func (m Member) String() string {
return m.User.String()
}
func (m Member) Mention() string {
return m.String()
}
// EffectiveName returns either the nickname or username depending on if the user has a nickname
func (m Member) EffectiveName() string {
if m.Nick != nil {
return *m.Nick
}
return m.User.Username
}
func (m Member) EffectiveAvatarURL(opts ...CDNOpt) string {
if m.Avatar == nil {
return m.User.EffectiveAvatarURL(opts...)
}
if avatar := m.AvatarURL(opts...); avatar != nil {
return *avatar
}
return ""
}
func (m Member) AvatarURL(opts ...CDNOpt) *string {
if m.Avatar == nil {
return nil
}
url := formatAssetURL(MemberAvatar, opts, m.GuildID, m.User.ID, *m.Avatar)
return &url
}
func (m Member) CreatedAt() time.Time {
return m.User.CreatedAt()
}
// MemberAdd is used to add a member via the oauth2 access token to a guild
type MemberAdd struct {
AccessToken string `json:"access_token"`
Nick string `json:"nick,omitempty"`
Roles []snowflake.ID `json:"roles,omitempty"`
Mute bool `json:"mute,omitempty"`
Deaf bool `json:"deaf,omitempty"`
}
// MemberUpdate is used to modify
type MemberUpdate struct {
ChannelID *snowflake.ID `json:"channel_id,omitempty"`
Nick *string `json:"nick,omitempty"`
Roles *[]snowflake.ID `json:"roles,omitempty"`
Mute *bool `json:"mute,omitempty"`
Deaf *bool `json:"deaf,omitempty"`
CommunicationDisabledUntil *json.Nullable[time.Time] `json:"communication_disabled_until,omitempty"`
}
// CurrentMemberUpdate is used to update the current member
type CurrentMemberUpdate struct {
Nick string `json:"nick"`
}