diff --git a/pkg/api/randomduck.go b/pkg/api/randomduck.go new file mode 100644 index 0000000..0de634e --- /dev/null +++ b/pkg/api/randomduck.go @@ -0,0 +1,30 @@ +package api + +import ( + "encoding/json" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" +) + +type randomDuckResponse struct { + Url string `json:"url"` +} + +func RandomDuck() string { + response, err := http.Get("https://random-d.uk/api/random") + if err != nil { + log.Error(err) + } + + responseData, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Error(err) + } + + var responseObject randomDuckResponse + json.Unmarshal(responseData, &responseObject) + + return string(responseObject.Url) +} diff --git a/pkg/commands/randomduck.go b/pkg/commands/randomduck.go new file mode 100644 index 0000000..70b82a6 --- /dev/null +++ b/pkg/commands/randomduck.go @@ -0,0 +1,12 @@ +package commands + +import ( + "github.com/lyx0/nourybot/cmd/bot" + "github.com/lyx0/nourybot/pkg/api" +) + +func RandomDuck(channel string, nb *bot.Bot) { + reply := api.RandomDuck() + + nb.Send(channel, reply) +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 6cc9735..7497af4 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -186,9 +186,24 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) { case "randomcat": commands.RandomCat(target, nb) return + case "cat": + commands.RandomCat(target, nb) + return case "randomdog": commands.RandomDog(target, nb) return + case "dog": + commands.RandomDog(target, nb) + return + case "randomduck": + commands.RandomDuck(target, nb) + return + case "duck": + commands.RandomDuck(target, nb) + return + case "fox": + commands.RandomFox(target, nb) + return case "randomfox": commands.RandomFox(target, nb) return