-
Notifications
You must be signed in to change notification settings - Fork 3
/
version.lic
273 lines (234 loc) · 7.84 KB
/
version.lic
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
=begin
Reports versions of Lich, Ruby, and other important builtins, as well as other diagnostic information.
author: LostRanger ([email protected])
game: any
tags: utility
version: 0.4 (2019-11-17)
changelog:
version 0.4 (2019-11-17)
* Minor improvements.
version 0.3 (2019-10-13)
* ;version SCRIPT reports the currently-installed version of the specified script, if available.
SCRIPT may be a partial name or 'all' for all installed scripts.
version 0.2 (2019-10-07)
* Now reports where the Ruby interpreter is.
version 0.1 (2019-07-09)
* First release.
=end
def const_get(sym, parent: Object, missing: 'not installed')
return missing unless parent.const_defined?(sym)
return parent.const_get(sym).to_s
end
def module_version(sym)
begin
return 'not installed' unless Object.const_defined?(sym)
v = Object.const_get(sym)::VERSION
return v.join('.') if v.is_a?(Array)
return v.to_s
end
return 'error'
end
def format_report(report, width)
report.map{|k, v| "#{k.ljust(width, '.')}: #{v}" }
end
def get_script_version(filename)
data = open(filename, 'r').read
if data =~ /^=begin\r?\n?(.+?)^=end/m
comments = $1.split("\n")
else
comments = []
data.split("\n").each {|line|
if line =~ /^[\t\s]*#/
comments.push(line)
elsif line !~ /^[\t\s]*$/
break
end
}
end
for line in comments
if line =~ /^[\s\t#]*version:[\s\t]*([\w,\s\.\d]+)/i
return $1.sub(/\s\(.*?\)/, '').strip
end
end
return nil
end
def reward_source_divers
first = true
while true
5.times do |x|
if x == 0
next if first # Doesn't happen the first time around.
_respond "It's a badger"
sleep 0.4
elsif x == 1
_respond "Badger"
sleep 0.4
end
11.times do |y|
if y == 0 and x > 1
_respond "A badger"
else
_respond "Badger"
end
sleep 0.4
end
if x <= 2
2.times do
respond "Mushroom"
sleep 0.7
end
elsif x == 3
respond "Mush-"
sleep 0.3
respond "-Mushroom"
sleep 0.7
end
end
2.times { _respond "A..."; sleep 0.2; _respond "snake"; sleep 0.3 }
_respond "Snaaake!"
sleep 0.5
_respond "A snaaaake"
sleep 0.5
_respond "Oooh, it's a snake"
sleep 3
_respond "[You can stop this at any time with ;kill #{Script.current.name}]"
end
end
if script.vars[1]
if script.vars[1].downcase == script.name and script.vars[2].downcase == script.name
reward_source_divers
exit
end
unless $SAFE == 0
msg = []
msg << "To report version information of specific scripts, this script must be trusted:"
msg << " #{$lich_char}trust #{script.name}"
exit
end
if script.vars[1] =~ /^(?:all|full|details?)$/i
show_report = true
scripts_to_check = Dir["#{SCRIPT_DIR}/*"].find_all{|x| x =~ /\.lic$/i}
else
show_report = false
scripts_to_check = Set.new
script.vars[1..-1].each do |prefix|
scripts = Dir["#{SCRIPT_DIR}/#{prefix}*"].find_all{|x| x =~ /\.lic$/i}
if scripts.length == 0
echo "#{prefix}: No matching scripts found!"
end
scripts.each{|x| scripts_to_check << x}
end
scripts_to_check = scripts_to_check.to_a
scripts_to_check.sort!
end
else
show_report = true
scripts_to_check = []
end
msg = []
if show_report
msg << "```"
report = {
"Ruby version" => const_get(:RUBY_VERSION, missing: 'unknown'),
"Ruby platform" => const_get(:RUBY_PLATFORM, missing: 'unknown'),
"Ruby engine" => const_get(:RUBY_ENGINE, missing: 'unknown'),
"Lich version" => const_get(:LICH_VERSION, missing: 'unknown'),
"SQLite3 version" => module_version(:SQLite3),
"Gtk version" => module_version(:Gtk),
"Cairo version" => module_version(:Cairo),
"#{$lich_char}version Version" => "0.3"
}
msg += format_report(report, 20)
msg << ''
report = {}
[:LICH_DIR, :SCRIPT_DIR, :DATA_DIR, :TEMP_DIR, :LOG_DIR, :MAP_DIR, :BACKUP_DIR].each do |sym|
report[sym.to_s] = const_get(sym, missing: 'unknown')
end
if $SAFE == 0
begin
report["Ruby location"] = Win32.GetModuleFileName[:lpFilename]
rescue
report["Ruby location"] = 'error'
end
end
msg += format_report(report, 20)
msg << ''
if $SAFE == 0
report = {}
begin
fn = Dir.entries("#{DATA_DIR}/#{XMLData.game}").find_all { |filename| filename =~ /^map\-[0-9]+\.(?:dat|xml)$/ }.collect { |filename| "#{DATA_DIR}/#{XMLData.game}/#{filename}" }.sort[-1]
if fn
report["MapDB filename"] = File.basename(fn)
report["MapDB last modified"] = File.mtime(fn).to_s
else
report["MapDB filename"] = 'not found'
end
rescue
report["MapDB filename"] = 'error'
end
["gameobj-data", "spell-list"].each do |file|
time = nil
[DATA_DIR, SCRIPT_DIR].each do |dir|
begin
fn = "#{dir}/#{file}.xml"
time = File.mtime(fn) if File.exists?(fn)
break
rescue
time = nil
end
end
time = time.to_s if time
time ||= 'unknown'
report["#{file} last modified"] = time
end
msg += format_report(report, 30)
msg << ''
end
report = {
"Running scripts" => Script.list.map{|x| x.name}.join(', '),
"Downstream hooks" => DownstreamHook.list.join(', '),
"Upstream hooks" => UpstreamHook.list.join(', '),
"Current threads" => Thread.list.length.to_s
}
msg += format_report(report, 20)
msg << "```"
end
if scripts_to_check.length > 0
msg << "```"
known_versions = []
unknown_versions = []
error_versions = []
if scripts_to_check.length > 20
echo "Checking the versions of #{scripts_to_check.length} scripts. This may take a moment..."
if scripts_to_check.length > 100
echo "... or several moments, depending on just how many scripts you have and the speed of your PC..."
end
end
scripts_to_check.each do |filename|
name = File::basename(filename)
name.gsub!(/\.lic$/i, '')
begin
version = get_script_version(filename)
if version
known_versions << "#{name}==#{version}"
else
unknown_versions << name
end
rescue
error_versions << name
end
end
msg << "Installed script versions: #{known_versions.join(', ')}" if known_versions.length > 0
msg << "Unknown script versions: #{unknown_versions.join(', ')}" if unknown_versions.length > 0
msg << "Failed to retrieve data for: #{error_versions.join(', ')}" if error_versions.length > 0
msg << "```"
end
if scripts_to_check.length == 0
msg << "Use `;version SCRIPT [SCRIPT2 [SCRIPT3...]]` to report the installed versions of one or more Lich scripts."
msg << "Use `;version ALL` to report the installed versions of ALL downloaded Lich scripts."
end
unless $SAFE == 0
msg << "I can report information on some of Lich's support files if you trust this script:"
msg << " #{$lich_char}trust #{script.name}"
end
respond msg