From 64e3fef45b563aaab8de4c59f4746297e10d24b8 Mon Sep 17 00:00:00 2001 From: Mahtra <93822896+MahtraDR@users.noreply.github.com> Date: Wed, 27 May 2026 14:11:54 +1200 Subject: [PATCH 1/2] refactor(autostart): remove legacy guards, require lich 5.17.2+ Core lich 5.17.2+ provides get_settings, start_scripts_if_available, and Map.apply_wayto_overrides natively. Remove the respond_to? guards and the entire legacy DR dependency install path that predated these. Changes: - Remove legacy DR dependency path (first-run install, old lich fallback) - Remove respond_to?(:get_settings) guard (always true on 5.17.2+) - Remove Map.respond_to?(:apply_wayto_overrides) guard (always true) - Remove Gem::Version lich5-update check (5.17.2 > 5.6.2 always) - Consolidate lich5-update into the skip list - Update comment: dependency loads for runtime helpers, not parse_args - Bump version to 0.72, required to Lich >= 5.17.2 - Update spec helpers to match simplified code Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/autostart.lic | 84 +++++++++----------------------- spec/autostart/autostart_spec.rb | 25 +++------- 2 files changed, 30 insertions(+), 79 deletions(-) diff --git a/scripts/autostart.lic b/scripts/autostart.lic index 5d33d4919..7960e413f 100644 --- a/scripts/autostart.lic +++ b/scripts/autostart.lic @@ -9,10 +9,12 @@ contributors: Athias game: any tags: core - version: 0.71 - required: Lich >= 4.6.58 + version: 0.72 + required: Lich >= 5.17.2 changelog: + 0.72 (2026-05-27): + remove legacy DR dependency path and respond_to? guards (lich 5.17.2+ provides all) 0.71 (2026-05-07): Force population of Account.subscription for newer Lich5 when using non-Lich authentication 0.70 (2026-05-07): @@ -150,79 +152,41 @@ 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') - Lich::Util::Update.request("--announce") - end + Lich::Util::Update.request("--announce") - # 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. - if respond_to?(:get_settings, true) - UserVars.autostart_scripts ||= [] - all_autostarts = (UserVars.autostart_scripts.to_a + - get_settings.autostarts.to_a).uniq - - Map.apply_wayto_overrides if Map.respond_to?(:apply_wayto_overrides) + UserVars.autostart_scripts ||= [] + all_autostarts = (UserVars.autostart_scripts.to_a + + get_settings.autostarts.to_a).uniq - all_autostarts.each do |script_name| - next if script_name == 'dependency' - next if defined?(DR_OBSOLETE_SCRIPTS) && DR_OBSOLETE_SCRIPTS.include?(script_name) - next if Script.running?(script_name) + Map.apply_wayto_overrides - unless Script.exists?(script_name) - respond "\n--- autostart: '#{script_name}' not found, skipping\n\n" - next - end + all_autostarts.each do |script_name| + next if script_name == 'dependency' + next if defined?(DR_OBSOLETE_SCRIPTS) && DR_OBSOLETE_SCRIPTS.include?(script_name) + next if Script.running?(script_name) - start_script(script_name) + unless Script.exists?(script_name) + respond "\n--- autostart: '#{script_name}' not found, skipping\n\n" + next end - did_something = true unless all_autostarts.empty? + + start_script(script_name) end + did_something = true unless all_autostarts.empty? for script_list in [Settings['scripts'], CharSettings['scripts']] if script_list.is_a?(Array) # Loop through list 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') + if ['infomon', 'repository', 'dependency', 'lich5-update'].include?(script_info[:name]) 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'" diff --git a/spec/autostart/autostart_spec.rb b/spec/autostart/autostart_spec.rb index edfb4f8b7..f91a29323 100644 --- a/spec/autostart/autostart_spec.rb +++ b/spec/autostart/autostart_spec.rb @@ -123,28 +123,24 @@ 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, nil] simulated get_settings.autostarts -# @param has_get_settings [Boolean] whether get_settings is available # @param respond_output [Array] collects warning messages -# @return [Array, nil] list of started script names, or nil if skipped +# @return [Array] list of started script names def run_yaml_autostart_loop(script_mod: MockScript, map_mod: MockMap, user_vars_mod: MockUserVars, yaml_autostarts: [], - has_get_settings: true, respond_output: []) - return unless has_get_settings - user_vars_mod.autostart_scripts ||= [] all_autostarts = (user_vars_mod.autostart_scripts.to_a + yaml_autostarts.to_a).uniq - map_mod.apply_wayto_overrides if map_mod.respond_to?(:apply_wayto_overrides) + map_mod.apply_wayto_overrides started = [] all_autostarts.each do |script_name| @@ -177,12 +173,11 @@ def run_generic_autostart_loop(settings_mod: MockSettings, char_settings_mod: MockCharSettings, script_mod: MockScript, xml_data_mod: MockXMLData, - lich_version: "5.7.0", respond_output: []) for script_list in [settings_mod['scripts'], char_settings_mod['scripts']] if script_list.is_a?(Array) for script_info in script_list - if ['infomon', 'repository', 'dependency'].include?(script_info[:name]) + if ['infomon', 'repository', 'dependency', 'lich5-update'].include?(script_info[:name]) # dependency removal for DR if script_info[:name] == 'dependency' && xml_data_mod.game =~ /^DR/ respond_output << "dependency removed" @@ -200,9 +195,6 @@ 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') - next else next if script_mod.running?(script_info[:name]) @@ -326,10 +318,10 @@ 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" do MockSettings['scripts'] = [{ name: 'lich5-update', args: [] }] - run_generic_autostart_loop(lich_version: "5.7.0") + run_generic_autostart_loop expect(MockScript.started).to be_empty end end @@ -396,11 +388,6 @@ 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 - started = run_yaml_autostart_loop(yaml_autostarts: ['esp'], has_get_settings: false) - expect(started).to be_nil - end - it "handles empty YAML autostarts" do started = run_yaml_autostart_loop(yaml_autostarts: []) expect(started).to eq([]) From 18fffc9c454245a37e5e95b9c1631b75ca6c5e1a Mon Sep 17 00:00:00 2001 From: Mahtra <93822896+MahtraDR@users.noreply.github.com> Date: Wed, 27 May 2026 16:00:38 +1200 Subject: [PATCH 2/2] fix(autostart): restore respond_to? guards for GS backward compatibility autostart.lic is game-agnostic (game: any). GS players on older lich may not have get_settings, Map.apply_wayto_overrides, or Lich::Util::Update. Restore respond_to? guards for these while keeping the DR legacy path removal (dependency.lic enforces 5.17.2). Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/autostart.lic | 44 +++++++++++++++++++------------- spec/autostart/autostart_spec.rb | 29 +++++++++++++++++---- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/scripts/autostart.lic b/scripts/autostart.lic index 7960e413f..d3ea1bba0 100644 --- a/scripts/autostart.lic +++ b/scripts/autostart.lic @@ -10,11 +10,12 @@ game: any tags: core version: 0.72 - required: Lich >= 5.17.2 + required: Lich >= 4.6.58 changelog: 0.72 (2026-05-27): - remove legacy DR dependency path and respond_to? guards (lich 5.17.2+ provides all) + 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): @@ -152,7 +153,9 @@ if script.vars.empty? end # Check for Lich5 updates and announce if available - Lich::Util::Update.request("--announce") + if defined?(Lich::Util::Update) + Lich::Util::Update.request("--announce") + end # DR: load dependency for its runtime helpers (bankbot, slackbot, hometown). # Core lich 5.17.2+ provides parse_args, get_settings, map overrides natively. @@ -162,31 +165,36 @@ if script.vars.empty? end # YAML-based autostarts, UserVars autostarts, and wayto overrides. - UserVars.autostart_scripts ||= [] - all_autostarts = (UserVars.autostart_scripts.to_a + - get_settings.autostarts.to_a).uniq + # 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 + + get_settings.autostarts.to_a).uniq - Map.apply_wayto_overrides + Map.apply_wayto_overrides if Map.respond_to?(:apply_wayto_overrides) - all_autostarts.each do |script_name| - next if script_name == 'dependency' - next if defined?(DR_OBSOLETE_SCRIPTS) && DR_OBSOLETE_SCRIPTS.include?(script_name) - next if Script.running?(script_name) + all_autostarts.each do |script_name| + next if script_name == 'dependency' + next if defined?(DR_OBSOLETE_SCRIPTS) && DR_OBSOLETE_SCRIPTS.include?(script_name) + next if Script.running?(script_name) - unless Script.exists?(script_name) - respond "\n--- autostart: '#{script_name}' not found, skipping\n\n" - next - end + unless Script.exists?(script_name) + respond "\n--- autostart: '#{script_name}' not found, skipping\n\n" + next + end - start_script(script_name) + start_script(script_name) + end + did_something = true unless all_autostarts.empty? end - did_something = true unless all_autostarts.empty? for script_list in [Settings['scripts'], CharSettings['scripts']] if script_list.is_a?(Array) # Loop through list for script_info in script_list - if ['infomon', 'repository', 'dependency', 'lich5-update'].include?(script_info[:name]) + if ['infomon', 'repository', 'dependency'].include?(script_info[:name]) + next + 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'" diff --git a/spec/autostart/autostart_spec.rb b/spec/autostart/autostart_spec.rb index f91a29323..fd103a688 100644 --- a/spec/autostart/autostart_spec.rb +++ b/spec/autostart/autostart_spec.rb @@ -129,18 +129,22 @@ def reset! # @param map_mod [Module] mock for Map (apply_wayto_overrides) # @param user_vars_mod [Module] mock for UserVars (autostart_scripts) # @param yaml_autostarts [Array, nil] simulated get_settings.autostarts +# @param has_get_settings [Boolean] whether get_settings is available (false on old GS lich) # @param respond_output [Array] collects warning messages -# @return [Array] list of started script names +# @return [Array, nil] list of started script names, or nil if skipped def run_yaml_autostart_loop(script_mod: MockScript, map_mod: MockMap, user_vars_mod: MockUserVars, yaml_autostarts: [], + has_get_settings: true, respond_output: []) + return unless has_get_settings + user_vars_mod.autostart_scripts ||= [] all_autostarts = (user_vars_mod.autostart_scripts.to_a + yaml_autostarts.to_a).uniq - map_mod.apply_wayto_overrides + map_mod.apply_wayto_overrides if map_mod.respond_to?(:apply_wayto_overrides) started = [] all_autostarts.each do |script_name| @@ -173,11 +177,12 @@ def run_generic_autostart_loop(settings_mod: MockSettings, char_settings_mod: MockCharSettings, script_mod: MockScript, xml_data_mod: MockXMLData, + has_lich_update: true, respond_output: []) for script_list in [settings_mod['scripts'], char_settings_mod['scripts']] if script_list.is_a?(Array) for script_info in script_list - if ['infomon', 'repository', 'dependency', 'lich5-update'].include?(script_info[:name]) + if ['infomon', 'repository', 'dependency'].include?(script_info[:name]) # dependency removal for DR if script_info[:name] == 'dependency' && xml_data_mod.game =~ /^DR/ respond_output << "dependency removed" @@ -195,6 +200,8 @@ def run_generic_autostart_loop(settings_mod: MockSettings, end end next + elsif script_info[:name] == 'lich5-update' && has_lich_update + next else next if script_mod.running?(script_info[:name]) @@ -318,12 +325,19 @@ def run_generic_autostart_loop(settings_mod: MockSettings, expect(MockScript.started).to be_empty end - it "skips lich5-update" do + it "skips lich5-update when Lich::Util::Update is available" do MockSettings['scripts'] = [{ name: 'lich5-update', args: [] }] - run_generic_autostart_loop + 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 @@ -388,6 +402,11 @@ def run_generic_autostart_loop(settings_mod: MockSettings, expect(started).to eq(['esp', 'afk']) end + 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 + it "handles empty YAML autostarts" do started = run_yaml_autostart_loop(yaml_autostarts: []) expect(started).to eq([])