Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 11 additions & 39 deletions scripts/autostart.lic
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
contributors: Athias
game: any
tags: core
version: 0.71
version: 0.72
required: Lich >= 4.6.58

changelog:
0.72 (2026-05-27):
remove legacy DR dependency path (dependency.lic enforces 5.17.2 for DR)
keep respond_to? guards for GS backward compatibility on older lich
0.71 (2026-05-07):
Force population of Account.subscription for newer Lich5 when using non-Lich authentication
0.70 (2026-05-07):
Expand Down Expand Up @@ -150,50 +153,19 @@ if script.vars.empty?
end

# Check for Lich5 updates and announce if available
if Gem::Version.new(LICH_VERSION) > Gem::Version.new('5.6.2')
if defined?(Lich::Util::Update)
Lich::Util::Update.request("--announce")
end

# DR: load dependency before other scripts.
# dependency.lic defines the parse_args() bridge that DR scripts need.
# DR: load dependency for its runtime helpers (bankbot, slackbot, hometown).
# Core lich 5.17.2+ provides parse_args, get_settings, map overrides natively.
if XMLData.game =~ /^DR/
if respond_to?(:start_scripts_if_available, true)
Script.run('dependency') if Script.exists?('dependency') && !Script.running?('dependency')
did_something = true
else
# Legacy path: dependency.lic handles everything (script sync, autostarts, map edits)
begin
did_dependency_install = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='did_dependency_install';")
rescue SQLite3::BusyException
sleep 0.1
retry
end
if did_dependency_install.nil?
unless File.exist?("#{SCRIPT_DIR}/dependency.lic")
_respond Lich::Messaging.monsterbold("DR First run detected. Downloading dependency.")
Script.run('repository', 'download dependency')
sleep 1
end
unless File.exist?("#{SCRIPT_DIR}/hunting-buddy.lic") && File.exist?("#{SCRIPT_DIR}/combat-trainer.lic") && File.exist?("#{SCRIPT_DIR}/get2.lic") && File.exist?("#{SCRIPT_DIR}/dependency.lic")
_respond Lich::Messaging.monsterbold("DR First run detected. Performing dependency install. - Please wait until the process finishes completely before proceeding.")
sleep 0.5
Script.run('dependency', 'install')
end
begin
Lich.db.execute("INSERT INTO lich_settings(name,value) VALUES('did_dependency_install', 'yes');")
rescue SQLite3::BusyException
sleep 0.1
retry
end
else
Script.start('dependency') unless Script.running?('dependency')
sleep 1
end
end
Script.run('dependency') if Script.exists?('dependency') && !Script.running?('dependency')
did_something = true
end

# YAML-based autostarts, UserVars autostarts, and wayto overrides.
# Game-agnostic -- requires modern Lich with get_settings support.
# Guarded for GS backward compatibility on lich < 5.17.
if respond_to?(:get_settings, true)
UserVars.autostart_scripts ||= []
all_autostarts = (UserVars.autostart_scripts.to_a +
Expand Down Expand Up @@ -222,7 +194,7 @@ if script.vars.empty?
for script_info in script_list
if ['infomon', 'repository', 'dependency'].include?(script_info[:name])
next
elsif script_info[:name] == 'lich5-update' && Gem::Version.new(LICH_VERSION) > Gem::Version.new('5.6.2')
elsif script_info[:name] == 'lich5-update' && defined?(Lich::Util::Update)
next
elsif script_info[:name] == 'dependency' && XMLData.game =~ /^DR/
respond "\n--- dependency found in autostart list. Attempting to remove it now. If unsuccessful, it can be safely removed with '#{$clean_lich_char}autostart remove --global dependency'"
Expand Down
22 changes: 14 additions & 8 deletions spec/autostart/autostart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ def reset!

# -- Helper that mirrors the game-agnostic YAML autostart loop ------------

# Replicates lines 137-158 of autostart.lic.
# Replicates the YAML autostart loop of autostart.lic.
#
# @param script_mod [Module] mock for Script (running?, exists?, start)
# @param map_mod [Module] mock for Map (apply_wayto_overrides)
# @param user_vars_mod [Module] mock for UserVars (autostart_scripts)
# @param yaml_autostarts [Array<String>, nil] simulated get_settings.autostarts
# @param has_get_settings [Boolean] whether get_settings is available
# @param has_get_settings [Boolean] whether get_settings is available (false on old GS lich)
# @param respond_output [Array<String>] collects warning messages
# @return [Array<String>, nil] list of started script names, or nil if skipped
def run_yaml_autostart_loop(script_mod: MockScript,
Expand Down Expand Up @@ -177,7 +177,7 @@ def run_generic_autostart_loop(settings_mod: MockSettings,
char_settings_mod: MockCharSettings,
script_mod: MockScript,
xml_data_mod: MockXMLData,
lich_version: "5.7.0",
has_lich_update: true,
respond_output: [])
for script_list in [settings_mod['scripts'], char_settings_mod['scripts']]
if script_list.is_a?(Array)
Expand All @@ -200,8 +200,7 @@ def run_generic_autostart_loop(settings_mod: MockSettings,
end
end
next
elsif script_info[:name] == 'lich5-update' &&
Gem::Version.new(lich_version) > Gem::Version.new('5.6.2')
elsif script_info[:name] == 'lich5-update' && has_lich_update
next
else
next if script_mod.running?(script_info[:name])
Expand Down Expand Up @@ -326,12 +325,19 @@ def run_generic_autostart_loop(settings_mod: MockSettings,
expect(MockScript.started).to be_empty
end

it "skips lich5-update when LICH_VERSION > 5.6.2" do
it "skips lich5-update when Lich::Util::Update is available" do
MockSettings['scripts'] = [{ name: 'lich5-update', args: [] }]

run_generic_autostart_loop(lich_version: "5.7.0")
run_generic_autostart_loop(has_lich_update: true)
expect(MockScript.started).to be_empty
end

it "does not skip lich5-update on old lich without Lich::Util::Update" do
MockSettings['scripts'] = [{ name: 'lich5-update', args: [] }]

run_generic_autostart_loop(has_lich_update: false)
expect(MockScript.started).to eq([{ name: 'lich5-update', args: [] }])
end
end

describe "DR dependency removal" do
Expand Down Expand Up @@ -396,7 +402,7 @@ def run_generic_autostart_loop(settings_mod: MockSettings,
expect(started).to eq(['esp', 'afk'])
end

it "does nothing when get_settings is not available" do
it "does nothing when get_settings is not available (old GS lich)" do
started = run_yaml_autostart_loop(yaml_autostarts: ['esp'], has_get_settings: false)
expect(started).to be_nil
end
Expand Down
Loading