Chatty: Replace usernames by Twitch IDs

This commit is contained in:
Fijxu 2024-10-15 18:50:17 -03:00
parent 61f6cf281b
commit 4aa51045eb
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
4 changed files with 28 additions and 16 deletions

View file

@ -7,6 +7,7 @@ class Config
property db : String = "./db.sqlite3"
property redisUrl : String = "127.0.0.1:6379"
property log_level : LogLevel = LogLevel::Debug
property key_expiration_time : Int32 = 60
def self.load
config_file = "./config.yml"

View file

@ -9,20 +9,31 @@ module Providers::Chatty
res
end
private def postprocessing(res) : Nil
private def postprocessing(res) : JSON::Any
users = 0
# Counts the chatty supporters
res.as_a.each do |item|
next if item["id"] != "chatty"
users += item["usernames"].size
end
wg = WaitGroup.new(users)
res.as_a.each_with_index do |item, index|
item["id"].as_a if item["id"] != "chatty"
puts item
next if item["id"] != "chatty"
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
spawn do
id = JSON::Any.new(Utils::GQL.new.get_user_id(username.to_s))
item["usernames"].as_a[index] = id
ensure
wg.done
end
end
end
pp res
# Waits for all the fibers to complete before returning res
wg.wait
return res
end
end

View file

@ -16,8 +16,7 @@ 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) }
Providers::Chatty.get_badges
# spawn { info[4].send(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 = {
@ -25,7 +24,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

View file

@ -17,6 +17,7 @@ Kemal.config.app_name = "vanity-tester-backend"
SQL = DB.open("sqlite3://#{CONFIG.db}")
REDIS_DB = Redis::Client.new(URI.parse("redis://#{CONFIG.redisUrl}"))
LOGGER = LogHandler.new(STDOUT, CONFIG.log_level)
REDIS_PREFIX = "vanity-tester-backend"
Utils.create_db
@ -33,7 +34,7 @@ get "/badges" do |env|
next data
end
data = Handlers.parse_badges(env)
Utils::Redis.save("badges", data, 300)
Utils::Redis.save("badges", data, CONFIG.key_expiration_time)
data
end
@ -42,7 +43,7 @@ get "/7tv/badges" do |env|
next data
end
data = Handlers.parse_7tv_badges(env)
Utils::Redis.save("7tvbadges", data, 300)
Utils::Redis.save("7tvbadges", data, CONFIG.key_expiration_time)
data
end
@ -51,7 +52,7 @@ get "/7tv/paints" do |env|
next data
end
data = Handlers.parse_7tv_paints(env)
Utils::Redis.save("7tvpaints", data, 300)
Utils::Redis.save("7tvpaints", data, CONFIG.key_expiration_time)
data
end