Add aliases for animal command

This commit is contained in:
Michał Gdula 2025-04-02 19:09:37 +01:00
parent fa6bf5ddb8
commit b727751f31

View file

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