0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 05:02:58 -05:00
safetwitch-backend/extractor/twitch/Badges.go

66 lines
1.5 KiB
Go

package twitch
import (
"safetwitch-backend/extractor/structs"
"github.com/tidwall/gjson"
)
func GetTwitchBadges() ([]structs.Badge, error) {
payload := []TwitchPayload{
{
"operationName": "ChannelPointsPredictionBadges",
"variables": map[string]interface{}{},
"extensions": map[string]interface{}{
"persistedQuery": map[string]interface{}{
"sha256Hash": "36995b30b22c31d1cd0aa329987ac9b5368bb7e6e1ab1df42808bdaa80a6dbf9",
"version": 1,
},
},
},
}
_, body, err := parseResponse(payload)
if err != nil {
return []structs.Badge{}, err
}
rawBadges := gjson.Get(string(body), "0.data.badges")
formattedBadges, err := ParseBadges(rawBadges)
if err != nil {
return []structs.Badge{}, err
}
return formattedBadges, nil
}
func GetStreamerBadges(streamerName string) ([]structs.Badge, error) {
payload := []TwitchPayload{
{
"extensions": map[string]interface{}{
"persistedQuery": map[string]interface{}{
"sha256Hash": "86f43113c04606e6476e39dcd432dee47c994d77a83e54b732e11d4935f0cd08",
"version": 1,
},
},
"operationName": "ChatList_Badges",
"variables": map[string]interface{}{
"channelLogin": streamerName,
},
},
}
_, body, err := parseResponse(payload)
if err != nil {
return []structs.Badge{}, err
}
rawBadges := gjson.Get(string(body), "0.data.user.broadcastBadges")
formattedBadges, err := ParseBadges(rawBadges)
if err != nil {
return []structs.Badge{}, err
}
return formattedBadges, nil
}