diff --git a/discord/guild.go b/discord/guild.go index ca133a8e..d1f92c13 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -164,7 +164,7 @@ type Guild struct { PreferredLocale string `json:"preferred_locale"` PublicUpdatesChannelID *snowflake.ID `json:"public_updates_channel_id"` MaxVideoChannelUsers int `json:"max_video_channel_users"` - WelcomeScreen WelcomeScreen `json:"welcome_screen"` + WelcomeScreen GuildWelcomeScreen `json:"welcome_screen"` NSFWLevel NSFWLevel `json:"nsfw_level"` BoostProgressBarEnabled bool `json:"premium_progress_bar_enabled"` JoinedAt time.Time `json:"joined_at"` @@ -265,13 +265,13 @@ type OAuth2Guild struct { Features []GuildFeature `json:"features"` } -// WelcomeScreen is the Welcome Screen of a Guild -type WelcomeScreen struct { +// GuildWelcomeScreen is the Welcome Screen of a Guild +type GuildWelcomeScreen struct { Description *string `json:"description,omitempty"` WelcomeChannels []GuildWelcomeChannel `json:"welcome_channels"` } -// GuildWelcomeChannel is one of the channels in a WelcomeScreen +// GuildWelcomeChannel is one of the channels in a GuildWelcomeScreen type GuildWelcomeChannel struct { ChannelID snowflake.ID `json:"channel_id"` Description string `json:"description"` @@ -279,6 +279,13 @@ type GuildWelcomeChannel struct { EmojiName *string `json:"emoji_name,omitempty"` } +// GuildWelcomeScreenUpdate is used to update the GuildWelcomeScreen of a Guild +type GuildWelcomeScreenUpdate struct { + Enabled *bool `json:"enabled,omitempty"` + WelcomeChannels *[]GuildWelcomeChannel `json:"welcome_channels,omitempty"` + Description *string `json:"description,omitempty"` +} + // GuildPreview is used for previewing public Guild(s) before joining them type GuildPreview struct { ID snowflake.ID `json:"id"` @@ -350,3 +357,13 @@ type GuildCreateChannel struct { ID int `json:"id,omitempty"` ParentID int `json:"parent_id,omitempty"` } + +type GuildPrune struct { + Days int `json:"days"` + ComputePruneCount bool `json:"compute_prune_count"` + IncludeRoles []snowflake.ID `json:"include_roles"` +} + +type GuildPruneResult struct { + Pruned *int `json:"pruned"` +} diff --git a/discord/invite.go b/discord/invite.go index b59936f3..b8aaae5b 100644 --- a/discord/invite.go +++ b/discord/invite.go @@ -43,6 +43,11 @@ type ExtendedInvite struct { CreatedAt time.Time `json:"created_at"` } +type PartialInvite struct { + Code *string `json:"code"` + Uses int `json:"uses"` +} + type InviteChannel struct { ID snowflake.ID `json:"id"` Type ChannelType `json:"type"` diff --git a/rest/guilds.go b/rest/guilds.go index 16df5f7e..e8ee9429 100644 --- a/rest/guilds.go +++ b/rest/guilds.go @@ -20,6 +20,8 @@ type Guilds interface { UpdateGuild(guildID snowflake.ID, guildUpdate discord.GuildUpdate, opts ...RequestOpt) (*discord.RestGuild, error) DeleteGuild(guildID snowflake.ID, opts ...RequestOpt) error + GetGuildVanityURL(guildID snowflake.ID, opts ...RequestOpt) (*discord.PartialInvite, error) + CreateGuildChannel(guildID snowflake.ID, guildChannelCreate discord.GuildChannelCreate, opts ...RequestOpt) (discord.GuildChannel, error) GetGuildChannels(guildID snowflake.ID, opts ...RequestOpt) ([]discord.GuildChannel, error) UpdateChannelPositions(guildID snowflake.ID, guildChannelPositionUpdates []discord.GuildChannelPositionUpdate, opts ...RequestOpt) error @@ -40,10 +42,18 @@ type Guilds interface { GetIntegrations(guildID snowflake.ID, opts ...RequestOpt) ([]discord.Integration, error) DeleteIntegration(guildID snowflake.ID, integrationID snowflake.ID, opts ...RequestOpt) error + GetGuildPruneCount(guildID snowflake.ID, days int, includeRoles []snowflake.ID, opts ...RequestOpt) (*discord.GuildPruneResult, error) + BeginGuildPrune(guildID snowflake.ID, guildPrune discord.GuildPrune, opts ...RequestOpt) (*discord.GuildPruneResult, error) + GetAllWebhooks(guildID snowflake.ID, opts ...RequestOpt) ([]discord.Webhook, error) + GetGuildVoiceRegions(guildID snowflake.ID, opts ...RequestOpt) ([]discord.VoiceRegion, error) + GetAuditLog(guildID snowflake.ID, userID snowflake.ID, actionType discord.AuditLogEvent, before snowflake.ID, limit int, opts ...RequestOpt) (*discord.AuditLog, error) GetAuditLogPage(guildID snowflake.ID, userID snowflake.ID, actionType discord.AuditLogEvent, startID snowflake.ID, limit int, opts ...RequestOpt) AuditLogPage + + GetGuildWelcomeScreen(guildID snowflake.ID, opts ...RequestOpt) (*discord.GuildWelcomeScreen, error) + UpdateGuildWelcomeScreen(guildID snowflake.ID, screenUpdate discord.GuildWelcomeScreenUpdate, opts ...RequestOpt) (*discord.GuildWelcomeScreen, error) } type guildImpl struct { @@ -77,6 +87,11 @@ func (s *guildImpl) DeleteGuild(guildID snowflake.ID, opts ...RequestOpt) error return s.client.Do(DeleteGuild.Compile(nil, guildID), nil, nil, opts...) } +func (s *guildImpl) GetGuildVanityURL(guildID snowflake.ID, opts ...RequestOpt) (partialInvite *discord.PartialInvite, err error) { + err = s.client.Do(GetGuildVanityURL.Compile(nil, guildID), nil, &partialInvite, opts...) + return +} + func (s *guildImpl) CreateGuildChannel(guildID snowflake.ID, guildChannelCreate discord.GuildChannelCreate, opts ...RequestOpt) (guildChannel discord.GuildChannel, err error) { var ch discord.UnmarshalChannel err = s.client.Do(CreateGuildChannel.Compile(nil, guildID), guildChannelCreate, &ch, opts...) @@ -180,13 +195,34 @@ func (s *guildImpl) DeleteIntegration(guildID snowflake.ID, integrationID snowfl return s.client.Do(DeleteIntegration.Compile(nil, guildID, integrationID), nil, nil, opts...) } +func (s *guildImpl) GetGuildPruneCount(guildID snowflake.ID, days int, includeRoles []snowflake.ID, opts ...RequestOpt) (result *discord.GuildPruneResult, err error) { + values := discord.QueryValues{ + "days": days, + } + var joinedRoles string + for i, roleID := range includeRoles { + joinedRoles += roleID.String() + if i != len(includeRoles)-1 { + joinedRoles += "," + } + } + values["include_roles"] = joinedRoles + err = s.client.Do(GetGuildPruneCount.Compile(values, guildID), nil, &result, opts...) + return +} + +func (s *guildImpl) BeginGuildPrune(guildID snowflake.ID, guildPrune discord.GuildPrune, opts ...RequestOpt) (result *discord.GuildPruneResult, err error) { + err = s.client.Do(BeginGuildPrune.Compile(nil, guildID), guildPrune, &result, opts...) + return +} + func (s *guildImpl) GetAllWebhooks(guildID snowflake.ID, opts ...RequestOpt) (webhooks []discord.Webhook, err error) { err = s.client.Do(GetGuildWebhooks.Compile(nil, guildID), nil, &webhooks, opts...) return } -func (s *guildImpl) GetEmojis(guildID snowflake.ID, opts ...RequestOpt) (emojis []discord.Emoji, err error) { - err = s.client.Do(GetEmojis.Compile(nil, guildID), nil, &emojis, opts...) +func (s *guildImpl) GetGuildVoiceRegions(guildID snowflake.ID, opts ...RequestOpt) (regions []discord.VoiceRegion, err error) { + err = s.client.Do(GetGuildVoiceRegions.Compile(nil, guildID), nil, ®ions, opts...) return } @@ -221,3 +257,13 @@ func (s *guildImpl) GetAuditLogPage(guildID snowflake.ID, userID snowflake.ID, a ID: startID, } } + +func (s *guildImpl) GetGuildWelcomeScreen(guildID snowflake.ID, opts ...RequestOpt) (welcomeScreen *discord.GuildWelcomeScreen, err error) { + err = s.client.Do(GetGuildWelcomeScreen.Compile(nil, guildID), nil, &welcomeScreen, opts...) + return +} + +func (s *guildImpl) UpdateGuildWelcomeScreen(guildID snowflake.ID, screenUpdate discord.GuildWelcomeScreenUpdate, opts ...RequestOpt) (welcomeScreen *discord.GuildWelcomeScreen, err error) { + err = s.client.Do(UpdateGuildWelcomeScreen.Compile(nil, guildID), screenUpdate, &welcomeScreen, opts...) + return +} diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index c63b1be3..469898a4 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -75,8 +75,8 @@ var ( UpdateCurrentMember = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/members/@me") - GetPruneMembersCount = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/prune") - PruneMembers = NewEndpoint(http.MethodPost, "/guilds/{guild.id}/prune") + GetGuildPruneCount = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/prune") + BeginGuildPrune = NewEndpoint(http.MethodPost, "/guilds/{guild.id}/prune") GetGuildWebhooks = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/webhooks") @@ -84,6 +84,9 @@ var ( GetGuildVoiceRegions = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/regions") + GetGuildWelcomeScreen = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/welcome-screen") + UpdateGuildWelcomeScreen = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/welcome-screen") + UpdateCurrentUserVoiceState = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/voice-states/@me") UpdateUserVoiceState = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/voice-states/{user.id}") )