Cleanup, Bug fixes

Contrast_Picker
Arcidayne 9 years ago
parent ef91da2f7a
commit 8ae8f91a98

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, September 10, 2015, 11:08 PM -->
<!-- Saved on Monday, October 26, 2015, 12:46 PM -->
<!-- MuClient version 4.98 -->
<!-- Plugin "Epic_Calendar" generated by Plugin Wizard -->
<!-- Plugin "Epic_CalendarV2" generated by Plugin Wizard -->
<muclient>
<plugin
name="Epic_Calendar"
name="Epic_CalendarV2"
author="Arcidayne"
id="b14b904695ffa4f7c77ba823"
id="365b29d0ecd49b468c0c00f5"
language="Lua"
purpose="Shows upcoming Epic Runs"
purpose="Future Epic events shown right in the MUD!"
save_state="y"
date_written="2015-09-10 23:06:41"
date_written="2015-10-26 12:43:55"
requires="4.00"
version="1.0"
version="2.0"
>
</plugin>
@ -33,7 +33,7 @@
sequence="100"
>
<send>if "%1" == "" then
ColourNote("white","","======================== How To Use =======================\\n\\ngetcal &lt;if/icefall|inferno|oc|all&gt;\\n\\n===========================================================")
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>
@ -45,51 +45,56 @@
<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
-- [[Many thanks to Shaelynne for keeping everyone up-to-date with the Epic Calendars! ]]--
if async_ok then
tzrpage = async.request(tzpage, "HTTPS")
end
function date_check(dateTime)
retval, page, status, headers, full_status = tzrpage:join()
tzrpage = nil
if (os.time(os.date("!*t"))-dateTime) < 0 then
return true
else
return false
end
if status == 200 then
tzopage = json.decode(page)
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
local eastern_offset = tzopage.rawOffset+tzopage.dstOffset -- Adds the offset information together (includes Daylight Savings)
function get_tz_offset(dateTime, offset)
return eastern_offset
end
local xyear, xmonth, xday = string.match(dateTime,"(%d+)%-(%d+)%-(%d+)")
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 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 UTC_from_Eastern = os.time({year = xyear, month = xmonth, day = xday, hour = xhour or 23, min = xmin or 59, sec = 0}) + (offset*3600)
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
local UTC_time, local_time = os.time(os.date("!*t")), os.time()
local time_zone = os.difftime(local_time, UTC_time)
return os.date("%A, %B %d %Y at %I:%M%p", (utc_event_time-localoffset)) -- Should return local time of the event
end
local converted_time = UTC_from_Eastern + time_zone
return converted_time
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")
json = require 'json'
require('tprint')
local cal_output = {}
local epic_list, key, calid = "all if icefall inferno oc", "AIzaSyAHEnr8iiK42hzM21pXSbTrBIQ2ezEEUHA", ""
if string.match(epic_list, epic:lower()) then
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
@ -100,12 +105,22 @@ function get_cal(epic)
calid = "shaelynne22%40gmail.com"
end
rpage = "https://www.googleapis.com/calendar/v3/calendars/" .. calid .. "/events?key=" .. key
tzpage = "http://wwp.greenwichmeantime.com/time/scripts/clock-8/runner.php?tz=america_cayman"
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 = "+" .. 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")
tpage = async.request(tzpage, "HTTP")
else
ColourNote("async_ok check failed!")
end
retval, page, status, headers, full_status = epage:join()
@ -113,43 +128,46 @@ function get_cal(epic)
if status == 200 then
epage = json.decode(page)
else
print(status .. ": Status failed!")
end
retval, page, status, headers, full_status = tpage:join()
tpage = nil
if status == 200 then
tz_off = string.match(page,"%(GMT %-(%d):00%)")
end
if epage.items[1] then
for i = 1, #epage.items do
local starttime, summary = "", ""
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 #epage.items[i].summary < 20 then
summary = epage.items[i].summary .. string.rep(" ", 20-#epage.items[i].summary) .. "- "
else
summary = epage.items[i].summary .. "- "
if #summary < 30 then
summary = summary .. string.rep(" ", 22-#summary) .. "- "
end
if date_check(get_tz_offset(starttime, tz_off)) then
table.insert(cal_output, summary .. os.date("%A, %B %d %Y at %I:%M%p",get_tz_offset(starttime, tz_off)) .. " " .. date_note(starttime))
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","","================ Upcoming Runs (Local time) ===============\n\n" .. table.concat(cal_output,"\n") .. "\n\n===========================================================")
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","","================ Upcoming Runs (Local time) ===============\n\nNo upcoming runs for " .. epic .. "!\n\n===========================================================")
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("white", "", "======================== EpicError ========================\n\nNot a valid calendar choice (IF/Icefall, Inferno, OC, All)\n\n===========================================================")
ColourNote("cyan", "", "Epic Calendar Error: ", "white", "", "Valid choices are: IF/Icefall, Inferno, OC, All)")
end
epage, tz_off = nil, nil
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")
end
]]>
</script>

Loading…
Cancel
Save