Skip to content

Commit

Permalink
feat: user apps (#1511)
Browse files Browse the repository at this point in the history
* feat: add integration types

* feat(ApplicationCommand): add integration_types

* feat(interactions): implement contexts

* feat(Interaction): add authorizing_integration_owners

* chore(ApplicationCommand): deprecate DMPermission

* feat(Application): add integration_types_config

* feat(Message): add InteractionMetadata

* feat(ApplicationIntegrationTypeConfig): add omitempty tag to OAuth2InstallParams

* feat(Application): add omitempty tag to IntegrationTypesConfig
  • Loading branch information
FedorLap2006 authored Jun 20, 2024
1 parent cf4e4e0 commit a31fd86
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 20 deletions.
24 changes: 22 additions & 2 deletions interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ type ApplicationCommand struct {
Type ApplicationCommandType `json:"type,omitempty"`
Name string `json:"name"`
NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
// NOTE: DefaultPermission will be soon deprecated. Use DefaultMemberPermissions and DMPermission instead.

// NOTE: DefaultPermission will be soon deprecated. Use DefaultMemberPermissions and Contexts instead.
DefaultPermission *bool `json:"default_permission,omitempty"`
DefaultMemberPermissions *int64 `json:"default_member_permissions,string,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`

// Deprecated: use Contexts instead.
DMPermission *bool `json:"dm_permission,omitempty"`
Contexts *[]InteractionContextType `json:"contexts,omitempty"`
IntegrationTypes *[]ApplicationIntegrationType `json:"integration_types,omitempty"`

// NOTE: Chat commands only. Otherwise it mustn't be set.

Description string `json:"description,omitempty"`
Expand Down Expand Up @@ -200,6 +205,18 @@ func (t InteractionType) String() string {
return fmt.Sprintf("InteractionType(%d)", t)
}

// InteractionContextType represents the context in which interaction can be used or was triggered from.
type InteractionContextType uint

const (
// InteractionContextGuild indicates that interaction can be used within guilds.
InteractionContextGuild InteractionContextType = 0
// InteractionContextBotDM indicates that interaction can be used within DMs with the bot.
InteractionContextBotDM InteractionContextType = 1
// InteractionContextPrivateChannel indicates that interaction can be used within group DMs and DMs with other users.
InteractionContextPrivateChannel InteractionContextType = 2
)

// Interaction represents data of an interaction.
type Interaction struct {
ID string `json:"id"`
Expand Down Expand Up @@ -233,6 +250,9 @@ type Interaction struct {
// NOTE: this field is only filled when the interaction was invoked in a guild.
GuildLocale *Locale `json:"guild_locale"`

Context InteractionContextType `json:"context"`
AuthorizingIntegrationOwners map[ApplicationIntegrationType]string `json:"authorizing_integration_owners"`

Token string `json:"token"`
Version int `json:"version"`
}
Expand Down
24 changes: 24 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ type Message struct {
// If the field exists but is null, the referenced message was deleted.
ReferencedMessage *Message `json:"referenced_message"`

// Deprecated, use InteractionMetadata.
// Is sent when the message is a response to an Interaction, without an existing message.
// This means responses to message component interactions do not include this property,
// instead including a MessageReference, as components exist on preexisting messages.
Interaction *MessageInteraction `json:"interaction"`

InteractionMetadata *MessageInteractionMetadata `json:"interaction_metadata"`

// The flags of the message, which describe extra features of a message.
// This is a combination of bit masks; the presence of a certain permission can
// be checked by performing a bitwise AND between this int and the flag.
Expand Down Expand Up @@ -567,3 +570,24 @@ type MessageInteraction struct {
// Member is only present when the interaction is from a guild.
Member *Member `json:"member"`
}

// MessageInteractionMetadata contains metadata of an interaction, including relevant user info.
type MessageInteractionMetadata struct {
// ID of the interaction.
ID string `json:"id"`
// Type of the interaction.
Type InteractionType `json:"type"`
// User who triggered the interaction.
User *User `json:"user"`
// IDs for installation context(s) related to an interaction.
AuthorizingIntegrationOwners map[ApplicationIntegrationType]string `json:"authorizing_integration_owners"`
// ID of the original response message.
// NOTE: present only on followup messages.
OriginalResponseMessageID string `json:"original_response_message_id,omitempty"`
// ID of the message that contained interactive component.
// NOTE: present only on message component interactions.
InteractedMessageID string `json:"interacted_message_id,omitempty"`
// Metadata for interaction that was used to open a modal.
// NOTE: present only on modal submit interactions.
TriggeringInteractionMetadata *MessageInteractionMetadata `json:"triggering_interaction_metadata,omitempty"`
}
59 changes: 41 additions & 18 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,49 @@ type Session struct {
wsMutex sync.Mutex
}

// ApplicationIntegrationType dictates where application can be installed and its available interaction contexts.
type ApplicationIntegrationType uint

const (
// ApplicationIntegrationGuildInstall indicates that app is installable to guilds.
ApplicationIntegrationGuildInstall ApplicationIntegrationType = 0
// ApplicationIntegrationUserInstall indicates that app is installable to users.
ApplicationIntegrationUserInstall ApplicationIntegrationType = 1
)

// ApplicationInstallParams represents application's installation parameters
// for default in-app oauth2 authorization link.
type ApplicationInstallParams struct {
Scopes []string `json:"scopes"`
Permissions int64 `json:"permissions,string"`
}

// ApplicationIntegrationTypeConfig represents application's configuration for a particular integration type.
type ApplicationIntegrationTypeConfig struct {
OAuth2InstallParams *ApplicationInstallParams `json:"oauth2_install_params,omitempty"`
}

// Application stores values for a Discord Application
type Application struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Icon string `json:"icon,omitempty"`
Description string `json:"description,omitempty"`
RPCOrigins []string `json:"rpc_origins,omitempty"`
BotPublic bool `json:"bot_public,omitempty"`
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
TermsOfServiceURL string `json:"terms_of_service_url"`
PrivacyProxyURL string `json:"privacy_policy_url"`
Owner *User `json:"owner"`
Summary string `json:"summary"`
VerifyKey string `json:"verify_key"`
Team *Team `json:"team"`
GuildID string `json:"guild_id"`
PrimarySKUID string `json:"primary_sku_id"`
Slug string `json:"slug"`
CoverImage string `json:"cover_image"`
Flags int `json:"flags,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name"`
Icon string `json:"icon,omitempty"`
Description string `json:"description,omitempty"`
RPCOrigins []string `json:"rpc_origins,omitempty"`
BotPublic bool `json:"bot_public,omitempty"`
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
TermsOfServiceURL string `json:"terms_of_service_url"`
PrivacyProxyURL string `json:"privacy_policy_url"`
Owner *User `json:"owner"`
Summary string `json:"summary"`
VerifyKey string `json:"verify_key"`
Team *Team `json:"team"`
GuildID string `json:"guild_id"`
PrimarySKUID string `json:"primary_sku_id"`
Slug string `json:"slug"`
CoverImage string `json:"cover_image"`
Flags int `json:"flags,omitempty"`
IntegrationTypesConfig map[ApplicationIntegrationType]*ApplicationIntegrationTypeConfig `json:"integration_types,omitempty"`
}

// ApplicationRoleConnectionMetadataType represents the type of application role connection metadata.
Expand Down

0 comments on commit a31fd86

Please sign in to comment.