From b727751f31b6a89fbb829bc62012757e442df66d Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Wed, 2 Apr 2025 19:09:37 +0100 Subject: [PATCH] Add aliases for animal command --- commands/tinyfox/tinyfox.go | 74 ++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/commands/tinyfox/tinyfox.go b/commands/tinyfox/tinyfox.go index 9ecd0b1..046b4f0 100644 --- a/commands/tinyfox/tinyfox.go +++ b/commands/tinyfox/tinyfox.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "slices" + "strings" "time" "github.com/Fluffy-Bean/lynxie/app" @@ -22,9 +23,66 @@ func RegisterTinyfoxCommands(a *app.App) { } var animals = []string{ - "fox", "yeen", "dog", "guara", "serval", "ott", "jackal", "bleat", "woof", "chi", "puma", "skunk", "tig", "wah", - "manul", "snep", "jaguar", "badger", "chee", "racc", "bear", "capy", "bun", "marten", "caracal", "snek", - "shiba", "dook", "leo", "yote", "poss", "chee", "lynx", + "fox", + "yeen", + "dog", + "guara", + "serval", + "ott", + "jackal", + "bleat", + "woof", + "chi", + "puma", + "skunk", + "tig", + "wah", + "manul", + "snep", + "jaguar", + "badger", + "chee", + "racc", + "bear", + "capy", + "bun", + "marten", + "caracal", + "snek", + "shiba", + "dook", + "leo", + "yote", + "poss", + "lynx", +} + +var animalAliases = map[string]string{ + "hyena": "yeen", + "serv": "serval", + "otter": "ott", + "deer": "bleat", + "wolf": "woof", + "tiger": "tig", + "red-panda": "wah", + "panda": "wah", + "manual": "manul", + "palas": "manul", + "palas-cat": "manul", + "snow-leopard": "snep", + "jag": "jaguar", + "cheetah": "chee", + "raccoon": "racc", + "rac": "racc", + "capybara": "capy", + "bunny": "bun", + "carac": "caracal", + "snake": "snek", + "ferret": "dook", + "leopard": "leo", + "coyote": "yote", + "possum": "poss", + "opossum": "poss", } func registerAnimal(a *app.App) app.Callback { @@ -46,10 +104,14 @@ func registerAnimal(a *app.App) app.Callback { } } if !slices.Contains(animals, options.Kind) { - return app.Error{ - Msg: fmt.Sprintf("Animal %s is invalid", options.Kind), - Err: errors.New("entered invalid animal name"), + alias, ok := animalAliases[options.Kind] + if !ok { + return app.Error{ + Msg: fmt.Sprintf("Animal \"%s\" is invalid. The following animals are supported:\n%s", options.Kind, strings.Join(animals, ", ")), + Err: errors.New("entered invalid animal name"), + } } + options.Kind = alias } req, err := http.NewRequest(http.MethodGet, "https://api.tinyfox.dev/img?animal="+options.Kind, nil)