add even more shit shit

This commit is contained in:
Fijxu 2025-01-08 23:52:14 -03:00
parent db4c3881d9
commit 4c3b9a5b05
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
3 changed files with 229 additions and 118 deletions

View file

@ -10,8 +10,8 @@ func root(w http.ResponseWriter, r *http.Request) {
}
func getAllBadges(w http.ResponseWriter, r *http.Request) {
parseAllBadges()
io.WriteString(w, "test")
asd := parseAllBadges()
io.WriteString(w, asd)
}
// func sevenTvPaints(w http.ResponseWriter, r *http.Request) {

View file

@ -2,21 +2,80 @@ package main
import "encoding/json"
type Parser struct {
SevenTV string `json:"SevenTV"`
Bttv string `json:"BTTV"`
Ffz string `json:"FFZ"`
Chatterino string `json:"Chatterino"`
Chatty string `json:"Chatty"`
Homies string `json:"Homies"`
Ptv string `json:"PurpleTV"`
type _Chatterino struct {
Badges []struct {
Name string `json:"name"`
Url string `json:"url"`
Users []string `json:"users"`
} `json:"badges"`
}
func parseAllBadges() {
stv := &SevenTv{}
stv.getBadges()
json, _ := json.Marshal(stv.Badges)
logger.Trace().Msg(string(json))
type _FrankerFz struct {
Badges []struct {
Name string `json:"name"`
Url string `json:"url"`
Users []string `json:"users"`
} `json:"badges"`
}
type _SevenTv struct {
Badges []struct {
Name string `json:"name"`
Url string `json:"url"`
Users []string `json:"users"`
} `json:"badges"`
Paints []struct {
}
}
type Format struct {
Chatterino _Chatterino `json:"chatterino"`
SevenTv _SevenTv `json:"7tv"`
Ffz _FrankerFz `json:"ffz"`
}
func parseChatterino(format *Format) {
chatterino := &Chatterino{}
chatterino.getBadges()
for _, badge := range chatterino.Badges {
format.Chatterino.Badges = append(format.Chatterino.Badges, struct {
Name string `json:"name"`
Url string `json:"url"`
Users []string `json:"users"`
}{
Name: badge.Tooltip,
Url: badge.Image3,
Users: badge.Users,
})
}
}
func parseSevenTv(format *Format) {
sevenTv := &Chatterino{}
sevenTv.getBadges()
for _, badge := range sevenTv.Badges {
format.Chatterino.Badges = append(format.Chatterino.Badges, struct {
Name string `json:"name"`
Url string `json:"url"`
Users []string `json:"users"`
}{
Name: badge.Tooltip,
Url: badge.Image3,
Users: badge.Users,
})
}
}
func parseAllBadges() string {
format := &Format{}
parseChatterino(format)
json, _ := json.Marshal(format)
return string(json)
// bttv := &Bttv{}
// ffz := &FrankerFz{}
// chatterino := &Chatterino{}

View file

@ -18,6 +18,7 @@ type GqlQuery struct {
type SevenTv struct {
Query GqlQuery `json:"query"`
UserID string
Badges struct {
Data struct {
Cosmetics struct {
@ -35,11 +36,41 @@ type SevenTv struct {
} `json:"sevenTvBadges"`
}
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"`
}
type Bttv struct{}
type FrankerFz struct{}
type Chatterino struct{}
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"`
}
type Chatty struct{}
type DankChat struct{}
type DankChat struct {
Type string `json:"type"`
URL string `json:"url"`
Users []string `json:"users"`
}
type Homies struct{}
type PurpleTV struct{}
@ -75,9 +106,9 @@ func doPostRequest(url string, data []byte) []byte {
return body
}
func (s *SevenTv) getUserID(userId string) []byte {
func (s *SevenTv) getUserID(userId string) (string, error) {
req := doGetRequest("https://7tv.io/v3/users/twitch/" + userId)
return req
return string(req), nil
}
func (s *SevenTv) getBadges() *SevenTv {
@ -101,16 +132,15 @@ func (s *SevenTv) getBadges() *SevenTv {
Query: query,
}
data, _ := json.Marshal(s.Query)
// if err != nil {
// return "", err
// }
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))
logger.Info().Msg(string(res))
err := json.Unmarshal(res, &s.Badges)
err = json.Unmarshal(res, &s.Badges)
if err != nil {
logger.Error().Msg(err.Error())
}
@ -118,106 +148,128 @@ func (s *SevenTv) getBadges() *SevenTv {
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
// }
// }
// }`
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,
// }
s.Query = GqlQuery{
OperationName: "GetCosmestics",
Query: query,
}
// data, err := json.Marshal(s.Query)
// if err != nil {
// return "", err
// }
// logger.Trace().Msg(string(data))
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 res, nil
// }
res := doPostRequest("https://7tv.io/v3/gql", data)
return string(res), nil
}
// func (s *SevenTv) getUserCosmetics(userId string) (string, error) {
// query := `
// query GetUserCosmetics($id: ObjectID!) {
// user(id: $id) {
// id
// cosmetics {
// id
// kind
// selected
// __typename
// }
// __typename
// }
// }`
// 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,
// }
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))
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 res, nil
// }
res := doPostRequest("https://7tv.io/v3/gql", data)
return string(res), nil
}
// func (s *Bttv) getBadges() string {
// req := doGetRequest("https://api.betterttv.net/3/cached/badges/twitch")
// return req
// }
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
}
// func (s *FrankerFz) getBadges() string {
// req := doGetRequest("https://api.frankerfacez.com/v1/badges/ids")
// return req
// }
func (s *Bttv) getBadges() *Bttv {
res := doGetRequest("https://api.betterttv.net/3/cached/badges/twitch")
err := json.Unmarshal(res, &s)
if err != nil {
logger.Error().Msg(err.Error())
}
return s
}
// func (s *Chatty) getBadges() string {
// req := doGetRequest("https://api.betterttv.net/3/cached/badges/twitch")
// return req
// }
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
}
// func (s *DankChat) getBadges() string {
// req := doGetRequest("https://flxrs.com/api/badges")
// return req
// }
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())
}
return s
}
// func (s *Chatterino) getBadges() string {
// req := doGetRequest("https://api.chatterino.com/badges")
// return req
// }
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
}