mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add randomdog command
This commit is contained in:
parent
1433efa100
commit
590e7b866d
3 changed files with 44 additions and 0 deletions
29
pkg/api/randomdog.go
Normal file
29
pkg/api/randomdog.go
Normal 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
12
pkg/commands/randomdog.go
Normal 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)
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue