add randomdog command

This commit is contained in:
lyx0 2021-10-18 18:33:49 +02:00
parent 1433efa100
commit 590e7b866d
3 changed files with 44 additions and 0 deletions

29
pkg/api/randomdog.go Normal file
View file

@ -0,0 +1,29 @@
package api
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type randomDogResponse struct {
Url string `json:"url"`
}
func RandomDog() string {
response, err := http.Get("https://random.dog/woof.json")
if err != nil {
log.Fatalln(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
}
var responseObject randomDogResponse
json.Unmarshal(responseData, &responseObject)
return string(responseObject.Url)
}

12
pkg/commands/randomdog.go Normal file
View file

@ -0,0 +1,12 @@
package commands
import (
"github.com/gempir/go-twitch-irc/v2"
"github.com/lyx0/nourybot/pkg/api"
)
func RandomDog(channel string, client *twitch.Client) {
reply := api.RandomDog()
client.Say(channel, reply)
}

View file

@ -165,6 +165,9 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
case "randomcat":
commands.RandomCat(message.Channel, twitchClient)
return
case "randomdog":
commands.RandomDog(message.Channel, twitchClient)
return
case "randomfox":
commands.RandomFox(message.Channel, twitchClient)
return