Mercurial > wow > itemauditor
comparison Modules/Utils.lua @ 65:32d53abee666
Converting ItemAuditor modules into true modules instead of a bunch of files that all write to the ItemAuditor table.
| author | Asa Ayers <Asa.Ayers@Gmail.com> |
|---|---|
| date | Tue, 27 Jul 2010 18:15:38 -0700 |
| parents | e7d287cc3b02 |
| children | 8d5ad3b71f6f |
comparison
equal
deleted
inserted
replaced
| 64:e92a5adf75bf | 65:32d53abee666 |
|---|---|
| 1 local ItemAuditor = select(2, ...) | 1 local ItemAuditor = select(2, ...) |
| 2 local Utils = ItemAuditor:NewModule("Utils") | 2 local Utils = ItemAuditor:NewModule("Utils") |
| 3 | 3 |
| 4 function ItemAuditor:FormatMoney(copper, color, textOnly) | 4 function Utils.FormatMoney(copper, color, textOnly) |
| 5 color = color or "|cFFFFFFFF" | 5 color = color or "|cFFFFFFFF" |
| 6 local prefix = "" | 6 local prefix = "" |
| 7 if copper < 0 then | 7 if copper < 0 then |
| 8 prefix = "-" | 8 prefix = "-" |
| 9 copper = abs(copper) | 9 copper = abs(copper) |
| 38 | 38 |
| 39 return format("%s%s%s%s", prefix, gold, silver, copper) | 39 return format("%s%s%s%s", prefix, gold, silver, copper) |
| 40 end | 40 end |
| 41 | 41 |
| 42 -- Copied from QuickAuctions | 42 -- Copied from QuickAuctions |
| 43 function ItemAuditor.validateMoney(value) | 43 function Utils.validateMoney(value) |
| 44 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) | 44 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) |
| 45 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) | 45 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) |
| 46 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) | 46 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) |
| 47 | 47 |
| 48 if( not gold and not silver and not copper ) then | 48 if( not gold and not silver and not copper ) then |
| 52 | 52 |
| 53 return true | 53 return true |
| 54 end | 54 end |
| 55 | 55 |
| 56 -- Copied from QuickAuctions | 56 -- Copied from QuickAuctions |
| 57 function ItemAuditor.parseMoney(value) | 57 function Utils.parseMoney(value) |
| 58 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) | 58 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g")) |
| 59 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) | 59 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s")) |
| 60 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) | 60 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c")) |
| 61 | 61 |
| 62 -- Convert it all into copper | 62 -- Convert it all into copper |
| 63 return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) | 63 return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER) |
| 64 | |
| 65 end | 64 end |
| 66 | 65 |
| 67 -- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called | |
| 68 local item_db = {} | |
| 69 | 66 |
| 70 function ItemAuditor:ReplaceItemCache(new_cache) | |
| 71 item_db = new_cache | |
| 72 end | |
| 73 | |
| 74 -- This will be reset every session | |
| 75 local tmp_item_cache = {} | 67 local tmp_item_cache = {} |
| 76 function ItemAuditor:GetItemID(itemName) | 68 function Utils.GetItemID(itemName) |
| 77 if item_db[itemName] ~= nil then | |
| 78 return item_db[itemName] | |
| 79 end | |
| 80 | |
| 81 if tmp_item_cache[itemName] == nil then | 69 if tmp_item_cache[itemName] == nil then |
| 82 local _, itemLink = GetItemInfo (itemName); | 70 local _, itemLink = GetItemInfo (itemName); |
| 83 if itemLink ~= nil then | 71 if itemLink ~= nil then |
| 84 local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") | 72 local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?") |
| 85 tmp_item_cache[itemName] = tonumber(itemID) | 73 tmp_item_cache[itemName] = tonumber(itemID) |
| 98 end | 86 end |
| 99 | 87 |
| 100 return tmp_item_cache[itemName] | 88 return tmp_item_cache[itemName] |
| 101 end | 89 end |
| 102 | 90 |
| 91 | |
| 103 function ItemAuditor:GetLinkFromName(itemName) | 92 function ItemAuditor:GetLinkFromName(itemName) |
| 104 local itemID = self:GetItemID(itemName) | 93 local itemID = self:GetItemID(itemName) |
| 105 local itemLink | 94 local itemLink |
| 106 if itemID ~= nil then | 95 if itemID ~= nil then |
| 107 _, itemLink = GetItemInfo(itemID) | 96 _, itemLink = GetItemInfo(itemID) |
| 108 end | 97 end |
| 109 | 98 |
| 110 return itemLink | 99 return itemLink |
| 111 end | 100 end |
| 112 | 101 |
| 113 function ItemAuditor:SaveItemID(itemName, id) | 102 local SubjectPatterns = { |
| 114 item_db[itemName] = tonumber(id) | |
| 115 end | |
| 116 | |
| 117 ItemAuditor.SubjectPatterns = { | |
| 118 AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), | 103 AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"), |
| 119 AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"), | 104 AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"), |
| 120 AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"), | 105 AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"), |
| 121 AHSuccess = gsub(AUCTION_SOLD_MAIL_SUBJECT, "%%s", ".*"), | 106 AHSuccess = gsub(AUCTION_SOLD_MAIL_SUBJECT, "%%s", ".*"), |
| 122 AHWon = gsub(AUCTION_WON_MAIL_SUBJECT, "%%s", ".*"), | 107 AHWon = gsub(AUCTION_WON_MAIL_SUBJECT, "%%s", ".*"), |
| 123 CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"), | 108 CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"), |
| 124 } | 109 } |
| 125 | 110 |
| 126 function ItemAuditor:GetMailType(msgSubject) | 111 function Utils.GetMailType(msgSubject) |
| 127 if msgSubject then | 112 if msgSubject then |
| 128 for k, v in pairs(self.SubjectPatterns) do | 113 for k, v in pairs(SubjectPatterns) do |
| 129 if msgSubject:find(v) then return k end | 114 if msgSubject:find(v) then return k end |
| 130 end | 115 end |
| 131 end | 116 end |
| 132 return "NonAHMail" | 117 return "NonAHMail" |
| 133 end | 118 end |
| 153 if input then | 138 if input then |
| 154 value = "on" | 139 value = "on" |
| 155 end | 140 end |
| 156 self:Print("Debugging is now: " .. value) | 141 self:Print("Debugging is now: " .. value) |
| 157 end | 142 end |
| 143 | |
| 144 -- TODO: Once everything points to the correct Utils method, all of these should be removed | |
| 145 | |
| 146 function ItemAuditor:FormatMoney(copper, color, textOnly) | |
| 147 return Utils.FormatMoney(copper, color, textOnly) | |
| 148 end | |
| 149 | |
| 150 | |
| 151 function ItemAuditor:GetMailType(msgSubject) | |
| 152 return Utils.GetMailType(msgSubject) | |
| 153 end | |
| 154 | |
| 155 function ItemAuditor:GetItemID(itemName) | |
| 156 return Utils.GetItemID(itemName) | |
| 157 end | |
| 158 | |
| 159 ItemAuditor.parseMoney = Utils.parseMoney | |
| 160 ItemAuditor.validateMoney = Utils.validateMoney |
