2023-10-10 19:07:49 +02:00
|
|
|
package ivr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2024-02-15 21:58:57 +01:00
|
|
|
type ivrResponse struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Stream ivrStream `json:"stream"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ivrStream struct {
|
|
|
|
Title string `json:"title"`
|
|
|
|
Game ivrGame `json:"game"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ivrGame struct {
|
|
|
|
DisplayName string `json:"displayName"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func TitleByUsername(login string) string {
|
|
|
|
baseUrl := "https://api.ivr.fi/v2/twitch/user?login="
|
|
|
|
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, login))
|
|
|
|
if err != nil {
|
|
|
|
return "xd"
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
responseList := make([]ivrResponse, 0)
|
|
|
|
_ = json.NewDecoder(resp.Body).Decode(&responseList)
|
|
|
|
if len(responseList) == 0 {
|
|
|
|
return "xd"
|
|
|
|
}
|
|
|
|
|
|
|
|
return responseList[0].Stream.Title
|
|
|
|
}
|
|
|
|
|
|
|
|
func GameByUsername(login string) string {
|
|
|
|
baseUrl := "https://api.ivr.fi/v2/twitch/user?login="
|
|
|
|
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, login))
|
|
|
|
if err != nil {
|
|
|
|
return "xd"
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
responseList := make([]ivrResponse, 0)
|
|
|
|
_ = json.NewDecoder(resp.Body).Decode(&responseList)
|
|
|
|
if len(responseList) == 0 {
|
|
|
|
return "xd"
|
|
|
|
}
|
|
|
|
|
|
|
|
return responseList[0].Stream.Game.DisplayName
|
2023-10-10 19:07:49 +02:00
|
|
|
}
|
|
|
|
|
2023-12-20 02:18:57 +01:00
|
|
|
func IDByUsernameReply(username string) string {
|
2023-10-10 19:07:49 +02:00
|
|
|
baseUrl := "https://api.ivr.fi/v2/twitch/user?login="
|
|
|
|
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, username))
|
|
|
|
if err != nil {
|
|
|
|
return "xd"
|
|
|
|
}
|
|
|
|
|
2024-02-15 21:58:57 +01:00
|
|
|
responseList := make([]ivrResponse, 0)
|
2024-02-14 21:57:58 +01:00
|
|
|
err = json.NewDecoder(resp.Body).Decode(&responseList)
|
|
|
|
if len(responseList) == 0 {
|
|
|
|
return "xd"
|
|
|
|
}
|
2023-10-10 19:07:49 +02:00
|
|
|
|
2023-12-17 22:12:48 +01:00
|
|
|
reply := fmt.Sprintf("%s=%s", username, responseList[0].ID)
|
|
|
|
return reply
|
2023-10-10 19:07:49 +02:00
|
|
|
}
|
2023-12-20 02:18:57 +01:00
|
|
|
|
|
|
|
func IDByUsername(username string) string {
|
|
|
|
baseUrl := "https://api.ivr.fi/v2/twitch/user?login="
|
|
|
|
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s%s", baseUrl, username))
|
|
|
|
if err != nil {
|
|
|
|
return "xd"
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2024-02-15 21:58:57 +01:00
|
|
|
responseList := make([]ivrResponse, 0)
|
2023-12-20 02:18:57 +01:00
|
|
|
_ = json.NewDecoder(resp.Body).Decode(&responseList)
|
2024-02-14 21:57:58 +01:00
|
|
|
if len(responseList) == 0 {
|
|
|
|
return "xd"
|
|
|
|
}
|
2023-12-20 02:18:57 +01:00
|
|
|
|
|
|
|
return responseList[0].ID
|
|
|
|
}
|