mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add randomcat command
This commit is contained in:
parent
21ee59eb7e
commit
f7d23a7497
3 changed files with 44 additions and 1 deletions
29
pkg/api/randomcat.go
Normal file
29
pkg/api/randomcat.go
Normal 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
12
pkg/commands/randomcat.go
Normal 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)
|
||||||
|
}
|
|
@ -162,7 +162,9 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, u
|
||||||
} else {
|
} else {
|
||||||
twitchClient.Say(message.Channel, "Pleb's can't pyramid FeelsBadMan")
|
twitchClient.Say(message.Channel, "Pleb's can't pyramid FeelsBadMan")
|
||||||
}
|
}
|
||||||
|
case "randomcat":
|
||||||
|
commands.RandomCat(message.Channel, twitchClient)
|
||||||
|
return
|
||||||
case "subage":
|
case "subage":
|
||||||
if msgLen < 3 {
|
if msgLen < 3 {
|
||||||
twitchClient.Say(message.Channel, "Usage: ()subage [user] [streamer]")
|
twitchClient.Say(message.Channel, "Usage: ()subage [user] [streamer]")
|
||||||
|
|
Loading…
Reference in a new issue