0.0.999999

This commit is contained in:
Fijxu 2024-09-01 23:14:10 -04:00
parent a85b01621c
commit b734d5d6ef
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
7 changed files with 218 additions and 86 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Fijxu <fijxu@nadeko.net>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -22,59 +22,11 @@ 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
# badge_de.each do |badgename|
# j.object do
# j.field "name", badgename
# j.field "url", badgename
# end
# end
# end
# end
# end
# end
j.field "ffz" do
j.field "7tv" do
j.object do
j.field "badges" do
j.array do
badges_tuple[:ffz]["badges"]?.try &.as_a.each do |item|
j.object do
j.field "id", item["id"]
j.field "name", item["name"]
j.field "title", item["title"]
j.field "color", item["color"]
j.field "url1x", item["urls"]["1"]
j.field "url2x", item["urls"]["2"]
j.field "url4x", item["urls"]["4"]
j.field "users", badges_tuple[:ffz]["users"][item["id"].to_s]
# end
end
end
end
end
end
end
j.field "dankchat" do
j.object do
j.field "badges" do
j.array do
badges_tuple[:dankchat]?.try &.as_a.each do |item|
badges_tuple[:seventv]?.try &.as_a.each do |item|
j.object do
j.field "name", item["type"]
j.field "url", item["url"]
@ -82,24 +34,98 @@ module Handlers
end
end
end
j.field "paints" do
j.array do
badges_tuple[:seventv]?.try &.as_a.each do |item|
j.object do
j.field "name", item["type"]
j.field "url", item["url"]
j.field "users", item["users"]
end
end
end
end
end
end
end
j.field "chatty" do
j.object do
j.field "badges" do
j.array do
badges_tuple[:chatty]?.try &.as_a.each do |item|
# Chatty also returns the badges from FFZ, which is not needed since
# we already pull them directly from the api
next if item["id"] != "chatty"
j.object do
j.field "name", item["meta_title"]?
j.field "badgeUrl", item["meta_url"]?
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"]?
# 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
# badge_de.each do |badgename|
# j.object do
# j.field "name", badgename
# j.field "url", badgename
# end
# end
# end
# end
# end
# end
j.field "ffz" do
j.object do
j.field "badges" do
j.array do
badges_tuple[:ffz]["badges"]?.try &.as_a.each do |item|
j.object do
j.field "id", item["id"]
j.field "name", item["name"]
j.field "title", item["title"]
j.field "color", item["color"]
j.field "url1x", item["urls"]["1"]
j.field "url2x", item["urls"]["2"]
j.field "url4x", item["urls"]["4"]
j.field "users", badges_tuple[:ffz]["users"][item["id"].to_s]
# end
end
end
end
end
end
end
j.field "dankchat" do
j.object do
j.field "badges" do
j.array do
badges_tuple[:dankchat]?.try &.as_a.each do |item|
j.object do
j.field "name", item["type"]
j.field "url", item["url"]
j.field "users", item["users"]
end
end
end
end
end
end
j.field "chatty" do
j.object do
j.field "badges" do
j.array do
badges_tuple[:chatty]?.try &.as_a.each do |item|
# Chatty also returns the badges from FFZ, which is not needed since
# we already pull them directly from the api
next if item["id"] != "chatty"
j.object do
j.field "name", item["meta_title"]?
j.field "badgeUrl", item["meta_url"]?
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
end
end
@ -109,4 +135,15 @@ module Handlers
end
end
end
def parse_7tv_paints(env)
paints = Providers::SevenTV.get_all_paints
JSON.build do |j|
j.object do
j.field "paints", paints["data"]["cosmetics"]["paints"]
end
end
end
# MODULE END
end

View file

@ -1,11 +1,13 @@
module Providers::SevenTV
extend self
def get_user_id(user_id : String)
def get_seventv_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)
seventv_user_id = get_seventv_user_id(user_id)["user"]["id"]
query = %q(
query GetUserCosmetics($id: ObjectID!) {
user(id: $id) {
@ -18,28 +20,75 @@ query GetUserCosmetics($id: ObjectID!) {
}
__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
j.field "id", seventv_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)
response = HTTP::Client.post("https://7tv.io/v3/gql",
headers: HTTP::Headers{"Content-Type" => "application/json"},
body: data)
if response.success?
(response.body)
else
raise "7tv is retarded #{response.status_code}: #{response.body}"
if response.success?
response.body
else
raise "7tv is retarded: #{response.body}"
end
end
def get_all_paints
query = %q(
query GetCosmestics($list: [ObjectID!]) {
cosmetics(list: $list) {
paints {
id
kind
name
function
color
angle
shape
image_url
repeat
stops {
at
color
__typename
}
__typename
}
}
})
data = JSON.build do |j|
j.object do
j.field "operationName", "GetCosmestics"
# j.field "variables" do
# j.object do
# end
# end
j.field "query", query
end
end
response = HTTP::Client.post("https://7tv.io/v3/gql",
headers: HTTP::Headers{"Content-Type" => "application/json"},
body: data)
if response.success?
JSON.parse(response.body)
else
raise "7tv is retarded: #{response.body}"
end
end
def get_badges(user_id : String)
res = get_user_cosmetics(user_id)
JSON.parse(res)
end
end
end

View file

@ -10,21 +10,23 @@ module Providers
# bttv = Channel(JSON::Any).new
# dankchat = Channel(JSON::Any).new
# ffz = Channel(JSON::Any).new
info = [Channel(JSON::Any).new, Channel(JSON::Any).new, Channel(JSON::Any).new, Channel(JSON::Any).new, Channel(JSON::Any).new]
info = [Channel(JSON::Any).new, Channel(JSON::Any).new, Channel(JSON::Any).new, Channel(JSON::Any).new, Channel(JSON::Any).new, Channel(JSON::Any).new]
# Compile with -Dpreview_mt
spawn { info[0].send(Providers::Chatterino.get_badges) }
spawn { info[1].send(Providers::BTTV.get_badges) }
spawn { info[2].send(Providers::FFZ.get_badges) }
spawn { info[3].send(Providers::DankChat.get_badges) }
spawn { info[4].send(Providers::Chatty.get_badges) }
# spawn { info[5].send(Providers::SevenTV.get_badges) }
# items = {chatterino: info[0].receive, bttv: info.receive, ffz: ffz.receive, dankchat: dankchat.receive, chatty: chatty.receive}
items = {
chatterino: info[0].receive,
bttv: info[1].receive,
ffz: info[2].receive,
dankchat: info[3].receive,
chatty: info[4].receive,
bttv: info[1].receive,
# seventv: info[5].receive,
}
return items
end
end
end

View file

@ -0,0 +1,8 @@
module Providers::PurpleTV
extend self
def get_badges
res = HTTP::Client.get("", headers: HEADERS)
JSON.parse(res.body)
end
end

View file

@ -17,10 +17,20 @@ 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)
get "/badges" do |env|
Handlers.parse_badges(env)
end
get "/7tv" do |env|
Handlers.parse_badges(env)
end
get "/7tv/paints" do |env|
Handlers.parse_7tv_paints(env)
end
# get "/7tv/badges" do |env|
# Handlers.parse_7tv_badges(env)
# end
Providers::SevenTV.get_user_cosmetics("60ae872eac03cad60747208d")
Kemal.run