2021-10-17 18:55:51 +02:00
|
|
|
package ivr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2021-10-17 19:31:54 +02:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2021-10-17 18:55:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// https://api.ivr.fi
|
|
|
|
type followageApiResponse struct {
|
|
|
|
User string `json:"user"`
|
|
|
|
UserID string `json:"userid"`
|
|
|
|
Channel string `json:"channel"`
|
|
|
|
ChannelId string `json:"channelid"`
|
|
|
|
FollowedAt string `json:"followedAt"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
2021-10-20 23:21:13 +02:00
|
|
|
// Followage returns the time since a given user followed a given streamer
|
2021-10-17 18:55:51 +02:00
|
|
|
func Followage(streamer string, username string) (string, error) {
|
2021-10-22 17:59:52 +02:00
|
|
|
baseUrl := "https://api.ivr.fi/twitch/subage"
|
2021-10-22 22:24:13 +02:00
|
|
|
|
2021-10-22 17:59:52 +02:00
|
|
|
resp, err := http.Get(fmt.Sprintf("%s/%s/%s", baseUrl, username, streamer))
|
2021-10-17 18:55:51 +02:00
|
|
|
if err != nil {
|
2021-10-17 19:31:54 +02:00
|
|
|
log.Error(err)
|
2021-10-17 18:55:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
2021-10-17 19:31:54 +02:00
|
|
|
log.Error(err)
|
2021-10-17 18:55:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var responseObject followageApiResponse
|
|
|
|
json.Unmarshal(body, &responseObject)
|
|
|
|
|
|
|
|
// User or channel was not found
|
|
|
|
if responseObject.Error != "" {
|
|
|
|
return fmt.Sprintf(responseObject.Error + " FeelsBadMan"), nil
|
|
|
|
} else if responseObject.FollowedAt == "" {
|
|
|
|
return fmt.Sprintf(username + " is not following " + streamer), nil
|
|
|
|
} else {
|
|
|
|
d := responseObject.FollowedAt[:10]
|
|
|
|
return fmt.Sprintf(username + " has been following " + streamer + " since " + d + "."), nil
|
|
|
|
}
|
|
|
|
}
|