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

Slash commands #856

Merged
merged 31 commits into from Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d7f3449
UnknownBan error code addition
FedorLap2006 Dec 11, 2020
356455e
GuildBan method implementation
FedorLap2006 Dec 12, 2020
d703a29
Gofmt fix
FedorLap2006 Dec 12, 2020
854e96d
Merge branch 'master' of github.com:bwmarrin/discordgo into slashes
FedorLap2006 Dec 19, 2020
4aeca90
Interactions: application commands basic API and gateway integration
FedorLap2006 Dec 24, 2020
af426c1
Some gitignore update
FedorLap2006 Jan 16, 2021
c1d8bff
Application commands and interactions API implementation
FedorLap2006 Jan 16, 2021
3f37ec0
Some fixes
FedorLap2006 Jan 17, 2021
5b23e34
Some improvements of slash-commands example and slash-commands API
FedorLap2006 Jan 17, 2021
1c8faf9
OAuth2 endpoints backward compatibility
FedorLap2006 Jan 17, 2021
9c6bf00
Gofmt fix
FedorLap2006 Jan 17, 2021
f554a2f
Requested fixes and documentation improvement for application commands
FedorLap2006 Jan 19, 2021
b76c150
Merge branch 'master' of github.com:bwmarrin/discordgo into slashes
FedorLap2006 Jan 22, 2021
f4cfc0f
Merge branch 'master' of github.com:bwmarrin/discordgo into slashes
FedorLap2006 Feb 6, 2021
2028ce6
Some fixes
FedorLap2006 Feb 16, 2021
75a2e2d
New and more interesting example of slash-commands usage, merging "in…
FedorLap2006 Feb 16, 2021
f5375a0
Gofmt and documentation fixes
FedorLap2006 Feb 16, 2021
00e6233
More fixes
FedorLap2006 Feb 17, 2021
a1b4fed
Gofmt fixes
FedorLap2006 Feb 17, 2021
8718e2d
More fixes!
FedorLap2006 Feb 17, 2021
4b3f141
Doc and endpoint fixes
FedorLap2006 Feb 28, 2021
3bc1011
Gofmt fix
FedorLap2006 Feb 28, 2021
1f39a0c
Remove dependence on open gateway connection
CarsonHoffman Mar 1, 2021
4d4cfa2
Remove redundant command ID checks
CarsonHoffman Mar 1, 2021
01ab497
Fix typo in ApplicationCommandCreate comment
CarsonHoffman Mar 1, 2021
372eb32
Tidy up function calls returning body
CarsonHoffman Mar 1, 2021
f6396f4
Add upcoming API changes
CarsonHoffman Mar 1, 2021
ae60d65
Correct return value name, swap parameter order
CarsonHoffman Mar 1, 2021
da4ca39
Add Version field to ApplicationCommand
CarsonHoffman Mar 1, 2021
2274e22
Fix up language in comments
CarsonHoffman Mar 1, 2021
4a31b48
Remove redundant conversion to float64
CarsonHoffman Mar 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,2 +1,5 @@
# IDE-specific metadata
.idea/

# Environment variables. Useful for examples.
.env
52 changes: 47 additions & 5 deletions endpoints.go
Expand Up @@ -121,6 +121,9 @@ var (
EndpointChannelWebhooks = func(cID string) string { return EndpointChannel(cID) + "/webhooks" }
EndpointWebhook = func(wID string) string { return EndpointWebhooks + wID }
EndpointWebhookToken = func(wID, token string) string { return EndpointWebhooks + wID + "/" + token }
EndpointWebhookMessage = func(wID, token, messageID string) string {
return EndpointWebhookToken(wID, token) + "/messages/" + messageID
}

EndpointMessageReactionsAll = func(cID, mID string) string {
return EndpointChannelMessage(cID, mID) + "/reactions"
Expand All @@ -132,6 +135,35 @@ var (
return EndpointMessageReactions(cID, mID, eID) + "/" + uID
}

EndpointApplicationGlobalCommands = func(aID string) string {
return EndpointApplication(aID) + "/commands"
}
EndpointApplicationGlobalCommand = func(aID, cID string) string {
return EndpointApplicationGlobalCommands(aID) + "/" + cID
}

EndpointApplicationGuildCommands = func(aID, gID string) string {
return EndpointApplication(aID) + "/guilds/" + gID + "/commands"
}
EndpointApplicationGuildCommand = func(aID, gID, cID string) string {
return EndpointApplicationGuildCommands(aID, gID) + "/" + cID
}
EndpointInteraction = func(aID, iToken string) string {
return EndpointAPI + "interactions/" + aID + "/" + iToken
}
EndpointInteractionResponse = func(iID, iToken string) string {
return EndpointInteraction(iID, iToken) + "/callback"
}
EndpointInteractionResponseActions = func(aID, iToken string) string {
return EndpointWebhookMessage(aID, iToken, "@original")
}
EndpointFollowupMessage = func(aID, iToken string) string {
return EndpointWebhookToken(aID, iToken)
}
EndpointFollowupMessageActions = func(aID, iToken, mID string) string {
return EndpointWebhookMessage(aID, iToken, mID)
}

EndpointRelationships = func() string { return EndpointUsers + "@me" + "/relationships" }
EndpointRelationship = func(uID string) string { return EndpointRelationships() + "/" + uID }
EndpointRelationshipsMutual = func(uID string) string { return EndpointUsers + uID + "/relationships" }
Expand All @@ -145,9 +177,19 @@ var (
EndpointEmoji = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".png" }
EndpointEmojiAnimated = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".gif" }

EndpointOauth2 = EndpointAPI + "oauth2/"
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
EndpointApplications = EndpointOauth2 + "applications"
EndpointApplication = func(aID string) string { return EndpointApplications + "/" + aID }
EndpointApplicationsBot = func(aID string) string { return EndpointApplications + "/" + aID + "/bot" }
EndpointApplicationAssets = func(aID string) string { return EndpointApplications + "/" + aID + "/assets" }
EndpointApplications = EndpointAPI + "applications"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is changing the value of EndpointApplications to mean another thing really a good idea?

Note to others: The previous EndpointApplications is now known as EndpointOAuth2Applications.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to change it. Because EndpointApplications now doesn't belong to OAuth2. It belongs to applications and their commands.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but this might cause a problem on the off chance someone was relying on EndpointApplications to be with OAuth2.
It IS an exported variable after all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but this might cause a problem on the off chance someone was relying on EndpointApplications to be with OAuth2.
It IS an exported variable after all.

Reasonable question: how I need to name it then, tell me. Applications and OAuth2 applications isn't the same thing now. And also, why are everyone tries to save backward compatibility even when WE JUST CAN'T???? Because API is changed and we need to change something, not sit on the same place as we was before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding things to an API doesn't break compatibility, but removing and modifying things can eg:

For example, something as innocuous as:

fmt.Println(discordgo.EndpointApplication)

This will now cause a compiler error when updating with this PR.

It's our job as library maintainers to minimize these scenarios, even when they cause the code to not be exactly what we would like in a perfect world.

Ps. It feels like you're getting upset by this code review, please remember that these comments aren't a criticism of you as a person, just they reflect the combined experience of a number of people also trying to do a good job - we're working together to make this the best PR possible!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like you're getting upset by this code review

Of course I'm upset.

but removing and modifying things

I can't save EndpointApplication here, because Discord API changed it and it no longer "OAuth2" applications. Or at least, I'm waiting for suggestions what name I should pick for new ones if I will return EndpointApplications and other OAuth2 stuff back to original.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review isn't a criticism of you as a person, I'm sorry you're feeling upset, but that is not the intention. As the maintainers of the library, we have a responsibility to our users, and we are essentially signing up to being the maintainers of this code in the future.

My apologies for speaking without fully getting context on this.

I've done some searching, it seems like there is no code on Github or Google currently using EndpointApplication, I'm happy with renaming this to EndpointOauth2Application, but I would like us to add a warning in the release notes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right, I appreciate that decision. Well, actually, we can try to create another name for current applications endpoint, but... that would be really hard to rename in future. So, yeah, you're right, warning in release notes is enough for this. Btw, when will be release?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done some searching, it seems like there is no code on Github or Google currently using EndpointApplication

Just want to note that many of the larger discord bots tend to be private codebases, and those may be more likely to use oauth flows in e.g. web dashboards or what not, where these variables may be used @iopred

EndpointApplication = func(aID string) string { return EndpointApplications + "/" + aID }

EndpointOAuth2 = EndpointAPI + "oauth2/"
EndpointOAuth2Applications = EndpointOAuth2 + "applications"
EndpointOAuth2Application = func(aID string) string { return EndpointOAuth2Applications + "/" + aID }
EndpointOAuth2ApplicationsBot = func(aID string) string { return EndpointOAuth2Applications + "/" + aID + "/bot" }
EndpointOAuth2ApplicationAssets = func(aID string) string { return EndpointOAuth2Applications + "/" + aID + "/assets" }

// TODO: Deprecated, remove in the next release
EndpointOauth2 = EndpointOAuth2
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
EndpointOauth2Applications = EndpointOAuth2Applications
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
EndpointOauth2Application = EndpointOAuth2Application
EndpointOauth2ApplicationsBot = EndpointOAuth2ApplicationsBot
EndpointOauth2ApplicationAssets = EndpointOAuth2ApplicationAssets
)
24 changes: 24 additions & 0 deletions eventhandlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions events.go
Expand Up @@ -267,3 +267,8 @@ type WebhooksUpdate struct {
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
}

// InteractionCreate is the data for a InteractionCreate event
type InteractionCreate struct {
*Interaction
}