forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moonwatch.lic
149 lines (123 loc) · 5.4 KB
/
moonwatch.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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#moonwatch
=end
custom_require.call(%w(common))
arg_definitions = [
[
{ name: 'debug', regex: /debug/i, optional: true },
{ name: 'alias', regex: /alias/i, optional: true, description: 'Add an alias for the command moon that will display moon status.' },
{ name: 'window', regex: /window/i, optional: true, description: 'Toggle a window for the moon status.' },
{ name: 'correct', regex: /correct/i, optional: true, description: 'Set up a moonbot to deal with new moons' }
]
]
args = parse_args(arg_definitions)
$debug_mode_mm = UserVars.moon_debug || args.debug
enable_moon_connection
pause 3
if args.alias
UpstreamHook.run("<c>#{$clean_lich_char}alias add --global moon = #{$clean_lich_char}eq respond(\"#{UserVars.moons['katamba']['pretty']} : #{UserVars.moons['yavash']['pretty']} : #{UserVars.moons['xibar']['pretty']}\")")
end
CharSettings['moon_window'] = !CharSettings['moon_window'] if args.window
UserVars.moons = { 'katamba' => {}, 'yavash' => {}, 'xibar' => {}, 'visible' => [] }
UserVars.sun = {}
Settings['xibar'] ||= Time.now
Settings['yavash'] ||= Time.now
Settings['katamba'] ||= Time.now
Settings['rise'] = {}
Settings['rise']['yavash'] = 175 * 60
Settings['rise']['xibar'] = 172 * 60
Settings['rise']['katamba'] = 174 * 60
# Time until moon sets after rising
Settings['set'] = {}
Settings['set']['yavash'] = 177 * 60
Settings['set']['xibar'] = 174 * 60
Settings['set']['katamba'] = 177 * 60
if CharSettings['moon_window']
_respond("<streamWindow id='moonWindow' title='Moons' location='center' save='true' />")
_respond("<exposeStream id='moonWindow'/>")
CharSettings['moon_window_cache'] = nil
end
def check_for_new_moons
UserVars.moons.each do |moon, data|
next if moon == 'visible' || data['timer'] >= 0
set = 'should rise' == DRC.bput("perc #{moon}", 'should rise', 'roundtime')
moon_change(moon, !set) if data[(set ? 'set' : 'rise')]
waitrt?
end
end
def update_moon_window
new_message = [UserVars.moons['katamba']['short'], UserVars.moons['yavash']['short'], UserVars.moons['xibar']['short']].join(' ')
return if CharSettings['moon_window_cache'] == new_message
CharSettings['moon_window_cache'] = new_message
_respond("<clearStream id=\"moonWindow\"/>\r\n")
_respond("<pushStream id=\"moonWindow\"/> #{new_message}<popStream/>\r\n")
end
def moon_change(moon, is_up)
echo("moon_change #{moon}:#{is_up}") if $debug_mode_mm
snapshot = Time.now
snapshot = (snapshot - snapshot.sec).utc.to_s
update_moon_data(moon, 'time' => snapshot, 'event' => is_up ? 'rise' : 'set')
end
def minutes_apart(first, second)
((first - second) / 60).to_i
end
def minutes_to_next_sun_event(past, current)
delta = minutes_apart(current, past)
360 - delta - minutes_apart(Time.now, current)
end
def update_sun_info(latest_data)
return if latest_data.nil? || latest_data.empty?
sun_data = latest_data['sun']
set_time = Time.parse(sun_data['set']).localtime
rise_time = Time.parse(sun_data['rise']).localtime
if set_time > rise_time
UserVars.sun['day'] = false
UserVars.sun['night'] = true
UserVars.sun['timer'] = minutes_to_next_sun_event(rise_time, set_time)
else
UserVars.sun['day'] = true
UserVars.sun['night'] = false
UserVars.sun['timer'] = minutes_to_next_sun_event(set_time, rise_time)
end
end
def update_moon_info(latest_data)
return if latest_data.nil? || latest_data.empty?
%w(katamba yavash xibar).each do |moon|
data = latest_data[moon]
event = data['event']
coming_event = (%w(rise set) - [event]).first
snapshot = Time.parse(data['time']).localtime
UserVars.moons[moon].delete(event)
UserVars.moons[moon][coming_event] = snapshot + Settings[coming_event][moon]
UserVars.moons[moon]['timer'] = minutes_apart(UserVars.moons[moon][coming_event], Time.now)
if event == 'rise'
UserVars.moons[moon]['pretty'] = "#{moon} is up for #{UserVars.moons[moon]['timer']} minutes"
UserVars.moons[moon]['short'] = "[#{moon[0]}]+(#{UserVars.moons[moon]['timer']})"
UserVars.moons['visible'].push(moon) unless UserVars.moons['visible'].include?(moon)
else
UserVars.moons[moon]['pretty'] = "#{moon} will rise in #{UserVars.moons[moon]['timer']} minutes"
UserVars.moons[moon]['short'] = "[#{moon[0]}]-(#{UserVars.moons[moon]['timer']})"
UserVars.moons['visible'].delete(moon) if UserVars.moons['visible'].include?(moon)
end
end
end
loop do
line = script.gets?
case line
when /^(Katamba|Xibar|Yavash) sets/
moon_change(Regexp.last_match(1).downcase, false)
when /^(Katamba|Xibar|Yavash) slowly rises/
moon_change(Regexp.last_match(1).downcase, true)
when /heralding another fine day|rises to create the new day|as the sun rises, hidden|as the sun rises behind it|faintest hint of the rising sun|The rising sun slowly/
old = get_all_moon_data['sun']
update_moon_data('sun', 'set' => old['set'], 'rise' => Time.now.utc.to_s)
when /The sun sinks below the horizon|night slowly drapes its starry banner|sun slowly sinks behind the scattered clouds and vanishes|grey light fades into a heavy mantle of black/
old = get_all_moon_data['sun']
update_moon_data('sun', 'rise' => old['rise'], 'set' => Time.now.utc.to_s)
end
update_moon_info(get_all_moon_data)
update_sun_info(get_all_moon_data)
update_moon_window if CharSettings['moon_window']
check_for_new_moons if args.correct
pause 0.1 unless line
end