From 4617d8e379c7605a0dc622914393417f473a6f8b Mon Sep 17 00:00:00 2001 From: Jim Eagle Date: Wed, 24 Feb 2021 17:10:18 +0000 Subject: [PATCH] Add guild preview endpoint (#818) --- endpoints.go | 1 + restapi.go | 12 ++++++++++++ structs.go | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/endpoints.go b/endpoints.go index 89d56edab..0dc27f442 100644 --- a/endpoints.go +++ b/endpoints.go @@ -78,6 +78,7 @@ var ( EndpointUserNotes = func(uID string) string { return EndpointUsers + "@me/notes/" + uID } EndpointGuild = func(gID string) string { return EndpointGuilds + gID } + EndpointGuildPreview = func(gID string) string { return EndpointGuilds + gID + "/preview" } EndpointGuildChannels = func(gID string) string { return EndpointGuilds + gID + "/channels" } EndpointGuildMembers = func(gID string) string { return EndpointGuilds + gID + "/members" } EndpointGuildMember = func(gID, uID string) string { return EndpointGuilds + gID + "/members/" + uID } diff --git a/restapi.go b/restapi.go index fc89e7fe0..3eedf4288 100644 --- a/restapi.go +++ b/restapi.go @@ -588,6 +588,18 @@ func (s *Session) Guild(guildID string) (st *Guild, err error) { return } +// GuildPreview returns a GuildPreview structure of a specific public Guild. +// guildID : The ID of a Guild +func (s *Session) GuildPreview(guildID string) (st *GuildPreview, err error) { + body, err := s.RequestWithBucketID("GET", EndpointGuildPreview(guildID), nil, EndpointGuildPreview(guildID)) + if err != nil { + return + } + + err = unmarshal(body, &st) + return +} + // GuildCreate creates a new Guild // name : A name for the Guild (2-100 characters) func (s *Session) GuildCreate(name string) (st *Guild, err error) { diff --git a/structs.go b/structs.go index eb84ea80f..5ce89014a 100644 --- a/structs.go +++ b/structs.go @@ -152,7 +152,7 @@ type Integration struct { SyncedAt Timestamp `json:"synced_at"` } -//ExpireBehavior of Integration +// ExpireBehavior of Integration // https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors type ExpireBehavior int @@ -572,6 +572,40 @@ type Guild struct { Permissions int64 `json:"permissions,string"` } +// A GuildPreview holds data related to a specific public Discord Guild, even if the user is not in the guild. +type GuildPreview struct { + // The ID of the guild. + ID string `json:"id"` + + // The name of the guild. (2–100 characters) + Name string `json:"name"` + + // The hash of the guild's icon. Use Session.GuildIcon + // to retrieve the icon itself. + Icon string `json:"icon"` + + // The hash of the guild's splash. + Splash string `json:"splash"` + + // The hash of the guild's discovery splash. + DiscoverySplash string `json:"discovery_splash"` + + // A list of the custom emojis present in the guild. + Emojis []*Emoji `json:"emojis"` + + // The list of enabled guild features + Features []string `json:"features"` + + // Approximate number of members in this guild, returned from the GET /guild/ endpoint when with_counts is true + ApproximateMemberCount int `json:"approximate_member_count"` + + // Approximate number of non-offline members in this guild, returned from the GET /guild/ endpoint when with_counts is true + ApproximatePresenceCount int `json:"approximate_presence_count"` + + // the description for the guild + Description string `json:"description"` +} + // MessageNotifications is the notification level for a guild // https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level type MessageNotifications int