Skip to content

Commit

Permalink
Merge pull request #23 from DisgoOrg/development
Browse files Browse the repository at this point in the history
v0.4.2
  • Loading branch information
Skye-31 authored Jun 1, 2021
2 parents 368a96f + f8ecdd2 commit bde2653
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 123 deletions.
77 changes: 10 additions & 67 deletions api/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func (c Command) FromGuild() bool {
return c.GuildID == nil
}

// ToCreate return the CommandCreate for this Command
func (c *Command) ToCreate() *CommandCreate {
return &CommandCreate{
Name: c.Name,
Description: c.Description,
DefaultPermission: c.DefaultPermission,
Options: c.Options,
}
}

// Fetch updates/fetches the current Command from discord
func (c *Command) Fetch() error {
if c.Disgo == nil {
Expand Down Expand Up @@ -105,73 +115,6 @@ func (c Command) Delete() error {
return c.Disgo.RestClient().DeleteGuildCommand(c.Disgo.ApplicationID(), *c.GuildID, c.ID)
}

// CommandOptionType specifies the type of the arguments used in Command.Options
type CommandOptionType int

// Constants for each slash command option type
const (
CommandOptionTypeSubCommand CommandOptionType = iota + 1
CommandOptionTypeSubCommandGroup
CommandOptionTypeString
CommandOptionTypeInteger
CommandOptionTypeBoolean
CommandOptionTypeUser
CommandOptionTypeChannel
CommandOptionTypeRole
)

// CommandOption are the arguments used in Command.Options
type CommandOption struct {
Type CommandOptionType `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Required bool `json:"required,omitempty"`
Choices []*OptionChoice `json:"choices,omitempty"`
Options []*CommandOption `json:"options,omitempty"`
}

// OptionChoice contains the data for a user using your command
type OptionChoice struct {
Name string `json:"name"`
Value interface{} `json:"value"`
}

// GuildCommandPermissions holds all permissions for a Command
type GuildCommandPermissions struct {
Disgo Disgo
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
GuildID Snowflake `json:"guild_id"`
Permissions []*CommandPermission `json:"permissions"`
}

// TODO: add methods to update those

// CommandPermissionType is the type of the CommandPermission
type CommandPermissionType int

// types of CommandPermissionType
const (
CommandPermissionTypeRole = iota + 1
CommandPermissionTypeUser
)

// CommandPermission holds a User or Role and if they are allowed to use the Command
type CommandPermission struct {
ID Snowflake `json:"id"`
Type CommandPermissionType `json:"type"`
Permission bool `json:"permission"`
}

// SetGuildCommandsPermissions holds a slice of SetGuildCommandPermissions
type SetGuildCommandsPermissions []*SetGuildCommandPermissions

// SetGuildCommandPermissions is used to update CommandPermission ID should be omitted fro bulk update
type SetGuildCommandPermissions struct {
ID Snowflake `json:"id,omitempty"`
Permissions []*CommandPermission `json:"permissions"`
}

// CommandCreate is used to create an Command. all fields are optional
type CommandCreate struct {
Name string `json:"name,omitempty"`
Expand Down
104 changes: 104 additions & 0 deletions api/command_option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package api

// CommandOptionType specifies the type of the arguments used in Command.Options
type CommandOptionType int

// Constants for each slash command option type
const (
CommandOptionTypeSubCommand CommandOptionType = iota + 1
CommandOptionTypeSubCommandGroup
CommandOptionTypeString
CommandOptionTypeInteger
CommandOptionTypeBoolean
CommandOptionTypeUser
CommandOptionTypeChannel
CommandOptionTypeRole
CommandOptionTypeMentionable
)

// NewCommandOption creates a new CommandOption with the provided params
func NewCommandOption(optionType CommandOptionType, name string, description string, options ...*CommandOption) *CommandOption {
return &CommandOption{
Type: optionType,
Name: name,
Description: description,
Options: options,
}
}

// NewSubCommand creates a new CommandOption with CommandOptionTypeSubCommand
func NewSubCommand(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeSubCommand, name, description, options...)
}

// NewSubCommandGroup creates a new CommandOption with CommandOptionTypeSubCommandGroup
func NewSubCommandGroup(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeSubCommandGroup, name, description, options...)
}

// NewStringOption creates a new CommandOption with CommandOptionTypeSubCommand
func NewStringOption(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeString, name, description, options...)
}

// NewIntegerOption creates a new CommandOption with CommandOptionTypeSubCommand
func NewIntegerOption(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeInteger, name, description, options...)
}

// NewBooleanOption creates a new CommandOption with CommandOptionTypeSubCommand
func NewBooleanOption(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeBoolean, name, description, options...)
}

// NewUserOption creates a new CommandOption with CommandOptionTypeSubCommand
func NewUserOption(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeUser, name, description, options...)
}

// NewChannelOption creates a new CommandOption with CommandOptionTypeSubCommand
func NewChannelOption(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeChannel, name, description, options...)
}

// NewMentionableOption creates a new CommandOption with CommandOptionTypeUser or CommandOptionTypeRole
func NewMentionableOption(name string, description string, options ...*CommandOption) *CommandOption {
return NewCommandOption(CommandOptionTypeMentionable, name, description, options...)
}

// CommandOption are the arguments used in Command.Options
type CommandOption struct {
Type CommandOptionType `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Required bool `json:"required,omitempty"`
Choices []*OptionChoice `json:"choices,omitempty"`
Options []*CommandOption `json:"options,omitempty"`
}

// AddChoice adds a new choice to the the CommandOption
func (o *CommandOption) AddChoice(name string, value interface{}) *CommandOption {
o.Choices = append(o.Choices, &OptionChoice{
Name: name,
Value: value,
})
return o
}

// AddOptions adds multiple choices to the the CommandOption
func (o *CommandOption) AddOptions(options ...*CommandOption) *CommandOption {
o.Options = append(o.Options, options...)
return o
}

// SetRequired sets if the CommandOption is required
func (o *CommandOption) SetRequired(required bool) *CommandOption {
o.Required = required
return o
}

// OptionChoice contains the data for a user using your command
type OptionChoice struct {
Name string `json:"name"`
Value interface{} `json:"value"`
}
37 changes: 37 additions & 0 deletions api/command_permission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package api

// GuildCommandPermissions holds all permissions for a Command
type GuildCommandPermissions struct {
Disgo Disgo
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
GuildID Snowflake `json:"guild_id"`
Permissions []*CommandPermission `json:"permissions"`
}

// TODO: add methods to update those

// CommandPermissionType is the type of the CommandPermission
type CommandPermissionType int

// types of CommandPermissionType
const (
CommandPermissionTypeRole = iota + 1
CommandPermissionTypeUser
)

// CommandPermission holds a User or Role and if they are allowed to use the Command
type CommandPermission struct {
ID Snowflake `json:"id"`
Type CommandPermissionType `json:"type"`
Permission bool `json:"permission"`
}

// SetGuildCommandsPermissions holds a slice of SetGuildCommandPermissions
type SetGuildCommandsPermissions []*SetGuildCommandPermissions

// SetGuildCommandPermissions is used to update CommandPermission ID should be omitted fro bulk update
type SetGuildCommandPermissions struct {
ID Snowflake `json:"id,omitempty"`
Permissions []*CommandPermission `json:"permissions"`
}
12 changes: 12 additions & 0 deletions api/disgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ type Disgo interface {
EditCommand(commandID Snowflake, command *CommandUpdate) (*Command, error)
DeleteCommand(commandID Snowflake) error
SetCommands(commands ...*CommandCreate) ([]*Command, error)

GetGuildCommand(guildID Snowflake, commandID Snowflake) (*Command, error)
GetGuildCommands(guildID Snowflake, ) ([]*Command, error)
CreateGuildCommand(guildID Snowflake, command *CommandCreate) (*Command, error)
EditGuildCommand(guildID Snowflake, commandID Snowflake, command *CommandUpdate) (*Command, error)
DeleteGuildCommand(guildID Snowflake, commandID Snowflake) error
SetGuildCommands(guildID Snowflake, commands ...*CommandCreate) ([]*Command, error)

GetGuildCommandsPermissions(guildID Snowflake) ([]*GuildCommandPermissions, error)
GetGuildCommandPermissions(guildID Snowflake, commandID Snowflake) (*GuildCommandPermissions, error)
SetGuildCommandsPermissions(guildID Snowflake, commandPermissions ...*SetGuildCommandPermissions) ([]*GuildCommandPermissions, error)
SetGuildCommandPermissions(guildID Snowflake, commandID Snowflake, permissions *SetGuildCommandPermissions) (*GuildCommandPermissions, error)
}

// EventHandler provides info about the EventHandler
Expand Down
2 changes: 1 addition & 1 deletion api/events/listener_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type ListenerAdapter struct {

// api.Interaction Events
OnGenericInteractionEvent func(event *GenericInteractionEvent)
OnCommand func(event *CommandEvent)
OnCommand func(event *CommandEvent)
OnButtonClick func(event *ButtonClickEvent)

// api.Message Events
Expand Down
2 changes: 1 addition & 1 deletion api/events/ready_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import "github.com/DisgoOrg/disgo/api"
// ReadyEvent indicates we received the ReadyEvent from the api.Gateway
type ReadyEvent struct {
GenericEvent
api.ReadyGatewayEvent
*api.ReadyGatewayEvent
}
6 changes: 3 additions & 3 deletions api/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const (
GatewayEventResumed GatewayEventType = "RESUMED"
GatewayEventReconnect GatewayEventType = "RECONNECT"
GatewayEventInvalidSession GatewayEventType = "INVALID_SESSION"
GatewayEventCommandCreate GatewayEventType = "APPLICATION_COMMAND_CREATE"
GatewayEventCommandUpdate GatewayEventType = "APPLICATION_COMMAND_UPDATE"
GatewayEventCommandDelete GatewayEventType = "APPLICATION_COMMAND_DELETE"
GatewayEventCommandCreate GatewayEventType = "APPLICATION_COMMAND_CREATE"
GatewayEventCommandUpdate GatewayEventType = "APPLICATION_COMMAND_UPDATE"
GatewayEventCommandDelete GatewayEventType = "APPLICATION_COMMAND_DELETE"
GatewayEventChannelCreate GatewayEventType = "CHANNEL_CREATE"
GatewayEventChannelUpdate GatewayEventType = "CHANNEL_UPDATE"
GatewayEventChannelDelete GatewayEventType = "CHANNEL_DELETE"
Expand Down
Loading

0 comments on commit bde2653

Please sign in to comment.