Add ApplicationID field to Interaction (#1125)

* add application_id to interaction struct and remove appID param from rest routes

* revert voice receive go mod & sum
This commit is contained in:
ToπSenpai 2022-04-14 21:07:53 +02:00 committed by GitHub
parent 16efe0842b
commit 4d72c306b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 31 deletions

View file

@ -139,7 +139,7 @@ var (
panic(err) panic(err)
} }
time.Sleep(time.Second) // Doing that so user won't see instant response. 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. " + 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.", "Try calling `/selects multi` command.",
Flags: 1 << 6, Flags: 1 << 6,
@ -164,7 +164,7 @@ var (
panic(err) panic(err)
} }
time.Sleep(time.Second) // Doing that so user won't see instant response. 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.", Content: "Now you know everything about select component. If you want to know more or ask a question - feel free to.",
Components: []discordgo.MessageComponent{ Components: []discordgo.MessageComponent{
discordgo.ActionsRow{ discordgo.ActionsRow{

View file

@ -85,7 +85,7 @@ var (
i.ApplicationCommandData().TargetID, i.ApplicationCommandData().TargetID,
) )
if err != nil { 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()), Content: fmt.Sprintf("Mission failed. Cannot send a message to this user: %q", err.Error()),
Flags: 1 << 6, Flags: 1 << 6,
}) })

View file

@ -369,7 +369,7 @@ var (
Type: discordgo.InteractionResponseType(i.ApplicationCommandData().Options[0].IntValue()), Type: discordgo.InteractionResponseType(i.ApplicationCommandData().Options[0].IntValue()),
}) })
if err != nil { 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", Content: "Something went wrong",
}) })
} }
@ -383,25 +383,25 @@ var (
}, },
}) })
if err != nil { 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", Content: "Something went wrong",
}) })
return return
} }
time.AfterFunc(time.Second*5, func() { 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. " + 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 " + "But you still don't know how to delete them... so... wait 10 seconds and this " +
"message will be deleted.", "message will be deleted.",
}) })
if err != nil { 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", Content: "Something went wrong",
}) })
return return
} }
time.Sleep(time.Second * 10) 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) { "followups": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
@ -419,26 +419,26 @@ var (
Content: "Surprise!", 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", Content: "Followup message has been created, after 5 seconds it will be edited",
}) })
if err != nil { 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", Content: "Something went wrong",
}) })
return return
} }
time.Sleep(time.Second * 5) 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.", Content: "Now the original message is gone and after 10 seconds this message will ~~self-destruct~~ be deleted.",
}) })
time.Sleep(time.Second * 10) 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, " + Content: "For those, who didn't skip anything and followed tutorial along fairly, " +
"take a unicorn :unicorn: as reward!\n" + "take a unicorn :unicorn: as reward!\n" +
"Also, as bonus... look at the original interaction response :D", "Also, as bonus... look at the original interaction response :D",

View file

@ -180,6 +180,7 @@ func (t InteractionType) String() string {
// Interaction represents data of an interaction. // Interaction represents data of an interaction.
type Interaction struct { type Interaction struct {
ID string `json:"id"` ID string `json:"id"`
AppID string `json:"application_id"`
Type InteractionType `json:"type"` Type InteractionType `json:"type"`
Data InteractionData `json:"data"` Data InteractionData `json:"data"`
GuildID string `json:"guild_id"` GuildID string `json:"guild_id"`

View file

@ -2823,25 +2823,22 @@ func (s *Session) InteractionRespond(interaction *Interaction, resp *Interaction
} }
// InteractionResponse gets the response to an interaction. // InteractionResponse gets the response to an interaction.
// appID : The application ID.
// interaction : Interaction instance. // interaction : Interaction instance.
func (s *Session) InteractionResponse(appID string, interaction *Interaction) (*Message, error) { func (s *Session) InteractionResponse(interaction *Interaction) (*Message, error) {
return s.WebhookMessage(appID, interaction.Token, "@original") return s.WebhookMessage(interaction.AppID, interaction.Token, "@original")
} }
// InteractionResponseEdit edits the response to an interaction. // InteractionResponseEdit edits the response to an interaction.
// appID : The application ID.
// interaction : Interaction instance. // interaction : Interaction instance.
// newresp : Updated response message data. // newresp : Updated response message data.
func (s *Session) InteractionResponseEdit(appID string, interaction *Interaction, newresp *WebhookEdit) (*Message, error) { func (s *Session) InteractionResponseEdit(interaction *Interaction, newresp *WebhookEdit) (*Message, error) {
return s.WebhookMessageEdit(appID, interaction.Token, "@original", newresp) return s.WebhookMessageEdit(interaction.AppID, interaction.Token, "@original", newresp)
} }
// InteractionResponseDelete deletes the response to an interaction. // InteractionResponseDelete deletes the response to an interaction.
// appID : The application ID.
// interaction : Interaction instance. // interaction : Interaction instance.
func (s *Session) InteractionResponseDelete(appID string, interaction *Interaction) error { func (s *Session) InteractionResponseDelete(interaction *Interaction) error {
endpoint := EndpointInteractionResponseActions(appID, interaction.Token) endpoint := EndpointInteractionResponseActions(interaction.AppID, interaction.Token)
_, err := s.RequestWithBucketID("DELETE", endpoint, nil, endpoint) _, err := s.RequestWithBucketID("DELETE", endpoint, nil, endpoint)
@ -2849,29 +2846,26 @@ func (s *Session) InteractionResponseDelete(appID string, interaction *Interacti
} }
// FollowupMessageCreate creates the followup message for an interaction. // FollowupMessageCreate creates the followup message for an interaction.
// appID : The application ID.
// interaction : Interaction instance. // interaction : Interaction instance.
// wait : Waits for server confirmation of message send and ensures that the return struct is populated (it is nil otherwise) // 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. // data : Data of the message to send.
func (s *Session) FollowupMessageCreate(appID string, interaction *Interaction, wait bool, data *WebhookParams) (*Message, error) { func (s *Session) FollowupMessageCreate(interaction *Interaction, wait bool, data *WebhookParams) (*Message, error) {
return s.WebhookExecute(appID, interaction.Token, wait, data) return s.WebhookExecute(interaction.AppID, interaction.Token, wait, data)
} }
// FollowupMessageEdit edits a followup message of an interaction. // FollowupMessageEdit edits a followup message of an interaction.
// appID : The application ID.
// interaction : Interaction instance. // interaction : Interaction instance.
// messageID : The followup message ID. // messageID : The followup message ID.
// data : Data to update the message // data : Data to update the message
func (s *Session) FollowupMessageEdit(appID string, interaction *Interaction, messageID string, data *WebhookEdit) (*Message, error) { func (s *Session) FollowupMessageEdit(interaction *Interaction, messageID string, data *WebhookEdit) (*Message, error) {
return s.WebhookMessageEdit(appID, interaction.Token, messageID, data) return s.WebhookMessageEdit(interaction.AppID, interaction.Token, messageID, data)
} }
// FollowupMessageDelete deletes a followup message of an interaction. // FollowupMessageDelete deletes a followup message of an interaction.
// appID : The application ID.
// interaction : Interaction instance. // interaction : Interaction instance.
// messageID : The followup message ID. // messageID : The followup message ID.
func (s *Session) FollowupMessageDelete(appID string, interaction *Interaction, messageID string) error { func (s *Session) FollowupMessageDelete(interaction *Interaction, messageID string) error {
return s.WebhookMessageDelete(appID, interaction.Token, messageID) return s.WebhookMessageDelete(interaction.AppID, interaction.Token, messageID)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------