buh
This commit is contained in:
parent
2e1a851fe5
commit
61f6cf281b
7 changed files with 86 additions and 21 deletions
|
@ -10,11 +10,16 @@ module Handlers
|
|||
j.field "badges" do
|
||||
j.array do
|
||||
badges_tuple[:chatterino]["badges"]?.try &.as_a.each do |item|
|
||||
images = [item["image1"], item["image2"], item["image3"]]
|
||||
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 "urls" do
|
||||
j.array do
|
||||
images.each do |imageurl|
|
||||
j.string imageurl
|
||||
end
|
||||
end
|
||||
end
|
||||
j.field "users", item["users"]
|
||||
end
|
||||
end
|
||||
|
@ -79,16 +84,20 @@ module Handlers
|
|||
j.field "badges" do
|
||||
j.array do
|
||||
badges_tuple[:ffz]?.try &.["badges"]?.try &.as_a.each do |item|
|
||||
images = [item["urls"]["1"], item["urls"]["2"], item["urls"]["4"]]
|
||||
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 "urls" do
|
||||
j.array do
|
||||
images.each do |imageurl|
|
||||
j.string imageurl
|
||||
end
|
||||
end
|
||||
end
|
||||
j.field "users", badges_tuple[:ffz]["users"][item["id"].to_s]
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -102,7 +111,11 @@ module Handlers
|
|||
badges_tuple[:dankchat]?.try &.as_a.each do |item|
|
||||
j.object do
|
||||
j.field "name", item["type"]
|
||||
j.field "url", item["url"]
|
||||
j.field "urls" do
|
||||
j.array do
|
||||
j.string item["url"]
|
||||
end
|
||||
end
|
||||
j.field "users", item["users"]
|
||||
end
|
||||
end
|
||||
|
@ -118,12 +131,19 @@ module Handlers
|
|||
# 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"
|
||||
|
||||
images = [item["image_url"], item["image_url_2"], item["image_url_4"]]
|
||||
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"]?}"
|
||||
# Zonian pidio que lo eliminara
|
||||
# j.field "badgeUrl", item["meta_url"]?
|
||||
j.field "urls" do
|
||||
j.array do
|
||||
images.each do |imageurl|
|
||||
j.string imageurl
|
||||
end
|
||||
end
|
||||
end
|
||||
j.field "users", item["usernames"]?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,28 @@
|
|||
require "wait_group"
|
||||
|
||||
module Providers::Chatty
|
||||
extend self
|
||||
|
||||
def get_badges
|
||||
res = HTTP::Client.get("https://tduva.com/res/badges", headers: HEADERS)
|
||||
JSON.parse(res.body)
|
||||
res = postprocessing(JSON.parse(res.body))
|
||||
res
|
||||
end
|
||||
|
||||
private def postprocessing(res) : Nil
|
||||
res.as_a.each_with_index do |item, index|
|
||||
item["id"].as_a if item["id"] != "chatty"
|
||||
puts item
|
||||
item["usernames"].as_a.each_with_index do |username, index|
|
||||
item["usernames"].as_a.size.times do
|
||||
spawn do
|
||||
id = JSON::Any.new(Utils::GQL.new.get_user_id(username.to_s))
|
||||
puts "username: #{username}, id: #{id}"
|
||||
item["usernames"].as_a[index] = id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
pp res
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,8 +45,8 @@ module Providers::FFZ
|
|||
JSON.parse(res.body)
|
||||
end
|
||||
|
||||
# def get_channel(channel_id : String)
|
||||
# res = HTTP::Client.get("https://api.frankerfacez.com/v1/room/id/#{channel_id}", headers: HEADERS)
|
||||
# channel_data = JSON.parse(res.body)
|
||||
|
||||
def get_channel(channel_id : String)
|
||||
res = HTTP::Client.get("https://api.frankerfacez.com/v1/room/id/#{channel_id}", headers: HEADERS)
|
||||
JSON.parse(res.body)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,8 @@ module Providers
|
|||
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) }
|
||||
Providers::Chatty.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 = {
|
||||
|
@ -24,7 +25,7 @@ module Providers
|
|||
bttv: info[1].receive,
|
||||
ffz: info[2].receive,
|
||||
dankchat: info[3].receive,
|
||||
chatty: info[4].receive,
|
||||
# chatty: info[4].receive,
|
||||
# seventv: info[5].receive,
|
||||
}
|
||||
return items
|
||||
|
|
22
src/utils/gql.cr
Normal file
22
src/utils/gql.cr
Normal file
|
@ -0,0 +1,22 @@
|
|||
class Utils::GQL
|
||||
private def req(query)
|
||||
headers = HTTP::Headers{
|
||||
"Content-Type" => "application/json",
|
||||
"Client-Id" => "ue6666qo983tsx6so1t0vnawi233wa",
|
||||
}
|
||||
data = {"query" => query}
|
||||
response = HTTP::Client.post("https://gql.twitch.tv/gql", headers: headers, body: data.to_json)
|
||||
|
||||
if response.success?
|
||||
response.body
|
||||
else
|
||||
raise "GQL Twitch API returned #{response.status_code}: #{response.body}"
|
||||
end
|
||||
end
|
||||
|
||||
def get_user_id(username : String) : String | Nil
|
||||
query = %( query { user(login: "#{username}") { id } } )
|
||||
res = JSON.parse(req(query))
|
||||
return res["data"]["user"]["id"]?.try &.to_s
|
||||
end
|
||||
end
|
|
@ -2,11 +2,13 @@ module Utils
|
|||
extend self
|
||||
|
||||
def create_db
|
||||
# TODO: Check if the chatty table exists too!
|
||||
if !SQL.query_one "SELECT EXISTS (SELECT 1 FROM sqlite_schema WHERE type='table' AND name='seventv_ids')
|
||||
AND EXISTS (SELECT 1 FROM sqlite_schema WHERE type='table' AND name='seventv_ids');", as: Bool
|
||||
LOGGER.info "Creating sqlite3 database at '#{CONFIG.db}'"
|
||||
begin
|
||||
SQL.exec "CREATE TABLE IF NOT EXISTS seventv_ids (twitch_id text UNIQUE, seventv_id text UNIQUE, username text UNIQUE)"
|
||||
SQL.exec "CREATE TABLE IF NOT EXISTS seventv_ids (username text UNIQUE, twitch_id text UNIQUE, seventv_id text UNIQUE, )"
|
||||
SQL.exec "CREATE TABLE IF NOT EXISTS chatty_ids (username text UNIQUE, twitch_id text UNIQUE)"
|
||||
# SQL.exec "CREATE TABLE IF NOT EXISTS #{CONFIG.ipTableName} (ip text UNIQUE, count integer DEFAULT 0, date integer)"
|
||||
rescue ex
|
||||
LOGGER.fatal "#{ex.message}"
|
|
@ -7,7 +7,7 @@ require "http/client"
|
|||
require "./config"
|
||||
require "./handling"
|
||||
require "./logger"
|
||||
require "./utils"
|
||||
require "./utils/**"
|
||||
require "./providers/**"
|
||||
|
||||
CONFIG = Config.load
|
||||
|
|
Loading…
Reference in a new issue