Okay, found a function in the wow files that I didn't see in wowprogramming and must have missed from wowpedia, and it all seems to work apart from your main requirement ... updating the MotD text automatically. Here's the code anyway. Hopefully Phanx can see what is wrong.
Lua Code:
-- Get the localised addon information
local addonName,addonData = ...
addonData.MotD = ""
addonData.CheckGuildEvents = function()
addonData.NumGuildEvents = CalendarGetNumGuildEvents()
if ( addonData.NumGuildEvents == 0 ) then return end
local month, day, weekday, hour, minute, eventType, title, calendarType, textureName
for i = 1,addonData.NumGuildEvents do
month, day, weekday, hour, minute, eventType, title, calendarType, textureName = CalendarGetGuildEventInfo(i);
thisInfo = tostring(i) .. ": " .. title .. " at " .. GameTime_GetFormattedTime(hour, minute, true) .. " on " .. string.format(GUILD_NEWS_DATE, CALENDAR_WEEKDAY_NAMES[weekday], day, month)
-- GuildSetMOTD(thisInfo) -- This works
if ( strlen(addonData.MotD) + strlen(thisInfo) > 128 ) then
-- GuildSetMOTD(addonData.MotD) -- This doesn't work, wipes out old MotD but this doesn't appear in its place
break
else
addonData.MotD = string.format("%s\n%s",addonData.MotD, thisInfo)
-- GuildSetMOTD(addonData.MotD) -- This doesn't work, wipes out old MotD but this doesn't appear in its place
end
end
print(addonData.MotD, "(", strlen(addonData.MotD), ")")
GuildSetMOTD(addonData.MotD) -- This doesn't work, wipes out old MotD but this doesn't appear in its place
--GuildSetMOTD("Testing testing 1 2 3") -- This works
end
local function OnEvent(self,event,arg1,arg2,arg3,arg4,arg5)
if ( event == "ADDON_LOADED" and arg1 == addonName ) then
if not IsAddOnLoaded("Blizzard_Calendar") then
LoadAddOn("Blizzard_Calendar")
end
elseif ( event == "PLAYER_ENTERING_WORLD" ) then
local weekday,month,day,year = CalendarGetDate()
local month, year, numDays, firstWeekday = CalendarGetMonth(0)
CalendarSetAbsMonth(month,year)
OpenCalendar()
elseif ( event == "CALENDAR_UPDATE_GUILD_EVENTS" ) then
addonData.CheckGuildEvents()
elseif ( event == "CALENDAR_UPDATE_EVENT_LIST" ) then
addonData.CheckGuildEvents()
end
end
local XGMotDFrame = CreateFrame("Frame","XGMotDFrame",UIParent)
XGMotDFrame:SetScript("OnEvent", OnEvent)
XGMotDFrame:RegisterEvent("ADDON_LOADED")
XGMotDFrame:RegisterEvent("CALENDAR_UPDATE_GUILD_EVENTS")
XGMotDFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
XGMotDFrame:RegisterEvent("PLAYER_GUILD_UPDATE")
XGMotDFrame:RegisterEvent("CALENDAR_UPDATE_EVENT_LIST")
CALENDAR_UPDATE_EVENT_LIST is triggered everytime you reload the UI and CALENDAR_UPDATE_GUILD_EVENTS is triggered when you first log in and when new guild events are added.