-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxraffle.lic
777 lines (695 loc) · 27.9 KB
/
xraffle.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
=begin
Raffle tracking script. Experimental.
Basic usage:
;xraffle Add nearby raffles and show the list
;xraffle list Detailed list, in a similar style to ;traffle
;xraffle brief Abbreviated list that fits many raffles in little space
;xraffle soon Only show raffles that recently drew or draw within the next hour
;xraffle full Show all raffles, including those that drew days ago
Many more options and features including tools for Wiki editors, see ;xraffle help.
author: LostRanger (thisgenericname@gmail.com)
game: GS
tags: utility
required: Lich >= 4.6.0.
version: 0.1.1 (2019-10-20)
changelog:
version 0.1.2 (2019-10-20)
* Fix ;xraffle brief not respecting any options
version 0.1.1 (2019-10-20)
* Remove accidental debug code when using the 'est' option
version 0.1 (2019-10-20)
* Initial release.
=end
module XRaffleScript
VERSION = '0.1.1 (2019-10-20)'
VERSION_INT = 1_001
CONFIG_VERSION = 1
PATTERNS = {
# $1 = Item desc w/ XML still $2 = exist ID
:raffle_where => /^You look on (.*<a exist="(-?\d+)"[^>]+>.*) and see|^What were you referring to/,
# $1 = Description
:raffle_for => /^The raffle is for "(.*)\"./,
# $1 = ticket cost $2 = currency
:raffle_cost => /^The tickets sell for (\d+) (.*) each/,
# $1 = time in hours $2 = time in minutes $3 = # of winners
:raffle_time => /^The drawing will be in (?:(\d+) hours and )?(\d+) minutes for (\d+) winner/,
:raffle_winner_start => /^The drawing has been held with the following winner/,
:raffle_winner_name => /^ ([A-Z][a-z]+)\s*$/,
}
def self.anon_hook(prefix = '')
now = Time.now
"XRaffle::#{prefix}-#{now.tv_sec}.#{now.tv_usec}-#{Random.rand(10000)}"
end
def self.cleanup
[DownstreamHook, UpstreamHook].each{|provider|
provider.list.find_all{|name| name.start_with?('XRaffle::')}.each{|name| provider.remove(name)}
}
end
def self.send(what)
unless $fake_stormfront
return _respond(what)
end
unless what.is_a?(Array)
what = [what]
end
return _respond what.map{|line|
if line =~ /^\s*<\/?output[^>]*>$/
nil
else
line = line.gsub(/<preset.*?>(.*?)<\/preset>/, "\\1")
line.gsub!('<pushBold/>', monsterbold_start)
line.gsub!('<popBold/>', monsterbold_end)
line.gsub!(/<\/?d.*?>/, '')
line
end
}.keep_if{|x| x}
end
def self.send_formatted(msg, mono=true)
unless $fake_stormfront
msg = REXML::Text.new(msg, respect_whitespace: true).to_s
msg.gsub!(/\*\*(.*?)\*\*/, '<preset id="whisper">\1</preset>')
msg = "<output class=\"mono\" />\n#{msg}\n<output class=\"\" />" if mono
puts msg
else
msg.gsub!('**', '')
respond msg
end
end
def self.send_help_formatted(msg)
unless $fake_stormfront
msg = REXML::Text.new(msg, respect_whitespace: true).to_s
msg.gsub!(/\*\*(.*?)\*\*/, '<preset id="whisper">\1</preset>')
msg.gsub!(/`(.*?)`/, '<preset id="speech">\1</preset>')
msg.gsub!("#{name} help", "</preset><d cmd=\"#{name} help\">#{name} help</d><preset id=\"whisper\">")
puts "<output class=\"mono\" />\n#{msg}\n<output class=\"\" />"
else
msg.gsub!('**', '')
msg.gsub!('`', '')
respond msg
end
end
def self.show_changelog
prev = GameSettings[:current_version] || 0
changelog = {
1_001 => [
"Version 0.1.1:",
'',
" * Remove accidental debugging code that would spam timestamps when using the 'est' option.",
],
}
if prev != VERSION_INT
msg = []
msg << "<preset id='speech'>--------------------</preset>"
msg << "<preset id='speech'>Welcome to #{$lich_char}#{@script.name}</preset> <preset id='whisper'>#{VERSION}</preset>"
msg << ''
changelog.each do |version, notes|
if version > prev or version == VERSION_INT
msg << "<preset id='whisper'>#{notes[0]}</preset>"
msg += notes[1..-1]
msg << ''
end
end
msg << '<output class="mono" />'
msg << "For a more detailed changelog: <d>#{$lich_char}repo info #{@script.name}</d>."
msg << "To enable automatic updates: <d>#{$lich_char}repo set-updatable #{@script.name}</d>`."
msg << "For details on new features: <d>#{$lich_char}#{@script.name} help</d>"
msg << "For more LostRanger scripts: https://bit.ly/lostranger-scripts"
msg << '<output class="" />'
msg << ''
msg << "This message will only be displayed once unless a new version is downloaded."
msg << "<preset id='speech'>--------------------</preset>"
send msg
GameSettings[:current_version] = VERSION_INT
sleep 1.5
end
end
def self.show_help
name = "#{$lich_char}#{@script.name}"
msg = []
msg << "**This is #{@script.name} version #{VERSION}**"
msg << "**Usage:**"
msg << " Options denoted with a * may renumber the raffle list."
msg << " * `#{name}`"
msg << " Display all known raffles, and add or update all raffles in the current room."
msg << " * `#{name} quiet`"
msg << " Add or update all raffles in the current room. Does not show details."
msg << " `#{name} list` [OPTIONS]"
msg << " Display all known raffles."
msg << " `#{name} brief` [OPTIONS]"
msg << " Display all known raffles in an abbreviated format."
msg << " `#{name} show` NUMBER"
msg << " Show information on raffle with specified number."
msg << " The word `show` is optional."
msg << " `#{name} search` PATTERN"
msg << " Find raffles that match the specified PATTERN. (PATTERN is a regular expression.)"
msg << " * `#{name} delete` NUMBER"
msg << " Delete the raffle with specified number."
msg << " * `#{name} clean`"
msg << " Remove all completed raffles (except for those that ended within the last 5 minutes.)"
msg << " * `#{name} reset`"
msg << " Remove all raffles."
msg << " * `#{name}` table/shelf/credenza/etc."
msg << " Add just the specified raffle. Partial matches are permitted ('tab' matches a table)"
msg << " `#{name} wiki`"
msg << " Dump output suitable for generating a wiki table of raffles."
msg << " **NOTE:** This option has some technical requirements and may be unavailable on your system."
msg << "**Options**:"
msg << " `REVERSE` - Show raffles in reverse order (oldest last)"
msg << " `SOON` - Show raffles that recently ended or draw within one hour."
msg << " `FULL` - Show all raffles, including completed ones."
msg << " `EST` - Force all displayed timezones to EST, even if you are not EST."
msg << " **NOTE:** This option has some technical requirements and may be unavailable on your system."
msg << ""
msg << " REVERSE and EST may be combined with other options."
msg << " Example: `#{name} SOON REVERSE`"
msg << ""
msg << " `#{name} OPTION` is equivalent to `#{name} list OPTION`"
msg << " Example: `#{name} SOON`"
return send_help_formatted(msg.join("\n"))
end
def self.quiet_command(command, start_pattern, end_pattern = /<prompt/, include_end = true, timeout=5)
result = []
name = self.anon_hook
filter = false
begin
Timeout::timeout(timeout, Interrupt) {
DownstreamHook.add(name, proc {|xml|
if filter
if xml =~ end_pattern
DownstreamHook.remove(name)
filter = false
# result << xml.rstrip if include_end
# thread.raise(Interrupt)
# next(include_end ? nil : xml)
else
# result << xml.rstrip
next(nil)
end
elsif xml =~ start_pattern
filter = true
# result << xml.rstrip
next(nil)
else
xml
end
})
fput command
until (xml = get) =~ start_pattern; end
result << xml.rstrip
until (xml = get) =~ end_pattern
result << xml.rstrip
end
if include_end
result << xml.rstrip
end
}
rescue Interrupt
nil
end
return result
end
def self.format_timedelta(delta)
return "COMPLETED" if delta <= -30
return "IMMINENT" if delta <= 60
delta = (delta / 60).to_i
h, m = delta.divmod(60)
d, h = h.divmod(24)
return "#{d}d,#{h.to_s.rjust(2,'0')}h#{m.to_s.rjust(2,'0')}m" if d > 0
return "#{h}h#{m.to_s.rjust(2,'0')}m" if h > 0
return "#{m}m"
end
def self.format_commas(n)
return n.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
end
def self.text(t)
if $fake_stormfront
return t
else
return REXML::Text.new(t, respect_whitespace: true).to_s
end
end
def self.pretty_room_number(n, pad=nil)
return "????".just(pad) unless n
n = n.to_s
if pad
pad -= 1
if pad > n.length
pad = ' '*(pad - n.length)
else
pad = ''
end
else
pad = ''
end
if $fake_stormfront
return "#{pad}##{n}"
else
return "#{pad}<d cmd=';go2 #{n}'>##{n}</d>"
end
end
def self.format_brief(raffle)
result = []
ttl = format_timedelta(raffle[:time] - Time.now)
time = raffle[:time].strftime("%a, %b %d %I:%M %P")
result << text("#{(raffle[:index]+1).to_s.rjust(3)}. #{ttl.rjust(10)} at #{time} ")
result << pretty_room_number(raffle[:room_id], 8)
result << text(" #{raffle[:room_title]} on #{raffle[:location]}")
result << "\n"
desc = raffle[:for].dup
desc.strip!
desc.gsub!(/^(?:This raffle is|a raffle|The winners? of this raffle will be able )/i, '')
desc.gsub!(/^for /, '')
desc = desc[0..74] + "[...]" if desc.length > 80
result << text(" #{format_commas(raffle[:cost])} #{raffle[:currency]}/#{raffle[:winners]} winner")
result << 's' if raffle[:winners] != 1
result << text(": \"#{desc}\"")
result << "\n"
return result.join
end
def self.format_full(raffle)
result = []
ttl = format_timedelta(raffle[:time] - Time.now)
time = raffle[:time].strftime("%A, %B %d %Y at %I:%M %P")
result << "##{raffle[:index]+1} #{time} (#{ttl})\n"
result << text(raffle[:room_title])
if raffle[:room_id]
result << " Room "
result << pretty_room_number(raffle[:room_id])
else
result << " Unknown Room \#"
end
result << "\nTicket cost: "
result << text("#{format_commas(raffle[:cost])} #{raffle[:currency]} | Winners: ")
result << "#{raffle[:winners]}\nLocated on: "
result << text(raffle[:location])
result << "\n"
result << text("\"#{raffle[:for]}\"")
result << "\n"
if raffle[:winner_names] and raffle[:winner_names].length > 0
result << "Won by: #{raffle[:winner_names].join(', ')}\n"
end
return result.join
end
def self.format_all_full(raffles, updated=nil)
msg = []
raffles.each do |raffle|
desc = format_full(raffle)
desc = "#{monsterbold_start}#{desc}#{monsterbold_end}" if (updated and updated.include?(raffle))
msg << desc
end
return msg.join("\n")
end
def self.format_all_brief(raffles, updated=nil)
msg = []
msg << '<output class="mono" />' unless $fake_stormfront
raffles.each do |raffle|
desc = format_brief(raffle)
desc = "#{monsterbold_start}#{desc}#{monsterbold_end}" if (updated and updated.include?(raffle))
msg << desc
end
msg << '<output class="" />' unless $fake_stormfront
return msg.join("\n")
end
def self.run(script)
@script = script
@script.want_downstream = false
@script.want_downstream_xml = true
show_changelog
GameSettings['raffles'] ||= []
@raffles = GameSettings['raffles']
raffles = @raffles
cmd, args = @script.vars[0].strip.split(/\s+/, 2)
updated = []
if cmd and cmd != ''
cmd.downcase!
else
updated = merge_raffles(get_raffles) if GameObj.loot.find{|x| x.name =~ /\braffle\b/ }
cmd = 'list'
args = nil
end
if cmd =~ /^\d+$/
args = cmd
cmd = 'show'
end
if cmd =~ /^(?:r|reverse|s|soon|f|full|e|est)$/i
if args
args += " #{cmd}"
else
args = cmd
end
cmd = 'list'
end
case cmd
when 'quiet', 'q'
updated = merge_raffles(get_raffles) if GameObj.loot.find{|x| x.name =~ /\braffle\b/ }
if updated
echo "Added/updated #{updated.length} raffles."
end
exit
when 'list', 'l', 'ls', 'brief', 'b'
raffles = @raffles
args = '' unless args
reversed = (args =~ /\br(?:eversed?)?\b/i)
full = (args =~ /\bf(?:ull)?\b/i)
soon = (args =~ /\bs(?:oon)?\b/i)
est = (args =~ /\be(?:st)?\b/i)
if est
require_tzinfo
est = TZInfo::Timezone.get('America/New_York')
raffles = raffles.map{|x|
x = x.dup
x[:time] = est.to_local(x[:time])
x
}
end
if full
raffles = raffles.reverse if reversed
else
after = Time.now - 300
if args =~ /\bs(?:oon)?\b/i
before = Time.now + 3600
raffles = raffles.find_all{|x| after <= x[:time] and x[:time] <= before}
else
raffles = raffles.find_all{|x| after <= x[:time]}
end
raffles.reverse! if reversed
end
if raffles.length == 0
if full
echo "There are no known raffles."
elsif soon
echo "No known raffles are drawing soon."
else
echo "There are no upcoming raffles."
end
exit
end
if cmd[0] == 'l'
_respond format_all_full(raffles, updated)
else
_respond format_all_brief(raffles, updated)
end
when 'clean'
t = Time.now - 300
n = @raffles.length
@raffles.delete_if{|x| x[:time] < t}
n -= @raffles.length
if n == 0
echo "No completed raffles were found."
elsif n == 1
echo "Cleaned 1 completed raffle."
else
echo "Cleaned #{n} completed raffles."
end
sort_raffles
when 'reset'
@raffles.clear
echo "Removed all raffles."
when 'show'
unless args
echo "Show details on which raffle? Use `#{$lich_char}#{@script.name} brief` for a list of all raffles."
exit
end
args = args.to_i - 1
if args < 0 or args >= @raffles.length
echo "Invalid raffle #. Valid range is 1 to #{@raffles.length}"
end
_respond format_full(@raffles[args])
exit
when 'del', 'delete'
unless args
echo "Delete which raffle? Use `#{$lich_char}#{@script.name} brief` for a list of all raffles."
exit
end
args = args.to_i - 1
if args < 0 or args >= @raffles.length
echo "Invalid raffle #. Valid range is 1 to #{@raffles.length}"
end
@raffles.delete_at(args)
sort_raffles
echo "Deleted raffle ##{args+1}"
exit
when 'help'
show_help
when 'search'
unless args
echo "Search for what?"
exit
end
pattern = /#{args}/i
raffles = @raffles.find_all{|x| x[:for] =~ pattern}
if raffles.length == 0
echo "No matching raffles found."
else
_respond format_all_full(raffles)
end
when 'wiki'
respond wikify_raffles(@raffles)
else
pattern = @script.vars[0].downcase
if GameObj.loot.find{|x| x.name =~ /\braffle\b/ }
raffles = get_raffles.find_all{|x| x[:location].downcase.include?(pattern)}
unless raffles.length > 0
echo "Found no nearby raffles on a container matching '#{pattern}'"
echo "Maybe you want: `#{$lich_char}#{@script.name} help`?"
exit
end
merge_raffles(raffles)
else
echo "Found no nearby raffles on a container matching '#{pattern}'"
echo "Maybe you want: `#{$lich_char}#{@script.name} help`?"
exit
end
end
end
def self.strip_xml(xml)
line = xml.gsub(/<[^>]+>/, '')
line.gsub!('>', '>')
line.gsub!('<', '<')
return line
end
def self.describe_raffle(raffle)
return format_brief(raffle)
end
def self.merge_raffles(input)
updated = []
input.each do |raffle|
merged = false
@raffles.each_with_index do |orig, index|
# Must be same room title
next unless orig[:room_title] == raffle[:room_title]
# Must be same raffle table/shelf/etc
next unless orig[:location] == raffle[:location]
# Must be same cost and winner count
next unless orig[:cost] == raffle[:cost]
next unless orig[:winners] == raffle[:winners] or raffle[:winners].nil?
if raffle[:time]
next unless orig[:time] # Can't go from having won to having time remaining
next if (orig[:time] - raffle[:time]).abs > 100 # Too far apart
end
# Probably the same, but catch some subtle cues.
merge_issues = []
if (raffle[:room_id] and orig[:room_id] and raffle[:room_id] != orig[:room_id])
merge_issues << "appear to be in different rooms (##{orig[:room_id]} != ##{raffle[:room_id]})"
end
if raffle[:for] != orig[:for]
merge_issues << "have different descriptions"
end
if merge_issues.length > 0
msg = [
describe_raffle(orig), "\n", describe_raffle(raffle)
]
msg << "These two raffles look very similar, but they #{merge_issues.join(' and' )}."
msg << "Are these the same raffle? ;send yes if they are, ;send no if they are not."
toggle_unique
_respond msg
nil until (line = get) =~ /^\s*(yes|no)\s*$/i
# break if line =~ /^\s*(yes|no)\s*$/i
# end
toggle_unique
next unless $1.downcase == 'yes'
end
merged = true
# Update the raffle
orig[:room_id] = raffle[:room_id] if raffle[:room_id]
orig[:time] = raffle[:time] if raffle[:time] < orig[:time] or orig[:time].nil?
orig[:winners] = raffle[:winners] if raffle[:winners]
orig[:winner_names] = raffle[:winner_names] if raffle[:winner_names]
# orig[:time] = min(raffle[:time], orig[:time]) if raffle[:time]
orig[:for] = raffle[:for]
updated << orig
break
end
unless merged
# raffle[:time] ||= Time.now-100 # TODO REMOVE ME -- temporarily to force completed raffles to be added.
next unless raffle[:time] # Don't add completed raffles, even though we'll update them.
raffle = raffle.dup
raffle[:index] = @raffles.length
@raffles << raffle
updated << raffle
end
end
sort_raffles
return updated
end
def self.sort_raffles
@raffles.sort! do |a, b|
d = a[:time] <=> b[:time]
next d unless d == 0
next a[:index] <=> b[:index]
end
@raffles.each_with_index{|r,i| r[:index] = i}
end
def self.get_raffles
data = self.quiet_command("gaze ticket", PATTERNS[:raffle_where])
raffles = []
raffle = nil
data.each do |line|
if line =~ PATTERNS[:raffle_where] and $1
raffles << raffle if raffle
raffle = {
:room_id => Room.current.id,
:room_title => XMLData.room_title,
:location => strip_xml($1),
:exist => $2,
}
elsif line =~ PATTERNS[:raffle_for]
raffle[:for] = $1
elsif line =~ PATTERNS[:raffle_cost]
raffle[:cost] = $1.to_i
raffle[:currency] = $2
elsif line =~ PATTERNS[:raffle_time]
if $2
t = Time.now
t += ($2.to_i) * 60
t += ($1.to_i) * 3600 if $1
t -= t.sec # Round to earliest minute since we can't get per-second resolution
raffle[:time] = t
raffle[:winners] = $3.to_i
else
raffle[:time] = nil # Raffle drew already
raffle[:winners] = nil
end
elsif line =~ PATTERNS[:raffle_winner_start]
raffle[:winner_names] = []
elsif line =~ PATTERNS[:raffle_winner_name] and raffle[:winner_names]
raffle[:winner_names] << $1
end
end
raffles << raffle if raffle
return raffles
end
def self.require_tzinfo
unless $SAFE == 0
echo "This function requires that this script is trusted."
return false
end
begin
Gem.clear_paths if Gem
require 'tzinfo'
rescue ScriptError
self.install_dep('tzinfo', 'in order to convert timezones to EST for the wiki')
Gem.clear_paths if Gem
require 'tzinfo'
end
begin
Gem.clear_paths if Gem
require 'tzinfo/data'
return true
rescue ScriptError
self.install_dep('tzinfo-data', 'in order to convert timezones to EST for the wiki')
Gem.clear_paths if Gem
require 'tzinfo/data'
end
return true
end
def self.wikify_raffles(raffles)
exit unless require_tzinfo
est = TZInfo::Timezone.get('America/New_York')
# Headers
msg = []
msg << "{|class=\"wikitable sortable\" {{prettytable}}\n"
msg << "!style=\"width: 32%;\"| '''ITEM'''\n"
msg << "!style=\"width: 8%;\"| '''RAFFLE DRAW TIME'''\n"
msg << "!style=\"width: 8%;\"| '''TICKET PRICE'''\n"
msg << "!style=\"width: 8%;\"| '''LOCATION'''\n"
msg << "!style=\"width: 10%;\"|'''WON BY'''\n"
raffles.each do |raffle|
time = est.to_local(raffle[:time]).strftime("%a, %b %d %I:%M %P")
msg << "|- style=\"vertical-align:top\"\n"
msg << "| <nowiki>#{raffle[:for]}</nowiki>"
msg << " '''#{raffle[:winners]} winners'''" if raffle[:winners] > 1
msg << " || #{time} || #{format_commas(raffle[:cost])} #{raffle[:currency]} || <nowiki>#{raffle[:room_title]}</nowiki>"
msg << " ''##{raffle[:room_id]}''" if raffle[:room_id]
msg << " || "
msg << raffle[:winner_names].join('<br />') if raffle[:winner_names]
msg << "\n"
end
msg << "\n"
return msg.join
end
def self.install_dep(package, reason)
name = Script.current.name
line = '-'*50
msg = []
msg << line
msg << "#{name} requires the '#{package}' RubyGem #{reason}."
msg << ''
unless RUBY_VERSION =~ /^(\d+)\.(\d+)/
msg << "It is not able to automatically install it because it cannot determine what version of Ruby you are running."
msg << "The automatic install requires Ruby 2.4 or later. Your current version is listed as #{RUBY_VERSION.inspect}"
msg << ''
msg << "Please update your Ruby install and/or install #{package} manually, then try again."
msg << line
respond msg
exit
end
major = $1.to_i
minor = $2.to_i
unless Gem
msg << "'Gem' does not appear to be available."
msg << ''
msg << "Please update your Ruby install, install gem, or install #{package} manually, then try again."
msg << line
respond msg
exit
end
warning = nil
if major == 2
if minor < 4
warning = "Your version of Ruby (#{RUBY_VERSION}) is probably too old for automatic installation to succeed."
end
elsif major < 2
warning = "Your version of Ruby (#{RUBY_VERSION}) is too old for Lich(!) much less this script."
else
warning = "Your version of Ruby (#{RUBY_VERSION}) is too new and exotic, and the outcome of automatic installation is not guaranteed."
end
if warning
msg << warning
msg << "If you want to attempt automatic installation anyways:"
else
msg << "If you want to attempt automatic installation:"
end
msg << " #{$lich_char}unpause #{name}"
msg << ''
msg << "Otherwise:"
msg << " #{$lich_char}kill #{name}"
msg << line
respond msg
pause_script
echo "Installing #{package}. This may take a minute..."
Gem.install(package, verbose: true)
Gem.clear_paths
end
end
# if EXPERIMENTAL_EXPIRES
# if EXPERIMENTAL_EXPIRES > Time.now
# echo "** This is an EXPERIMENTAL foreach build. It should be updated by #{EXPERIMENTAL_EXPIRES}."
# else
# echo "** This is an OUTDATED EXPERIMENTAL foreach build. It should probably have been updated by now. It expired at#{EXPERIMENTAL_EXPIRES}."
# echo "You can still use it, but you may encounter bugs and minor annoyances."
# sleep 2 # Minor annoyances.
# end
# end
#
XRaffleScript.run(script)