0.0.999999
This commit is contained in:
parent
a85b01621c
commit
b734d5d6ef
7 changed files with 218 additions and 86 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
/docs/
|
||||
/lib/
|
||||
/bin/
|
||||
/.shards/
|
||||
*.dwarf
|
21
LICENSE
Normal file
21
LICENSE
Normal 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.
|
|
@ -22,6 +22,31 @@ module Handlers
|
|||
end
|
||||
end
|
||||
end
|
||||
j.field "7tv" do
|
||||
j.object do
|
||||
j.field "badges" 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
|
||||
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
|
||||
# badge_id = [] of String
|
||||
# badge_de = [] of String
|
||||
# badge_im = [] of String
|
||||
|
@ -109,4 +134,16 @@ module Handlers
|
|||
end
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
response.body
|
||||
else
|
||||
raise "7tv is retarded #{response.status_code}: #{response.body}"
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
8
src/providers/purpletv.cr
Normal file
8
src/providers/purpletv.cr
Normal 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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue