vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Name: SpecialEvents-Mail-2.0
3 Revision: $Rev: 9518 $
4 Author: Tekkub Stoutwrithe (tekkub@gmail.com)
5 Website: http://wiki.wowace.com/index.php/SpecialEvents_Addon
6 Documentation: http://wiki.wowace.com/index.php/SpecialEvents-Mail-2.0
7 SVN: svn://svn.wowace.com/root/trunk/SpecialEventsEmbed/SpecialEvents-Mail-2.0
8 Description: Special events for mail (received, auction notices, etc)
9 Dependencies: AceLibrary, AceEvent-2.0
10 ]]
11  
12  
13 local vmajor, vminor = "SpecialEvents-Mail-2.0", "$Revision: 9518 $"
14  
15 if not AceLibrary then error(vmajor .. " requires AceLibrary.") end
16 if not AceLibrary:HasInstance("AceEvent-2.0") then error(vmajor .. " requires AceEvent-2.0.") end
17 if not AceLibrary:IsNewVersion(vmajor, vminor) then return end
18  
19 local lib = {}
20 AceLibrary("AceEvent-2.0"):embed(lib)
21  
22 local closedelay = 5
23  
24  
25 -- Activate a new instance of this library
26 function activate(self, oldLib, oldDeactivate)
27 if oldLib then self.vars = oldLib.vars
28 else self.vars = {} end
29  
30 self:RegisterEvent("PLAYER_ENTERING_WORLD")
31 self:RegisterEvent("MAIL_CLOSED")
32 self:RegisterEvent("UPDATE_PENDING_MAIL")
33 self:RegisterEvent("CHAT_MSG_SYSTEM")
34  
35 if oldDeactivate then oldDeactivate(oldLib) end
36 end
37  
38  
39 --------------------------------
40 -- Tracking methods --
41 --------------------------------
42  
43 function lib:PLAYER_ENTERING_WORLD()
44 self.vars.zoneevent = true
45 end
46  
47  
48 function lib:MAIL_CLOSED()
49 self.vars.lastclose = GetTime()
50 end
51  
52  
53 function lib:UPDATE_PENDING_MAIL()
54 if self.vars.lastclose and (self.vars.lastclose + closedelay) > GetTime() then self.vars.ignorenext = true end
55  
56 if self.vars.zoneevent then
57 self.vars.zoneevent = nil
58 self:TriggerEvent("SpecialEvents_MailInit")
59 return
60 end
61  
62 if self.vars.ignorenext then
63 self.vars.ignorenext = nil
64 return
65 end
66  
67 self:TriggerEvent("SpecialEvents_MailReceived")
68 end
69  
70  
71 -- Events that don't fire UPDATE_PENDING_MAIL like they should
72 local brokenevents = {
73 [ERR_AUCTION_WON_S] = false,
74 [ERR_AUCTION_SOLD_S] = false,
75 [ERR_AUCTION_OUTBID_S] = true,
76 [ERR_AUCTION_EXPIRED_S] = false,
77 [ERR_AUCTION_REMOVED_S] = false,
78 }
79 local eventnames = {
80 [ERR_AUCTION_WON_S] = "WON",
81 [ERR_AUCTION_SOLD_S] = "SOLD",
82 [ERR_AUCTION_OUTBID_S] = "OUTBID",
83 [ERR_AUCTION_EXPIRED_S] = "EXPIRED",
84 [ERR_AUCTION_REMOVED_S] = "REMOVED",
85 }
86 local aucstr = {}
87 for i in pairs(brokenevents) do aucstr[i] = string.gsub(i, "%%[^%s]+", "(.+)") end
88  
89 function lib:CHAT_MSG_SYSTEM(msg)
90 if not msg then return end
91  
92 for i,searchstr in pairs(aucstr) do
93 local _, _, item = string.find(msg, searchstr)
94 if item then
95 self:TriggerEvent("SpecialEvents_AHAlert", eventnames[i], item)
96 if brokenevents[i] then
97 self:TriggerEvent("SpecialEvents_MailReceived")
98 return
99 end
100 end
101 end
102 end
103  
104  
105 --------------------------------
106 -- Load this bitch! --
107 --------------------------------
108 AceLibrary:Register(lib, vmajor, vminor, activate)