2021-10-18 20:33:51 +02:00
|
|
|
package ivr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2021-10-19 15:33:23 +02:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2021-10-18 20:33:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// https://api.ivr.fi
|
|
|
|
type uidApiResponse struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
2021-10-20 23:21:13 +02:00
|
|
|
// Userid returns the userID of a given user
|
2021-10-18 20:33:51 +02:00
|
|
|
func Userid(username string) string {
|
2021-10-22 17:59:52 +02:00
|
|
|
baseUrl := "https://api.ivr.fi/twitch/resolve"
|
|
|
|
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s/%s", baseUrl, username))
|
2021-10-18 20:33:51 +02:00
|
|
|
if err != nil {
|
2021-10-19 15:33:23 +02:00
|
|
|
log.Error(err)
|
2021-10-18 20:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
2021-10-19 15:33:23 +02:00
|
|
|
log.Error(err)
|
2021-10-18 20:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var responseObject uidApiResponse
|
|
|
|
json.Unmarshal(body, &responseObject)
|
|
|
|
|
|
|
|
// User not found
|
|
|
|
if responseObject.Error != "" {
|
|
|
|
return fmt.Sprintf(responseObject.Error + " FeelsBadMan")
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf(responseObject.Id)
|
|
|
|
}
|
|
|
|
}
|