Skip to content

Commit

Permalink
reduce timeout to 3s for retry on Lich::Util. Made nested match N+ ch…
Browse files Browse the repository at this point in the history
…aracters to prevent overflow into default case.
  • Loading branch information
desertkaz authored Jul 9, 2024
1 parent 5c12560 commit 048ef8c
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions inventory-manager.lic
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class InventoryManager
# Counting all items in inventory
capture = []
until capture != []
capture = Lich::Util.issue_command('inv list', /^You have:/)
capture = Lich::Util.issue_command('inv list', /^You have:/, timeout: 3)
end
capture.each do |line|
item = line.lstrip
Expand All @@ -172,7 +172,7 @@ class InventoryManager
# Counting items matching the description, i.e., inv count pouch
capture = []
until capture != []
capture = Lich::Util.issue_command("inv search #{desc}", /rummage about your person/)
capture = Lich::Util.issue_command("inv search #{desc}", /rummage about your person/, timeout: 3)
end
capture.each do |line|
item = line.lstrip
Expand All @@ -197,7 +197,7 @@ class InventoryManager

capture = []
until capture != []
capture = Lich::Util.issue_command(command, end_pattern)
capture = Lich::Util.issue_command(command, end_pattern, timeout: 3)
end
lines = capture
# when rummaging, this block splits the items, including the last two that are split by and instead of a comma
Expand All @@ -214,6 +214,7 @@ class InventoryManager
end

container = ""
sub_container = ""
lines.each do |line|
line.sub!(/\(\d+\)/, '') if command == 'vault standard'
item = line.lstrip
Expand Down Expand Up @@ -242,18 +243,24 @@ class InventoryManager
end
elsif command == "read my storage book" || command == "read my vault book"
# items in vault/storage book output are prefixed by 6 spaces
if line =~ /\s{6}(?:a|an|some) /
item.concat(" (in container - #{container})")
else
container = item.to_s
end
if line =~ /\s{8,}(?:a|an|some) /
item.concat(" (nested container - #{sub_container})")
elsif line =~ /\s{6}(?:a|an|some) /
item.concat(" (in container - #{container})")
sub_container = item.to_s
else
container = item.to_s
end
elsif command == 'vault standard'
# items in a container are prefixed by 11 spaces once the item count is removed
if line =~ /\s{11}(?:a|an|some) /
item.concat(" (in container - #{container})")
else
container = item.to_s
end
if line =~ /\s{16,}(?:a|an|some) /
item.concat(" (nested container - #{sub_container})")
elsif line =~ /\s{11}(?:a|an|some) /
item.concat(" (in container - #{container})")
sub_container = item.to_s
else
container = item.to_s
end
elsif inventory_type == 'home'
if !item.start_with?("Attached:")
item = clean_home_string(item)
Expand Down Expand Up @@ -390,7 +397,7 @@ class InventoryManager
spells = []
capture = []
until capture != []
capture = Lich::Util.issue_command("flip my #{stacker.split.last}", /^You flip through the #{stacker.split.last}, checking each section before closing it.$/)
capture = Lich::Util.issue_command("flip my #{stacker.split.last}", /^You flip through the #{stacker.split.last}, checking each section before closing it.$/, timeout: 3)
end
capture.each do |line|
if line =~ /The (.+) section has (\d+)/
Expand Down Expand Up @@ -434,7 +441,7 @@ class InventoryManager
surfaces = Hash.new
capture = []
until capture != []
capture = Lich::Util.issue_command("shop customer", /^The following items contain goods for sale:/)
capture = Lich::Util.issue_command("shop customer", /^The following items contain goods for sale:/, timeout: 3)
end
capture.each do |line|
line = line.lstrip
Expand All @@ -450,7 +457,7 @@ class InventoryManager
surfaces.each do |surface|
capture = []
until capture != []
capture = Lich::Util.issue_command(surface[1], /, you see:/)
capture = Lich::Util.issue_command(surface[1], /, you see:/, timeout: 3)
end
capture.each do |line|
line = line.lstrip
Expand Down

0 comments on commit 048ef8c

Please sign in to comment.