add random ducks

This commit is contained in:
lyx0 2021-10-20 17:27:00 +02:00
parent 97892b9127
commit 8359a525c3
3 changed files with 57 additions and 0 deletions

30
pkg/api/randomduck.go Normal file
View file

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

View file

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

View file

@ -186,9 +186,24 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
case "randomcat": case "randomcat":
commands.RandomCat(target, nb) commands.RandomCat(target, nb)
return return
case "cat":
commands.RandomCat(target, nb)
return
case "randomdog": case "randomdog":
commands.RandomDog(target, nb) commands.RandomDog(target, nb)
return 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": case "randomfox":
commands.RandomFox(target, nb) commands.RandomFox(target, nb)
return return