Skip to content

Commit

Permalink
Add support for user apps
Browse files Browse the repository at this point in the history
  • Loading branch information
mlnrDev committed Mar 18, 2024
1 parent 1cd20b5 commit afb04c4
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 150 deletions.
86 changes: 51 additions & 35 deletions discord/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@ import (
)

type Application struct {
ID snowflake.ID `json:"id"`
Name string `json:"name"`
Icon *string `json:"icon,omitempty"`
Description string `json:"description"`
RPCOrigins []string `json:"rpc_origins"`
BotPublic bool `json:"bot_public"`
BotRequireCodeGrant bool `json:"bot_require_code_grant"`
Bot *User `json:"bot,omitempty"`
TermsOfServiceURL *string `json:"terms_of_service_url,omitempty"`
PrivacyPolicyURL *string `json:"privacy_policy_url,omitempty"`
CustomInstallURL *string `json:"custom_install_url,omitempty"`
InteractionsEndpointURL *string `json:"interactions_endpoint_url,omitempty"`
RoleConnectionsVerificationURL *string `json:"role_connections_verification_url"`
InstallParams *InstallParams `json:"install_params"`
Tags []string `json:"tags"`
Owner *User `json:"owner,omitempty"`
Summary string `json:"summary"`
VerifyKey string `json:"verify_key"`
Team *Team `json:"team,omitempty"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
Guild *Guild `json:"guild,omitempty"`
PrimarySkuID *snowflake.ID `json:"primary_sku_id,omitempty"`
Slug *string `json:"slug,omitempty"`
CoverImage *string `json:"cover_image,omitempty"`
Flags ApplicationFlags `json:"flags,omitempty"`
ApproximateGuildCount *int `json:"approximate_guild_count,omitempty"`
ID snowflake.ID `json:"id"`
Name string `json:"name"`
Icon *string `json:"icon,omitempty"`
Description string `json:"description"`
RPCOrigins []string `json:"rpc_origins"`
BotPublic bool `json:"bot_public"`
BotRequireCodeGrant bool `json:"bot_require_code_grant"`
Bot *User `json:"bot,omitempty"`
TermsOfServiceURL *string `json:"terms_of_service_url,omitempty"`
PrivacyPolicyURL *string `json:"privacy_policy_url,omitempty"`
CustomInstallURL *string `json:"custom_install_url,omitempty"`
InteractionsEndpointURL *string `json:"interactions_endpoint_url,omitempty"`
RoleConnectionsVerificationURL *string `json:"role_connections_verification_url"`
InstallParams *InstallParams `json:"install_params"`
Tags []string `json:"tags"`
Owner *User `json:"owner,omitempty"`
Summary string `json:"summary"`
VerifyKey string `json:"verify_key"`
Team *Team `json:"team,omitempty"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
Guild *Guild `json:"guild,omitempty"`
PrimarySkuID *snowflake.ID `json:"primary_sku_id,omitempty"`
Slug *string `json:"slug,omitempty"`
CoverImage *string `json:"cover_image,omitempty"`
Flags ApplicationFlags `json:"flags,omitempty"`
ApproximateGuildCount *int `json:"approximate_guild_count,omitempty"`
IntegrationTypes []ApplicationIntegrationType `json:"integration_types"`
IntegrationTypesConfig ApplicationIntegrationTypesConfig `json:"integration_types_config"`
}

func (a Application) IconURL(opts ...CDNOpt) *string {
Expand All @@ -61,15 +63,16 @@ func (a Application) CreatedAt() time.Time {
}

type ApplicationUpdate struct {
CustomInstallURL *string `json:"custom_install_url,omitempty"`
Description *string `json:"description,omitempty"`
RoleConnectionsVerificationURL *string `json:"role_connections_verification_url,omitempty"`
InstallParams *InstallParams `json:"install_params,omitempty"`
Flags *ApplicationFlags `json:"flags,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
CoverImage *json.Nullable[Icon] `json:"cover_image,omitempty"`
InteractionsEndpointURL *string `json:"interactions_endpoint_url,omitempty"`
Tags []string `json:"tags,omitempty"`
CustomInstallURL *string `json:"custom_install_url,omitempty"`
Description *string `json:"description,omitempty"`
RoleConnectionsVerificationURL *string `json:"role_connections_verification_url,omitempty"`
InstallParams *InstallParams `json:"install_params,omitempty"`
Flags *ApplicationFlags `json:"flags,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
CoverImage *json.Nullable[Icon] `json:"cover_image,omitempty"`
InteractionsEndpointURL *string `json:"interactions_endpoint_url,omitempty"`
Tags []string `json:"tags,omitempty"`
IntegrationTypesConfig *ApplicationIntegrationTypesConfig `json:"integration_types_config,omitempty"`
}

type PartialApplication struct {
Expand Down Expand Up @@ -259,3 +262,16 @@ type TeamPermissions string
const (
TeamPermissionAdmin = "*"
)

type ApplicationIntegrationType int

const (
ApplicationIntegrationTypeGuildInstall ApplicationIntegrationType = iota
ApplicationIntegrationTypeUserInstall
)

type ApplicationIntegrationTypesConfig map[ApplicationIntegrationType]ApplicationIntegrationTypeConfiguration

type ApplicationIntegrationTypeConfiguration struct {
OAuth2InstallParams InstallParams `json:"oauth2_install_params"`
}
44 changes: 44 additions & 0 deletions discord/application_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type ApplicationCommand interface {
Version() snowflake.ID
CreatedAt() time.Time
NSFW() bool
IntegrationTypes() []ApplicationIntegrationType
Contexts() []InteractionContextType
applicationCommand()
}

Expand Down Expand Up @@ -95,6 +97,8 @@ type SlashCommand struct {
defaultMemberPermissions Permissions
dmPermission bool
nsfw bool
integrationTypes []ApplicationIntegrationType
contexts []InteractionContextType
version snowflake.ID
}

Expand All @@ -117,6 +121,8 @@ func (c *SlashCommand) UnmarshalJSON(data []byte) error {
c.defaultMemberPermissions = v.DefaultMemberPermissions
c.dmPermission = v.DMPermission
c.nsfw = v.NSFW
c.integrationTypes = v.IntegrationTypes
c.contexts = v.Contexts
c.version = v.Version
return nil
}
Expand All @@ -137,6 +143,8 @@ func (c SlashCommand) MarshalJSON() ([]byte, error) {
DefaultMemberPermissions: c.defaultMemberPermissions,
DMPermission: c.dmPermission,
NSFW: c.nsfw,
IntegrationTypes: c.integrationTypes,
Contexts: c.contexts,
Version: c.version,
})
}
Expand Down Expand Up @@ -180,6 +188,14 @@ func (c SlashCommand) NSFW() bool {
return c.nsfw
}

func (c SlashCommand) IntegrationTypes() []ApplicationIntegrationType {
return c.integrationTypes
}

func (c SlashCommand) Contexts() []InteractionContextType {
return c.contexts
}

func (c SlashCommand) Version() snowflake.ID {
return c.version
}
Expand All @@ -206,6 +222,8 @@ type UserCommand struct {
defaultMemberPermissions Permissions
dmPermission bool
nsfw bool
integrationTypes []ApplicationIntegrationType
contexts []InteractionContextType
version snowflake.ID
}

Expand All @@ -224,6 +242,8 @@ func (c *UserCommand) UnmarshalJSON(data []byte) error {
c.defaultMemberPermissions = v.DefaultMemberPermissions
c.dmPermission = v.DMPermission
c.nsfw = v.NSFW
c.integrationTypes = v.IntegrationTypes
c.contexts = v.Contexts
c.version = v.Version
return nil
}
Expand All @@ -240,6 +260,8 @@ func (c UserCommand) MarshalJSON() ([]byte, error) {
DefaultMemberPermissions: c.defaultMemberPermissions,
DMPermission: c.dmPermission,
NSFW: c.nsfw,
IntegrationTypes: c.integrationTypes,
Contexts: c.contexts,
Version: c.version,
})
}
Expand Down Expand Up @@ -283,6 +305,14 @@ func (c UserCommand) NSFW() bool {
return c.nsfw
}

func (c UserCommand) IntegrationTypes() []ApplicationIntegrationType {
return c.integrationTypes
}

func (c UserCommand) Contexts() []InteractionContextType {
return c.contexts
}

func (c UserCommand) Version() snowflake.ID {
return c.version
}
Expand All @@ -305,6 +335,8 @@ type MessageCommand struct {
defaultMemberPermissions Permissions
dmPermission bool
nsfw bool
integrationTypes []ApplicationIntegrationType
contexts []InteractionContextType
version snowflake.ID
}

Expand All @@ -323,6 +355,8 @@ func (c *MessageCommand) UnmarshalJSON(data []byte) error {
c.defaultMemberPermissions = v.DefaultMemberPermissions
c.dmPermission = v.DMPermission
c.nsfw = v.NSFW
c.integrationTypes = v.IntegrationTypes
c.contexts = v.Contexts
c.version = v.Version
return nil
}
Expand All @@ -339,6 +373,8 @@ func (c MessageCommand) MarshalJSON() ([]byte, error) {
DefaultMemberPermissions: c.defaultMemberPermissions,
DMPermission: c.dmPermission,
NSFW: c.nsfw,
IntegrationTypes: c.integrationTypes,
Contexts: c.contexts,
Version: c.version,
})
}
Expand Down Expand Up @@ -382,6 +418,14 @@ func (c MessageCommand) NSFW() bool {
return c.nsfw
}

func (c MessageCommand) IntegrationTypes() []ApplicationIntegrationType {
return c.integrationTypes
}

func (c MessageCommand) Contexts() []InteractionContextType {
return c.contexts
}

func (c MessageCommand) Version() snowflake.ID {
return c.version
}
Expand Down
21 changes: 15 additions & 6 deletions discord/application_command_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ type SlashCommandCreate struct {
DescriptionLocalizations map[Locale]string `json:"description_localizations,omitempty"`
Options []ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"` // different behavior for 0 and null, optional
DMPermission *bool `json:"dm_permission,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
// Deprecated: Use Contexts instead
DMPermission *bool `json:"dm_permission,omitempty"`
IntegrationTypes []ApplicationIntegrationType `json:"integration_types,omitempty"`
Contexts []InteractionContextType `json:"contexts,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
}

func (c SlashCommandCreate) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -45,8 +48,11 @@ type UserCommandCreate struct {
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
// Deprecated: Use Contexts instead
DMPermission *bool `json:"dm_permission,omitempty"`
IntegrationTypes []ApplicationIntegrationType `json:"integration_types,omitempty"`
Contexts []InteractionContextType `json:"contexts,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
}

func (c UserCommandCreate) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -74,8 +80,11 @@ type MessageCommandCreate struct {
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
// Deprecated: Use Contexts instead
DMPermission *bool `json:"dm_permission,omitempty"`
IntegrationTypes []ApplicationIntegrationType `json:"integration_types,omitempty"`
Contexts []InteractionContextType `json:"contexts,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
}

func (c MessageCommandCreate) MarshalJSON() ([]byte, error) {
Expand Down
56 changes: 30 additions & 26 deletions discord/application_command_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import (
)

type rawSlashCommand struct {
ID snowflake.ID `json:"id"`
Type ApplicationCommandType `json:"type"`
ApplicationID snowflake.ID `json:"application_id"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
NameLocalized string `json:"name_localized,omitempty"`
Description string `json:"description,omitempty"`
DescriptionLocalizations map[Locale]string `json:"description_localizations,omitempty"`
DescriptionLocalized string `json:"description_localized,omitempty"`
Options []ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
NSFW bool `json:"nsfw"`
Version snowflake.ID `json:"version"`
ID snowflake.ID `json:"id"`
Type ApplicationCommandType `json:"type"`
ApplicationID snowflake.ID `json:"application_id"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
NameLocalized string `json:"name_localized,omitempty"`
Description string `json:"description,omitempty"`
DescriptionLocalizations map[Locale]string `json:"description_localizations,omitempty"`
DescriptionLocalized string `json:"description_localized,omitempty"`
Options []ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
NSFW bool `json:"nsfw"`
IntegrationTypes []ApplicationIntegrationType `json:"integration_types"`
Contexts []InteractionContextType `json:"contexts"`
Version snowflake.ID `json:"version"`
}

func (c *rawSlashCommand) UnmarshalJSON(data []byte) error {
Expand All @@ -46,15 +48,17 @@ func (c *rawSlashCommand) UnmarshalJSON(data []byte) error {
}

type rawContextCommand struct {
ID snowflake.ID `json:"id"`
Type ApplicationCommandType `json:"type"`
ApplicationID snowflake.ID `json:"application_id"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
NameLocalized string `json:"name_localized,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
NSFW bool `json:"nsfw"`
Version snowflake.ID `json:"version"`
ID snowflake.ID `json:"id"`
Type ApplicationCommandType `json:"type"`
ApplicationID snowflake.ID `json:"application_id"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
NameLocalized string `json:"name_localized,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
NSFW bool `json:"nsfw"`
IntegrationTypes []ApplicationIntegrationType `json:"integration_types"`
Contexts []InteractionContextType `json:"contexts"`
Version snowflake.ID `json:"version"`
}
Loading

0 comments on commit afb04c4

Please sign in to comment.