Mercurial > wow > itemauditor
changeset 6:5dddd73b2220
Removed dependency on postal. It was only being used to determine the mail type which has been moved into ItemAuditor so I can support CODPayments. Paying for COD items works, but getting the payments back can't reliably associate the payment with an item yet.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Wed, 26 May 2010 22:41:47 -0700 |
parents | 7d0f4ebedf8c |
children | bbba2fae0f69 |
files | Core.lua ItemAuditor.toc Modules/Events.lua Modules/Utils.lua |
diffstat | 4 files changed, 49 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Wed May 26 21:26:24 2010 -0700 +++ b/Core.lua Wed May 26 22:41:47 2010 -0700 @@ -85,14 +85,18 @@ end + function addon:ScanMail() local results = {} for mailIndex = 1, GetInboxNumItems() or 0 do local sender, msgSubject, msgMoney, msgCOD, _, msgItem, _, _, msgText, _, isGM = select(3, GetInboxHeaderInfo(mailIndex)) - local mailType = Postal:GetMailType(msgSubject) - + local mailType = utils:GetMailType(msgSubject) + + results[mailType] = (results[mailType] or {}) + if mailType == "NonAHMail" and msgCOD > 0 then - -- Don't know how to handle these yet + mailType = 'COD' + results[mailType] = (results[mailType] or {}) local itemTypes = {} for itemIndex = 1, ATTACHMENTS_MAX_RECEIVE do @@ -104,20 +108,23 @@ if utils:tcount(itemTypes) == 1 then for itemName, count in pairs(itemTypes) do - results[itemName] = (results[itemName] or 0) - msgCOD + results[mailType][itemName] = (results[mailType][itemName] or 0) - msgCOD end else self:Debug("Don't know what to do with more than one item type on COD mail.") end + elseif mailType == "CODPayment" then + itemName = msgSubject:gsub(utils.SubjectPatterns[mailType], function(item) return item end) + results[mailType][itemName] = (results[mailType][itemName] or 0) + msgMoney elseif mailType == "AHSuccess" then local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); - results[itemName] = (results[itemName] or 0) + deposit + buyout - consignment + results[mailType][itemName] = (results[mailType][itemName] or 0) + deposit + buyout - consignment elseif mailType == "AHWon" then local invoiceType, itemName, playerName, bid, buyout, deposit, consignment = GetInboxInvoiceInfo(mailIndex); - results[itemName] = (results[itemName] or 0) - bid + results[mailType][itemName] = (results[mailType][itemName] or 0) - bid elseif mailType == "AHExpired" or mailType == "AHCancelled" or mailType == "AHOutbid" then -- These should be handled when you pay the deposit at the AH else @@ -131,12 +138,13 @@ function addon:SaveValue(item, value) local item_account = self.db.factionrealm.item_account - if item_account[item] == nil then - item_account[item] = 0 - end - item_account[item] = item_account[item] + value + + item_account[item] = (item_account[item] or 0) + value + + self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(item_account[item]) .. "(change: " .. utils:FormatMoney(value) .. ")") if item_account[item] >= 0 then + self:Debug("Updated price of " .. item .. " to " .. utils:FormatMoney(0)) item_account[item] = nil end end
--- a/ItemAuditor.toc Wed May 26 21:26:24 2010 -0700 +++ b/ItemAuditor.toc Wed May 26 22:41:47 2010 -0700 @@ -4,7 +4,7 @@ ## Author: Asa Ayers <Asa.Ayers@Gmail.com> ## Version: 0.1 ## SavedVariables: ItemAuditorDB -## Dependencies: Postal, Altoholic, DevTools +## Dependencies: Altoholic, DevTools embeds.xml
--- a/Modules/Events.lua Wed May 26 21:26:24 2010 -0700 +++ b/Modules/Events.lua Wed May 26 22:41:47 2010 -0700 @@ -27,16 +27,15 @@ function addon:MAIL_INBOX_UPDATE() local newScan = addon:ScanMail() local diff - for item, total in pairs(self.lastMailScan) do + for mailType, collection in pairs(self.lastMailScan) do + for item, total in pairs(collection) do - if newScan[item] == nil then - newScan[item] = 0 + diff = total - (newScan[mailType][item] or 0) + if diff ~= 0 then + self:SaveValue(item, diff) + end + end - diff = total - newScan[item] - if diff ~= 0 then - self:SaveValue(item, diff) - end - end self.lastMailScan = newScan
--- a/Modules/Utils.lua Wed May 26 21:26:24 2010 -0700 +++ b/Modules/Utils.lua Wed May 26 22:41:47 2010 -0700 @@ -7,7 +7,29 @@ addonTable.utils = addon function addon:FormatMoney(money) - return Altoholic:GetMoneyString(money, WHITE, false) + local prefix = "" + if money < 0 then + prefix = "-" + end + return prefix .. Altoholic:GetMoneyString(abs(money), WHITE, false) +end + +local SubjectPatterns = { + AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), + AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"), + AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"), + AHSuccess = gsub(AUCTION_SOLD_MAIL_SUBJECT, "%%s", ".*"), + AHWon = gsub(AUCTION_WON_MAIL_SUBJECT, "%%s", ".*"), + CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"), +} + +function addon:GetMailType(msgSubject) + if msgSubject then + for k, v in pairs(SubjectPatterns) do + if msgSubject:find(v) then return k end + end + end + return "NonAHMail" end function addon:tcount(tab)