add randomcat command

This commit is contained in:
lyx0 2021-10-18 14:20:42 +02:00
parent 21ee59eb7e
commit f7d23a7497
3 changed files with 44 additions and 1 deletions

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

@ -0,0 +1,29 @@
package api
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type randomCatResponse struct {
File string `json:"file"`
}
func RandomCat() string {
response, err := http.Get("https://aws.random.cat/meow")
if err != nil {
log.Fatalln(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
}
var responseObject randomCatResponse
json.Unmarshal(responseData, &responseObject)
return string(responseObject.File)
}

12
pkg/commands/randomcat.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 RandomCat(channel string, client *twitch.Client) {
reply := api.RandomCat()
client.Say(channel, reply)
}

View file

@ -162,7 +162,9 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
} else {
twitchClient.Say(message.Channel, "Pleb's can't pyramid FeelsBadMan")
}
case "randomcat":
commands.RandomCat(message.Channel, twitchClient)
return
case "subage":
if msgLen < 3 {
twitchClient.Say(message.Channel, "Usage: ()subage [user] [streamer]")