feat: user apps (#1511)

* 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
This commit is contained in:
Fedor Lapshin 2024-06-20 17:56:18 +03:00 committed by GitHub
parent cf4e4e070f
commit a31fd8617e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 87 additions and 20 deletions

View file

@ -38,12 +38,17 @@ type ApplicationCommand struct {
Type ApplicationCommandType `json:"type,omitempty"` Type ApplicationCommandType `json:"type,omitempty"`
Name string `json:"name"` Name string `json:"name"`
NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"` 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"` DefaultPermission *bool `json:"default_permission,omitempty"`
DefaultMemberPermissions *int64 `json:"default_member_permissions,string,omitempty"` DefaultMemberPermissions *int64 `json:"default_member_permissions,string,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
NSFW *bool `json:"nsfw,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. // NOTE: Chat commands only. Otherwise it mustn't be set.
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
@ -200,6 +205,18 @@ func (t InteractionType) String() string {
return fmt.Sprintf("InteractionType(%d)", t) 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. // Interaction represents data of an interaction.
type Interaction struct { type Interaction struct {
ID string `json:"id"` ID string `json:"id"`
@ -233,6 +250,9 @@ type Interaction struct {
// NOTE: this field is only filled when the interaction was invoked in a guild. // NOTE: this field is only filled when the interaction was invoked in a guild.
GuildLocale *Locale `json:"guild_locale"` GuildLocale *Locale `json:"guild_locale"`
Context InteractionContextType `json:"context"`
AuthorizingIntegrationOwners map[ApplicationIntegrationType]string `json:"authorizing_integration_owners"`
Token string `json:"token"` Token string `json:"token"`
Version int `json:"version"` Version int `json:"version"`
} }

View file

@ -135,11 +135,14 @@ type Message struct {
// If the field exists but is null, the referenced message was deleted. // If the field exists but is null, the referenced message was deleted.
ReferencedMessage *Message `json:"referenced_message"` ReferencedMessage *Message `json:"referenced_message"`
// Deprecated, use InteractionMetadata.
// Is sent when the message is a response to an Interaction, without an existing message. // 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, // This means responses to message component interactions do not include this property,
// instead including a MessageReference, as components exist on preexisting messages. // instead including a MessageReference, as components exist on preexisting messages.
Interaction *MessageInteraction `json:"interaction"` Interaction *MessageInteraction `json:"interaction"`
InteractionMetadata *MessageInteractionMetadata `json:"interaction_metadata"`
// The flags of the message, which describe extra features of a message. // 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 // 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. // be checked by performing a bitwise AND between this int and the flag.
@ -567,3 +570,24 @@ type MessageInteraction struct {
// Member is only present when the interaction is from a guild. // Member is only present when the interaction is from a guild.
Member *Member `json:"member"` 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"`
}

View file

@ -136,26 +136,49 @@ type Session struct {
wsMutex sync.Mutex 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 // Application stores values for a Discord Application
type Application struct { type Application struct {
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Icon string `json:"icon,omitempty"` Icon string `json:"icon,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
RPCOrigins []string `json:"rpc_origins,omitempty"` RPCOrigins []string `json:"rpc_origins,omitempty"`
BotPublic bool `json:"bot_public,omitempty"` BotPublic bool `json:"bot_public,omitempty"`
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"` BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
TermsOfServiceURL string `json:"terms_of_service_url"` TermsOfServiceURL string `json:"terms_of_service_url"`
PrivacyProxyURL string `json:"privacy_policy_url"` PrivacyProxyURL string `json:"privacy_policy_url"`
Owner *User `json:"owner"` Owner *User `json:"owner"`
Summary string `json:"summary"` Summary string `json:"summary"`
VerifyKey string `json:"verify_key"` VerifyKey string `json:"verify_key"`
Team *Team `json:"team"` Team *Team `json:"team"`
GuildID string `json:"guild_id"` GuildID string `json:"guild_id"`
PrimarySKUID string `json:"primary_sku_id"` PrimarySKUID string `json:"primary_sku_id"`
Slug string `json:"slug"` Slug string `json:"slug"`
CoverImage string `json:"cover_image"` CoverImage string `json:"cover_image"`
Flags int `json:"flags,omitempty"` Flags int `json:"flags,omitempty"`
IntegrationTypesConfig map[ApplicationIntegrationType]*ApplicationIntegrationTypeConfig `json:"integration_types,omitempty"`
} }
// ApplicationRoleConnectionMetadataType represents the type of application role connection metadata. // ApplicationRoleConnectionMetadataType represents the type of application role connection metadata.