-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTradeParser.lua
More file actions
152 lines (137 loc) · 4.76 KB
/
TradeParser.lua
File metadata and controls
152 lines (137 loc) · 4.76 KB
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
ZugsTradeParser = LibStub("AceAddon-3.0"):NewAddon("ZugslistTradeParser", "AceConsole-3.0", "AceEvent-3.0")
local ZugsTradeParser = _G.ZugsTradeParser
-- local variables
local player = UnitName("player")
local guid = UnitGUID("player")
local faction = UnitFactionGroup("player")
local realmName = GetRealmName()
-- initialize the database structure
function ZugsTradeParser:OnInitialize()
if not ZugslistTradeParser then ZugslistTradeParser = {} end
end
-- register event handlers
function ZugsTradeParser:OnEnable()
self:RegisterEvent("CHAT_MSG_CHANNEL", "ChatEvent")
self:RegisterEvent("CHAT_MSG_SAY", "ChatEvent")
self:RegisterEvent("CHAT_MSG_WHISPER", "ChatEvent")
self:RegisterEvent("CHAT_MSG_YELL", "ChatEvent")
self:RegisterEvent("CHAT_MSG_GUILD", "ChatEvent")
self:RegisterEvent("TRADE_SKILL_SHOW", "WindowEvent")
end
-- get user trade data from tradeskill window
function ZugsTradeParser:WindowEvent(event)
if not IsTradeSkillLinked() then
local tradelink = GetTradeSkillListLink()
local guid = string.match(UnitGUID("player"), "0x0([0-9A-F]+)")
if tradelink then
ParseEvent(event, tradelink, player, guid)
end
end
end
-- get other users' trade window from links posted in chat channels
function ZugsTradeParser:ChatEvent(event, message, character, _, _, _, _, _, _, _, _, _, guid )
-- if (arg9 == "TCForwarder2IIll") then
-- local parsedCharname = string.match(message, "^_\$%d+([A-Za-z]+)_\$.*")
-- ParseEvent(event,message,parsedCharname)
-- else
local parsedGUID = string.match(guid, "0x0([0-9A-F]+)")
ParseEvent(event, message, character, parsedGUID)
-- end
end
-- parse trade info and store in global saved var ZugslistTradeParser
function ParseEvent(event, message, character, guid)
--refer to http://www.wowwiki.com/UI_escape_sequences for info on escape sequences
--|Htrade:TradeSpellID:CurrentLevel:MaxLevel:PlayerID:Recipes|hLinktext|h
if string.find(message, "|Htrade:") then
for link in string.gmatch(message, "|c%x+|Htrade:%d+:%d+:%d+:[0-9a-fA-F]+:[A-Za-z0-9+/]+|h%[[^]]+%]|h|r") do
local TradeSpellID,CurrentLevel,PlayerID,Recipes, LinkText = string.match(link,"|Htrade:(%d+):(%d+):%d+:([0-9a-fA-F]+):([A-Za-z0-9+/]+)|h%[([^]]+)%]|h|r")
-- store values
local profession = matchSpecialization(LinkText)
-- ZugsError:Print("Player id = "..PlayerID)
-- ZugsError:Print ("Player GUID = "..guid)
-- local PlayerID_check = string.match(UnitGUID(character), "0x0([0-9A-F]+)")
if guid == PlayerID then
if (string.len(profession) > 1) then
if not ZugslistTradeParser[realmName] then ZugslistTradeParser[realmName] = {} end
ZugslistTradeParser[realmName][character.."-"..profession]={
["server"] = realmName,
["faction"] = faction,
["character"] = character,
["playerid"] = PlayerID,
["tradespellid"] = TradeSpellID,
["level"] = CurrentLevel,
["recipes"] = Recipes,
["profession"] = profession,
["time_stamp"] = time(),
["link"] = link,
}
end
end
end
end
end
function matchSpecialization(LinkText)
if isProfession(LinkText) then
return LinkText
elseif isAlchemySpecialization(LinkText) then
return "Alchemy"
elseif isBlacksmithingSpecialization(LinkText) then
return "Blacksmithing"
elseif isEngineeringSpecialization(LinkText) then
return "Engineering"
elseif isLeatherworkingSpecialization(LinkText) then
return "Leatherworking"
elseif isTailoringSpecialization(LinkText) then
return "Tailoring"
else
return ""
end
end
function isProfession(LinkText)
if (in_table(LinkText,{'Alchemy','Blacksmithing','Enchanting','Engineering', 'Herbalism', 'Inscription', 'Jewelcrafting', 'Leatherworking', 'Mining', 'Skinning', 'Tailoring', 'Cooking','First Aid'})) then
return true
else
return false
end
end
function isAlchemySpecialization(LinkText)
if (in_table(LinkText,{"Potion Master", "Transmutation Master", "Elixir Master"})) then
return true
else
return false
end
end
function isBlacksmithingSpecialization(LinkText)
if (in_table(LinkText,{"Armorsmith", "Hammersmith", "Swordsmith"})) then
return true
else
return false
end
end
function isEngineeringSpecialization(LinkText)
if (string.match(LinkText,"Engineer")) then
return true
else
return false
end
end
function isLeatherworkingSpecialization(LinkText)
if (string.match(LinkText,"Leatherworking")) then
return true
else
return false
end
end
function isTailoringSpecialization(LinkText)
if (string.match(LinkText,"Tailoring")) then
return true
else
return false
end
end
function in_table ( e, t )
for _,v in pairs(t) do
if (v==e) then return true end
end
return false
end