Asa@63
|
1 local ItemAuditor = select(2, ...)
|
Asa@63
|
2 local Utils = ItemAuditor:NewModule("Utils")
|
Asa@3
|
3
|
Asa@65
|
4 function Utils.FormatMoney(copper, color, textOnly)
|
Asa@20
|
5 color = color or "|cFFFFFFFF"
|
Asa@6
|
6 local prefix = ""
|
Asa@16
|
7 if copper < 0 then
|
Asa@6
|
8 prefix = "-"
|
Asa@16
|
9 copper = abs(copper)
|
Asa@6
|
10 end
|
Asa@20
|
11
|
Asa@20
|
12 local copperTexture = COPPER_AMOUNT_TEXTURE
|
Asa@20
|
13 local silverTexture = SILVER_AMOUNT_TEXTURE
|
Asa@20
|
14 local goldTexture = GOLD_AMOUNT_TEXTURE
|
Asa@20
|
15 if textOnly then
|
Asa@20
|
16 copperTexture = '%dc'
|
Asa@20
|
17 silverTexture = '%ds'
|
Asa@20
|
18 goldTexture = '%dg'
|
Asa@20
|
19 end
|
Asa@16
|
20
|
Asa@16
|
21 local gold = floor( copper / 10000 );
|
Asa@16
|
22 copper = mod(copper, 10000)
|
Asa@16
|
23 local silver = floor( copper / 100 );
|
Asa@16
|
24 copper = mod(copper, 100)
|
Asa@16
|
25
|
Asa@16
|
26
|
Asa@20
|
27 copper = color .. format(copperTexture, copper, 13, 13)
|
Asa@16
|
28 if silver > 0 or gold > 0 then
|
Asa@20
|
29 silver = color.. format(silverTexture, silver, 13, 13) .. ' '
|
Asa@16
|
30 else
|
Asa@16
|
31 silver = ""
|
Asa@16
|
32 end
|
Asa@16
|
33 if gold > 0 then
|
Asa@20
|
34 gold = color.. format(goldTexture, gold, 13, 13) .. ' '
|
Asa@16
|
35 else
|
Asa@16
|
36 gold = ""
|
Asa@16
|
37 end
|
Asa@16
|
38
|
Asa@16
|
39 return format("%s%s%s%s", prefix, gold, silver, copper)
|
Asa@6
|
40 end
|
Asa@6
|
41
|
Asa@58
|
42 -- Copied from QuickAuctions
|
Asa@65
|
43 function Utils.validateMoney(value)
|
Asa@58
|
44 local gold = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)g|r") or string.match(value, "([0-9]+)g"))
|
Asa@58
|
45 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
|
Asa@58
|
46 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
|
Asa@58
|
47
|
Asa@58
|
48 if( not gold and not silver and not copper ) then
|
Asa@58
|
49 return false;
|
Asa@58
|
50 -- return L["Invalid monney format entered, should be \"#g#s#c\", \"25g4s50c\" is 25 gold, 4 silver, 50 copper."]
|
Asa@58
|
51 end
|
Asa@58
|
52
|
Asa@58
|
53 return true
|
Asa@58
|
54 end
|
Asa@58
|
55
|
Asa@58
|
56 -- Copied from QuickAuctions
|
Asa@65
|
57 function Utils.parseMoney(value)
|
Asa@58
|
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
|
59 local silver = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)s|r") or string.match(value, "([0-9]+)s"))
|
Asa@58
|
60 local copper = tonumber(string.match(value, "([0-9]+)|c([0-9a-fA-F]+)c|r") or string.match(value, "([0-9]+)c"))
|
Asa@58
|
61
|
Asa@58
|
62 -- Convert it all into copper
|
Asa@58
|
63 return (copper or 0) + ((gold or 0) * COPPER_PER_GOLD) + ((silver or 0) * COPPER_PER_SILVER)
|
Asa@58
|
64 end
|
Asa@58
|
65
|
Asa@7
|
66
|
Asa@7
|
67 local tmp_item_cache = {}
|
Asa@65
|
68 function Utils.GetItemID(itemName)
|
Asa@7
|
69 if tmp_item_cache[itemName] == nil then
|
Asa@7
|
70 local _, itemLink = GetItemInfo (itemName);
|
Asa@7
|
71 if itemLink ~= nil then
|
Asa@7
|
72 local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
|
Asa@7
|
73 tmp_item_cache[itemName] = tonumber(itemID)
|
Asa@7
|
74 end
|
Asa@7
|
75 end
|
Asa@7
|
76
|
Asa@9
|
77 if tmp_item_cache[itemName] == nil then
|
Asa@9
|
78 for link, data in pairs(ItemAuditor.db.factionrealm.items) do
|
Asa@9
|
79 local name, itemLink = GetItemInfo (link);
|
Asa@9
|
80 if name == itemName then
|
Asa@9
|
81 local _, _, _, _, itemID = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
|
Asa@9
|
82 tmp_item_cache[itemName] = tonumber(itemID)
|
Asa@9
|
83 end
|
Asa@9
|
84 end
|
Asa@9
|
85
|
Asa@9
|
86 end
|
Asa@9
|
87
|
Asa@7
|
88 return tmp_item_cache[itemName]
|
Asa@7
|
89 end
|
Asa@7
|
90
|
Asa@65
|
91
|
Asa@63
|
92 function ItemAuditor:GetLinkFromName(itemName)
|
Asa@9
|
93 local itemID = self:GetItemID(itemName)
|
Asa@9
|
94 local itemLink
|
Asa@9
|
95 if itemID ~= nil then
|
Asa@9
|
96 _, itemLink = GetItemInfo(itemID)
|
Asa@9
|
97 end
|
Asa@9
|
98
|
Asa@9
|
99 return itemLink
|
Asa@9
|
100 end
|
Asa@9
|
101
|
Asa@65
|
102 local SubjectPatterns = {
|
Asa@6
|
103 AHCancelled = gsub(AUCTION_REMOVED_MAIL_SUBJECT, "%%s", ".*"),
|
Asa@6
|
104 AHExpired = gsub(AUCTION_EXPIRED_MAIL_SUBJECT, "%%s", ".*"),
|
Asa@6
|
105 AHOutbid = gsub(AUCTION_OUTBID_MAIL_SUBJECT, "%%s", ".*"),
|
Asa@6
|
106 AHSuccess = gsub(AUCTION_SOLD_MAIL_SUBJECT, "%%s", ".*"),
|
Asa@6
|
107 AHWon = gsub(AUCTION_WON_MAIL_SUBJECT, "%%s", ".*"),
|
Asa@6
|
108 CODPayment = gsub(COD_PAYMENT, "%%s", "(.*)"),
|
Asa@6
|
109 }
|
Asa@6
|
110
|
Asa@65
|
111 function Utils.GetMailType(msgSubject)
|
Asa@6
|
112 if msgSubject then
|
Asa@65
|
113 for k, v in pairs(SubjectPatterns) do
|
Asa@6
|
114 if msgSubject:find(v) then return k end
|
Asa@6
|
115 end
|
Asa@6
|
116 end
|
Asa@6
|
117 return "NonAHMail"
|
Asa@3
|
118 end
|
Asa@3
|
119
|
Asa@63
|
120 function ItemAuditor:tcount(tab)
|
Asa@3
|
121 local n = #tab
|
Asa@3
|
122 if (n == 0) then
|
Asa@3
|
123 for _ in pairs(tab) do
|
Asa@3
|
124 n = n + 1
|
Asa@3
|
125 end
|
Asa@3
|
126 end
|
Asa@3
|
127 return n
|
Asa@3
|
128 end
|
Asa@3
|
129
|
Asa@63
|
130 function ItemAuditor:GetDebug(info)
|
Asa@11
|
131 return self.db.char.debug
|
Asa@3
|
132 end
|
Asa@3
|
133
|
Asa@63
|
134 function ItemAuditor:SetDebug(info, input)
|
Asa@11
|
135
|
Asa@11
|
136 ItemAuditor.db.char.debug = input
|
Asa@3
|
137 local value = "off"
|
Asa@3
|
138 if input then
|
Asa@3
|
139 value = "on"
|
Asa@3
|
140 end
|
Asa@11
|
141 self:Print("Debugging is now: " .. value)
|
Asa@3
|
142 end
|
Asa@65
|
143
|
Asa@65
|
144 -- TODO: Once everything points to the correct Utils method, all of these should be removed
|
Asa@65
|
145
|
Asa@65
|
146 function ItemAuditor:FormatMoney(copper, color, textOnly)
|
Asa@65
|
147 return Utils.FormatMoney(copper, color, textOnly)
|
Asa@65
|
148 end
|
Asa@65
|
149
|
Asa@65
|
150
|
Asa@65
|
151 function ItemAuditor:GetMailType(msgSubject)
|
Asa@65
|
152 return Utils.GetMailType(msgSubject)
|
Asa@65
|
153 end
|
Asa@65
|
154
|
Asa@65
|
155 function ItemAuditor:GetItemID(itemName)
|
Asa@65
|
156 return Utils.GetItemID(itemName)
|
Asa@65
|
157 end
|
Asa@65
|
158
|
Asa@65
|
159 ItemAuditor.parseMoney = Utils.parseMoney
|
Asa@65
|
160 ItemAuditor.validateMoney = Utils.validateMoney |