1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 09:12:53 +00:00
arikawa/api/cmdroute/application.go
2023-11-04 01:48:17 -07:00

33 lines
980 B
Go

package cmdroute
import (
"fmt"
"github.com/diamondburned/arikawa/v3/api"
"github.com/diamondburned/arikawa/v3/discord"
)
// BulkCommandsOverwriter is an interface that allows to overwrite all commands
// at once. Everything *api.Client will implement this interface, including
// *state.State.
type BulkCommandsOverwriter interface {
CurrentApplication() (*discord.Application, error)
BulkOverwriteCommands(appID discord.AppID, cmds []api.CreateCommandData) ([]discord.Command, error)
}
var _ BulkCommandsOverwriter = (*api.Client)(nil)
// OverwriteCommands overwrites all commands for the current application.
func OverwriteCommands(client BulkCommandsOverwriter, cmds []api.CreateCommandData) error {
app, err := client.CurrentApplication()
if err != nil {
return fmt.Errorf("cannot get current app ID: %w", err)
}
if _, err = client.BulkOverwriteCommands(app.ID, cmds); err != nil {
return fmt.Errorf("cannot overwrite commands: %w", err)
}
return nil
}