Files
site/app/workers/wow_characters_worker.rb

48 lines
1.7 KiB
Ruby

# frozen_string_literal: true
class WowCharactersWorker < WowSidekiqWorker
def perform(user_id)
# Update the WoW character list
return unless (user = User.find(user_id))
RBattlenet.set_options(locale: 'all')
result = RBattlenet::Wow::Profile::User.find(user.token)
return unless result.status_code == 200
result.wow_accounts&.each do |account|
account.characters&.each do |character|
wow_char = user.wow_characters.find_or_initialize_by(character_id: character.id)
wow_char.name = character.name
wow_char.gender = character.gender.type
wow_char.faction = character.faction.type
wow_char.href = character.character.href
wow_char.level = character.level
wow_char.wow_realm = WowRealm.find_by(realm_id: character.realm.id)
wow_char.wow_class = WowClass.find_by(class_id: character.playable_class.id)
wow_char.wow_race = WowRace.find_by(race_id: character.playable_race.id)
wow_char.user = user
wow_char.account_id = account.id
locales.each do |locale|
Mobility.with_locale(locale[0]) do
wow_char.translated_faction = character.faction.name[locale[1]]
wow_char.translated_gender = character.gender.name[locale[1]]
end
end
wow_char.save
next unless wow_char.persisted?
WowCharacterMediaWorker.perform_async(wow_char.character_id)
WowCharacterDetailWorker.perform_async(wow_char.character_id)
WowCharacterPositionsWorker.perform_async(wow_char.character_id)
WowStandingWorker.perform_async(wow_char.character_id)
# WowCharacterAchievementsWorker.perform_async(wow_char.character_id)
end
end
end
end