mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
30 lines
626 B
Go
30 lines
626 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Xkcd returns a link to the latest Xkcd comic.
|
|
// API used: https://xkcd.com/info.0.json
|
|
func Xkcd() string {
|
|
response, err := http.Get("https://xkcd.com/info.0.json")
|
|
if err != nil {
|
|
log.Error(err)
|
|
}
|
|
responseData, err := ioutil.ReadAll(response.Body)
|
|
if err != nil {
|
|
log.Error(err)
|
|
}
|
|
var responseObject XkcdResponse
|
|
json.Unmarshal(responseData, &responseObject)
|
|
|
|
reply := fmt.Sprint("Current Xkcd #", responseObject.Num, " Title: ", responseObject.SafeTitle, " ", responseObject.Img)
|
|
|
|
return reply
|
|
}
|