forked from amatsagu/tempest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.go
132 lines (111 loc) · 5.42 KB
/
target.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package tempest
import (
"strconv"
"strings"
"time"
)
// https://discord.com/developers/docs/resources/user#user-object-premium-types
type NitroType uint8
const (
NO_NITRO_TYPE NitroType = iota
CLASSIC_NITRO_TYPE
FULL_NITRO_TYPE
BASIC_NITRO_TYPE
)
// https://discord.com/developers/docs/resources/user#user-object-user-structure
type User struct {
ID Snowflake `json:"id"`
Username string `json:"username"`
Discriminator string `json:"discriminator"` // Deprecated: Read more at https://discord.com/blog/usernames.
AvatarHash string `json:"avatar,omitempty"` // Hash code used to access user's profile. Call User.AvatarURL to get direct url.
Bot bool `json:"bot,omitempty"`
MFA bool `json:"mfa_enabled,omitempty"`
BannerHash string `json:"banner,omitempty"` // Hash code used to access user's baner. Call User.BannerURL to get direct url.
AccentColor uint32 `json:"accent_color,omitempty"` // User's banner color, encoded as an integer representation of hexadecimal color code.
Locale string `json:"locale,omitempty"`
PremiumType NitroType `json:"premium_type,omitempty"`
PublicFlags uint64 `json:"public_flags,omitempty"` // (Same as regular flags)
}
// Deprecated: Read more at https://discord.com/blog/usernames.
func (user User) Tag() string {
return user.Username + "#" + user.Discriminator
}
func (user User) Mention() string {
return "<@" + user.ID.String() + ">"
}
// Returns a direct url to user's avatar. It'll return url to default Discord's avatar if targeted user don't use avatar.
func (user User) AvatarURL() string {
if user.AvatarHash == "" {
n, err := strconv.Atoi(user.Discriminator)
if err != nil {
return DISCORD_CDN_URL + "/embed/avatars/0.png"
}
return DISCORD_CDN_URL + "/embed/avatars/" + strconv.Itoa(n%5) + ".png"
}
if strings.HasPrefix(user.AvatarHash, "a_") {
return DISCORD_CDN_URL + "/avatars/" + user.ID.String() + "/" + user.AvatarHash + ".gif"
}
return DISCORD_CDN_URL + "/avatars/" + user.ID.String() + "/" + user.AvatarHash
}
// Returns a direct url to user's banner. It'll return empty string if targeted user don't use avatar.
func (user User) BannerURL() string {
if user.BannerHash == "" {
return ""
}
if strings.HasPrefix(user.BannerHash, "a_") {
return DISCORD_CDN_URL + "/banners/" + user.ID.String() + "/" + user.BannerHash + ".gif"
}
return DISCORD_CDN_URL + "/banners/" + user.ID.String() + "/" + user.BannerHash
}
// https://discord.com/developers/docs/resources/guild#guild-member-object-guild-member-structure
type Member struct {
User *User `json:"user,omitempty"`
Nickname string `json:"nick,omitempty"`
GuildAvatarHash string `json:"avatar,omitempty"` // Hash code used to access member's custom, guild profile. Call Member.GuildAvatarURL to get direct url.
RoleIDs []Snowflake `json:"roles"`
JoinedAt *time.Time `json:"joined_at,omitempty"`
PremiumSince *time.Time `json:"premium_since,omitempty"`
Dead bool `json:"deaf"`
Mute bool `json:"mute"`
Flags uint64 `json:"flags"`
Pending bool `json:"pending,omitempty"`
PermissionFlags uint64 `json:"permissions,string"`
CommunicationDisabledUntil *time.Time `json:"communication_disabled_until,omitempty"`
GuildID Snowflake `json:"-"`
}
// Returns a direct url to members's guild specific avatar. It'll return empty string if targeted member don't use custom avatar for that server.
func (member Member) GuildAvatarURL() string {
if member.GuildAvatarHash == "" {
return ""
}
if strings.HasPrefix(member.GuildAvatarHash, "a_") {
return DISCORD_CDN_URL + "/guilds/" + member.GuildID.String() + "/users/" + member.User.ID.String() + "/avatars/" + member.GuildAvatarHash + ".gif"
}
return DISCORD_CDN_URL + "/guilds/" + member.GuildID.String() + "/users/" + member.User.ID.String() + "/avatars/" + member.GuildAvatarHash
}
// https://discord.com/developers/docs/topics/permissions#role-object-role-structure
type Role struct {
ID Snowflake `json:"id"`
Name string `json:"name"`
Color uint32 `json:"color"` // Integer representation of hexadecimal color code. Roles without colors (color == 0) do not count towards the final computed color in the user list.
Hoist bool `json:"hoist"` // Whether this role is pinned in the user listing.
IconHash string `json:"icon,omitempty"`
UnicodeEmoji string `json:"unicode_emoji,omitempty"`
Position uint8 `json:"position"`
PermissionFlags uint64 `json:"permissions,string"`
Managed bool `json:"managed"` // Whether this role is managed by an integration.
Mentionable bool `json:"mentionable"` // Whether this role is mentionable.
Tags []*RoleTag `json:"tags,omitempty"`
}
// https://discord.com/developers/docs/topics/permissions#role-object-role-tags-structure
type RoleTag struct {
BotID Snowflake `json:"bot_id,omitempty"`
IntegrationID Snowflake `json:"integration_id,omitempty"`
// PremiumSubscriber bool <== UNKNOWN DOCUMENTATION
}
func (role Role) IconURL() string {
if role.IconHash == "" {
return ""
}
return DISCORD_CDN_URL + "/role-icons/" + role.ID.String() + "/" + role.IconHash + ".png"
}