diff --git a/discord/entitlement.go b/discord/entitlement.go index 61fe22d2..ffbd30cb 100644 --- a/discord/entitlement.go +++ b/discord/entitlement.go @@ -7,16 +7,19 @@ import ( ) type Entitlement struct { - ID snowflake.ID `json:"id"` - SkuID snowflake.ID `json:"sku_id"` - ApplicationID snowflake.ID `json:"application_id"` - UserID *snowflake.ID `json:"user_id"` - Type EntitlementType `json:"type"` - Deleted bool `json:"deleted"` - StartsAt *time.Time `json:"starts_at"` - EndsAt *time.Time `json:"ends_at"` - GuildID *snowflake.ID `json:"guild_id"` - Consumed *bool `json:"consumed"` + ID snowflake.ID `json:"id"` + SkuID snowflake.ID `json:"sku_id"` + ApplicationID snowflake.ID `json:"application_id"` + UserID *snowflake.ID `json:"user_id"` + PromotionID *snowflake.ID `json:"promotion_id"` + Type EntitlementType `json:"type"` + Deleted bool `json:"deleted"` + GiftCodeFlags int `json:"gift_code_flags"` + Consumed *bool `json:"consumed"` + StartsAt *time.Time `json:"starts_at"` + EndsAt *time.Time `json:"ends_at"` + GuildID *snowflake.ID `json:"guild_id"` + SubscriptionID *snowflake.ID `json:"subscription_id"` } type EntitlementType int diff --git a/rest/applications.go b/rest/applications.go index 906e5c5f..773e3b60 100644 --- a/rest/applications.go +++ b/rest/applications.go @@ -37,7 +37,8 @@ type Applications interface { GetApplicationRoleConnectionMetadata(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.ApplicationRoleConnectionMetadata, error) UpdateApplicationRoleConnectionMetadata(applicationID snowflake.ID, newRecords []discord.ApplicationRoleConnectionMetadata, opts ...RequestOpt) ([]discord.ApplicationRoleConnectionMetadata, error) - GetEntitlements(applicationID snowflake.ID, userID snowflake.ID, guildID snowflake.ID, before snowflake.ID, after snowflake.ID, limit int, excludeEnded bool, skuIDs []snowflake.ID, opts ...RequestOpt) ([]discord.Entitlement, error) + GetEntitlements(applicationID snowflake.ID, params GetEntitlementsParams, opts ...RequestOpt) ([]discord.Entitlement, error) + GetEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) (*discord.Entitlement, error) CreateTestEntitlement(applicationID snowflake.ID, entitlementCreate discord.TestEntitlementCreate, opts ...RequestOpt) (*discord.Entitlement, error) DeleteTestEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error ConsumeEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error @@ -51,6 +52,42 @@ type Applications interface { GetActivityInstance(applicationID snowflake.ID, instanceID string, opts ...RequestOpt) (*discord.ActivityInstance, error) } +// GetEntitlementsParams holds query parameters for Applications.GetEntitlements (https://discord.com/developers/docs/resources/entitlement#list-entitlements) +type GetEntitlementsParams struct { + UserID snowflake.ID + SkuIDs []snowflake.ID + Before int + After int + Limit int + GuildID snowflake.ID + ExcludeEnded bool + ExcludeDeleted bool +} + +func (p GetEntitlementsParams) ToQueryValues() discord.QueryValues { + queryValues := discord.QueryValues{ + "exclude_ended": p.ExcludeEnded, + "exclude_deleted": p.ExcludeDeleted, + "sku_ids": slicehelper.JoinSnowflakes(p.SkuIDs), + } + if p.UserID != 0 { + queryValues["user_id"] = p.UserID + } + if p.Before != 0 { + queryValues["before"] = p.Before + } + if p.After != 0 { + queryValues["after"] = p.After + } + if p.Limit != 0 { + queryValues["limit"] = p.Limit + } + if p.GuildID != 0 { + queryValues["guild_id"] = p.GuildID + } + return queryValues +} + type applicationsImpl struct { client Client } @@ -183,27 +220,13 @@ func (s *applicationsImpl) UpdateApplicationRoleConnectionMetadata(applicationID return } -func (s *applicationsImpl) GetEntitlements(applicationID snowflake.ID, userID snowflake.ID, guildID snowflake.ID, before snowflake.ID, after snowflake.ID, limit int, excludeEnded bool, skuIDs []snowflake.ID, opts ...RequestOpt) (entitlements []discord.Entitlement, err error) { - queryValues := discord.QueryValues{ - "exclude_ended": excludeEnded, - "sku_ids": slicehelper.JoinSnowflakes(skuIDs), - } - if userID != 0 { - queryValues["user_id"] = userID - } - if guildID != 0 { - queryValues["guild_id"] = guildID - } - if before != 0 { - queryValues["before"] = before - } - if after != 0 { - queryValues["after"] = after - } - if limit != 0 { - queryValues["limit"] = limit - } - err = s.client.Do(GetEntitlements.Compile(queryValues, applicationID), nil, &entitlements, opts...) +func (s *applicationsImpl) GetEntitlements(applicationID snowflake.ID, params GetEntitlementsParams, opts ...RequestOpt) (entitlements []discord.Entitlement, err error) { + err = s.client.Do(GetEntitlements.Compile(params.ToQueryValues(), applicationID), nil, &entitlements, opts...) + return +} + +func (s *applicationsImpl) GetEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) (entitlement *discord.Entitlement, err error) { + err = s.client.Do(GetEntitlement.Compile(nil, applicationID, entitlementID), nil, &entitlement, opts...) return } diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index e61bcf94..5eb04959 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -312,6 +312,7 @@ var ( UpdateApplicationRoleConnectionMetadata = NewEndpoint(http.MethodPut, "/applications/{application.id}/role-connections/metadata") GetEntitlements = NewEndpoint(http.MethodGet, "/applications/{application.id}/entitlements") + GetEntitlement = NewEndpoint(http.MethodGet, "/applications/{application.id}/entitlements/{entitlement.id}") CreateTestEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements") DeleteTestEntitlement = NewEndpoint(http.MethodDelete, "/applications/{application.id}/entitlements/{entitlement.id}") ConsumeEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements/{entitlement.id}/consume")