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