Skip to content

Commit

Permalink
Add ApplicationID field to Interaction (#1125)
Browse files Browse the repository at this point in the history
* add application_id to interaction struct and remove appID param from rest routes

* revert voice receive go mod & sum
  • Loading branch information
topi314 committed Apr 14, 2022
1 parent 16efe08 commit 4d72c30
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
4 changes: 2 additions & 2 deletions examples/components/main.go
Expand Up @@ -139,7 +139,7 @@ var (
panic(err)
}
time.Sleep(time.Second) // Doing that so user won't see instant response.
_, err = s.FollowupMessageCreate(*AppID, i.Interaction, true, &discordgo.WebhookParams{
_, err = s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Anyways, now when you know how to use single select menus, let's see how multi select menus work. " +
"Try calling `/selects multi` command.",
Flags: 1 << 6,
Expand All @@ -164,7 +164,7 @@ var (
panic(err)
}
time.Sleep(time.Second) // Doing that so user won't see instant response.
_, err = s.FollowupMessageCreate(*AppID, i.Interaction, true, &discordgo.WebhookParams{
_, err = s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Now you know everything about select component. If you want to know more or ask a question - feel free to.",
Components: []discordgo.MessageComponent{
discordgo.ActionsRow{
Expand Down
2 changes: 1 addition & 1 deletion examples/context_menus/main.go
Expand Up @@ -85,7 +85,7 @@ var (
i.ApplicationCommandData().TargetID,
)
if err != nil {
_, err = s.FollowupMessageCreate(*AppID, i.Interaction, true, &discordgo.WebhookParams{
_, err = s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: fmt.Sprintf("Mission failed. Cannot send a message to this user: %q", err.Error()),
Flags: 1 << 6,
})
Expand Down
20 changes: 10 additions & 10 deletions examples/slash_commands/main.go
Expand Up @@ -369,7 +369,7 @@ var (
Type: discordgo.InteractionResponseType(i.ApplicationCommandData().Options[0].IntValue()),
})
if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Something went wrong",
})
}
Expand All @@ -383,25 +383,25 @@ var (
},
})
if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Something went wrong",
})
return
}
time.AfterFunc(time.Second*5, func() {
_, err = s.InteractionResponseEdit(s.State.User.ID, i.Interaction, &discordgo.WebhookEdit{
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: content + "\n\nWell, now you know how to create and edit responses. " +
"But you still don't know how to delete them... so... wait 10 seconds and this " +
"message will be deleted.",
})
if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Something went wrong",
})
return
}
time.Sleep(time.Second * 10)
s.InteractionResponseDelete(s.State.User.ID, i.Interaction)
s.InteractionResponseDelete(i.Interaction)
})
},
"followups": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
Expand All @@ -419,26 +419,26 @@ var (
Content: "Surprise!",
},
})
msg, err := s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
msg, err := s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Followup message has been created, after 5 seconds it will be edited",
})
if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "Something went wrong",
})
return
}
time.Sleep(time.Second * 5)

s.FollowupMessageEdit(s.State.User.ID, i.Interaction, msg.ID, &discordgo.WebhookEdit{
s.FollowupMessageEdit(i.Interaction, msg.ID, &discordgo.WebhookEdit{
Content: "Now the original message is gone and after 10 seconds this message will ~~self-destruct~~ be deleted.",
})

time.Sleep(time.Second * 10)

s.FollowupMessageDelete(s.State.User.ID, i.Interaction, msg.ID)
s.FollowupMessageDelete(i.Interaction, msg.ID)

s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
Content: "For those, who didn't skip anything and followed tutorial along fairly, " +
"take a unicorn :unicorn: as reward!\n" +
"Also, as bonus... look at the original interaction response :D",
Expand Down
1 change: 1 addition & 0 deletions interactions.go
Expand Up @@ -180,6 +180,7 @@ func (t InteractionType) String() string {
// Interaction represents data of an interaction.
type Interaction struct {
ID string `json:"id"`
AppID string `json:"application_id"`
Type InteractionType `json:"type"`
Data InteractionData `json:"data"`
GuildID string `json:"guild_id"`
Expand Down
30 changes: 12 additions & 18 deletions restapi.go
Expand Up @@ -2823,55 +2823,49 @@ func (s *Session) InteractionRespond(interaction *Interaction, resp *Interaction
}

// InteractionResponse gets the response to an interaction.
// appID : The application ID.
// interaction : Interaction instance.
func (s *Session) InteractionResponse(appID string, interaction *Interaction) (*Message, error) {
return s.WebhookMessage(appID, interaction.Token, "@original")
func (s *Session) InteractionResponse(interaction *Interaction) (*Message, error) {
return s.WebhookMessage(interaction.AppID, interaction.Token, "@original")
}

// InteractionResponseEdit edits the response to an interaction.
// appID : The application ID.
// interaction : Interaction instance.
// newresp : Updated response message data.
func (s *Session) InteractionResponseEdit(appID string, interaction *Interaction, newresp *WebhookEdit) (*Message, error) {
return s.WebhookMessageEdit(appID, interaction.Token, "@original", newresp)
func (s *Session) InteractionResponseEdit(interaction *Interaction, newresp *WebhookEdit) (*Message, error) {
return s.WebhookMessageEdit(interaction.AppID, interaction.Token, "@original", newresp)
}

// InteractionResponseDelete deletes the response to an interaction.
// appID : The application ID.
// interaction : Interaction instance.
func (s *Session) InteractionResponseDelete(appID string, interaction *Interaction) error {
endpoint := EndpointInteractionResponseActions(appID, interaction.Token)
func (s *Session) InteractionResponseDelete(interaction *Interaction) error {
endpoint := EndpointInteractionResponseActions(interaction.AppID, interaction.Token)

_, err := s.RequestWithBucketID("DELETE", endpoint, nil, endpoint)

return err
}

// FollowupMessageCreate creates the followup message for an interaction.
// appID : The application ID.
// interaction : Interaction instance.
// wait : Waits for server confirmation of message send and ensures that the return struct is populated (it is nil otherwise)
// data : Data of the message to send.
func (s *Session) FollowupMessageCreate(appID string, interaction *Interaction, wait bool, data *WebhookParams) (*Message, error) {
return s.WebhookExecute(appID, interaction.Token, wait, data)
func (s *Session) FollowupMessageCreate(interaction *Interaction, wait bool, data *WebhookParams) (*Message, error) {
return s.WebhookExecute(interaction.AppID, interaction.Token, wait, data)
}

// FollowupMessageEdit edits a followup message of an interaction.
// appID : The application ID.
// interaction : Interaction instance.
// messageID : The followup message ID.
// data : Data to update the message
func (s *Session) FollowupMessageEdit(appID string, interaction *Interaction, messageID string, data *WebhookEdit) (*Message, error) {
return s.WebhookMessageEdit(appID, interaction.Token, messageID, data)
func (s *Session) FollowupMessageEdit(interaction *Interaction, messageID string, data *WebhookEdit) (*Message, error) {
return s.WebhookMessageEdit(interaction.AppID, interaction.Token, messageID, data)
}

// FollowupMessageDelete deletes a followup message of an interaction.
// appID : The application ID.
// interaction : Interaction instance.
// messageID : The followup message ID.
func (s *Session) FollowupMessageDelete(appID string, interaction *Interaction, messageID string) error {
return s.WebhookMessageDelete(appID, interaction.Token, messageID)
func (s *Session) FollowupMessageDelete(interaction *Interaction, messageID string) error {
return s.WebhookMessageDelete(interaction.AppID, interaction.Token, messageID)
}

// ------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 4d72c30

Please sign in to comment.