forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependency.lic
More file actions
151 lines (129 loc) · 5.55 KB
/
Copy pathdependency.lic
File metadata and controls
151 lines (129 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
=begin
Documentation: https://elanthipedia.play.net/Lich_script_development#dependency
As of 4.0.0, all gated class definitions (ArgParser, SetupFiles,
ScriptManager) and boot-sequence orchestration have been removed.
Core lich 5.18.0+ provides these natively via sentinels:
CORE_ARGPARSER, CORE_SETUPFILES, CORE_GET_SETTINGS,
CORE_SCRIPT_LOADER, CORE_MAP_OVERRIDES, CORE_DR_STARTUP
What remains are runtime helper functions (bankbot, slackbot,
hometown) that dr-scripts still call and have not yet been
upstreamed into core lich. verify_script now lives in core as
DRC.verify_script and the dead reportbot/format helpers have
been removed.
Dependency also warns at startup about scripts that have been
superseded by native core lich functionality (see
DR_OBSOLETE_SCRIPTS) so a lingering copy on disk can be found
and deleted before it duplicates work core now performs.
=end
$DEPENDENCY_VERSION = '4.2.3'
$DR_SCRIPTS_DISCORD_LINK = 'https://discord.gg/f8ne99pVva'
$MIN_LICH_VERSION = '5.21.0'
unless Gem::Version.new(LICH_VERSION) >= Gem::Version.new($MIN_LICH_VERSION)
10.times do
border = "*" * 107
_respond("<pushBold/>#{border}<popBold/>")
_respond("<pushBold/>* #{"Lich versions prior to #{$MIN_LICH_VERSION} are no longer supported.".ljust(103)} *<popBold/>")
_respond("<pushBold/>* #{"See https://github.com/elanthia-online/lich-5/wiki/Documentation-for-Installing-and-Upgrading-Lich".ljust(103)} *<popBold/>")
_respond("<pushBold/>* #{"For update instructions.".ljust(103)} *<popBold/>")
if LICH_VERSION.start_with?('5')
_respond("<pushBold/>* #{"Or to automatically update, run '#{$clean_lich_char}lich5-update --update'.".ljust(103)} *<popBold/>")
end
_respond("<pushBold/>* #{"Exiting Dependency now. Nothing much will work from here...".ljust(103)} *<popBold/>")
_respond("<pushBold/>#{border}<popBold/>")
pause 10
end
exit
end
unless XMLData.game =~ /^DR/
echo("This script is not intended for usage with games other than Dragonrealms. Exiting now")
exit
end
# --- Obsolete script detection ---
# Scripts that have been superseded by native core lich functionality and
# should no longer be run. A lingering copy on disk can still be launched
# (for example via a stale autostart entry) and will duplicate the work core
# lich now performs, so Dependency warns about any that remain.
#
# Stored frozen so the canonical list cannot be mutated at runtime.
#
# roomnumbers.lic was retired once core lich gained room-number, room-exit,
# and StringProc-exit display (toggled by Lich.display_lichid,
# Lich.display_uid, Lich.display_exits, and Lich.display_stringprocs).
#
# @return [Array<String>] obsolete script base names, without the ".lic" extension
DR_OBSOLETE_SCRIPTS = %w[
roomnumbers
].freeze
# Directories searched for a lingering copy of an obsolete script, in
# descending priority. A script only has to exist in one of these to be
# launchable, so #warn_obsolete_scripts reports the first match and stops.
#
# The custom directory is checked first because a user's local copy there
# shadows the shipped one and is the more likely culprit.
#
# @return [Array<String>] absolute directory paths, highest priority first
def obsolete_script_dirs
[File.join(SCRIPT_DIR, 'custom'), SCRIPT_DIR]
end
# Emit a warning for each obsolete script that still exists on disk.
#
# Presence on disk is the signal that matters: a script must exist to be run,
# so a missing file needs no warning while a present one can cause problems
# regardless of how it is launched. Each script is reported at most once,
# against the highest-priority directory in which it is found.
#
# @param obsolete [Array<String>] base names to check; defaults to
# DR_OBSOLETE_SCRIPTS. Injectable so callers (and specs) can supply their
# own list without mutating the frozen constant.
# @return [Array<String>] the base names that were found and warned about, in
# the order they appear in +obsolete+ (empty when nothing was found)
def warn_obsolete_scripts(obsolete = DR_OBSOLETE_SCRIPTS)
obsolete.select do |name|
dir = obsolete_script_dirs.find { |d| File.file?(File.join(d, "#{name}.lic")) }
next false unless dir
_respond Lich::Messaging.monsterbold(
"--- Lich: WARNING: '#{name}.lic' is obsolete and should be deleted from #{dir}. " \
'It is superseded by core lich and may cause duplicate output or other problems.'
)
true
end
end
echo("Dependency version #{$DEPENDENCY_VERSION}")
warn_obsolete_scripts
# --- Runtime helpers ---
def save_bankbot_transaction(transaction, ledger)
ledger_yaml = ledger.to_yaml
File.open(File.join(LICH_DIR, "#{checkname}-transactions.log"), 'a') do |file|
file.puts('----------')
file.puts(Time.now)
file.puts(transaction)
file.puts(ledger_yaml)
file.puts('----------')
end
File.open(File.join(LICH_DIR, "#{checkname}-ledger.yaml"), 'wb') { |file| file.puts(ledger_yaml) }
end
def load_bankbot_ledger
OpenStruct.new(YAML.unsafe_load_file(File.join(LICH_DIR, "#{checkname}-ledger.yaml"))).to_h
rescue => e
echo('*** ERROR PARSING YAML FILE ***')
echo(e.message)
{}
end
def send_slackbot_message(message)
return unless message
$slackbot_instance ||= nil
return unless $slackbot_instance
$slackbot_instance.direct_message($slackbot_username, message)
end
def register_slackbot(username)
return if $slackbot_instance
return if username.nil? || username.to_s.strip.empty?
$slackbot_username = username
$slackbot_instance = Lich::DragonRealms::SlackBot.new
end
def shift_hometown(town_name)
$HOMETOWN = town_name
end
def clear_hometown
$HOMETOWN = nil
end