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.

268 lines
8.2 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"
9 years ago
requires="4.90"
version="3.1"
>
</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
9 years ago
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
get_cal(string.gsub("%1"," ",""))
end</send>
</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
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
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
raw_version = tonumber(string.match(page, '%s%s+version="([0-9%.]_)"'))
end
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
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"
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)
if status == 200 then
tzopage = json.decode(page)
end
9 years ago
eastern_offset = tzopage.rawOffset+tzopage.dstOffset
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
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
local event_time = os.time({year = xyear, month = xmonth, day = xday, hour = xhour or 23, min = xmin or 59, sec = 0})
9 years ago
local utc_event_time = event_time - tonumber(eastern_offset)
9 years ago
local utctime, localtime = os.date("!*t", utc_event_time), os.date("*t", utc_event_time)
localtime.isdst = false
9 years ago
local localoffset = os.difftime(os.time(utctime), os.time(localtime))
9 years ago
return os.date("%A, %B %d %Y at %I:%M%p", (utc_event_time-localoffset))
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
function get_cal(epic)
async_ok, async = pcall (require, "async")
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()
else
not_found = 1
end
9 years ago
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
9 years ago
string_offset = "-" .. string.format("%02d", (offset_utc*-1)/3600) .. ":00"
else
string_offset = "%2b" .. string.format("%02d", math.floor(offset_utc/3600)) .. ":00"
end
9 years ago
timeMin = os.date("%Y-%m-%dT%H:%M:%S", os.time()) .. string_offset
9 years ago
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
9 years ago
epage = async.doAsyncRemoteRequest(rpage, get_results, "HTTPS")
else
9 years ago
ColourNote("white", "blue", "Epic Calendar Error: Please try again. If problem persists, please contact Arcidayne.")
end
9 years ago
else
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
9 years ago
function get_results(retval, page, status, headers, full_status, request_url)
9 years ago
local cal_output = {}
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
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
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
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
end
else
9 years ago
ColourNote("cyan", "", "Epic Calendar Error: Something went very wrong trying to get the epage. Let Arcidayne know!")
end
9 years ago
local header_string = " Upcoming Runs (Local time) "
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
]]>
</script>
</muclient>