Skip to content

Commit

Permalink
Slash commands (#856)
Browse files Browse the repository at this point in the history
* UnknownBan error code addition

* GuildBan method implementation

* Gofmt fix

Gofmt fix

* Interactions: application commands basic API and gateway integration

* Some gitignore update

* Application commands and interactions API implementation

* Some fixes

* Some improvements of slash-commands example and slash-commands API

* OAuth2 endpoints backward compatibility

* Gofmt fix

* Requested fixes and documentation improvement for application commands

* Some fixes

* New and more interesting example of slash-commands usage, merging "interaction.go" and "interactions.go" into a single file. And some fixes.

* Gofmt and documentation fixes

* More fixes

* Gofmt fixes

* More fixes!

* Doc and endpoint fixes

* Gofmt fix

* Remove dependence on open gateway connection

* Remove redundant command ID checks

* Fix typo in ApplicationCommandCreate comment

* Tidy up function calls returning body

* Add upcoming API changes

* Correct return value name, swap parameter order

* Add Version field to ApplicationCommand

* Fix up language in comments

* Remove redundant conversion to float64

Co-authored-by: Carson Hoffman <c@rsonhoffman.com>
  • Loading branch information
FedorLap2006 and CarsonHoffman committed Mar 1, 2021
1 parent 4617d8e commit b0fa920
Show file tree
Hide file tree
Showing 11 changed files with 921 additions and 49 deletions.
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 @@ -122,6 +122,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 @@ -133,6 +136,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 @@ -146,9 +178,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/"
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"
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
EndpointOauth2Applications = EndpointOAuth2Applications
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
}

0 comments on commit b0fa920

Please sign in to comment.