diff --git a/src/handling.cr b/src/handling.cr index d0e5c06..f0a9db3 100644 --- a/src/handling.cr +++ b/src/handling.cr @@ -8,12 +8,92 @@ module Handlers j.field "chatterino" do j.object do j.field "badges" do - j.object do - j.field "name", badges_tuple[:chatterino]["badges"][0]["tooltip"] - # j.field "url1x", badges_tuple[:chatterino]. - # j.field "url2x", badges_tuple[:chatterino]. - # j.field "url3x", badges_tuple[:chatterino]. - # j.field "users", badges_tuple[:chatterino]. + j.array do + badges_tuple[:chatterino]["badges"]?.try &.as_a.each do |item| + j.object do + j.field "name", item["tooltip"] + j.field "url1x", item["image1"] + j.field "url2x", item["image2"] + j.field "url3x", item["image3"] + j.field "users", item["users"] + end + end + end + end + end + end + # j.field "bttv" do + # j.object do + # j.field "badges" do + # j.array do + # badges_tuple[:bttv]?.try &.as_a.each do |item| + # 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"] + # 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", item["image_url"]? + j.field "url2x", item["image_url_2"]? + j.field "url4x", item["image_url_4"]? + j.field "users", item["usernames"]? + end + end end end end diff --git a/src/providers/main.cr b/src/providers/main.cr index 7fb8aa9..11d7e8e 100644 --- a/src/providers/main.cr +++ b/src/providers/main.cr @@ -10,15 +10,20 @@ 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] # Compile with -Dpreview_mt spawn { info[0].send(Providers::Chatterino.get_badges) } - # spawn { info[1].send(Providers::Chatty.get_badges) } - # spawn { info[2].send(Providers::BTTV.get_badges) } - # spawn { info[3].send(Providers::DankChat.get_badges) } - # spawn { info[4].send(Providers::FFZ.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) } # items = {chatterino: info[0].receive, bttv: info.receive, ffz: ffz.receive, dankchat: dankchat.receive, chatty: chatty.receive} - items = {chatterino: info[0].receive} + items = { + chatterino: info[0].receive, + ffz: info[2].receive, + dankchat: info[3].receive, + chatty: info[4].receive, + } return items end end