You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
6.1 KiB

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, October 26, 2015, 12:46 PM -->
<!-- MuClient version 4.98 -->
<!-- Plugin "Epic_CalendarV2" generated by Plugin Wizard -->
<muclient>
<plugin
name="Epic_CalendarV2"
author="Arcidayne"
id="365b29d0ecd49b468c0c00f5"
language="Lua"
purpose="Future Epic events shown right in the MUD!"
save_state="y"
date_written="2015-10-26 12:43:55"
requires="4.00"
version="2.0"
>
</plugin>
<!-- Aliases -->
<aliases>
<alias
match="^edebug (on|off)$"
enabled="y"
group="EpicTracking"
regexp="y"
send_to="12"
sequence="100"
>
<send>if "%1" == "on" then
SetEpicDebug = 1
ColourNote("cyan", "", "Epic debugging on!")
else
SetEpicDebug = 0
ColourNote("cyan", "", "Epic debugging off!")
end</send>
</alias>
<alias
match="^getcal(.*?)$"
enabled="y"
group="EpicTracking"
regexp="y"
send_to="12"
sequence="100"
>
<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;")
else
get_cal(string.gsub("%1"," ",""))
end</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
function get_eastern_offset(time)
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 async_ok then
tzrpage = async.request(tzpage, "HTTPS")
end
retval, page, status, headers, full_status = tzrpage:join()
tzrpage = nil
if status == 200 then
tzopage = json.decode(page)
end
local eastern_offset = tzopage.rawOffset+tzopage.dstOffset -- Adds the offset information together (includes Daylight Savings)
return eastern_offset
end
function get_local_time(dateTime)
local xyear, xmonth, xday = string.match(dateTime, "(%d+)%-(%d+)%-(%d+)") -- Date format is displayed as yyyy-mm-dd
local xhour, xmin = string.match(dateTime, "%a(%d+):(%d+)") -- Time format is displayed as Thh:mm
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 utc_event_time = event_time-get_eastern_offset(event_time) -- Sets UTC's time for the event
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
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
return os.date("%A, %B %d %Y at %I:%M%p", (utc_event_time-localoffset)) -- Should return local time of the event
end
function date_note(dateTime)
if string.match(dateTime, "%a%d+:%d+") then
return ""
else
return "Note: No start time given, may have already ran."
end
end
function get_cal(epic)
async_ok, async = pcall (require, "async")
local cal_output = {}
local epic_list, key, calid = "all if icefall inferno oc", "AIzaSyAHEnr8iiK42hzM21pXSbTrBIQ2ezEEUHA", ""
if string.match(epic_list, epic:lower()) then
if epic:lower() == "icefall" or epic:lower() == "if" then
calid = "h8jf8vbgsl0in0nmg3vj06r9g4%40group.calendar.google.com"
elseif epic:lower() == "inferno" then
calid = "p8est01hkro1bol0bqfsvfm41o%40group.calendar.google.com"
elseif epic:lower() == "oc" then
calid = "olvq8lncvoufh24b30ml9h2mio%40group.calendar.google.com"
elseif epic:lower() == "all" then
calid = "shaelynne22%40gmail.com"
end
local offset_utc, string_offset = os.difftime(os.time(os.date("*t")), os.time(os.date("!*t"))), ""
if offset_utc < 0 then
string_offset = "-" .. string.format("%02d",(offset_utc*-1)/3600) .. ":00"
else
string_offset = "%2b" .. string.format("%02d", math.floor(offset_utc/3600)) .. ":00"
end
local timeMin = os.date("%Y-%m-%dT%I:%M:%S" .. string_offset, os.time())
rpage = "https://www.googleapis.com/calendar/v3/calendars/" .. calid .. "/events?key=" .. key .. "&timeMin=" .. timeMin
if async_ok then
epage = async.request(rpage, "HTTPS")
else
ColourNote("async_ok check failed!")
end
retval, page, status, headers, full_status = epage:join()
epage = nil
if status == 200 then
epage = json.decode(page)
else
print(status .. ": Status failed!")
end
if SetEpicDebug == 1 then
ColourNote("cyan", "", "Debugging information:\n", "white", "", "rpage: " .. rpage .. "\nstring_offset: " .. string_offset .. "\noffset_utc: " .. offset_utc .. "\ntimeMin: " .. timeMin, "cyan", "", "\nEnd of information\n")
end
if epage.items[1] then
for i = 1, #epage.items do
starttime, summary = "", epage.items[i].summary or "No summary found!"
if epage.items[i].start.date then
starttime = epage.items[i].start.date
else
starttime = epage.items[i].start.dateTime
end
if #summary < 30 then
summary = summary .. string.rep(" ", 22-#summary) .. "- "
end
end
table.insert(cal_output, summary .. get_local_time(starttime) .. date_note(starttime))
end
local header_string = " Upcoming Runs (Local time) "
if cal_output[1] then
ColourNote("white", "", string.rep("=", 16), "cyan", "", header_string, "white", "", string.rep("=", 16) .. "\n\n", "green", "", table.concat(cal_output, "\n"), "white", "", "\n\n" .. string.rep("=", 60))
else
ColourNote("white", "", string.rep("=", 16), "cyan", "", header_string, "white", "", string.rep("=", 16) .. "\n\n", "green", "", "No upcoming runs for " .. epic .. "!", "white", "", "\n\n" .. string.rep("=", 60))
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
function OnPluginInstall()
if not json then json = require 'json' end
async_ok, async = pcall (require, "async")
SetEpicDebug = 0
end
]]>
</script>
</muclient>