Skip to content

Commit

Permalink
rename InteractionCallback to InteractionResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jun 14, 2022
1 parent 9f75fcd commit e36b668
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
26 changes: 13 additions & 13 deletions discord/interaction_callback.go → discord/interaction_response.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package discord

// InteractionCallbackType indicates the type of slash command response, whether it's responding immediately or deferring to edit your response later
type InteractionCallbackType int
// InteractionResponseType indicates the type of slash command response, whether it's responding immediately or deferring to edit your response later
type InteractionResponseType int

// Constants for the InteractionCallbackType(s)
// Constants for the InteractionResponseType(s)
const (
InteractionCallbackTypePong InteractionCallbackType = iota + 1
InteractionResponseTypePong InteractionResponseType = iota + 1
_
_
InteractionCallbackTypeCreateMessage
InteractionCallbackTypeDeferredCreateMessage
InteractionCallbackTypeDeferredUpdateMessage
InteractionCallbackTypeUpdateMessage
InteractionCallbackTypeApplicationCommandAutocompleteResult
InteractionCallbackTypeModal
InteractionResponseTypeCreateMessage
InteractionResponseTypeDeferredCreateMessage
InteractionResponseTypeDeferredUpdateMessage
InteractionResponseTypeUpdateMessage
InteractionResponseTypeApplicationCommandAutocompleteResult
InteractionResponseTypeModal
)

// InteractionResponse is how you answer interactions. If an answer is not sent within 3 seconds of receiving it, the interaction is failed, and you will be unable to respond to it.
type InteractionResponse struct {
Type InteractionCallbackType `json:"type"`
Data InteractionCallbackData `json:"data,omitempty"`
Type InteractionResponseType `json:"type"`
Data InteractionResponseData `json:"data,omitempty"`
}

// ToBody returns the InteractionResponse ready for body
Expand All @@ -30,7 +30,7 @@ func (r InteractionResponse) ToBody() (any, error) {
return r, nil
}

type InteractionCallbackData interface {
type InteractionResponseData interface {
interactionCallbackData()
}

Expand Down
2 changes: 1 addition & 1 deletion discord/modal_create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package discord

var _ InteractionCallbackData = (*ModalCreate)(nil)
var _ InteractionResponseData = (*ModalCreate)(nil)

type ModalCreate struct {
CustomID CustomID `json:"custom_id"`
Expand Down
34 changes: 17 additions & 17 deletions events/interaction_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// InteractionResponderFunc is a function that can be used to respond to a discord.Interaction.
type InteractionResponderFunc func(callbackType discord.InteractionCallbackType, data discord.InteractionCallbackData, opts ...rest.RequestOpt) error
type InteractionResponderFunc func(responseType discord.InteractionResponseType, data discord.InteractionResponseData, opts ...rest.RequestOpt) error

// InteractionCreate indicates that a new interaction has been created.
type InteractionCreate struct {
Expand Down Expand Up @@ -84,21 +84,21 @@ func (e *ApplicationCommandInteractionCreate) GuildChannel() (discord.GuildMessa

// CreateMessage responds to the interaction with a new message.
func (e *ApplicationCommandInteractionCreate) CreateMessage(messageCreate discord.MessageCreate, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeCreateMessage, messageCreate, opts...)
return e.Respond(discord.InteractionResponseTypeCreateMessage, messageCreate, opts...)
}

// DeferCreateMessage responds to the interaction with a "bot is thinking..." message which should be edited later.
func (e *ApplicationCommandInteractionCreate) DeferCreateMessage(ephemeral bool, opts ...rest.RequestOpt) error {
var data discord.InteractionCallbackData
var data discord.InteractionResponseData
if ephemeral {
data = discord.MessageCreate{Flags: discord.MessageFlagEphemeral}
}
return e.Respond(discord.InteractionCallbackTypeDeferredCreateMessage, data, opts...)
return e.Respond(discord.InteractionResponseTypeDeferredCreateMessage, data, opts...)
}

// CreateModal responds to the interaction with a new modal.
func (e *ApplicationCommandInteractionCreate) CreateModal(modalCreate discord.ModalCreate, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeModal, modalCreate, opts...)
return e.Respond(discord.InteractionResponseTypeModal, modalCreate, opts...)
}

// ComponentInteractionCreate indicates that a new component interaction has been created.
Expand Down Expand Up @@ -140,31 +140,31 @@ func (e *ComponentInteractionCreate) GuildChannel() (discord.GuildMessageChannel

// CreateMessage responds to the interaction with a new message.
func (e *ComponentInteractionCreate) CreateMessage(messageCreate discord.MessageCreate, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeCreateMessage, messageCreate, opts...)
return e.Respond(discord.InteractionResponseTypeCreateMessage, messageCreate, opts...)
}

// DeferCreateMessage responds to the interaction with a "bot is thinking..." message which should be edited later.
func (e *ComponentInteractionCreate) DeferCreateMessage(ephemeral bool, opts ...rest.RequestOpt) error {
var data discord.InteractionCallbackData
var data discord.InteractionResponseData
if ephemeral {
data = discord.MessageCreate{Flags: discord.MessageFlagEphemeral}
}
return e.Respond(discord.InteractionCallbackTypeDeferredCreateMessage, data, opts...)
return e.Respond(discord.InteractionResponseTypeDeferredCreateMessage, data, opts...)
}

// UpdateMessage responds to the interaction with updating the message the component is from.
func (e *ComponentInteractionCreate) UpdateMessage(messageUpdate discord.MessageUpdate, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeUpdateMessage, messageUpdate, opts...)
return e.Respond(discord.InteractionResponseTypeUpdateMessage, messageUpdate, opts...)
}

// DeferUpdateMessage responds to the interaction with nothing.
func (e *ComponentInteractionCreate) DeferUpdateMessage(opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeDeferredUpdateMessage, nil, opts...)
return e.Respond(discord.InteractionResponseTypeDeferredUpdateMessage, nil, opts...)
}

// CreateModal responds to the interaction with a new modal.
func (e *ComponentInteractionCreate) CreateModal(modalCreate discord.ModalCreate, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeModal, modalCreate, opts...)
return e.Respond(discord.InteractionResponseTypeModal, modalCreate, opts...)
}

// AutocompleteInteractionCreate indicates that a new autocomplete interaction has been created.
Expand Down Expand Up @@ -206,7 +206,7 @@ func (e *AutocompleteInteractionCreate) GuildChannel() (discord.GuildMessageChan

// Result responds to the interaction with a slice of choices.
func (e *AutocompleteInteractionCreate) Result(choices []discord.AutocompleteChoice, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeApplicationCommandAutocompleteResult, discord.AutocompleteResult{Choices: choices}, opts...)
return e.Respond(discord.InteractionResponseTypeApplicationCommandAutocompleteResult, discord.AutocompleteResult{Choices: choices}, opts...)
}

// ModalSubmitInteractionCreate indicates that a new modal submit interaction has been created.
Expand Down Expand Up @@ -248,24 +248,24 @@ func (e *ModalSubmitInteractionCreate) GuildChannel() (discord.GuildMessageChann

// CreateMessage responds to the interaction with a new message.
func (e *ModalSubmitInteractionCreate) CreateMessage(messageCreate discord.MessageCreate, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeCreateMessage, messageCreate, opts...)
return e.Respond(discord.InteractionResponseTypeCreateMessage, messageCreate, opts...)
}

// DeferCreateMessage responds to the interaction with a "bot is thinking..." message which should be edited later.
func (e *ModalSubmitInteractionCreate) DeferCreateMessage(ephemeral bool, opts ...rest.RequestOpt) error {
var data discord.InteractionCallbackData
var data discord.InteractionResponseData
if ephemeral {
data = discord.MessageCreate{Flags: discord.MessageFlagEphemeral}
}
return e.Respond(discord.InteractionCallbackTypeDeferredCreateMessage, data, opts...)
return e.Respond(discord.InteractionResponseTypeDeferredCreateMessage, data, opts...)
}

// UpdateMessage responds to the interaction with updating the message the component is from.
func (e *ModalSubmitInteractionCreate) UpdateMessage(messageUpdate discord.MessageUpdate, opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeUpdateMessage, messageUpdate, opts...)
return e.Respond(discord.InteractionResponseTypeUpdateMessage, messageUpdate, opts...)
}

// DeferUpdateMessage responds to the interaction with nothing.
func (e *ModalSubmitInteractionCreate) DeferUpdateMessage(opts ...rest.RequestOpt) error {
return e.Respond(discord.InteractionCallbackTypeDeferredUpdateMessage, nil, opts...)
return e.Respond(discord.InteractionResponseTypeDeferredUpdateMessage, nil, opts...)
}
4 changes: 2 additions & 2 deletions handlers/interaction_create_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func (h *gatewayHandlerInteractionCreate) HandleGatewayEvent(client bot.Client,
}

func respond(client bot.Client, respondFunc func(response discord.InteractionResponse) error, interaction discord.BaseInteraction) events.InteractionResponderFunc {
return func(callbackType discord.InteractionCallbackType, data discord.InteractionCallbackData, opts ...rest.RequestOpt) error {
return func(responseType discord.InteractionResponseType, data discord.InteractionResponseData, opts ...rest.RequestOpt) error {
response := discord.InteractionResponse{
Type: callbackType,
Type: responseType,
Data: data,
}
if respondFunc != nil {
Expand Down
2 changes: 1 addition & 1 deletion handlers/interaction_create_http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (h *httpserverHandlerInteractionCreate) HandleHTTPEvent(client bot.Client,
if interaction.Type() == discord.InteractionTypePing {
client.Logger().Debug("received http interaction ping. responding with pong")
if err := respondFunc(discord.InteractionResponse{
Type: discord.InteractionCallbackTypePong,
Type: discord.InteractionResponseTypePong,
}); err != nil {
client.Logger().Error("failed to respond to http interaction ping: ", err)
}
Expand Down

0 comments on commit e36b668

Please sign in to comment.