github.com/diamondburned/arikawa@v1.3.14/discord/guild.go (about)

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