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.
272 lines
8.3 KiB
272 lines
8.3 KiB
9 years ago
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||
|
<!DOCTYPE muclient>
|
||
9 years ago
|
<!-- Saved on Monday, October 26, 2015, 12:46 PM -->
|
||
9 years ago
|
<!-- MuClient version 4.98 -->
|
||
|
|
||
9 years ago
|
<!-- Plugin "Epic_CalendarV2" generated by Plugin Wizard -->
|
||
9 years ago
|
|
||
|
<muclient>
|
||
|
<plugin
|
||
9 years ago
|
name="Epic_CalendarV3"
|
||
9 years ago
|
author="Arcidayne"
|
||
9 years ago
|
id="365b29d0ecd49b468c0c00f5"
|
||
9 years ago
|
language="Lua"
|
||
9 years ago
|
purpose="Future Epic events shown right in the MUD!"
|
||
9 years ago
|
save_state="y"
|
||
9 years ago
|
date_written="2015-10-26 12:43:55"
|
||
9 years ago
|
requires="4.90"
|
||
|
version="3.1"
|
||
9 years ago
|
>
|
||
|
|
||
|
</plugin>
|
||
|
|
||
|
|
||
|
<!-- Aliases -->
|
||
|
|
||
|
<aliases>
|
||
9 years ago
|
<alias
|
||
9 years ago
|
match="^edebug (on|off)$"
|
||
9 years ago
|
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>
|
||
9 years ago
|
<alias
|
||
|
match="^getcal(.*?)$"
|
||
|
enabled="y"
|
||
|
group="EpicTracking"
|
||
|
regexp="y"
|
||
|
send_to="12"
|
||
|
sequence="100"
|
||
|
>
|
||
|
<send>if "%1" == "" then
|
||
9 years ago
|
ColourNote("cyan", "", "Epic Calendar Help: ", "white", "", "Type ", "green", "", "getcal <", "darkcyan", "", "icefall", "green", "", "|", "darkcyan", "", "if", "green", "", "|", "red", "", "inferno", "green", "", "|", "blue", "", "oc", "green", "", "|", "magenta", "", "genie", "green", "", "|", "white", "", "all", "green", "", "|", "yellow", "", "today", "green", "", ">", "gray", "", "\\n'update' will attempt to update plugin!")
|
||
9 years ago
|
else
|
||
|
get_cal(string.gsub("%1"," ",""))
|
||
|
end</send>
|
||
9 years ago
|
</alias>
|
||
|
</aliases>
|
||
|
|
||
|
<!-- Script -->
|
||
|
|
||
|
|
||
|
<script>
|
||
|
<![CDATA[
|
||
9 years ago
|
function OnPluginInstall()
|
||
|
if not json then json = require 'json' end
|
||
|
SetEpicDebug = 0
|
||
|
just_today = 0
|
||
|
not_found = 0
|
||
9 years ago
|
update_only = 0
|
||
9 years ago
|
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()
|
||
9 years ago
|
raw = "https://raw.githubusercontent.com/Arcidayne/Aardwolf-Scripts/master/Epic_Calendar/Epic_Calendar.xml"
|
||
9 years ago
|
|
||
|
async_ok, async = pcall (require, "async")
|
||
9 years ago
|
|
||
9 years ago
|
if async_ok then
|
||
9 years ago
|
plugin_page = async.doAsyncRemoteRequest(raw, raw_get, "HTTPS")
|
||
9 years ago
|
else
|
||
|
ColourNote("white", "blue", "Error on plugin update!")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function raw_get(retval, page, status, headers, full_status, request_url)
|
||
|
if status == 200 then
|
||
9 years ago
|
raw_version = tonumber(string.match(page, '%s%s+version="([0-9%.]+)"'))
|
||
9 years ago
|
end
|
||
9 years ago
|
|
||
9 years ago
|
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
|
||
9 years ago
|
|
||
9 years ago
|
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×tamp=" .. time .. "&key=AIzaSyBv_QnejlevQTnNxF3sF-j0NxzkDLOv4fY"
|
||
|
|
||
|
if async_ok then
|
||
|
tzrpage = async.doAsyncRemoteRequest(tzpage, eastern_from_utc, "HTTPS")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function eastern_from_utc(retval, page, status, headers, full_status, request_url)
|
||
9 years ago
|
if status == 200 then
|
||
|
tzopage = json.decode(page)
|
||
9 years ago
|
end
|
||
9 years ago
|
|
||
9 years ago
|
eastern_offset = tzopage.rawOffset+tzopage.dstOffset
|
||
9 years ago
|
|
||
9 years ago
|
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 current timezone and offset code
|
||
9 years ago
|
|
||
|
function get_local_time(dateTime)
|
||
9 years ago
|
local xyear, xmonth, xday = string.match(dateTime, "(%d+)%-(%d+)%-(%d+)")
|
||
|
local xhour, xmin = string.match(dateTime, "%a(%d+):(%d+)")
|
||
9 years ago
|
|
||
9 years ago
|
local event_time = os.time({year = xyear, month = xmonth, day = xday, hour = xhour or 23, min = xmin or 59, sec = 0})
|
||
9 years ago
|
|
||
9 years ago
|
local utc_event_time = event_time - tonumber(eastern_offset)
|
||
9 years ago
|
|
||
9 years ago
|
local utctime, localtime = os.date("!*t", utc_event_time), os.date("*t", utc_event_time)
|
||
9 years ago
|
localtime.isdst = false
|
||
9 years ago
|
local localoffset = os.difftime(os.time(utctime), os.time(localtime))
|
||
9 years ago
|
|
||
9 years ago
|
return os.date("%A, %B %d %Y at %I:%M%p", (utc_event_time-localoffset))
|
||
9 years ago
|
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
|
||
|
|
||
9 years ago
|
-- Get calendar information functions
|
||
|
|
||
9 years ago
|
function get_cal(epic)
|
||
|
async_ok, async = pcall (require, "async")
|
||
9 years ago
|
|
||
9 years ago
|
local key, calid = "AIzaSyAHEnr8iiK42hzM21pXSbTrBIQ2ezEEUHA", ""
|
||
|
epic_name = epic
|
||
|
|
||
|
if epic_list[epic:lower()] then
|
||
|
calid = epic_list[epic:lower()]
|
||
|
elseif epic:lower() == "today" then
|
||
|
just_today = 1
|
||
|
timeMax = os.date("%Y-%m-%dT23:59:59") .. hour_eastern_offset
|
||
|
calid = epic_list.all
|
||
|
elseif epic:lower() == "update" then
|
||
|
update_plugin()
|
||
9 years ago
|
update_only = 1
|
||
9 years ago
|
else
|
||
|
not_found = 1
|
||
|
end
|
||
9 years ago
|
|
||
9 years ago
|
if update_only == 0 then
|
||
|
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
|
||
|
string_offset = "-" .. string.format("%02d", (offset_utc*-1)/3600) .. ":00"
|
||
|
else
|
||
|
string_offset = "%2b" .. string.format("%02d", math.floor(offset_utc/3600)) .. ":00"
|
||
|
end
|
||
|
|
||
|
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
|
||
|
end
|
||
|
|
||
|
if async_ok then
|
||
|
epage = async.doAsyncRemoteRequest(rpage, get_results, "HTTPS")
|
||
|
else
|
||
|
ColourNote("white", "blue", "Epic Calendar Error: Please try again. If problem persists, please contact Arcidayne.")
|
||
|
end
|
||
9 years ago
|
else
|
||
9 years ago
|
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
|
||
9 years ago
|
end
|
||
|
end
|
||
|
end
|
||
9 years ago
|
|
||
9 years ago
|
function get_results(retval, page, status, headers, full_status, request_url)
|
||
9 years ago
|
|
||
9 years ago
|
local cal_output = {}
|
||
9 years ago
|
|
||
9 years ago
|
if status == 200 then
|
||
|
epage = json.decode(page)
|
||
|
else
|
||
|
ColourNote("white", "blue", "Epic Calendar Error: Status failed with code: " .. status .. ". Please try again. If problem persists, please contact Arcidayne.")
|
||
|
end
|
||
9 years ago
|
|
||
9 years ago
|
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
|
||
9 years ago
|
|
||
9 years ago
|
if epage then
|
||
|
if epage.items[1] then
|
||
|
for i = 1, #epage.items do
|
||
|
starttime, summary = "", epage.items[i].summary or "No summary found!"
|
||
9 years ago
|
|
||
9 years ago
|
if epage.items[i].start.date then
|
||
|
starttime = epage.items[i].start.date
|
||
|
else
|
||
|
starttime = epage.items[i].start.dateTime
|
||
|
end
|
||
|
|
||
|
if #summary < 22 then
|
||
|
summary = summary .. string.rep(" ", 22-#summary) .. "- "
|
||
|
end
|
||
|
table.insert(cal_output, summary .. get_local_time(starttime) .. date_note(starttime))
|
||
|
end
|
||
9 years ago
|
end
|
||
|
else
|
||
9 years ago
|
ColourNote("cyan", "", "Epic Calendar Error: Something went very wrong trying to get the epage. Let Arcidayne know!")
|
||
9 years ago
|
end
|
||
9 years ago
|
|
||
9 years ago
|
local header_string = " Upcoming Runs (Local time) "
|
||
9 years ago
|
|
||
9 years ago
|
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))
|
||
|
else
|
||
|
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
|
||
|
end
|
||
9 years ago
|
]]>
|
||
|
</script>
|
||
|
|
||
|
|
||
|
</muclient>
|