mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add random ducks
This commit is contained in:
parent
97892b9127
commit
8359a525c3
3 changed files with 57 additions and 0 deletions
30
pkg/api/randomduck.go
Normal file
30
pkg/api/randomduck.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
type randomDuckResponse struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomDuck() string {
|
||||||
|
response, err := http.Get("https://random-d.uk/api/random")
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData, err := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var responseObject randomDuckResponse
|
||||||
|
json.Unmarshal(responseData, &responseObject)
|
||||||
|
|
||||||
|
return string(responseObject.Url)
|
||||||
|
}
|
12
pkg/commands/randomduck.go
Normal file
12
pkg/commands/randomduck.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/lyx0/nourybot/cmd/bot"
|
||||||
|
"github.com/lyx0/nourybot/pkg/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RandomDuck(channel string, nb *bot.Bot) {
|
||||||
|
reply := api.RandomDuck()
|
||||||
|
|
||||||
|
nb.Send(channel, reply)
|
||||||
|
}
|
|
@ -186,9 +186,24 @@ func Command(message twitch.PrivateMessage, nb *bot.Bot) {
|
||||||
case "randomcat":
|
case "randomcat":
|
||||||
commands.RandomCat(target, nb)
|
commands.RandomCat(target, nb)
|
||||||
return
|
return
|
||||||
|
case "cat":
|
||||||
|
commands.RandomCat(target, nb)
|
||||||
|
return
|
||||||
case "randomdog":
|
case "randomdog":
|
||||||
commands.RandomDog(target, nb)
|
commands.RandomDog(target, nb)
|
||||||
return
|
return
|
||||||
|
case "dog":
|
||||||
|
commands.RandomDog(target, nb)
|
||||||
|
return
|
||||||
|
case "randomduck":
|
||||||
|
commands.RandomDuck(target, nb)
|
||||||
|
return
|
||||||
|
case "duck":
|
||||||
|
commands.RandomDuck(target, nb)
|
||||||
|
return
|
||||||
|
case "fox":
|
||||||
|
commands.RandomFox(target, nb)
|
||||||
|
return
|
||||||
case "randomfox":
|
case "randomfox":
|
||||||
commands.RandomFox(target, nb)
|
commands.RandomFox(target, nb)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue