-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuctionHistory.lua
167 lines (108 loc) · 3.87 KB
/
AuctionHistory.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
local _ah = {
totalScans = 0,
addonInitiated = false,
shard = ''
}
local addonInfo, Internal = ...
function getPriceHistory( item )
local result = AuctionHistory_Prices[item.id]
if( result == nil ) then
result = {
id = item.id,
name = item.name,
category = item.category,
rarity = item.rarity,
shards = {}
}
end
if(result.shards[_ah.shard] == nil) then
result.shards[_ah.shard] = {
time = Inspect.Time.Server(),
history = {}
}
end
return result
end
function _ah.OnVariablesLoaded(identifier)
if(AuctionHistory_Prices == nil) then
AuctionHistory_Prices = {}
end
end
function _ah.search(handle, args)
args = string.trim(args)
local arg1 = unpack(string.split(args, "%s+", true))
if(#args <= 0) then
Command.Console.Display("v0000000000000000", true, "Usage: /ah <search text>", false)
return
end
local status = Inspect.Interaction("auction")
if( status ~= true ) then
Command.Console.Display("v0000000000000000", true, "Need to be at the auction", true)
return
end
local params = {
type = "search",
index = 0,
text = args
}
-- Pull the shard that the search was initially kicked off from
_ah.shard = Inspect.Shard().name
-- The addon initiated the scan. Toggle the flag
_ah.addonInitiated = true;
Command.Auction.Scan(params)
end
function _ah.ScanComplete(handle, criteria, auctions)
if( ( criteria["type"] ~= "search" ) or ( _ah.addonInitiated == false ) ) then
return
end
local itemTypes = {}
_ah.totalScans = 0
for auctionID in pairs(auctions) do
-- Get the item detail for the current auction ID
local details = Inspect.Auction.Detail(auctionID)
-- Check to see if we've encountered this item type before
if( itemTypes[details["itemType"]] == nil ) then
-- We haven't. Flag it for search and increment the number
-- of items on which we're going to search
itemTypes[details["itemType"]] = true;
-- Increment the total number of stat calls to be made
_ah.totalScans = _ah.totalScans + 1
end
end
local now = Inspect.Time.Server()
local lastMonth = now - 3024000
for key, value in pairs(itemTypes) do
Command.Auction.Analyze(key, lastMonth, now)
end
end
function _ah.OnStatsComplete(handle, itemType, data)
-- Inspect the item to pull some useful information
local item = Inspect.Item.Detail(itemType)
local result = getPriceHistory(item)
local i = 1
for k, stat in pairs(data) do
local display = {
date = os.date("%x", stat.time),
average = stat.priceAverage,
volume = stat.volume
}
result.shards[_ah.shard].time = Inspect.Time.Server()
result.shards[_ah.shard].history[i] = display
i = i + 1
end
AuctionHistory_Prices[result.id] = result;
if( _ah.totalScans <= 0 ) then
return
end
Command.Console.Display("general", false, string.format("Collected price history for %s", result.name), false)
_ah.totalScans = _ah.totalScans - 1
-- Reset the addon initiated scan flag
if( _ah.totalScans == 0 ) then
_ah.addonInitiated = false
end
end
Command.Console.Display("general", false, string.format("%s v%s loaded...", addonInfo.nameShort, addonInfo.toc.Version), false)
Command.Event.Attach(Command.Slash.Register("ah"), _ah.search, "List all achievements")
Command.Event.Attach(Event.Auction.Scan, _ah.ScanComplete, "Callback function when the auction scan is complete")
Command.Event.Attach(Event.Auction.Statistics, _ah.OnStatsComplete, "Callback function when the auction statistics call is complete")
Command.Event.Attach(Event.Addon.SavedVariables.Load.End, _ah.OnVariablesLoaded, "Callback function when the addon's saved variables have been loaded")