-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventnotifier.lua
102 lines (88 loc) · 2.75 KB
/
eventnotifier.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
-- Options
local checkMail = true
local checkEvents = true
local checkGuildEvents = true
-- Addon itself
local numInvites = 0 -- store amount of invites to compare later, and only show banner when invites differ; events fire multiple times
local hasMail = false -- same with mail
local function GetGuildInvites()
local numGuildInvites = 0
local _, currentMonth = CalendarGetDate()
for i = 1, CalendarGetNumGuildEvents() do
local month, day = CalendarGetGuildEventInfo(i)
local monthOffset = month - currentMonth
local numDayEvents = CalendarGetNumDayEvents(monthOffset, day)
for i = 1, numDayEvents do
local _, _, _, _, _, _, _, _, inviteStatus = CalendarGetDayEvent(monthOffset, day, i)
if inviteStatus == 8 then
numGuildInvites = numGuildInvites + 1
end
end
end
return numGuildInvites
end
local function toggleCalendar()
if not CalendarFrame then LoadAddOn("Blizzard_Calendar") end
Calendar_Toggle()
end
local function alertEvents()
if CalendarFrame and CalendarFrame:IsShown() then return end
local num = CalendarGetNumPendingInvites()
if num ~= numInvites then
if num > 1 then
Notifications:Alert(format("You have %s pending calendar invites.", num), toggleCalendar)
elseif num > 0 then
Notifications:Alert("You have 1 pending calendar invite.", toggleCalendar)
end
numInvites = num
end
end
local function alertGuildEvents()
if CalendarFrame and CalendarFrame:IsShown() then return end
local num = GetGuildInvites()
if num > 1 then
Notifications:Alert(format("You have %s pending guild events.", num), toggleCalendar)
elseif num > 0 then
Notifications:Alert("You have 1 pending guild event.", toggleCalendar)
end
end
local f = CreateFrame("Frame", nil, frame)
f:RegisterEvent("PLAYER_ENTERING_WORLD")
if checkMail then
f:RegisterEvent("UPDATE_PENDING_MAIL")
end
if checkGuildEvents then
f:RegisterEvent("CALENDAR_UPDATE_GUILD_EVENTS")
end
f:SetScript("OnEvent", function(_, event)
if event == "PLAYER_ENTERING_WORLD" then
if checkEvents or checkGuildEvents then
OpenCalendar()
f:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
end
if checkEvents then
alertEvents()
end
if checkGuildEvents then
alertGuildEvents()
end
f:UnregisterEvent("PLAYER_ENTERING_WORLD")
elseif event == "UPDATE_PENDING_MAIL" then
local newMail = HasNewMail()
if hasMail ~= newMail then
hasMail = newMail
if hasMail then
Notifications:Alert("You have new mail.", nil, "Interface\\Icons\\inv_letter_15", .08, .92, .08, .92)
end
end
elseif event == "CALENDAR_UPDATE_PENDING_INVITES" then
if checkEvents then
alertEvents()
end
if checkGuildEvents then
alertGuildEvents()
end
else
alertGuildEvents()
end
end)