Created
November 12, 2014 23:33
-
-
Save t-mart/5f20d5e54facb12df84c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function difference(after, before) | |
return after - before | |
end | |
local function hms(seconds) | |
local hours = floor(seconds / 3600) | |
local minutes = floor((seconds % 3600) / 60) | |
local sec = floor(seconds % 60) | |
return hours, minutes, sec | |
end | |
local function stringify(value, label) | |
local s = value .. " " .. label | |
if value > 1 or value == 0 then | |
s = s .. "s" | |
end | |
return s | |
end | |
local function add_to_table_if_not_nil(t, value, label) | |
if value == 0 then | |
return false | |
else | |
table.insert(t, stringify(value, label)) | |
return true | |
end | |
end | |
local function str_hms(h, m, s) | |
local t = {} | |
add_to_table_if_not_nil(t, h, "hour") | |
add_to_table_if_not_nil(t, m, "minute") | |
add_to_table_if_not_nil(t, s, "second") | |
return table.concat(t, ", ") | |
end | |
local launch_table = { year = 2014, month = 11, day = 13, hour = 3, min = 0, sec = 0 } | |
local launch_time = time(launch_table) | |
local frame_timer = (10*60)-5 | |
local print_every = 10*60 | |
local trade_channel_id = GetChannelName("Trade - City") | |
local intro = "[timbot] {Circle} WOD LAUNCH {Circle} in " | |
local outro = "." | |
local function printLaunch(self, elapsed) | |
frame_timer = frame_timer + elapsed | |
if frame_timer >= print_every then | |
local now = time() | |
local diff = difference(launch_time, now) | |
local h, m, s = hms(diff) | |
local hms_string = str_hms(h, m, s) | |
--DEFAULT_CHAT_FRAME:AddMessage(hms_string) | |
SendChatMessage(intro .. hms_string .. outro, "CHANNEL", nil, trade_channel_id) | |
frame_timer = 0 | |
end | |
end | |
local f = CreateFrame("frame") | |
f:SetScript("OnUpdate", printLaunch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment