diff --git a/pkg/api/randomcat.go b/pkg/api/randomcat.go new file mode 100644 index 0000000..3796580 --- /dev/null +++ b/pkg/api/randomcat.go @@ -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) +} diff --git a/pkg/commands/randomcat.go b/pkg/commands/randomcat.go new file mode 100644 index 0000000..2987d56 --- /dev/null +++ b/pkg/commands/randomcat.go @@ -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) +} diff --git a/pkg/handlers/command.go b/pkg/handlers/command.go index 5056be6..2f17447 100644 --- a/pkg/handlers/command.go +++ b/pkg/handlers/command.go @@ -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]")