add randomfox

This commit is contained in:
lyx0 2021-10-18 14:31:44 +02:00
parent f7d23a7497
commit ef89fadb9b
3 changed files with 45 additions and 0 deletions

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

@ -0,0 +1,30 @@
package api
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type randomFoxResponse struct {
Image string `json:"image"`
Link string `json:"link"`
}
func RandomFox() string {
response, err := http.Get("https://randomfox.ca/floof/")
if err != nil {
log.Fatalln(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
}
var responseObject randomFoxResponse
json.Unmarshal(responseData, &responseObject)
return string(responseObject.Image)
}

12
pkg/commands/randomfox.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 RandomFox(channel string, client *twitch.Client) {
reply := api.RandomFox()
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 "randomfox":
commands.RandomFox(message.Channel, twitchClient)
return
case "subage":
if msgLen < 3 {
twitchClient.Say(message.Channel, "Usage: ()subage [user] [streamer]")