Spaghetti code do not look

This commit is contained in:
Fijxu 2024-05-18 22:29:36 -04:00
parent 7bd38e0a24
commit 00640f3ab6
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
4 changed files with 154 additions and 101 deletions

View file

@ -15,15 +15,45 @@ require "../twitchapi/*"
module Users module Users
def self.checkBanned(gql) def self.checkBanned(gql)
puts "tst2" # puts "checkBanned: #{gql}"
pp gql["userResultByLogin"] # puts (typeof(gql))
pp gql["userResultByID"] # if gql["userResultByLogin"]
if gql["userResultByLogin"].nil? # return false
return nil # if gql["userResultByLogin"]["result"]?
elsif gql["userResultByID"].nil? # return true
return nil # else
else # return false
# end
# elsif gql["userResultByID"]?
# return false
# if gql["userResultByID"]["reason"]?
# return true
# else
# return false
# end
# else
# return true
# end
# if gql["userResultByLogin"]["reason"]?
# return true
# elsif gql["userResultByID"]["reason"]?
# return true
# else
# return false
# end
# return false
if GqlAPI.urb().includes? "login"
if gql["userResultByLogin"]["reason"]?
return true return true
else
return false
end
elsif GqlAPI.urb().includes? "id"
if gql["userResultByID"]["reason"]?
return true
else
return false
end
end end
end end
@ -54,11 +84,14 @@ module Users
gql = GqlAPI.query(params) gql = GqlAPI.query(params)
panels = gql["user"]["panels"] panels = gql["user"]["panels"]
banned = checkBanned(gql) banned = checkBanned(gql)
pp gql # puts banned
# puts ("urb #{GqlAPI.urb()}")
# pp gql
json_data = [ json_data = [
{ {
# "banned" => banned, # TODO: FIX BANNED "banned" => banned,
"reason" => nil,
"displayName" => gql["user"]["displayName"], "displayName" => gql["user"]["displayName"],
"login" => gql["user"]["login"], "login" => gql["user"]["login"],
"id" => gql["user"]["id"], "id" => gql["user"]["id"],

View file

@ -38,4 +38,3 @@ class Config
return config return config
end end
end end

View file

@ -8,6 +8,11 @@ module GqlAPI
"Authorization" => "OAuth #{CONFIG.gqlOAuth}", "Authorization" => "OAuth #{CONFIG.gqlOAuth}",
"Client-Id" => "#{CONFIG.gqlClientID}", "Client-Id" => "#{CONFIG.gqlClientID}",
} }
@@urb : String = "fuck"
def self.urb
return @@urb
end
def self.userResultBy(params) def self.userResultBy(params)
if params.has_key?("id") if params.has_key?("id")
@ -17,6 +22,14 @@ module GqlAPI
end end
end end
def self.loginOrID(params)
if params.has_key?("id")
return %(userResultByID(id: "#{params["id"]}")), %(user(id: "#{params["id"]}" lookupType: ALL))
else
return %(userResultByLogin(login: "#{params["login"]}")), %(user(login: "#{params["login"]}" lookupType: ALL))
end
end
# def self.channel (params) # def self.channel (params)
# if params.has_key?("id") # if params.has_key?("id")
# return %(channel(id: "#{params["id"]}")) # return %(channel(id: "#{params["id"]}"))
@ -34,7 +47,7 @@ module GqlAPI
end end
def self.query(params) def self.query(params)
puts params # puts params
# id = params["id"] # id = params["id"]
# data = { "query" => "{user(id:#{id}){ # data = { "query" => "{user(id:#{id}){
@ -54,9 +67,10 @@ module GqlAPI
# stream{averageFPS,bitrate,codec,createdAt,width,height,id,viewersCount,type,game{displayName}}, # stream{averageFPS,bitrate,codec,createdAt,width,height,id,viewersCount,type,game{displayName}},
# lastBroadcast{game{displayName},id,startedAt,title} # lastBroadcast{game{displayName},id,startedAt,title}
# }}" } # }}" }
@@urb = userResultBy(params)
query = %( query = %(
query { query {
#{userResultBy(params)} { #{@@urb} {
... on UserDoesNotExist { ... on UserDoesNotExist {
key key
reason reason
@ -143,7 +157,12 @@ module GqlAPI
} }
} }
) )
return JSON.parse(gqlReq(params, query))["data"] # puts JSON.parse(gqlReqq)["data"]
# puts ("gqlReq JSON.parse typeof: #{typeof (gqlReqq)}")
# puts ("gqlReq JSON.parse typeof: #{typeof(JSON.parse(gqlReq(params, query))["data"])}")
# puts ("gqlReq JSON.parse.to-H typeof: #{typeof (gqlReqq.to_h)}")
# puts ((JSON.parse(gqlReq(params, query)))["data"])["userResultByID"]["reason"]?
return (JSON.parse(gqlReq(params, query)))["data"]
end end
# def self.isBanned(id : String) # def self.isBanned(id : String)
@ -167,9 +186,11 @@ module GqlAPI
def self.gqlReq(params, query) def self.gqlReq(params, query)
data = {"query" => query} data = {"query" => query}
# puts (typeof(data))
response = HTTP::Client.post(CONFIG.gqlEndpoint.to_s, headers: @@headers, body: data.to_json) response = HTTP::Client.post(CONFIG.gqlEndpoint.to_s, headers: @@headers, body: data.to_json)
if response.success? if response.success?
# puts (typeof(response.body))
return (response.body) return (response.body)
else else
raise "GQL Twitch API returned #{response.status_code}: #{response.body.to_s}" raise "GQL Twitch API returned #{response.status_code}: #{response.body.to_s}"