From 080c734b37ea6ef91be6da9291f1ce36f23e0830 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sat, 10 Dec 2022 06:02:37 -0800 Subject: [PATCH] cmdroute: Add OverwriteCommands This adds a small helper function just for convenience. --- api/cmdroute/application.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 api/cmdroute/application.go diff --git a/api/cmdroute/application.go b/api/cmdroute/application.go new file mode 100644 index 0000000..fbdda6c --- /dev/null +++ b/api/cmdroute/application.go @@ -0,0 +1,28 @@ +package cmdroute + +import ( + "github.com/diamondburned/arikawa/v3/api" + "github.com/diamondburned/arikawa/v3/discord" + "github.com/pkg/errors" +) + +// 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 errors.Wrap(err, "cannot get current app ID") + } + + _, err = client.BulkOverwriteCommands(app.ID, cmds) + return errors.Wrap(err, "cannot overwrite commands") +}