From a85b01621c4ea9e0a2c0adb75528d148af098895 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Wed, 28 Aug 2024 13:55:48 -0400 Subject: [PATCH] 0.0.0.99 --- src/handling.cr | 30 ++++++++++++++++--------- src/providers/7tv.cr | 43 ++++++++++++++++++++++++++++++++++++ src/providers/main.cr | 3 ++- src/vanity-tester-backend.cr | 8 ++++--- 4 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/handling.cr b/src/handling.cr index f0a9db3..6f51ffb 100644 --- a/src/handling.cr +++ b/src/handling.cr @@ -22,19 +22,27 @@ module Handlers end end end + # badge_id = [] of String + # badge_de = [] of String + # badge_im = [] of String + # badges_tuple[:bttv]?.try &.as_a.each do |item| + # if !badge_id.includes?(item["badge"]["type"]) + # badge_id << item["badge"]["type"].to_s + # badge_de << item["badge"]["description"].to_s + # badge_im << item["badge"]["svg"].to_s + # end + # end + # pp badge_id + # pp badge_de + # pp badge_im # j.field "bttv" do # j.object do # j.field "badges" do # j.array do - # badges_tuple[:bttv]?.try &.as_a.each do |item| + # badge_de.each do |badgename| # j.object do - # j.field "id", item["id"] - # j.field "name", item["name"] - # j.field "displayName", item["displayName"] - # j.field "providerId", item["providerId"] - # j.field "svg", item["badge"]["svg"] - # j.field "svg", item["badge"]["svg"] - # j.field "svg", item["badge"]["svg"] + # j.field "name", badgename + # j.field "url", badgename # end # end # end @@ -88,9 +96,9 @@ module Handlers j.object do j.field "name", item["meta_title"]? j.field "badgeUrl", item["meta_url"]? - j.field "url1x", item["image_url"]? - j.field "url2x", item["image_url_2"]? - j.field "url4x", item["image_url_4"]? + j.field "url1x", "https:#{item["image_url"]?}" + j.field "url2x", "https:#{item["image_url_2"]?}" + j.field "url4x", "https:#{item["image_url_4"]?}" j.field "users", item["usernames"]? end end diff --git a/src/providers/7tv.cr b/src/providers/7tv.cr index 8e3a3bf..aefdda4 100644 --- a/src/providers/7tv.cr +++ b/src/providers/7tv.cr @@ -1,2 +1,45 @@ module Providers::SevenTV + extend self + def get_user_id(user_id : String) + res = HTTP::Client.get("https://7tv.io/v3/users/twitch/#{user_id}", headers: HEADERS) + JSON.parse(res.body) + end + + def get_user_cosmetics(user_id : String) + query = %q( +query GetUserCosmetics($id: ObjectID!) { + user(id: $id) { + id + cosmetics { + id + kind + selected + __typename + } + __typename + } +} + ) + data = JSON.build do |j| + j.object do + j.field "operationName", "GetUserCosmetics" + j.field "variables" do + j.object do + j.field "id", user_id + end + end + j.field "query", query + end + end + headers = HTTP::Headers{ + "Content-Type" => "application/json", + } + response = HTTP::Client.post("https://7tv.io/v3/gql", headers: headers, body: data) + + if response.success? + (response.body) + else + raise "7tv is retarded #{response.status_code}: #{response.body}" + end +end end diff --git a/src/providers/main.cr b/src/providers/main.cr index 11d7e8e..d72925e 100644 --- a/src/providers/main.cr +++ b/src/providers/main.cr @@ -23,7 +23,8 @@ module Providers ffz: info[2].receive, dankchat: info[3].receive, chatty: info[4].receive, + bttv: info[1].receive, } return items - end +end end diff --git a/src/vanity-tester-backend.cr b/src/vanity-tester-backend.cr index 0c4c33f..52b75f3 100644 --- a/src/vanity-tester-backend.cr +++ b/src/vanity-tester-backend.cr @@ -17,8 +17,10 @@ REDIS_DB = Redis::Client.new(CONFIG.redisUrl) HEADERS = HTTP::Headers{"User-Agent" => "Vanity-Tester-Backend/0.1.0"} -get "/badges" do |env| - Handlers.parse_badges(env) -end +# get "/badges" do |env| +# Handlers.parse_badges(env) +# end + +Providers::SevenTV.get_user_cosmetics("60ae872eac03cad60747208d") Kemal.run