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

Add interaction callback response #386

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions discord/interaction_callback_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package discord

import "github.com/disgoorg/snowflake/v2"

type InteractionCallbackResponse struct {
Interaction CallbackInteraction `json:"interaction"`
Resource *CallbackResource `json:"resource"`
}

type CallbackInteraction struct {
ID snowflake.ID `json:"id"`
Type InteractionType `json:"type"`
ResponseMessageID *snowflake.ID `json:"response_message_id"`
ResponseMessageLoading *bool `json:"response_message_loading"`
ResponseMessageEphemeral *bool `json:"response_message_ephemeral"`
}

type CallbackResource struct {
Type InteractionResponseType `json:"type"`
Message *Message `json:"message"`
}
19 changes: 15 additions & 4 deletions rest/interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func NewInteractions(client Client) Interactions {
type Interactions interface {
GetInteractionResponse(applicationID snowflake.ID, interactionToken string, opts ...RequestOpt) (*discord.Message, error)
CreateInteractionResponse(interactionID snowflake.ID, interactionToken string, interactionResponse discord.InteractionResponse, opts ...RequestOpt) error
CreateInteractionResponseWithCallback(interactionID snowflake.ID, interactionToken string, interactionResponse discord.InteractionResponse, withCallback bool, opts ...RequestOpt) (*discord.InteractionCallbackResponse, error)
UpdateInteractionResponse(applicationID snowflake.ID, interactionToken string, messageUpdate discord.MessageUpdate, opts ...RequestOpt) (*discord.Message, error)
DeleteInteractionResponse(applicationID snowflake.ID, interactionToken string, opts ...RequestOpt) error

Expand All @@ -33,13 +34,23 @@ func (s *interactionImpl) GetInteractionResponse(interactionID snowflake.ID, int
return
}

func (s *interactionImpl) CreateInteractionResponse(interactionID snowflake.ID, interactionToken string, interactionResponse discord.InteractionResponse, opts ...RequestOpt) error {
// CreateInteractionResponse calls CreateInteractionResponseWithCallback with `withCallback: false`.
// The signature of this function might be adjusted in the future.
func (s *interactionImpl) CreateInteractionResponse(interactionID snowflake.ID, interactionToken string, interactionResponse discord.InteractionResponse, opts ...RequestOpt) (err error) {
_, err = s.CreateInteractionResponseWithCallback(interactionID, interactionToken, interactionResponse, false, opts...)
return
}

func (s *interactionImpl) CreateInteractionResponseWithCallback(interactionID snowflake.ID, interactionToken string, interactionResponse discord.InteractionResponse, withCallback bool, opts ...RequestOpt) (callback *discord.InteractionCallbackResponse, err error) {
body, err := interactionResponse.ToBody()
if err != nil {
return err
return nil, err
}

return s.client.Do(CreateInteractionResponse.Compile(nil, interactionID, interactionToken), body, nil, opts...)
values := discord.QueryValues{
"with_response": withCallback,
}
err = s.client.Do(CreateInteractionResponse.Compile(values, interactionID, interactionToken), body, &callback, opts...)
return
}

func (s *interactionImpl) UpdateInteractionResponse(applicationID snowflake.ID, interactionToken string, messageUpdate discord.MessageUpdate, opts ...RequestOpt) (message *discord.Message, err error) {
Expand Down
Loading