2021-01-27 17:43:38 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-06-09 17:29:03 +00:00
|
|
|
"mime/multipart"
|
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v3/utils/json/option"
|
2021-06-09 17:29:03 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/utils/sendpart"
|
2021-01-27 17:43:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var EndpointInteractions = Endpoint + "interactions/"
|
|
|
|
|
|
|
|
type InteractionResponseType uint
|
|
|
|
|
2021-05-30 04:28:37 +00:00
|
|
|
// https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactioncallbacktype
|
2021-01-27 17:43:38 +00:00
|
|
|
const (
|
|
|
|
PongInteraction InteractionResponseType = iota + 1
|
2021-05-30 04:28:37 +00:00
|
|
|
_
|
|
|
|
_
|
2021-01-27 17:43:38 +00:00
|
|
|
MessageInteractionWithSource
|
2021-05-30 04:28:37 +00:00
|
|
|
DeferredMessageInteractionWithSource
|
2021-05-12 05:36:03 +00:00
|
|
|
DeferredMessageUpdate
|
|
|
|
UpdateMessage
|
2021-01-27 17:43:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type InteractionResponse struct {
|
|
|
|
Type InteractionResponseType `json:"type"`
|
|
|
|
Data *InteractionResponseData `json:"data,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-06-12 08:49:43 +00:00
|
|
|
// InteractionResponseFlags implements flags for an InteractionApplicationCommandCallbackData.
|
|
|
|
// https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata
|
|
|
|
type InteractionResponseFlags uint
|
|
|
|
|
|
|
|
const EphemeralResponse InteractionResponseFlags = 64
|
|
|
|
|
2021-01-27 17:43:38 +00:00
|
|
|
// InteractionResponseData is InteractionApplicationCommandCallbackData in the
|
|
|
|
// official documentation.
|
|
|
|
type InteractionResponseData struct {
|
2021-06-12 08:49:43 +00:00
|
|
|
TTS option.NullableBool `json:"tts,omitempty"`
|
|
|
|
Content option.NullableString `json:"content,omitempty"`
|
|
|
|
Components *[]discord.Component `json:"components,omitempty"`
|
|
|
|
Embeds *[]discord.Embed `json:"embeds,omitempty"`
|
|
|
|
AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
|
|
|
|
Flags InteractionResponseFlags `json:"flags,omitempty"`
|
|
|
|
Files []sendpart.File `json:"-"`
|
2021-01-27 17:43:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RespondInteraction responds to an incoming interaction. It is also known as
|
|
|
|
// an "interaction callback".
|
|
|
|
func (c *Client) RespondInteraction(
|
2021-06-09 17:29:03 +00:00
|
|
|
id discord.InteractionID, token string, resp InteractionResponse) error {
|
|
|
|
var URL = EndpointInteractions + id.String() + "/" + token + "/callback"
|
|
|
|
return sendpart.POST(c.Client, resp, nil, URL)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NeedsMultipart returns true if the InteractionResponse has files.
|
|
|
|
func (resp InteractionResponse) NeedsMultipart() bool {
|
|
|
|
return resp.Data != nil && len(resp.Data.Files) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (resp InteractionResponse) WriteMultipart(body *multipart.Writer) error {
|
|
|
|
return sendpart.Write(body, resp, resp.Data.Files)
|
2021-01-27 17:43:38 +00:00
|
|
|
}
|