Skip to content

Commit

Permalink
Merge branch 'master' into patch/soundboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 authored Sep 21, 2024
2 parents e0fafc9 + ef757ee commit 05d0079
Show file tree
Hide file tree
Showing 42 changed files with 789 additions and 49 deletions.
8 changes: 4 additions & 4 deletions _examples/application_commands/http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ go 1.21
replace github.com/disgoorg/disgo => ../../../

require (
github.com/disgoorg/disgo v0.18.8
github.com/disgoorg/disgo v0.18.11
github.com/disgoorg/snowflake/v2 v2.0.3
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a
)

require (
github.com/disgoorg/json v1.1.0 // indirect
github.com/disgoorg/json v1.2.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/sys v0.25.0 // indirect
)
12 changes: 6 additions & 6 deletions _examples/application_commands/http/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/json v1.2.0 h1:6e/j4BCfSHIvucG1cd7tJPAOp1RgnnMFSqkvZUtEd1Y=
github.com/disgoorg/json v1.2.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
github.com/disgoorg/snowflake/v2 v2.0.3 h1:3B+PpFjr7j4ad7oeJu4RlQ+nYOTadsKapJIzgvSI2Ro=
github.com/disgoorg/snowflake/v2 v2.0.3/go.mod h1:W6r7NUA7DwfZLwr00km6G4UnZ0zcoLBRufhkFWgAc4c=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
Expand All @@ -14,9 +14,9 @@ github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad h1:qIQkSlF5vAUHxE
github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
31 changes: 24 additions & 7 deletions discord/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package discord

import (
"fmt"
"slices"
"strings"
"time"

Expand All @@ -28,7 +29,6 @@ type Application struct {
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"`
Expand Down Expand Up @@ -156,12 +156,7 @@ func SplitScopes(joinedScopes string) []OAuth2Scope {
}

func HasScope(scope OAuth2Scope, scopes ...OAuth2Scope) bool {
for _, s := range scopes {
if s == scope {
return true
}
}
return false
return slices.Contains(scopes, scope)
}

type TokenType string
Expand Down Expand Up @@ -277,3 +272,25 @@ type ApplicationIntegrationTypesConfig map[ApplicationIntegrationType]Applicatio
type ApplicationIntegrationTypeConfiguration struct {
OAuth2InstallParams *InstallParams `json:"oauth2_install_params"`
}

type ActivityInstance struct {
ApplicationID snowflake.ID `json:"application_id"`
InstanceID string `json:"instance_id"`
LaunchID snowflake.ID `json:"launch_id"`
Location ActivityLocation `json:"location"`
Users []snowflake.ID `json:"users"`
}

type ActivityLocation struct {
ID string `json:"id"`
Kind ActivityLocationKind `json:"kind"`
ChannelID snowflake.ID `json:"channel_id"`
GuildID *snowflake.ID `json:"guild_id"`
}

type ActivityLocationKind string

const (
ActivityLocationKindGC ActivityLocationKind = "gc"
ActivityLocationKindPC ActivityLocationKind = "pc"
)
133 changes: 133 additions & 0 deletions discord/application_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
ApplicationCommandTypeSlash ApplicationCommandType = iota + 1
ApplicationCommandTypeUser
ApplicationCommandTypeMessage
ApplicationCommandTypePrimaryEntryPoint
)

type ApplicationCommand interface {
Expand Down Expand Up @@ -69,6 +70,11 @@ func (u *UnmarshalApplicationCommand) UnmarshalJSON(data []byte) error {
err = json.Unmarshal(data, &v)
applicationCommand = v

case ApplicationCommandTypePrimaryEntryPoint:
var v EntryPointCommand
err = json.Unmarshal(data, &v)
applicationCommand = v

default:
err = fmt.Errorf("unknown application command with type %d received", cType.Type)
}
Expand Down Expand Up @@ -180,6 +186,7 @@ func (c SlashCommand) NameLocalized() string {
func (c SlashCommand) DefaultMemberPermissions() Permissions {
return c.defaultMemberPermissions
}

func (c SlashCommand) DMPermission() bool {
return c.dmPermission
}
Expand Down Expand Up @@ -297,6 +304,7 @@ func (c UserCommand) NameLocalized() string {
func (c UserCommand) DefaultMemberPermissions() Permissions {
return c.defaultMemberPermissions
}

func (c UserCommand) DMPermission() bool {
return c.dmPermission
}
Expand Down Expand Up @@ -410,6 +418,7 @@ func (c MessageCommand) NameLocalized() string {
func (c MessageCommand) DefaultMemberPermissions() Permissions {
return c.defaultMemberPermissions
}

func (c MessageCommand) DMPermission() bool {
return c.dmPermission
}
Expand All @@ -435,3 +444,127 @@ func (c MessageCommand) CreatedAt() time.Time {
}

func (MessageCommand) applicationCommand() {}

var _ ApplicationCommand = (*EntryPointCommand)(nil)

type EntryPointCommand struct {
id snowflake.ID
applicationID snowflake.ID
guildID *snowflake.ID
name string
nameLocalizations map[Locale]string
nameLocalized string
defaultMemberPermissions Permissions
dmPermission bool
nsfw bool
integrationTypes []ApplicationIntegrationType
contexts []InteractionContextType
version snowflake.ID
Handler EntryPointCommandHandlerType
}

func (c *EntryPointCommand) UnmarshalJSON(data []byte) error {
var v rawEntryPointCommand
if err := json.Unmarshal(data, &v); err != nil {
return err
}

c.id = v.ID
c.applicationID = v.ApplicationID
c.guildID = v.GuildID
c.name = v.Name
c.nameLocalizations = v.NameLocalizations
c.nameLocalized = v.NameLocalized
c.defaultMemberPermissions = v.DefaultMemberPermissions
c.dmPermission = v.DMPermission
c.nsfw = v.NSFW
c.integrationTypes = v.IntegrationTypes
c.contexts = v.Contexts
c.version = v.Version
c.Handler = v.Handler
return nil
}

func (c EntryPointCommand) MarshalJSON() ([]byte, error) {
return json.Marshal(rawEntryPointCommand{
ID: c.id,
Type: c.Type(),
ApplicationID: c.applicationID,
GuildID: c.guildID,
Name: c.name,
NameLocalizations: c.nameLocalizations,
NameLocalized: c.nameLocalized,
DefaultMemberPermissions: c.defaultMemberPermissions,
DMPermission: c.dmPermission,
NSFW: c.nsfw,
IntegrationTypes: c.integrationTypes,
Contexts: c.contexts,
Version: c.version,
Handler: c.Handler,
})
}

func (c EntryPointCommand) ID() snowflake.ID {
return c.id
}

func (EntryPointCommand) Type() ApplicationCommandType {
return ApplicationCommandTypePrimaryEntryPoint
}

func (c EntryPointCommand) ApplicationID() snowflake.ID {
return c.applicationID
}

func (c EntryPointCommand) GuildID() *snowflake.ID {
return c.guildID
}

func (c EntryPointCommand) Name() string {
return c.name
}

func (c EntryPointCommand) NameLocalizations() map[Locale]string {
return c.nameLocalizations
}

func (c EntryPointCommand) NameLocalized() string {
return c.nameLocalized
}

func (c EntryPointCommand) DefaultMemberPermissions() Permissions {
return c.defaultMemberPermissions
}

func (c EntryPointCommand) DMPermission() bool {
return c.dmPermission
}

func (c EntryPointCommand) NSFW() bool {
return c.nsfw
}

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

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

func (c EntryPointCommand) Version() snowflake.ID {
return c.version
}

func (c EntryPointCommand) CreatedAt() time.Time {
return c.id.Time()
}

func (EntryPointCommand) applicationCommand() {}

type EntryPointCommandHandlerType int

const (
EntryPointCommandHandlerTypeAppHandler EntryPointCommandHandlerType = iota + 1
EntryPointCommandHandlerTypeDiscordLaunchActivity
)
33 changes: 33 additions & 0 deletions discord/application_command_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,36 @@ func (c MessageCommandCreate) CommandName() string {
}

func (MessageCommandCreate) applicationCommandCreate() {}

type EntryPointCommandCreate struct {
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,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"`
Handler EntryPointCommandHandlerType `json:"handler,omitempty"`
}

func (c EntryPointCommandCreate) MarshalJSON() ([]byte, error) {
type entryPointCommandCreate EntryPointCommandCreate
return json.Marshal(struct {
Type ApplicationCommandType `json:"type"`
entryPointCommandCreate
}{
Type: c.Type(),
entryPointCommandCreate: entryPointCommandCreate(c),
})
}

func (EntryPointCommandCreate) Type() ApplicationCommandType {
return ApplicationCommandTypePrimaryEntryPoint
}

func (c EntryPointCommandCreate) CommandName() string {
return c.Name
}

func (EntryPointCommandCreate) applicationCommandCreate() {}
17 changes: 17 additions & 0 deletions discord/application_command_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,20 @@ type rawContextCommand struct {
Contexts []InteractionContextType `json:"contexts"`
Version snowflake.ID `json:"version"`
}

type rawEntryPointCommand 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"`
IntegrationTypes []ApplicationIntegrationType `json:"integration_types"`
Contexts []InteractionContextType `json:"contexts"`
Version snowflake.ID `json:"version"`
Handler EntryPointCommandHandlerType `json:"handler"`
}
33 changes: 33 additions & 0 deletions discord/application_command_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,36 @@ func (c MessageCommandUpdate) CommandName() *string {
}

func (MessageCommandUpdate) applicationCommandUpdate() {}

type EntryPointCommandUpdate struct {
Name *string `json:"name,omitempty"`
NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,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"`
Handler *EntryPointCommandHandlerType `json:"handler,omitempty"`
}

func (c EntryPointCommandUpdate) MarshalJSON() ([]byte, error) {
type entryPointCommandUpdate EntryPointCommandUpdate
return json.Marshal(struct {
Type ApplicationCommandType `json:"type"`
entryPointCommandUpdate
}{
Type: c.Type(),
entryPointCommandUpdate: entryPointCommandUpdate(c),
})
}

func (EntryPointCommandUpdate) Type() ApplicationCommandType {
return ApplicationCommandTypePrimaryEntryPoint
}

func (c EntryPointCommandUpdate) CommandName() *string {
return c.Name
}

func (EntryPointCommandUpdate) applicationCommandUpdate() {}
1 change: 1 addition & 0 deletions discord/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Connection struct {
type ConnectionType string

const (
ConnectionTypeAmazonMusic ConnectionType = "amazon-music"
ConnectionTypeBattleNet ConnectionType = "battlenet"
ConnectionTypeBungie ConnectionType = "bungie"
ConnectionTypeDomain ConnectionType = "domain"
Expand Down
Loading

0 comments on commit 05d0079

Please sign in to comment.