Fetches summons, characters and weapons

This commit is contained in:
Justin Edmund 2025-03-06 14:44:01 -08:00
parent 3fe2378b32
commit 0d2f1f2a31

View file

@ -62,6 +62,65 @@ class Dataminer
character_id: granblue_id character_id: granblue_id
} }
response = fetch_detail(url, body)
update_game_data('Character', granblue_id, response) if response
response
end
def fetch_weapon(granblue_id)
timestamp = Time.now.to_i * 1000
url = "/archive/weapon_detail?_=#{timestamp}&t=#{timestamp}&uid=#{BOT_UID}"
body = {
special_token: nil,
user_id: BOT_UID,
kind_name: '0',
attribute: '0',
event_id: nil,
story_id: nil,
weapon_id: granblue_id
}
response = fetch_detail(url, body)
update_game_data('Weapon', granblue_id, response) if response
response
end
def fetch_summon(granblue_id)
timestamp = Time.now.to_i * 1000
url = "/archive/summon_detail?_=#{timestamp}&t=#{timestamp}&uid=#{BOT_UID}"
body = {
special_token: nil,
user_id: BOT_UID,
kind_name: '0',
attribute: '0',
event_id: nil,
story_id: nil,
summon_id: granblue_id
}
response = fetch_detail(url, body)
update_game_data('Summon', granblue_id, response) if response
response
end
private
def format_cookies
cookies.map { |k, v| "#{k}=#{v}" }.join('; ')
end
def auth_failed?(response)
return true if response.code != 200
begin
parsed = JSON.parse(response.body)
parsed.is_a?(Hash) && parsed['auth_status'] == 'require_auth'
rescue JSON::ParserError
true
end
end
def fetch_detail(url, body)
puts "\n=== Request Details ===" puts "\n=== Request Details ==="
puts "URL: #{url}" puts "URL: #{url}"
puts 'Headers:' puts 'Headers:'
@ -101,21 +160,20 @@ class Dataminer
JSON.parse(response.body) JSON.parse(response.body)
end end
private def update_game_data(model_name, granblue_id, response_data)
return unless response_data.is_a?(Hash)
def format_cookies model = Object.const_get(model_name)
cookies.map { |k, v| "#{k}=#{v}" }.join('; ') record = model.find_by(granblue_id: granblue_id)
end
def auth_failed?(response) if record
return true if response.code != 200 record.update(game_raw_en: response_data)
puts "Updated #{model_name} #{granblue_id}"
begin else
parsed = JSON.parse(response.body) puts "#{model_name} with granblue_id #{granblue_id} not found in database"
parsed.is_a?(Hash) && parsed['auth_status'] == 'require_auth'
rescue JSON::ParserError
true
end end
rescue StandardError => e
puts "Error updating #{model_name} #{granblue_id}: #{e.message}"
end end
class AuthenticationError < StandardError; end class AuthenticationError < StandardError; end