* Create edit application command permissions endpoint * Add remaining command permissions endpoints * Clean up naming a bit * Add docs for application command permissions endpoints * Update comments * More comments * :^) * Put the verb in API method names at the end * Review feedback * Add default permissions * feat(restapi): rewording of comments to application command permissions endpoints * fix(rest): errors for application commands permissions endpoints * style(interactions): changed order of fields in ApplicationCommand Co-authored-by: NotUnlikeTheWaves <hleistra@gmail.com> Co-authored-by: nitroflap <fe.lap.prog@gmail.com>
This commit is contained in:
parent
0a0955c5f9
commit
d5bacb5401
3 changed files with 101 additions and 8 deletions
|
@ -133,6 +133,12 @@ var (
|
|||
EndpointApplicationGuildCommand = func(aID, gID, cID string) string {
|
||||
return EndpointApplicationGuildCommands(aID, gID) + "/" + cID
|
||||
}
|
||||
EndpointApplicationCommandPermissions = func(aID, gID, cID string) string {
|
||||
return EndpointApplicationGuildCommand(aID, gID, cID) + "/permissions"
|
||||
}
|
||||
EndpointApplicationCommandsGuildPermissions = func(aID, gID string) string {
|
||||
return EndpointApplicationGuildCommands(aID, gID) + "/permissions"
|
||||
}
|
||||
EndpointInteraction = func(aID, iToken string) string {
|
||||
return EndpointAPI + "interactions/" + aID + "/" + iToken
|
||||
}
|
||||
|
|
|
@ -30,15 +30,17 @@ const (
|
|||
|
||||
// ApplicationCommand represents an application's slash command.
|
||||
type ApplicationCommand struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
ApplicationID string `json:"application_id,omitempty"`
|
||||
Type ApplicationCommandType `json:"type,omitempty"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id,omitempty"`
|
||||
ApplicationID string `json:"application_id,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Type ApplicationCommandType `json:"type,omitempty"`
|
||||
Name string `json:"name"`
|
||||
DefaultPermission *bool `json:"default_permission,omitempty"`
|
||||
|
||||
// NOTE: Chat commands only. Otherwise it mustn't be set.
|
||||
Description string `json:"description,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
// NOTE: Chat commands only. Otherwise it mustn't be set.
|
||||
Options []*ApplicationCommandOption `json:"options"`
|
||||
|
||||
Description string `json:"description,omitempty"`
|
||||
Options []*ApplicationCommandOption `json:"options"`
|
||||
}
|
||||
|
||||
// ApplicationCommandOptionType indicates the type of a slash command's option.
|
||||
|
@ -107,6 +109,35 @@ type ApplicationCommandOptionChoice struct {
|
|||
Value interface{} `json:"value"`
|
||||
}
|
||||
|
||||
// ApplicationCommandPermissions represents a single user or role permission for a command.
|
||||
type ApplicationCommandPermissions struct {
|
||||
ID string `json:"id"`
|
||||
Type ApplicationCommandPermissionType `json:"type"`
|
||||
Permission bool `json:"permission"`
|
||||
}
|
||||
|
||||
// ApplicationCommandPermissionsList represents a list of ApplicationCommandPermissions, needed for serializing to JSON.
|
||||
type ApplicationCommandPermissionsList struct {
|
||||
Permissions []*ApplicationCommandPermissions `json:"permissions"`
|
||||
}
|
||||
|
||||
// GuildApplicationCommandPermissions represents all permissions for a single guild command.
|
||||
type GuildApplicationCommandPermissions struct {
|
||||
ID string `json:"id"`
|
||||
ApplicationID string `json:"application_id"`
|
||||
GuildID string `json:"guild_id"`
|
||||
Permissions []*ApplicationCommandPermissions `json:"permissions"`
|
||||
}
|
||||
|
||||
// ApplicationCommandPermissionType indicates whether a permission is user or role based.
|
||||
type ApplicationCommandPermissionType uint8
|
||||
|
||||
// Application command permission types.
|
||||
const (
|
||||
ApplicationCommandPermissionTypeRole ApplicationCommandPermissionType = 1
|
||||
ApplicationCommandPermissionTypeUser ApplicationCommandPermissionType = 2
|
||||
)
|
||||
|
||||
// InteractionType indicates the type of an interaction event.
|
||||
type InteractionType uint8
|
||||
|
||||
|
|
56
restapi.go
56
restapi.go
|
@ -2282,6 +2282,62 @@ func (s *Session) ApplicationCommands(appID, guildID string) (cmd []*Application
|
|||
return
|
||||
}
|
||||
|
||||
// GuildApplicationCommandsPermissions returns permissions for all application commands in a guild.
|
||||
// appID : The application ID
|
||||
// guildID : Guild ID to retrieve application commands permissions for.
|
||||
func (s *Session) GuildApplicationCommandsPermissions(appID, guildID string) (permissions []*GuildApplicationCommandPermissions, err error) {
|
||||
endpoint := EndpointApplicationCommandsGuildPermissions(appID, guildID)
|
||||
|
||||
var body []byte
|
||||
body, err = s.RequestWithBucketID("GET", endpoint, nil, endpoint)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = unmarshal(body, &permissions)
|
||||
return
|
||||
}
|
||||
|
||||
// ApplicationCommandPermissions returns all permissions of an application command
|
||||
// appID : The Application ID
|
||||
// guildID : The guild ID containing the application command
|
||||
// cmdID : The command ID to retrieve the permissions of
|
||||
func (s *Session) ApplicationCommandPermissions(appID, guildID, cmdID string) (permissions *GuildApplicationCommandPermissions, err error) {
|
||||
endpoint := EndpointApplicationCommandPermissions(appID, guildID, cmdID)
|
||||
|
||||
var body []byte
|
||||
body, err = s.RequestWithBucketID("GET", endpoint, nil, endpoint)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = unmarshal(body, &permissions)
|
||||
return
|
||||
}
|
||||
|
||||
// ApplicationCommandPermissionsEdit edits the permissions of an application command
|
||||
// appID : The Application ID
|
||||
// guildID : The guild ID containing the application command
|
||||
// cmdID : The command ID to edit the permissions of
|
||||
// permissions : An object containing a list of permissions for the application command
|
||||
func (s *Session) ApplicationCommandPermissionsEdit(appID, guildID, cmdID string, permissions *ApplicationCommandPermissionsList) (err error) {
|
||||
endpoint := EndpointApplicationCommandPermissions(appID, guildID, cmdID)
|
||||
|
||||
_, err = s.RequestWithBucketID("PUT", endpoint, permissions, endpoint)
|
||||
return
|
||||
}
|
||||
|
||||
// ApplicationCommandPermissionsBatchEdit edits the permissions of a batch of commands
|
||||
// appID : The Application ID
|
||||
// guildID : The guild ID to batch edit commands of
|
||||
// permissions : A list of permissions paired with a command ID, guild ID, and application ID per application command
|
||||
func (s *Session) ApplicationCommandPermissionsBatchEdit(appID, guildID string, permissions []*GuildApplicationCommandPermissions) (err error) {
|
||||
endpoint := EndpointApplicationCommandsGuildPermissions(appID, guildID)
|
||||
|
||||
_, err = s.RequestWithBucketID("PUT", endpoint, permissions, endpoint)
|
||||
return
|
||||
}
|
||||
|
||||
// InteractionRespond creates the response to an interaction.
|
||||
// appID : The application ID.
|
||||
// interaction : Interaction instance.
|
||||
|
|
Loading…
Reference in a new issue