Skip to content

Commit

Permalink
Merge pull request #3 from lloyd-delacroix/lloyd-delacroix-patch-3
Browse files Browse the repository at this point in the history
Added contacts manager to dependency
  • Loading branch information
lloyd-delacroix authored Feb 22, 2017
2 parents 0142ea5 + 3920753 commit 3d1b84f
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions dependency.lic
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) } } }

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 3d1b84f

Please sign in to comment.