diff --git a/dependency.lic b/dependency.lic index 7dc894ddc1..41630cc1ee 100644 --- a/dependency.lic +++ b/dependency.lic @@ -696,6 +696,52 @@ class ReportbotManager end end +class ContactsManager + def initialize(debug) + @debug = debug + @load = false + @contacts = [] + @personalcontacts = [] + end + + attr_reader :contacts + attr_reader :personalcontacts + + def loaded? + !@load + end + + def run_queue + load_contacts + end + + def load_contactsmanager_contacts + @load = true + end + + private + + def load_contacts + return unless @load + @contacts = safe_load_yaml('./scripts/data/base-contacts.yaml') + @contacts = contacts['contacts'] + if File.exist?("./scripts/personal-contacts.yaml") + @personalcontacts = safe_load_yaml('./scripts/personal-contacts.yaml') + @personalcontacts = personalcontacts['contacts'] + @contacts = contacts.merge!(personalcontacts) + end + @load = false + end + + def safe_load_yaml(path) + YAML.load_file(path) + rescue => e + echo('*** ERROR PARSING YAML FILE ***') + echo(e.message) + return [] + end +end + class SetupFiles def initialize(debug) @debug = debug @@ -845,14 +891,14 @@ class SetupFiles spells.select { |_name, data| data['abbrev'].casecmp(spell['abbrev'].downcase).zero? } .each { |_name, data| s.lockpick_buffs['spells'][i] = data.merge(spell) } end - + s.astrology_buffs['spells'] .each_with_index .select do |spell, i| spells.select { |_name, data| data['abbrev'].casecmp(spell['abbrev'].downcase).zero? } - .each { |_name, data| s.lockpick_buffs['spells'][i] = data.merge(spell) } + .each { |_name, data| s.astrology_buffs['spells'][i] = data.merge(spell) } end - + s.waggle_sets .select { |set_name, set_spells| set_spells.select { |spell_name, spell_data| spells[spell_name].each { s.waggle_sets[set_name][spell_name] = spells[spell_name].merge(spell_data) } } } @@ -943,6 +989,7 @@ $setupfiles = SetupFiles.new(debug) $manager = ScriptManager.new(debug) $bankbot = BankbotManager.new(debug) $reportbot = ReportbotManager.new(debug) +$contactsmanager = ContactsManager.new(debug) def enable_moon_connection $turn_on_moon_watch = true @@ -984,6 +1031,12 @@ def load_reportbot_whitelist $reportbot.whitelist end +def load_contactsmanager_contacts + $contactsmanager.load_contactsmanager_contacts + pause 0.1 until $contactsmanager.loaded? + $contactsmanager.contacts +end + def format_name(name) name =~ /\.lic$/ ? name : "#{name}.lic" end @@ -1193,6 +1246,7 @@ loop do $setupfiles.run_queue $bankbot.run_queue $reportbot.run_queue + $contactsmanager.run_queue $moon_watch.run_queue if $moon_watch pause 0.1 end