Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some missing guild endpoints #220

Merged
merged 4 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions discord/guild.go
Expand Up @@ -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"`
Expand Down Expand Up @@ -265,20 +265,27 @@ 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"`
EmojiID *snowflake.ID `json:"emoji_id,omitempty"`
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"`
Expand Down Expand Up @@ -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"`
}
5 changes: 5 additions & 0 deletions discord/invite.go
Expand Up @@ -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"`
Expand Down
50 changes: 48 additions & 2 deletions rest/guilds.go
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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, &regions, opts...)
return
}

Expand Down Expand Up @@ -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
}
7 changes: 5 additions & 2 deletions rest/rest_endpoints.go
Expand Up @@ -75,15 +75,18 @@ 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")

GetAuditLogs = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/audit-logs")

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}")
)
Expand Down