Asa@63: local ItemAuditor = select(2, ...) Asa@63: local Utils = ItemAuditor:NewModule("Utils") Asa@3: Asa@65: function Utils.FormatMoney(copper, color, textOnly) Asa@20: color = color or "|cFFFFFFFF" Asa@6: local prefix = "" Asa@16: if copper < 0 then Asa@6: prefix = "-" Asa@16: copper = abs(copper) Asa@6: end Asa@20: Asa@20: local copperTexture = COPPER_AMOUNT_TEXTURE Asa@20: local silverTexture = SILVER_AMOUNT_TEXTURE Asa@20: local goldTexture = GOLD_AMOUNT_TEXTURE Asa@20: if textOnly then Asa@20: copperTexture = '%dc' Asa@20: silverTexture = '%ds' Asa@20: goldTexture = '%dg' Asa@20: end Asa@16: Asa@16: local gold = floor( copper / 10000 ); Asa@16: copper = mod(copper, 10000) Asa@16: local silver = floor( copper / 100 ); Asa@16: copper = mod(copper, 100) Asa@16: Asa@16: Asa@20: copper = color .. format(copperTexture, copper, 13, 13) Asa@16: if silver > 0 or gold > 0 then Asa@20: silver = color.. format(silverTexture, silver, 13, 13) .. ' ' Asa@16: else Asa@16: silver = "" Asa@16: end Asa@16: if gold > 0 then Asa@20: gold = color.. format(goldTexture, gold, 13, 13) .. ' ' Asa@16: else Asa@16: gold = "" Asa@16: end Asa@16: Asa@16: return format("%s%s%s%s", prefix, gold, silver, copper) Asa@6: end Asa@6: Asa@58: -- Copied from QuickAuctions Asa@65: function Utils.validateMoney(value) Asa@58: local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) Asa@58: local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) Asa@58: local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) Asa@58: Asa@58: if( not gold and not silver and not copper ) then Asa@58: return false; Asa@58: -- return L["Invalid monney format entered, should be \"#g#s#c\", \"25g4s50c\" is 25 gold, 4 silver, 50 copper."] Asa@58: end Asa@58: Asa@58: return true Asa@58: end Asa@58: Asa@58: -- Copied from QuickAuctions Asa@65: function Utils.parseMoney(value) Asa@58: local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) Asa@58: local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) Asa@58: local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) Asa@58: Asa@58: -- Convert it all into copper Asa@58: return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) Asa@58: end Asa@58: Asa@7: Asa@7: local tmp_item_cache = {} Asa@86: function Utils.GetItemID(item) Asa@86: if not item then Asa@86: return nil Asa@86: end Asa@86: Asa@86: if tmp_item_cache[item] == nil then Asa@86: -- Whether item is a link or a name, both should return the full link Asa@86: DevTools_Dump(item) Asa@86: local _, itemLink = GetItemInfo (item); Asa@7: if itemLink ~= nil then Asa@7: local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") Asa@86: tmp_item_cache[item] = tonumber(itemID) Asa@7: end Asa@7: end Asa@7: Asa@86: if tmp_item_cache[item] == nil then Asa@9: for link, data in pairs(ItemAuditor.db.factionrealm.items) do Asa@9: local name, itemLink = GetItemInfo (link); Asa@86: if name == item then Asa@9: local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") Asa@86: tmp_item_cache[item] = tonumber(itemID) Asa@9: end Asa@9: end Asa@9: Asa@9: end Asa@9: Asa@86: return tmp_item_cache[item] Asa@7: end Asa@7: Asa@65: Asa@63: function ItemAuditor:GetLinkFromName(itemName) Asa@9: local itemID = self:GetItemID(itemName) Asa@9: local itemLink Asa@9: if itemID ~= nil then Asa@9: _, itemLink = GetItemInfo(itemID) Asa@9: end Asa@9: Asa@9: return itemLink Asa@9: end Asa@9: Asa@65: local SubjectPatterns = { Asa@6: AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), Asa@6: AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"), Asa@6: AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"), Asa@6: AHSuccess = gsub(AUCTION_SOLD_MAIL_SUBJECT, "%%s", ".*"), Asa@6: AHWon = gsub(AUCTION_WON_MAIL_SUBJECT, "%%s", ".*"), Asa@6: CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"), Asa@6: } Asa@6: Asa@65: function Utils.GetMailType(msgSubject) Asa@6: if msgSubject then Asa@65: for k, v in pairs(SubjectPatterns) do Asa@6: if msgSubject:find(v) then return k end Asa@6: end Asa@6: end Asa@6: return "NonAHMail" Asa@3: end Asa@3: Asa@63: function ItemAuditor:tcount(tab) Asa@3: local n = #tab Asa@3: if (n == 0) then Asa@3: for _ in pairs(tab) do Asa@3: n = n + 1 Asa@3: end Asa@3: end Asa@3: return n Asa@3: end Asa@3: Asa@63: function ItemAuditor:GetDebug(info) Asa@11: return self.db.char.debug Asa@3: end Asa@3: Asa@63: function ItemAuditor:SetDebug(info, input) Asa@11: Asa@11: ItemAuditor.db.char.debug = input Asa@3: local value = "off" Asa@3: if input then Asa@3: value = "on" Asa@3: end Asa@11: self:Print("Debugging is now: " .. value) Asa@3: end Asa@65: Asa@65: -- TODO: Once everything points to the correct Utils method, all of these should be removed Asa@65: Asa@65: function ItemAuditor:FormatMoney(copper, color, textOnly) Asa@65: return Utils.FormatMoney(copper, color, textOnly) Asa@65: end Asa@65: Asa@65: Asa@65: function ItemAuditor:GetMailType(msgSubject) Asa@65: return Utils.GetMailType(msgSubject) Asa@65: end Asa@65: Asa@65: function ItemAuditor:GetItemID(itemName) Asa@65: return Utils.GetItemID(itemName) Asa@65: end Asa@65: Asa@65: ItemAuditor.parseMoney = Utils.parseMoney Asa@65: ItemAuditor.validateMoney = Utils.validateMoney