From 5d67b2e2b03a4dc1fa47de59013e49271d7a9931 Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Thu, 24 Apr 2025 21:19:14 +0100 Subject: [PATCH] User `cmd.Args()` for extra values on commands --- commands/porb/porb.go | 4 +--- commands/tinyfox/tinyfox.go | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/commands/porb/porb.go b/commands/porb/porb.go index 6f97782..1772323 100644 --- a/commands/porb/porb.go +++ b/commands/porb/porb.go @@ -71,7 +71,6 @@ func RegisterPorbCommands(a *app.App) { func registerE621(a *app.App) app.Callback { return func(h *app.Handler, args []string) app.Error { var options struct { - Tags string Order string Rating string } @@ -80,7 +79,6 @@ func registerE621(a *app.App) app.Callback { cmd.StringVar(&options.Order, "order", "random", "Search order") cmd.StringVar(&options.Rating, "rating", "e", "Search rating") - cmd.StringVar(&options.Tags, "tags", "", "Search tags") cmd.Parse(args) @@ -90,7 +88,7 @@ func registerE621(a *app.App) app.Callback { "https://e621.net/posts.json/?limit=1&tags=order:%s+rating:%s+%s", options.Order, options.Rating, - options.Tags, + strings.Join(cmd.Args(), "+"), ), nil, ) diff --git a/commands/tinyfox/tinyfox.go b/commands/tinyfox/tinyfox.go index 1cd7f5c..0efa8e3 100644 --- a/commands/tinyfox/tinyfox.go +++ b/commands/tinyfox/tinyfox.go @@ -2,7 +2,6 @@ package tinyfox import ( "errors" - "flag" "fmt" "net/http" "slices" @@ -89,34 +88,27 @@ func RegisterTinyfoxCommands(a *app.App) { func registerAnimal(a *app.App) app.Callback { return func(h *app.Handler, args []string) app.Error { - var options struct { - Kind string - } - - cmd := flag.NewFlagSet("", flag.ContinueOnError) - - cmd.StringVar(&options.Kind, "kind", "", "Animal kind to search for") - - cmd.Parse(args) - - if options.Kind == "" { + if len(args) < 1 { return app.Error{ Msg: "Animal name is required!", Err: errors.New("animal name is required"), } } - if !slices.Contains(animals, options.Kind) { - alias, ok := animalAliases[options.Kind] + + animal := args[0] + + if !slices.Contains(animals, animal) { + alias, ok := animalAliases[animal] if !ok { return app.Error{ - Msg: fmt.Sprintf("Animal \"%s\" is invalid. The following animals are supported:\n%s", options.Kind, strings.Join(animals, ", ")), + Msg: fmt.Sprintf("Animal \"%s\" is invalid. The following animals are supported:\n%s", animal, strings.Join(animals, ", ")), Err: errors.New("entered invalid animal name"), } } - options.Kind = alias + animal = alias } - req, err := http.NewRequest(http.MethodGet, "https://api.tinyfox.dev/img?animal="+options.Kind, nil) + req, err := http.NewRequest(http.MethodGet, "https://api.tinyfox.dev/img?animal="+animal, nil) if err != nil { return app.Error{ Msg: "Failed to make request", @@ -137,13 +129,13 @@ func registerAnimal(a *app.App) app.Callback { Embed: &discordgo.MessageEmbed{ Title: "Animal", Image: &discordgo.MessageEmbedImage{ - URL: "attachment://image.png", + URL: "attachment://animal.png", }, Color: utils.ColorFromRGB(255, 255, 255), }, Files: []*discordgo.File{ { - Name: "image.png", + Name: "animal.png", ContentType: "", Reader: res.Body, },