2025-01-07 23:42:16 -03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-01-08 20:16:19 -03:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
2025-01-07 23:42:16 -03:00
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
type Variables struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
}
|
|
|
|
type GqlQuery struct {
|
|
|
|
OperationName string `json:"operationName"`
|
|
|
|
Variables Variables `json:"variables"`
|
|
|
|
Query string `json:"query"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SevenTv struct {
|
|
|
|
Query GqlQuery `json:"query"`
|
2025-01-08 23:52:14 -03:00
|
|
|
UserID string
|
2025-01-08 20:16:19 -03:00
|
|
|
Badges struct {
|
|
|
|
Data struct {
|
|
|
|
Cosmetics struct {
|
|
|
|
Badges []struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Kind string `json:"kind"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Tooltip string `json:"tooltip"`
|
|
|
|
Tag string `json:"tag"`
|
|
|
|
Typename string `json:"__typename"`
|
|
|
|
}
|
|
|
|
Typename string `json:"__typename"`
|
|
|
|
} `json:"cosmetics"`
|
|
|
|
} `json:"data"`
|
|
|
|
} `json:"sevenTvBadges"`
|
|
|
|
}
|
|
|
|
|
2025-01-08 23:52:14 -03:00
|
|
|
type Chatterino struct {
|
|
|
|
Badges []struct {
|
|
|
|
Tooltip string `json:"tooltip"`
|
|
|
|
Image1 string `json:"image1"`
|
|
|
|
Image2 string `json:"image2"`
|
|
|
|
Image3 string `json:"image3"`
|
|
|
|
Users []string `json:"users"`
|
|
|
|
} `json:"badges"`
|
|
|
|
}
|
|
|
|
|
2025-01-07 23:42:16 -03:00
|
|
|
type Bttv struct{}
|
2025-01-08 23:52:14 -03:00
|
|
|
|
|
|
|
type FrankerFz struct {
|
|
|
|
Badge struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Slot int64 `json:"slot"`
|
|
|
|
Replaces *string `json:"replaces"`
|
|
|
|
Color string `json:"color"`
|
|
|
|
Image string `json:"image"`
|
|
|
|
Urls map[string]string `json:"urls"`
|
|
|
|
CSS interface{} `json:"css"`
|
|
|
|
} `json:"badges"`
|
|
|
|
Users map[string][]int64 `json:"users"`
|
|
|
|
}
|
|
|
|
|
2025-01-07 23:42:16 -03:00
|
|
|
type Chatty struct{}
|
2025-01-08 23:52:14 -03:00
|
|
|
|
|
|
|
type DankChat struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
Users []string `json:"users"`
|
|
|
|
}
|
|
|
|
|
2025-01-07 23:42:16 -03:00
|
|
|
type Homies struct{}
|
|
|
|
type PurpleTV struct{}
|
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
func doGetRequest(url string) []byte {
|
|
|
|
request, err := http.NewRequest("GET", url, nil)
|
2025-01-07 23:42:16 -03:00
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
2025-01-08 20:16:19 -03:00
|
|
|
res, err := client.Do(request)
|
2025-01-07 23:42:16 -03:00
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
return body
|
2025-01-07 23:42:16 -03:00
|
|
|
}
|
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
func doPostRequest(url string, data []byte) []byte {
|
|
|
|
request, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
res, err := client.Do(request)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
2025-01-07 23:42:16 -03:00
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
body, err := io.ReadAll(res.Body)
|
2025-01-07 23:42:16 -03:00
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
return body
|
2025-01-07 23:42:16 -03:00
|
|
|
}
|
|
|
|
|
2025-01-08 23:52:14 -03:00
|
|
|
func (s *SevenTv) getUserID(userId string) (string, error) {
|
2025-01-08 20:16:19 -03:00
|
|
|
req := doGetRequest("https://7tv.io/v3/users/twitch/" + userId)
|
2025-01-08 23:52:14 -03:00
|
|
|
return string(req), nil
|
2025-01-07 23:42:16 -03:00
|
|
|
}
|
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
func (s *SevenTv) getBadges() *SevenTv {
|
|
|
|
query := `
|
|
|
|
query GetCosmestics($list: [ObjectID!]) {
|
|
|
|
cosmetics(list: $list) {
|
|
|
|
badges {
|
|
|
|
id
|
|
|
|
kind
|
|
|
|
name
|
|
|
|
tooltip
|
|
|
|
tag
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
}`
|
2025-01-07 23:42:16 -03:00
|
|
|
|
2025-01-08 20:16:19 -03:00
|
|
|
s.Query = GqlQuery{
|
|
|
|
OperationName: "GetCosmestics",
|
|
|
|
Query: query,
|
|
|
|
}
|
|
|
|
|
2025-01-08 23:52:14 -03:00
|
|
|
data, err := json.Marshal(s.Query)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
res := doPostRequest("https://7tv.io/v3/gql", data)
|
|
|
|
logger.Trace().Msg(string(res))
|
|
|
|
|
|
|
|
err = json.Unmarshal(res, &s.Badges)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SevenTv) getPaints() (string, error) {
|
|
|
|
query := `
|
|
|
|
query GetCosmestics($list: [ObjectID!]) {
|
|
|
|
cosmetics(list: $list) {
|
|
|
|
paints {
|
|
|
|
id
|
|
|
|
kind
|
|
|
|
name
|
|
|
|
function
|
|
|
|
color
|
|
|
|
angle
|
|
|
|
shape
|
|
|
|
image_url
|
|
|
|
repeat
|
|
|
|
stops {
|
|
|
|
at
|
|
|
|
color
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
shadows {
|
|
|
|
x_offset
|
|
|
|
y_offset
|
|
|
|
radius
|
|
|
|
color
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
|
|
|
s.Query = GqlQuery{
|
|
|
|
OperationName: "GetCosmestics",
|
|
|
|
Query: query,
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(s.Query)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
logger.Trace().Msg(string(data))
|
|
|
|
|
|
|
|
res := doPostRequest("https://7tv.io/v3/gql", data)
|
|
|
|
return string(res), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the costmetrics that a user has.
|
|
|
|
// userId, needs to be a 7TV ULID, call getUserID first.
|
|
|
|
func (s *SevenTv) getUserCosmetics(userId string) (string, error) {
|
|
|
|
query := `
|
|
|
|
query GetUserCosmetics($id: ObjectID!) {
|
|
|
|
user(id: $id) {
|
|
|
|
id
|
|
|
|
cosmetics {
|
|
|
|
id
|
|
|
|
kind
|
|
|
|
selected
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
|
|
|
s.Query = GqlQuery{
|
|
|
|
OperationName: "GetUserCosmetics",
|
|
|
|
Variables: Variables{
|
|
|
|
ID: userId,
|
|
|
|
},
|
|
|
|
Query: query,
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(s.Query)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
logger.Trace().Msg(string(data))
|
2025-01-08 20:16:19 -03:00
|
|
|
|
|
|
|
res := doPostRequest("https://7tv.io/v3/gql", data)
|
2025-01-08 23:52:14 -03:00
|
|
|
return string(res), nil
|
|
|
|
}
|
2025-01-08 20:16:19 -03:00
|
|
|
|
2025-01-08 23:52:14 -03:00
|
|
|
func (s *Chatterino) getBadges() *Chatterino {
|
|
|
|
res := doGetRequest("https://api.chatterino.com/badges")
|
|
|
|
err := json.Unmarshal(res, &s)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
2025-01-08 20:16:19 -03:00
|
|
|
|
2025-01-08 23:52:14 -03:00
|
|
|
func (s *Bttv) getBadges() *Bttv {
|
|
|
|
res := doGetRequest("https://api.betterttv.net/3/cached/badges/twitch")
|
|
|
|
err := json.Unmarshal(res, &s)
|
2025-01-08 20:16:19 -03:00
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
2025-01-08 23:52:14 -03:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FrankerFz) getBadges() *FrankerFz {
|
|
|
|
res := doGetRequest("https://api.frankerfacez.com/v1/badges/ids")
|
|
|
|
err := json.Unmarshal(res, &s)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
2025-01-08 20:16:19 -03:00
|
|
|
|
2025-01-08 23:52:14 -03:00
|
|
|
func (s *Chatty) getBadges() *Chatty {
|
|
|
|
res := doGetRequest("https://tduva.com/res/badges")
|
|
|
|
err := json.Unmarshal(res, &s)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
2025-01-08 20:16:19 -03:00
|
|
|
return s
|
2025-01-07 23:42:16 -03:00
|
|
|
}
|
2025-01-08 20:16:19 -03:00
|
|
|
|
2025-01-08 23:52:14 -03:00
|
|
|
func (s *DankChat) getBadges() *DankChat {
|
|
|
|
res := doGetRequest("https://flxrs.com/api/badges")
|
|
|
|
err := json.Unmarshal(res, &s)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error().Msg(err.Error())
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|