Mercurial > wow > itemauditor
comparison Core.lua @ 39:003de902ae64
Implemented COD mail. This loses the ability to track postage, but that will be restored next.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Mon, 19 Jul 2010 20:16:40 -0700 |
parents | e27d13095b49 |
children | a66f6fc57cfb |
comparison
equal
deleted
inserted
replaced
38:e27d13095b49 | 39:003de902ae64 |
---|---|
1 local addonName, addonTable = ...; | 1 local addonName, addonTable = ...; |
2 _G[addonName] = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceEvent-3.0", "AceBucket-3.0") | 2 _G[addonName] = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceEvent-3.0", "AceBucket-3.0") |
3 local addon = _G[addonName] | 3 local addon = _G[addonName] |
4 addonTable.ItemAuditor = addon | 4 addonTable.ItemAuditor = addon |
5 | |
6 local utils = addonTable.utils | |
7 | |
8 | 5 |
9 local WHITE = "|cFFFFFFFF" | 6 local WHITE = "|cFFFFFFFF" |
10 local RED = "|cFFFF0000" | 7 local RED = "|cFFFF0000" |
11 local GREEN = "|cFF00FF00" | 8 local GREEN = "|cFF00FF00" |
12 local YELLOW = "|cFFFFFF00" | 9 local YELLOW = "|cFFFFFF00" |
32 show_debug_frame_on_startup = false, | 29 show_debug_frame_on_startup = false, |
33 }, | 30 }, |
34 factionrealm = { | 31 factionrealm = { |
35 item_account = {}, | 32 item_account = {}, |
36 items = {}, | 33 items = {}, |
34 outbound_cod = {}, | |
37 }, | 35 }, |
38 } | 36 } |
39 self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true) | 37 self.db = LibStub("AceDB-3.0"):New("ItemAuditorDB", DB_defaults, true) |
40 addonTable.db= self.db | 38 addonTable.db= self.db |
41 self.items = self.db.factionrealm.items | 39 self.items = self.db.factionrealm.items |
167 end | 165 end |
168 | 166 |
169 return {items = diff, money = moneyDiff} | 167 return {items = diff, money = moneyDiff} |
170 end | 168 end |
171 | 169 |
172 | 170 local inboundCOD = {} |
173 | 171 local skipMail = {} |
174 function addon:ScanMail() | 172 function addon:ScanMail() |
175 local results = {} | 173 local results = {} |
174 local CODPaymentRegex = gsub(COD_PAYMENT, "%%s", "(.*)") | |
175 | |
176 for mailIndex = 1, GetInboxNumItems() or 0 do | 176 for mailIndex = 1, GetInboxNumItems() or 0 do |
177 local sender, msgSubject, msgMoney, msgCOD, _, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex)) | 177 local sender, msgSubject, msgMoney, msgCOD, daysLeft, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex)) |
178 local mailType = self:GetMailType(msgSubject) | 178 local mailType = self:GetMailType(msgSubject) |
179 | 179 |
180 local mailSignature = msgSubject .. '-' .. msgMoney .. '-' .. msgCOD .. '-' .. daysLeft | |
181 | |
180 results[mailType] = (results[mailType] or {}) | 182 results[mailType] = (results[mailType] or {}) |
181 | 183 |
182 if mailType == "NonAHMail" then | 184 if skipMail[mailSignature] ~= nil then |
183 --[[ | 185 -- do nothing |
184 and msgCOD > 0 | 186 elseif mailType == "NonAHMail" and msgCOD > 0 then |
185 | |
186 mailType = 'COD' | 187 mailType = 'COD' |
187 results[mailType] = (results[mailType] or {}) | 188 results[mailType] = (results[mailType] or {}) |
188 | 189 |
189 local itemTypes = {} | 190 local itemTypes = {} |
190 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do | 191 for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do |
191 local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex) | 192 local itemName, _, count, _, _= GetInboxItem(mailIndex, itemIndex) |
192 if itemName ~= nil then | 193 if itemName ~= nil then |
193 itemTypdes[itemName] = (itemTypes[itemName] or 0) + count | 194 itemTypes[itemName] = (itemTypes[itemName] or 0) + count |
194 end | 195 end |
195 end | 196 end |
196 | 197 |
197 if self:tcount(itemTypes) == 1 then | 198 if self:tcount(itemTypes) == 1 then |
198 for itemName, count in pairs(itemTypes) do | 199 for itemName, count in pairs(itemTypes) do |
199 results[mailType][itemName] = (results[mailType][itemName] or 0) - msgCOD | 200 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) |
201 results[mailType][itemName].total = results[mailType][itemName].total + msgCOD | |
202 | |
203 if inboundCOD[mailSignature] == nil then | |
204 results[mailType][itemName].count = results[mailType][itemName].count + count | |
205 inboundCOD[mailSignature] = (inboundCOD[mailSignature] or 0) + count | |
206 else | |
207 results[mailType][itemName].count = inboundCOD[mailSignature] | |
208 end | |
209 | |
210 | |
200 end | 211 end |
201 else | 212 else |
202 self:Debug("Don't know what to do with more than one item type on COD mail.") | 213 self:Debug("Don't know what to do with more than one item type on COD mail.") |
203 end | 214 end |
204 ]] | |
205 elseif mailType == "CODPayment" then | 215 elseif mailType == "CODPayment" then |
206 itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end) | 216 -- /dump ItemAuditor.db.factionrealm.outbound_cod |
207 | 217 self:Debug(msgSubject) |
208 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) | 218 self:Debug(CODPaymentRegex) |
209 results[mailType][itemName].total = results[mailType][itemName].total - msgMoney | 219 local outboundSubject = select(3, msgSubject:find(CODPaymentRegex)) |
220 local trackID | |
221 if outboundSubject ~= nil then | |
222 self:Debug(outboundSubject) | |
223 trackID = tonumber(select(3, outboundSubject:find('[[]IA: (%d*)[]]'))) | |
224 | |
225 self:Debug('COD ID: %s', trackID) | |
226 if trackID ~= nil then | |
227 local cod = self.db.factionrealm.outbound_cod[trackID] | |
228 if cod == nil then | |
229 skipMail[mailSignature] = true | |
230 self:Print("WARNING: {%s} has an invalid ItemAuditor tracking number.", msgSubject) | |
231 else | |
232 itemName = trackID .. "|" .. cod['link'] | |
233 | |
234 | |
235 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) | |
236 results[mailType][itemName].total = results[mailType][itemName].total - msgMoney | |
237 results[mailType][itemName].count = results[mailType][itemName].count - cod.count | |
238 end | |
239 end | |
240 end | |
241 | |
242 if trackID == nil then | |
243 skipMail[mailSignature] = true | |
244 self:Print("WARNING: {%s} is a COD payment but doesn't have an ItemAuditor tracking number.", msgSubject) | |
245 end | |
210 | 246 |
211 elseif mailType == "AHSuccess" then | 247 elseif mailType == "AHSuccess" then |
212 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); | 248 local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); |
213 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) | 249 results[mailType][itemName] = (results[mailType][itemName] or {total=0,count=0}) |
214 results[mailType][itemName].total = results[mailType][itemName].total - deposit - buyout + consignment | 250 results[mailType][itemName].total = results[mailType][itemName].total - deposit - buyout + consignment |