2022-12-10 14:02:37 +00:00
|
|
|
package cmdroute
|
|
|
|
|
|
|
|
import (
|
2023-09-19 15:23:25 +00:00
|
|
|
"fmt"
|
2023-09-19 15:25:48 +00:00
|
|
|
|
2022-12-10 14:02:37 +00:00
|
|
|
"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 {
|
2023-09-19 15:23:25 +00:00
|
|
|
return fmt.Errorf("cannot get current app ID: %w", err)
|
2022-12-10 14:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.BulkOverwriteCommands(app.ID, cmds)
|
2023-09-19 15:23:25 +00:00
|
|
|
return fmt.Errorf("cannot overwrite commands: %w", err)
|
2022-12-10 14:02:37 +00:00
|
|
|
}
|