1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 09:12:53 +00:00

cmdroute: Add OverwriteCommands

This adds a small helper function just for convenience.
This commit is contained in:
diamondburned 2022-12-10 06:02:37 -08:00
parent feb624758b
commit 080c734b37
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -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")
}