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

feat: user apps #1511

Merged
merged 17 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading