github.com/diamondburned/arikawa/v2@v2.1.0/discord/guild.go (about) 1 package discord 2 3 import "time" 4 5 // https://discord.com/developers/docs/resources/guild#guild-object 6 type Guild struct { 7 // ID is the guild id. 8 ID GuildID `json:"id"` 9 // Name is the guild name (2-100 characters, excluding trailing and leading 10 // whitespace). 11 Name string `json:"name"` 12 // Icon is the icon hash.&nullableUint64{} 13 Icon Hash `json:"icon"` 14 // Splash is the splash hash. 15 Splash Hash `json:"splash,omitempty"` 16 // DiscoverySplash is the discovery splash hash. 17 // 18 // Only present for guilds with the "DISCOVERABLE" feature. 19 DiscoverySplash Hash `json:"discovery_splash,omitempty"` 20 21 // Owner is true if the user is the owner of the guild. 22 Owner bool `json:"owner,omitempty"` 23 // Widget is true if the server widget is enabled. 24 Widget bool `json:"widget_enabled,omitempty"` 25 26 // SystemChannelFlags are the system channel flags. 27 SystemChannelFlags SystemChannelFlags `json:"system_channel_flags"` 28 // Verification is the verification level required for the guild. 29 Verification Verification `json:"verification_level"` 30 // Notification is the default message notifications level. 31 Notification Notification `json:"default_message_notifications"` 32 // ExplicitFilter is the explicit content filter level. 33 ExplicitFilter ExplicitFilter `json:"explicit_content_filter"` 34 // NitroBoost is the premium tier (Server Boost level). 35 NitroBoost NitroBoost `json:"premium_tier"` 36 // MFA is the required MFA level for the guild. 37 MFA MFALevel `json:"mfa"` 38 39 // OwnerID is the id of owner. 40 OwnerID UserID `json:"owner_id"` 41 // WidgetChannelID is the channel id that the widget will generate an 42 // invite to, or null if set to no invite. 43 WidgetChannelID ChannelID `json:"widget_channel_id,omitempty"` 44 // SystemChannelID is the the id of the channel where guild notices such as 45 // welcome messages and boost events are posted. 46 SystemChannelID ChannelID `json:"system_channel_id,omitempty"` 47 48 // Permissions are the total permissions for the user in the guild 49 // (excludes overrides). 50 Permissions Permissions `json:"permissions,string,omitempty"` 51 52 // VoiceRegion is the voice region id for the guild. 53 VoiceRegion string `json:"region"` 54 55 // AFKChannelID is the id of the afk channel. 56 AFKChannelID ChannelID `json:"afk_channel_id,omitempty"` 57 // AFKTimeout is the afk timeout in seconds. 58 AFKTimeout Seconds `json:"afk_timeout"` 59 60 // Roles are the roles in the guild. 61 Roles []Role `json:"roles"` 62 // Emojis are the custom guild emojis. 63 Emojis []Emoji `json:"emojis"` 64 // Features are the enabled guild features. 65 Features []GuildFeature `json:"guild_features"` 66 67 // AppID is the application id of the guild creator if it is bot-created. 68 // 69 // This field is nullable. 70 AppID AppID `json:"application_id,omitempty"` 71 72 // RulesChannelID is the id of the channel where guilds with the "PUBLIC" 73 // feature can display rules and/or guidelines. 74 RulesChannelID ChannelID `json:"rules_channel_id"` 75 76 // MaxPresences is the maximum number of presences for the guild (the 77 // default value, currently 25000, is in effect when null is returned, so 78 // effectively when this field is 0). 79 MaxPresences uint64 `json:"max_presences,omitempty"` 80 // MaxMembers the maximum number of members for the guild. 81 MaxMembers uint64 `json:"max_members,omitempty"` 82 83 // VanityURL is the the vanity url code for the guild. 84 VanityURLCode string `json:"vanity_url_code,omitempty"` 85 // Description is the description for the guild, if the guild is 86 // discoverable. 87 Description string `json:"description,omitempty"` 88 89 // Banner is the banner hash. 90 Banner Hash `json:"banner,omitempty"` 91 92 // NitroBoosters is the number of boosts this guild currently has. 93 NitroBoosters uint64 `json:"premium_subscription_count,omitempty"` 94 95 // PreferredLocale is the the preferred locale of a guild with the "PUBLIC" 96 // feature; used in server discovery and notices from Discord. Defaults to 97 // "en-US". 98 PreferredLocale string `json:"preferred_locale"` 99 100 // PublicUpdatesChannelID is the id of the channel where admins and 101 // moderators of guilds with the "PUBLIC" feature receive notices from 102 // Discord. 103 PublicUpdatesChannelID ChannelID `json:"public_updates_channel_id"` 104 105 // MaxVideoChannelUsers is the maximum amount of users in a video channel. 106 MaxVideoChannelUsers uint64 `json:"max_video_channel_users,omitempty"` 107 108 // ApproximateMembers is the approximate number of members in this guild, 109 // returned by the GuildWithCount method. 110 ApproximateMembers uint64 `json:"approximate_member_count,omitempty"` 111 // ApproximatePresences is the approximate number of non-offline members in 112 // this guild, returned by the GuildWithCount method. 113 ApproximatePresences uint64 `json:"approximate_presence_count,omitempty"` 114 } 115 116 // CreatedAt returns a time object representing when the guild was created. 117 func (g Guild) CreatedAt() time.Time { 118 return g.ID.Time() 119 } 120 121 // IconURL returns the URL to the guild icon and auto detects a suitable type. 122 // An empty string is returned if there's no icon. 123 func (g Guild) IconURL() string { 124 return g.IconURLWithType(AutoImage) 125 } 126 127 // IconURLWithType returns the URL to the guild icon using the passed 128 // ImageType. An empty string is returned if there's no icon. 129 // 130 // Supported ImageTypes: PNG, JPEG, WebP, GIF 131 func (g Guild) IconURLWithType(t ImageType) string { 132 if g.Icon == "" { 133 return "" 134 } 135 136 return "https://cdn.discordapp.com/icons/" + g.ID.String() + "/" + t.format(g.Icon) 137 } 138 139 // BannerURL returns the URL to the banner, which is the image on top of the 140 // channels list. This will always return a link to a PNG file. 141 func (g Guild) BannerURL() string { 142 return g.BannerURLWithType(PNGImage) 143 } 144 145 // BannerURLWithType returns the URL to the banner, which is the image on top 146 // of the channels list using the passed image type. 147 // 148 // Supported ImageTypes: PNG, JPEG, WebP 149 func (g Guild) BannerURLWithType(t ImageType) string { 150 if g.Banner == "" { 151 return "" 152 } 153 154 return "https://cdn.discordapp.com/banners/" + 155 g.ID.String() + "/" + t.format(g.Banner) 156 } 157 158 // SplashURL returns the URL to the guild splash, which is the invite page's 159 // background. This will always return a link to a PNG file. 160 func (g Guild) SplashURL() string { 161 return g.SplashURLWithType(PNGImage) 162 } 163 164 // SplashURLWithType returns the URL to the guild splash, which is the invite 165 // page's background, using the passed ImageType. 166 // 167 // Supported ImageTypes: PNG, JPEG, WebP 168 func (g Guild) SplashURLWithType(t ImageType) string { 169 if g.Splash == "" { 170 return "" 171 } 172 173 return "https://cdn.discordapp.com/splashes/" + 174 g.ID.String() + "/" + t.format(g.Splash) 175 } 176 177 // DiscoverySplashURL returns the URL to the guild discovery splash. 178 // This will always return a link to a PNG file. 179 func (g Guild) DiscoverySplashURL() string { 180 return g.DiscoverySplashURLWithType(PNGImage) 181 } 182 183 // DiscoverySplashURLWithType returns the URL to the guild discovery splash, 184 // using the passed ImageType. 185 // 186 // Supported ImageTypes: PNG, JPEG, WebP 187 func (g Guild) DiscoverySplashURLWithType(t ImageType) string { 188 if g.DiscoverySplash == "" { 189 return "" 190 } 191 192 return "https://cdn.discordapp.com/splashes/" + 193 g.ID.String() + "/" + t.format(g.DiscoverySplash) 194 } 195 196 // https://discord.com/developers/docs/resources/guild#guild-preview-object 197 type GuildPreview struct { 198 // ID is the guild id. 199 ID GuildID `json:"id"` 200 // Name is the guild name (2-100 characters). 201 Name string `json:"name"` 202 203 // Icon is the icon hash. 204 Icon Hash `json:"icon"` 205 // Splash is the splash hash. 206 Splash Hash `json:"splash"` 207 // DiscoverySplash is the discovery splash hash. 208 DiscoverySplash Hash `json:"discovery_splash"` 209 210 // Emojis are the custom guild emojis. 211 Emojis []Emoji `json:"emojis"` 212 // Features are the enabled guild features. 213 Features []GuildFeature `json:"guild_features"` 214 215 // ApproximateMembers is the approximate number of members in this guild. 216 ApproximateMembers uint64 `json:"approximate_member_count"` 217 // ApproximatePresences is the approximate number of online members in this 218 // guild. 219 ApproximatePresences uint64 `json:"approximate_presence_count"` 220 221 // Description is the description for the guild. 222 Description string `json:"description,omitempty"` 223 } 224 225 // CreatedAt returns a time object representing when the guild the preview 226 // represents was created. 227 func (g GuildPreview) CreatedAt() time.Time { 228 return g.ID.Time() 229 } 230 231 // IconURL returns the URL to the guild icon and auto detects a suitable type. 232 // An empty string is returned if there's no icon. 233 func (g GuildPreview) IconURL() string { 234 return g.IconURLWithType(AutoImage) 235 } 236 237 // IconURLWithType returns the URL to the guild icon using the passed 238 // ImageType. An empty string is returned if there's no icon. 239 // 240 // Supported ImageTypes: PNG, JPEG, WebP, GIF 241 func (g GuildPreview) IconURLWithType(t ImageType) string { 242 if g.Icon == "" { 243 return "" 244 } 245 246 return "https://cdn.discordapp.com/icons/" + g.ID.String() + "/" + t.format(g.Icon) 247 } 248 249 // SplashURL returns the URL to the guild splash, which is the invite page's 250 // background. This will always return a link to a PNG file. 251 func (g GuildPreview) SplashURL() string { 252 return g.SplashURLWithType(PNGImage) 253 } 254 255 // SplashURLWithType returns the URL to the guild splash, which is the invite 256 // page's background, using the passed ImageType. 257 // 258 // Supported ImageTypes: PNG, JPEG, WebP 259 func (g GuildPreview) SplashURLWithType(t ImageType) string { 260 if g.Splash == "" { 261 return "" 262 } 263 264 return "https://cdn.discordapp.com/splashes/" + 265 g.ID.String() + "/" + t.format(g.Splash) 266 } 267 268 // DiscoverySplashURL returns the URL to the guild discovery splash. 269 // This will always return a link to a PNG file. 270 func (g GuildPreview) DiscoverySplashURL() string { 271 return g.DiscoverySplashURLWithType(PNGImage) 272 } 273 274 // DiscoverySplashURLWithType returns the URL to the guild discovery splash, 275 // using the passed ImageType. 276 // 277 // Supported ImageTypes: PNG, JPEG, WebP 278 func (g GuildPreview) DiscoverySplashURLWithType(t ImageType) string { 279 if g.DiscoverySplash == "" { 280 return "" 281 } 282 283 return "https://cdn.discordapp.com/splashes/" + 284 g.ID.String() + "/" + t.format(g.DiscoverySplash) 285 } 286 287 // https://discord.com/developers/docs/topics/permissions#role-object 288 type Role struct { 289 // ID is the role id. 290 ID RoleID `json:"id"` 291 // Name is the role name. 292 Name string `json:"name"` 293 294 // Permissions is the permission bit set. 295 Permissions Permissions `json:"permissions,string"` 296 297 // Position is the position of this role. 298 Position int `json:"position"` 299 // Color is the integer representation of hexadecimal color code. 300 Color Color `json:"color"` 301 302 // Hoist specifies if this role is pinned in the user listing. 303 Hoist bool `json:"hoist"` 304 // Manages specifies whether this role is managed by an integration. 305 Managed bool `json:"managed"` 306 // Mentionable specifies whether this role is mentionable. 307 Mentionable bool `json:"mentionable"` 308 } 309 310 // CreatedAt returns a time object representing when the role was created. 311 func (r Role) CreatedAt() time.Time { 312 return r.ID.Time() 313 } 314 315 // Mention returns the mention of the Role. 316 func (r Role) Mention() string { 317 return r.ID.Mention() 318 } 319 320 // https://discord.com/developers/docs/resources/guild#guild-member-object 321 // 322 // The field user won't be included in the member object attached to 323 // MESSAGE_CREATE and MESSAGE_UPDATE gateway events. 324 type Member struct { 325 // User is the user this guild member represents. 326 User User `json:"user"` 327 // Nick is this users guild nickname. 328 Nick string `json:"nick,omitempty"` 329 // RoleIDs is an array of role object ids. 330 RoleIDs []RoleID `json:"roles"` 331 332 // Joined specifies when the user joined the guild. 333 Joined Timestamp `json:"joined_at"` 334 // BoostedSince specifies when the user started boosting the guild. 335 BoostedSince Timestamp `json:"premium_since,omitempty"` 336 337 // Deaf specifies whether the user is deafened in voice channels. 338 Deaf bool `json:"deaf"` 339 // Mute specifies whether the user is muted in voice channels. 340 Mute bool `json:"mute"` 341 } 342 343 // Mention returns the mention of the role. 344 func (m Member) Mention() string { 345 return "<@!" + m.User.ID.String() + ">" 346 } 347 348 // https://discord.com/developers/docs/resources/guild#ban-object 349 type Ban struct { 350 // Reason is the reason for the ban. 351 Reason string `json:"reason,omitempty"` 352 // User is the banned user. 353 User User `json:"user"` 354 } 355 356 // https://discord.com/developers/docs/resources/guild#integration-object 357 type Integration struct { 358 // ID is the integration id. 359 ID IntegrationID `json:"id"` 360 // Name is the integration name. 361 Name string `json:"name"` 362 // Type is the integration type (twitch, youtube, discord). 363 Type Service `json:"type"` 364 365 // Enables specifies if the integration is enabled. 366 Enabled bool `json:"enabled"` 367 // Syncing specifies if the integration is syncing. 368 // This field is not provided for bot integrations. 369 Syncing bool `json:"syncing,omitempty"` 370 371 // RoleID is the id that this integration uses for "subscribers". 372 // This field is not provided for bot integrations. 373 RoleID RoleID `json:"role_id,omitempty"` 374 375 // EnableEmoticons specifies whether emoticons should be synced for this 376 // integration (twitch only currently). 377 // This field is not provided for bot integrations. 378 EnableEmoticons bool `json:"enable_emoticons,omitempty"` 379 380 // ExpireBehavior is the behavior of expiring subscribers. 381 // This field is not provided for bot integrations. 382 ExpireBehavior ExpireBehavior `json:"expire_behavior,omitempty"` 383 // ExpireGracePeriod is the grace period (in days) before expiring 384 // subscribers. 385 // This field is not provided for bot integrations. 386 ExpireGracePeriod int `json:"expire_grace_period,omitempty"` 387 388 // User is the user for this integration. 389 // This field is not provided for bot integrations. 390 User User `json:"user,omitempty"` 391 // Account is the integration account information. 392 Account IntegrationAccount `json:"account"` 393 394 // SyncedAt specifies when this integration was last synced. 395 // This field is not provided for bot integrations. 396 SyncedAt Timestamp `json:"synced_at,omitempty"` 397 // SubscriberCount specifies how many subscribers the integration has. 398 // This field is not provided for bot integrations. 399 SubscriberCount int `json:"subscriber_count,omitempty"` 400 // Revoked specifies whether the integration has been revoked. 401 // This field is not provided for bot integrations. 402 Revoked bool `json:"revoked,omitempty"` 403 // Application is the bot/OAuth2 application for integrations. 404 Application *IntegrationApplication `json:"application,omitempty"` 405 } 406 407 // CreatedAt returns a time object representing when the integration was created. 408 func (i Integration) CreatedAt() time.Time { 409 return i.ID.Time() 410 } 411 412 // https://discord.com/developers/docs/resources/guild#integration-account-object 413 type IntegrationAccount struct { 414 // ID is the id of the account. 415 ID string `json:"id"` 416 // Name is the name of the account. 417 Name string `json:"name"` 418 } 419 420 // https://discord.com/developers/docs/resources/guild#integration-application-object 421 type IntegrationApplication struct { 422 // ID is the id of the app. 423 ID IntegrationID `json:"id"` 424 // Name is the name of the app. 425 Name string `json:"name"` 426 // Icon is the icon hash of the app. 427 Icon *Hash `json:"icon"` 428 // Description is the description of the app. 429 Description string `json:"description"` 430 // Summary is a summary of the app. 431 Summary string `json:"summary"` 432 // Bot is the bot associated with the app. 433 Bot User `json:"bot,omitempty"` 434 } 435 436 // CreatedAt returns a time object representing when the integration application 437 // was created. 438 func (i IntegrationApplication) CreatedAt() time.Time { 439 return i.ID.Time() 440 } 441 442 // https://discord.com/developers/docs/resources/guild#get-guild-widget-example-get-guild-widget 443 type GuildWidget struct { 444 // ID is the ID of the guild. 445 ID GuildID `json:"id"` 446 // Name is the name of the guild. 447 Name string `json:"name"` 448 // InviteURl is the url of an instant invite to the guild. 449 InviteURL string `json:"instant_invite"` 450 Channels []Channel `json:"channels"` 451 Members []User `json:"members"` 452 // Presence count is the amount of presences in the guild 453 PresenceCount int `json:"presence_count"` 454 } 455 456 // https://discord.com/developers/docs/resources/guild#guild-widget-object 457 type GuildWidgetSettings struct { 458 // Enabled specifies whether the widget is enabled. 459 Enabled bool `json:"enabled"` 460 // ChannelID is the widget channel id. 461 ChannelID ChannelID `json:"channel_id,omitempty"` 462 } 463 464 // DefaultMemberColor is the color used for members without colored roles. 465 var DefaultMemberColor Color = 0x0 466 467 // MemberColor computes the effective color of the Member, taking into account 468 // the role colors. 469 func MemberColor(guild Guild, member Member) Color { 470 var c = DefaultMemberColor 471 var pos int 472 473 for _, r := range guild.Roles { 474 for _, mr := range member.RoleIDs { 475 if mr != r.ID { 476 continue 477 } 478 479 if r.Color > 0 && r.Position > pos { 480 c = r.Color 481 pos = r.Position 482 } 483 } 484 } 485 486 return c 487 }