Okay, as I discovered when I played with this before, some of the functions operate differently when you first log in and when you do a reloading of the UI. I haven't figured out why that is though so cannot comment further on it.
Here are a couple of images of my results though :
Images 1 and 2 are using PLAYER_ENTERING_WORLD to Initialise Data
Image 1 is after using a reloadUI
Image 2 is after a character relog
Images 3 and 4 are using VARIABLES_LOADED to update information that may not have been available.
Image 3 is after using a reloadUI
Image 4 is after a character relog
As you can see an extra event is triggered on a character relog that isn't triggered on a reloading of the UI but I suspect it will also trigger when you get an invite while you are in game. That is something I can't test for personally as I am usually the one that sets up the guilds events rofl and these tests are on characters on the same account and I only have 1 account. But it will give you some idea as to how you can progress with it.
Anyway here's the code I used in this test. It doesn't handle the checking of x days ahead but with the function I mentioned earlier to test for the number of days and the functions I use in here to get information for a specific day it should put you in the right direction to tweak them to cater for checking x days ahead.
Code:
local weekday, month, day, year, monthOffset
local numEvents, numInvites
local title, hour, minute, calendarType, sequenceType, eventType, texture, modStatus, inviteStatus, invitedBy, difficulty, inviteType
local name, level, className, classFileName, inviteStatus, modStatus, inviteIsMine, inviteType2
local eventTypes,weekdayNames,monthNames
local currentEvent,currentQuery
local pendingInvite
local updateEventListCount = 0
local function RespondTo_CalendarUpdatePendingInvites()
print("Getting Number of Pending Invites")
numInvites = CalendarGetNumPendingInvites()
print("You have ", numInvites, " you have not responded to")
if ( numInvites == 0 ) then return end
print("Getting Number of events for day/monthoffset : ", day,monthOffset)
numEvents = CalendarGetNumDayEvents(monthOffset, day)
print("Number of events/monthOffset = ", numEvents, monthOffset)
if ( numEvents == 0 ) then return end
print("Events you need to be aware of are as follows : ");
for index = 1,numEvents do
title, hour, minute, calendarType, sequenceType, eventType, texture, modStatus, inviteStatus, invitedBy, difficulty, inviteType = CalendarGetDayEvent(monthOffset, day, index)
print("Title:", title, "Time:", hour..":"..minute, "Calendar Type:", calendarType, "Sequence Type:",sequenceType, "Event Type:", eventType, "Invite Status:", inviteStatus, "Invited By:", invitedBy, "Difficulty:", difficulty, "Invite Type:", inviteType);
if ( calendarType == GUILD_EVENT or calendarType == GUILD_ANNOUNCEMENT or calendarType == PLAYER ) then
print("This is a guild event or announcement or a player created event")
if ( inviteStatus == 1 or inviteStatus == 8 or inviteStatus == 5 ) then
print("You have been invited or have not signed up or the invite is out");
end
end
end
end
local function QueryCalendar()
print("Querying Calendar")
OpenCalendar();
print("Generating list of months and weekdays and event types")
monthNames = { CalendarGetMonthNames() }
weekdayNames = { CalendarGetWeekdayNames() }
eventTypes = { CalendarEventGetTypes() }
weekday, month, day, year = CalendarGetDate()
print("CalendarGetDate returned: ", weekday,"(",weekdayNames[weekday],")", day, month, "(",monthNames[month],")", year)
print("Setting calendar to month/year : ", month, "(",monthNames[month],")", year)
CalendarSetAbsMonth(month,year)
monthOffset = 0
print("Getting Number of events for day/monthoffset : ", day,monthOffset)
numEvents = CalendarGetNumDayEvents(monthOffset, day)
print("Number of events/monthOffset = ", numEvents, monthOffset)
RespondTo_CalendarUpdatePendingInvites()
end
local function OnEvent(self,event,...)
print(event,...)
if event == "ADDON_LOADED" then
if arg1 == addonName then
if not IsAddOnLoaded("Blizzard_Calendar") then
LoadAddOn("Blizzard_Calendar")
end
self:UnregisterEvent(event)
end
elseif event == "VARIABLES_LOADED" then
QueryCalendar()
self:UnregisterEvent(event)
elseif event == "PLAYER_ENTERING_WORLD" then
QueryCalendar()
self:UnregisterEvent(event);
elseif event == "CALENDAR_UPDATE_PENDING_INVITES" then
RespondTo_CalendarUpdatePendingInvites()
end
end
local XCalendarFrame = CreateFrame("Frame","XCalendarFrame",UIParent)
XCalendarFrame:SetScript("OnEvent",OnEvent)
XCalendarFrame:RegisterEvent("ADDON_LOADED")
XCalendarFrame:RegisterEvent("VARIABLES_LOADED")
XCalendarFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
XCalendarFrame:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")