New feature!

Contrast_Picker
Arcidayne 9 years ago
parent 4effcd90a0
commit 3aa4ab7647

@ -15,7 +15,7 @@
save_state="y" save_state="y"
date_written="2015-10-26 12:43:55" date_written="2015-10-26 12:43:55"
requires="4.00" requires="4.00"
version="2.0" version="3.0"
> >
</plugin> </plugin>
@ -49,7 +49,7 @@
sequence="100" sequence="100"
> >
<send>if "%1" == "" then <send>if "%1" == "" then
ColourNote("cyan", "", "Epic Calendar Help: ", "white", "", "Type ", "green", "", "getcal &lt;", "darkcyan", "", "icefall", "green", "", "|", "darkcyan", "", "if", "green", "", "|", "red", "", "inferno", "green", "", "|", "blue", "", "oc", "green", "", "|", "white", "", "all", "green", "", "&gt;") ColourNote("cyan", "", "Epic Calendar Help: ", "white", "", "Type ", "green", "", "getcal &lt;", "darkcyan", "", "icefall", "green", "", "|", "darkcyan", "", "if", "green", "", "|", "red", "", "inferno", "green", "", "|", "blue", "", "oc", "green", "", "|", "magenta", "", "genie", "green", "", "|", "white", "", "all", "green", "", "|", "yellow", "", "today", "green", "", "&gt;", "gray", "", "\\n'update' will attempt to update plugin!")
else else
get_cal(string.gsub("%1"," ","")) get_cal(string.gsub("%1"," ",""))
end</send> end</send>
@ -61,38 +61,103 @@
<script> <script>
<![CDATA[ <![CDATA[
function get_eastern_offset(time) function OnPluginInstall()
tzpage = "https://maps.googleapis.com/maps/api/timezone/json?location=28.4158,-81.2989&timestamp=" .. time .. "&key=AIzaSyBv_QnejlevQTnNxF3sF-j0NxzkDLOv4fY" -- Gets offset data for Eastern Time Zone if not json then json = require 'json' end
SetEpicDebug = 0
just_today = 0
not_found = 0
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
get_eastern_offset(os.time())
epic_list = {
["icefall"] = "h8jf8vbgsl0in0nmg3vj06r9g4%40group.calendar.google.com",
["if"] = "h8jf8vbgsl0in0nmg3vj06r9g4%40group.calendar.google.com",
["inferno"] = "p8est01hkro1bol0bqfsvfm41o%40group.calendar.google.com",
["oc"] = "olvq8lncvoufh24b30ml9h2mio%40group.calendar.google.com",
["genie"] = "1a0r0briqqgei08o4tam13oi9g%40group.calendar.google.com",
["all"] = "shaelynne22%40gmail.com"
}
end
-- Update code --
function update_plugin()
local raw = "https://raw.githubusercontent.com/Arcidayne/Aardwolf-Scripts/master/Epic_Calendar/Epic_Calendar.xml"
async_ok, async = pcall (require, "async")
if async_ok then if async_ok then
tzrpage = async.request(tzpage, "HTTPS") plugin_page = async_doAsyncRemoteRequest(raw, raw_get, "HTTPS")
else
ColourNote("white", "blue", "Error on plugin update!")
end end
end
function raw_get(retval, page, status, headers, full_status, request_url)
if status == 200 then
raw_version = tonumber(string.match(page, '%s%s+version="([0-9%.]_)"'))
end
if raw_version == PLUGIN_VERSION then
ColourNote("white", "blue", PLUGIN_NAME .. " is up-to-date.")
elseif raw_version > PLUGIN_VERSION then
ColourNote("white", "blue", "Updating from version " .. PLUGIN_VERSION .. " to " .. raw_version .. ". Do not touch anything!")
local file = io.open(GetPluginInfo(GetPluginID(), 6), "w")
file:write(page)
file:close()
end
raw_version = nil
if "" == GetAlphaOption("script_prefix") then
SetAlphaOption("script_prefix", "\\\\\\")
end
Execute(GetAlphaOption("script_prefix") .. "DoAfterSpecial(1, \"ReloadPlugin('" .. GetPluginID() .. "')\", sendto.script)")
end -- end Update code
-- Get current timezone and offset --
function get_eastern_offset(time)
async_ok, async = pcall (require, "async")
tzpage = "https://maps.googleapis.com/maps/api/timezone/json?location=28.4158,-81.2989&timestamp=" .. time .. "&key=AIzaSyBv_QnejlevQTnNxF3sF-j0NxzkDLOv4fY"
retval, page, status, headers, full_status = tzrpage:join() if async_ok then
tzrpage = nil tzrpage = async.doAsyncRemoteRequest(tzpage, eastern_from_utc, "HTTPS")
end
end
function eastern_from_utc(retval, page, status, headers, full_status, request_url)
if status == 200 then if status == 200 then
tzopage = json.decode(page) tzopage = json.decode(page)
end end
local eastern_offset = tzopage.rawOffset+tzopage.dstOffset -- Adds the offset information together (includes Daylight Savings) eastern_offset = tzopage.rawOffset+tzopage.dstOffset
return eastern_offset if tonumber(eastern_offset) < 0 then
local timeflip = string.format("%02d", (eastern_offset * -1)/3600)
hour_eastern_offset = "-" .. timeflip .. ":00"
else
hour_eastern_offset = eastern_offset/3600 .. ":00"
end end
end -- end current timezone and offset code
function get_local_time(dateTime) function get_local_time(dateTime)
local xyear, xmonth, xday = string.match(dateTime, "(%d+)%-(%d+)%-(%d+)") -- Date format is displayed as yyyy-mm-dd local xyear, xmonth, xday = string.match(dateTime, "(%d+)%-(%d+)%-(%d+)")
local xhour, xmin = string.match(dateTime, "%a(%d+):(%d+)") -- Time format is displayed as Thh:mm local xhour, xmin = string.match(dateTime, "%a(%d+):(%d+)")
local event_time = os.time({year = xyear, month = xmonth, day = xday, hour = xhour or 23, min = xmin or 59, sec = 0}) -- Gets epoch time for event time local event_time = os.time({year = xyear, month = xmonth, day = xday, hour = xhour or 23, min = xmin or 59, sec = 0})
local utc_event_time = event_time-get_eastern_offset(event_time) -- Sets UTC's time for the event local utc_event_time = event_time - tonumber(eastern_offset)
local utctime, localtime = os.date("!*t", utc_event_time), os.date("*t", utc_event_time) -- Sets table data for events based on UTC's time of the event local utctime, localtime = os.date("!*t", utc_event_time), os.date("*t", utc_event_time)
localtime.isdst = false localtime.isdst = false
local localoffset = os.difftime(os.time(utctime), os.time(localtime)) -- Sets the time difference between UTC and local time at the time of the event UTC local localoffset = os.difftime(os.time(utctime), os.time(localtime))
return os.date("%A, %B %d %Y at %I:%M%p", (utc_event_time-localoffset)) -- Should return local time of the event return os.date("%A, %B %d %Y at %I:%M%p", (utc_event_time-localoffset))
end end
function date_note(dateTime) function date_note(dateTime)
@ -103,25 +168,28 @@ function date_note(dateTime)
end end
end end
-- Get calendar information functions
function get_cal(epic) function get_cal(epic)
async_ok, async = pcall (require, "async") async_ok, async = pcall (require, "async")
local key, calid = "AIzaSyAHEnr8iiK42hzM21pXSbTrBIQ2ezEEUHA", ""
local cal_output = {} epic_name = epic
local epic_list, key, calid = "all if icefall inferno oc", "AIzaSyAHEnr8iiK42hzM21pXSbTrBIQ2ezEEUHA", ""
if epic_list[epic:lower()] then
if string.match(epic_list, epic:lower()) then calid = epic_list[epic:lower()]
if epic:lower() == "icefall" or epic:lower() == "if" then elseif epic:lower() == "today" then
calid = "h8jf8vbgsl0in0nmg3vj06r9g4%40group.calendar.google.com" just_today = 1
elseif epic:lower() == "inferno" then timeMax = os.date("%Y-%m-%dT23:59:59") .. hour_eastern_offset
calid = "p8est01hkro1bol0bqfsvfm41o%40group.calendar.google.com" calid = epic_list.all
elseif epic:lower() == "oc" then elseif epic:lower() == "update" then
calid = "olvq8lncvoufh24b30ml9h2mio%40group.calendar.google.com" update_plugin()
elseif epic:lower() == "all" then else
calid = "shaelynne22%40gmail.com" not_found = 1
end end
local offset_utc, string_offset = os.difftime(os.time(os.date("*t")), os.time(os.date("!*t"))), "" if not_found == 0 then
offset_utc, string_offset = os.difftime(os.time(os.date("*t")), os.time(os.date("!*t"))), ""
if offset_utc < 0 then if offset_utc < 0 then
string_offset = "-" .. string.format("%02d", (offset_utc*-1)/3600) .. ":00" string_offset = "-" .. string.format("%02d", (offset_utc*-1)/3600) .. ":00"
@ -129,23 +197,34 @@ function get_cal(epic)
string_offset = "%2b" .. string.format("%02d", math.floor(offset_utc/3600)) .. ":00" string_offset = "%2b" .. string.format("%02d", math.floor(offset_utc/3600)) .. ":00"
end end
local timeMin = os.date("%Y-%m-%dT%H:%M:%S", os.time()) .. string_offset timeMin = os.date("%Y-%m-%dT%H:%M:%S", os.time()) .. string_offset
if just_today == 1 then
rpage = "https://www.googleapis.com/calendar/v3/calendars/" .. calid .. "/events?key=" .. key .. "&timeMin=" .. timeMin .. "&timeMax=" .. timeMax
just_today = 0
else
rpage = "https://www.googleapis.com/calendar/v3/calendars/" .. calid .. "/events?key=" .. key .. "&timeMin=" .. timeMin rpage = "https://www.googleapis.com/calendar/v3/calendars/" .. calid .. "/events?key=" .. key .. "&timeMin=" .. timeMin
end
if async_ok then if async_ok then
epage = async.request(rpage, "HTTPS") epage = async.doAsyncRemoteRequest(rpage, get_results, "HTTPS")
else
ColourNote("white", "blue", "Epic Calendar Error: Please try again. If problem persists, please contact Arcidayne.")
end
else else
ColourNote("async_ok check failed!") ColourNote("cyan", "", "Epic Calendar Error: ", "white", "", "Valid choices are: IF/Icefall, Inferno, OC, Genie, All, Today")
epage, starttime, summary, not_found = nil, nil, nil, 0
end end
end
function get_results(retval, page, status, headers, full_status, request_url)
retval, page, status, headers, full_status = epage:join() local cal_output = {}
epage = nil
if status == 200 then if status == 200 then
epage = json.decode(page) epage = json.decode(page)
else else
print(status .. ": Status failed!") ColourNote("white", "blue", "Epic Calendar Error: Status failed with code: " .. status .. ". Please try again. If problem persists, please contact Arcidayne.")
end end
if SetEpicDebug == 1 then if SetEpicDebug == 1 then
@ -170,7 +249,7 @@ function get_cal(epic)
end end
end end
else else
ColourNote("cyan", "", "Epic Calendar Error! Something went very wrong trying to get the epage. Let Arcidayne know!") ColourNote("cyan", "", "Epic Calendar Error: Something went very wrong trying to get the epage. Let Arcidayne know!")
end end
local header_string = " Upcoming Runs (Local time) " local header_string = " Upcoming Runs (Local time) "
@ -178,20 +257,9 @@ function get_cal(epic)
if cal_output[1] then if cal_output[1] then
ColourNote("white", "", string.rep("=", 18), "cyan", "", header_string, "white", "", string.rep("=", 18) .. "\n\n", "green", "", table.concat(cal_output, "\n"), "white", "", "\n\n" .. string.rep("=", 64)) ColourNote("white", "", string.rep("=", 18), "cyan", "", header_string, "white", "", string.rep("=", 18) .. "\n\n", "green", "", table.concat(cal_output, "\n"), "white", "", "\n\n" .. string.rep("=", 64))
else else
ColourNote("white", "", string.rep("=", 18), "cyan", "", header_string, "white", "", string.rep("=", 18) .. "\n\n", "green", "", "No upcoming runs for " .. epic .. "!", "white", "", "\n\n" .. string.rep("=", 64)) ColourNote("white", "", string.rep("=", 18), "cyan", "", header_string, "white", "", string.rep("=", 18) .. "\n\n", "green", "", "No upcoming runs for " .. epic_name .. "!", "white", "", "\n\n" .. string.rep("=", 64))
end
else
ColourNote("cyan", "", "Epic Calendar Error: ", "white", "", "Valid choices are: IF/Icefall, Inferno, OC, All)")
end
epage, starttime, summary, cal_output = nil, nil, nil, nil
end end
function OnPluginInstall()
if not json then json = require 'json' end
async_ok, async = pcall (require, "async")
SetEpicDebug = 0
end end
]]> ]]>
</script> </script>

Loading…
Cancel
Save