-
Notifications
You must be signed in to change notification settings - Fork 1
/
guild.go
260 lines (231 loc) · 10.3 KB
/
guild.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
package discord
import (
"fmt"
"github.com/BOOMfinity/bfcord/api/cdn"
"github.com/BOOMfinity/bfcord/discord/permissions"
"github.com/BOOMfinity/bfcord/internal/timeconv"
"github.com/BOOMfinity/go-utils/nullable"
"github.com/andersfylling/snowflake/v5"
"strconv"
)
type GuildWithData struct {
Members []MemberWithUser `json:"members"`
Channels []Channel `json:"channels"`
Threads []Channel `json:"threads"`
Presences []Presence `json:"presences"`
VoiceStates []VoiceState `json:"voice_states"`
StageInstances []StageInstance `json:"stage_instances"`
ScheduledEvents []GuildScheduledEvent `json:"guild_scheduled_events"`
Owner User `json:"owner"`
Guild
}
func (g *GuildWithData) Patch() {
g.Guild.Patch()
for i := range g.Members {
g.Members[i].UserID = g.Members[i].User.ID
g.Members[i].GuildID = g.ID
}
for i := range g.Channels {
g.Channels[i].GuildID = g.ID
}
for i := range g.Threads {
g.Threads[i].GuildID = g.ID
}
for i := range g.Presences {
g.Presences[i].UserID = g.Presences[i].User.ID
g.Presences[i].GuildID = g.ID
}
for i := range g.StageInstances {
g.StageInstances[i].GuildID = g.ID
}
for i := range g.ScheduledEvents {
g.ScheduledEvents[i].GuildID = g.ID
}
}
type Guild struct {
JoinedAt timeconv.Timestamp `json:"joined_at"`
Banner string `json:"banner"`
Name string `json:"name"`
IconHash string `json:"icon_hash"`
Splash string `json:"splash"`
VanityUrlCode string `json:"vanity_url_code"`
PreferredLocale string `json:"preferred_locale"`
DiscoverySplash string `json:"discovery_splash"`
Icon string `json:"icon"`
Permissions string `json:"permissions"`
Description string `json:"description"`
Features []string `json:"features"`
Stickers []GuildSticker `json:"stickers"`
Roles RoleSlice `json:"roles"`
Emojis []Emoji `json:"emojis"`
AFKTimeout timeconv.Seconds `json:"afk_timeout"`
MFALevel int `json:"mfa_level"`
ApplicationID snowflake.ID `json:"application_id"`
SystemChannelID snowflake.ID `json:"system_channel_id"`
SystemChannelFlags int `json:"system_channel_flags"`
RulesChannelID snowflake.ID `json:"rules_channel_id"`
OwnerID snowflake.ID `json:"owner_id"`
PublicUpdatesChannelID snowflake.ID `json:"public_updates_channel_id"`
AFKChannelID snowflake.ID `json:"afk_channel_id"`
PremiumSubscriptionCount int `json:"premium_subscription_count"`
MaxPresences int `json:"max_presences"`
MaxMembers int `json:"max_members"`
WidgetChannelID snowflake.ID `json:"widget_channel_id"`
MaxVideoChannelUsers int `json:"max_video_channel_users"`
MemberCount int `json:"member_count"`
ID snowflake.ID `json:"id"`
PremiumTier GuildPremiumTier `json:"premium_tier"`
ExplicitContentFilter GuildExplicitContentFilter `json:"explicit_content_filter"`
Unavailable bool `json:"unavailable"`
DefaultMessageNotifications GuildDefaultNotifications `json:"default_message_notifications"`
NSFWLevel GuildNSFWLevel `json:"nsfw_level"`
VerificationLevel GuildVerificationLevel `json:"verification_level"`
WidgetEnabled bool `json:"widget_enabled"`
PremiumProgressBarEnabled bool `json:"premium_progress_bar_enabled"`
Large bool `json:"large"`
}
func (v Guild) Patch() {
for i := range v.Emojis {
v.Emojis[i].GuildID = v.ID
}
for i := range v.Roles {
v.Roles[i].GuildID = v.ID
}
for i := range v.Stickers {
v.Stickers[i].GuildID = v.ID
}
}
func (v Guild) MemberPermissions(api ClientQuery, member snowflake.ID) (perm permissions.Permission, err error) {
if v.OwnerID == member {
return permissions.All, nil
}
return api.Guild(v.ID).Member(member).Permissions()
}
// IconURL returns a URL of Guild icon.
//
// Size can be any power of two between 16 and 4096 (use constants from cdn package, or 0 for default).
func (v Guild) IconURL(format cdn.ImageFormat, size cdn.ImageSize) string {
url := fmt.Sprintf("%v/icons/%v/%v.%v", cdn.Url, v.ID.String(), v.Icon, format)
if size != 0 {
url += "?size=" + strconv.Itoa(int(size))
}
return url
}
type GuildUpdate struct {
Name *string `json:"name,omitempty"`
VerificationLevel *GuildVerificationLevel `json:"verification_level,omitempty"`
DefaultMessageNotifications *GuildDefaultNotifications `json:"default_message_notifications,omitempty"`
ExplicitContentFilter *GuildExplicitContentFilter `json:"explicit_content_filter,omitempty"`
AFKChannelID *nullable.Nullable[snowflake.ID] `json:"afk_channel_id,omitempty"`
AFKTimeout *uint32 `json:"afk_timeout,omitempty"`
Icon *nullable.Nullable[string] `json:"icon,omitempty"`
OwnerID *snowflake.ID `json:"owner_id,omitempty"`
Splash *nullable.Nullable[string] `json:"splash,omitempty"`
DiscoverySplash *nullable.Nullable[string] `json:"discovery_splash,omitempty"`
Banner *nullable.Nullable[string] `json:"banner,omitempty"`
SystemChannelID *nullable.Nullable[snowflake.ID] `json:"system_channel_id,omitempty"`
SystemChannelFlags *SystemChannelFlag `json:"system_channel_flags,omitempty"`
RulesChannelID *snowflake.ID `json:"rules_channel_id,omitempty"`
PublicUpdatesChannelID *snowflake.ID `json:"public_updates_channel_id,omitempty"`
PreferredLocale *string `json:"preferred_locale,omitempty"`
Description *string `json:"description,omitempty"`
PremiumProgressBarEnabled *bool `json:"premium_progress_bar_enabled,omitempty"`
}
type SystemChannelFlag uint8
const (
ChannelFlagDisableMemberJoin SystemChannelFlag = 1 << iota
ChannelFlagDisableBoost
ChannelFlagDisableSetupTips
ChannelFlagDisableReplyButton
)
type GuildSticker struct {
Name string `json:"name"`
Description string `json:"description"`
Tags string `json:"tags"`
User User `json:"user"`
ID snowflake.ID `json:"id"`
GuildID snowflake.ID `json:"guild_id"`
PackID snowflake.ID `json:"pack_id"`
SortValue int `json:"sort_value"`
Available bool `json:"available"`
}
// StageInstance
//
// Reference: https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-stage-instance-structure
type StageInstance struct {
Topic string `json:"topic"`
ID snowflake.ID `json:"id"`
GuildID snowflake.ID `json:"guild_id"`
ChannelID snowflake.ID `json:"channel_id"`
PrivacyLevel int `json:"privacy_level"`
DiscoverableDisabled bool `json:"discoverable_disabled"`
}
type GuildNSFWLevel uint8
const (
GuildNSFWDefault GuildNSFWLevel = iota
GuildNSFWExplicit
GuildNSFWSafe
GuildNSFWAgeRestricted
)
type GuildPremiumTier uint8
const (
GuildPremiumNone GuildPremiumTier = iota
GuildPremiumTier1
GuildPremiumTier2
GuildPremiumTier3
)
type GuildExplicitContentFilter uint8
const (
GuildExplicitContentFilterDisabled GuildExplicitContentFilter = iota
GuildExplicitContentFilterWithoutRoles
GuildExplicitContentFilterAll
)
type GuildDefaultNotifications uint8
const (
GuildDefaultNotificationsAll GuildDefaultNotifications = iota
GuildDefaultNotificationsMentions
)
type GuildVerificationLevel uint8
const (
GuildVerificationNone GuildVerificationLevel = iota
GuildVerificationLow
GuildVerificationMedium
GuildVerificationHigh
GuildVerificationVeryHigh
)
// GuildScheduledEvent
//
// Reference: https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-structure
type GuildScheduledEvent struct {
ScheduledStartTime timeconv.Timestamp `json:"scheduled_start_time"`
ScheduledEndTime timeconv.Timestamp `json:"scheduled_end_time"`
EntityMetadata ScheduledEventMeta `json:"entity_metadata"`
Name string `json:"name"`
Description string `json:"description"`
Creator User `json:"creator"`
ID snowflake.ID `json:"id"`
CreatorID snowflake.ID `json:"creator_id"`
PrivacyLevel int `json:"privacy_level"`
ChannelID snowflake.ID `json:"channel_id"`
GuildID snowflake.ID `json:"guild_id"`
EntityID snowflake.ID `json:"entity_id"`
UserCount int `json:"user_count"`
EntityType ScheduledEventType `json:"entity_type"`
Status ScheduledEventStatus `json:"status"`
}
type ScheduledEventMeta struct {
Location string `json:"location"`
}
type ScheduledEventType uint8
const (
ScheduledEventStage ScheduledEventType = iota + 1
ScheduledEventVoice
ScheduledEventExternal
)
type ScheduledEventStatus uint8
const (
ScheduledEventStatusScheduled ScheduledEventStatus = iota + 1
ScheduledEventStatusActive
ScheduledEventStatusCompleted
ScheduledEventStatusCanceled
)