-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
432 lines (375 loc) · 10.8 KB
/
main.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
local WP_TargetName
local WP_MouseoverName
local WP_ShowPrintOnClick = true
local _G = getfenv(0)
local iWclPlayerScore = _G.LibStub("AceAddon-3.0"):NewAddon("iWclPlayerScore", "AceTimer-3.0")
SLASH_WP_Commands1 = "/wcl"
SlashCmdList["WP_Commands"] = function(msg)
print "iWclPlayerScore Version: 1.8.56 Date:20201201 "
end
local function expand(name)
local switch = {
["T"] = function()
return "TAQ"
end,
["B"] = function()
return "BWL"
end,
["M"] = function()
return "MC"
end,
["A"] = function()
return "|cFFE5CC80"
end,
["L"] = function()
return "|cFFFF8000"
end,
["S"] = function()
return "|cFFE26880"
end,
["N"] = function()
return "|cFFBE8200"
end,
["E"] = function()
return "|cFFA335EE"
end,
["R"] = function()
return "|cFF0070FF"
end,
["U"] = function()
return "|cFF1EFF00"
end,
["C"] = function()
return "|cFF666666"
end,
["%"] = function()
return "% "
end
}
local out = ""
local max = strlen(name)
for j=1,max do
ts = strsub(name,j,j)
local f = switch[ts]
if f then
out = out .. f()
else
out = out .. ts
end
end
return out
end
local function cut_str(str)
if str ~= nil then
local s1,s2,s3 = strsplit("%",str);
if s1 ~= nil then
s1 = s1 .. "%"
if s2 ~= nil then
s1 = s1 .. s2 .. "%"
end
return s1
end
end
return nil
end
local function load_data(tname)
if type(WP_Database) ~= "table" then
return nil
end
if WP_Database[tname] then
return expand(WP_Database[tname])
elseif WP_Database_1[tname] then
return expand(WP_Database_1[tname])
elseif WP_Database_2[tname] then
return expand(WP_Database_2[tname])
elseif WP_Database_3[tname] then
return expand(WP_Database_3[tname])
end
return nil
end
local function load_stopg(tname)
if type(CTOPG_Database) == "table" then
sname = tname .. "_" .. GetRealmName()
if CTOPG_Database[sname] then
return CTOPG_Database[sname]
end
end
if type(STOPG_Database) == "table" then
if STOPG_Database[tname] then
return STOPG_Database[tname]
end
end
return nil
end
local function load_stop(tname)
if type(STOP_Database) ~= "table" then
return nil
end
if STOP_Database[tname] then
return STOP_Database[tname]
else
return nil
end
end
local function load_ctop(tname)
if type(CTOP_Database) ~= "table" then
return nil
end
tname = tname .. "_" .. GetRealmName()
if CTOP_Database[tname] then
return CTOP_Database[tname]
else
return nil
end
end
hooksecurefunc("ChatFrame_OnHyperlinkShow", function(chatFrame, link, text, button)
if (IsModifiedClick("CHATLINK")) then
if (link and button) then
local args = {};
for v in string.gmatch(link, "[^:]+") do
table.insert(args, v);
end
if (args[1] and args[1] == "player") then
args[2] = Ambiguate(args[2], "short")
WP_TargetName = args[2]
if WP_ShowPrintOnClick == true then
dstr = load_data(WP_TargetName)
if dstr then
DEFAULT_CHAT_FRAME:AddMessage('WCL ' .. WP_TargetName .. ': ' .. dstr, 255, 209, 0)
end
end
end
end
end
end)
local function printInfo(self)
print("|cFFFFFF00WCL-" .. self.value)
end
hooksecurefunc("UnitPopup_ShowMenu", function(dropdownMenu, which, unit, name, userData)
WP_TargetName = dropdownMenu.name
if (UIDROPDOWNMENU_MENU_LEVEL > 1) then
return
end
local dstr = load_data(WP_TargetName)
if dstr and UnitExists(unit) and UnitIsPlayer(unit) then
local info = UIDropDownMenu_CreateInfo()
local s1,s2,s3 = strsplit(" ",dstr)
info.text = 'WCL: ' .. s1
info.owner = which
info.notCheckable = 1
info.func = printInfo
info.value = WP_TargetName .. ": " .. dstr
UIDropDownMenu_AddButton(info)
end
end)
function iWclPlayerScore:InitCode()
GameTooltip:HookScript("OnTooltipSetUnit", function(self)
local _, unit = self:GetUnit()
local dstr = ""
if UnitExists(unit) and UnitIsPlayer(unit) then
WP_MouseoverName = UnitName(unit)
local guildName = GetGuildInfo(WP_MouseoverName)
if (guildName ~= nil and guildName ~= "") then
dstr = load_stopg(guildName)
if dstr then
GameTooltip:AddLine(dstr, 255, 209, 0)
end
end
dstr = load_ctop(WP_MouseoverName)
if dstr then
GameTooltip:AddLine(dstr, 255, 209, 0)
end
dstr = load_stop(WP_MouseoverName)
if dstr then
GameTooltip:AddLine("Server " .. dstr, 255, 209, 0)
end
dstr = cut_str(load_data(WP_MouseoverName))
if dstr then
GameTooltip:AddLine(dstr, 255, 209, 0)
end
GameTooltip:Show()
end
end)
end
local Addon_EventFrame = CreateFrame("Frame")
Addon_EventFrame:RegisterEvent("ADDON_LOADED")
Addon_EventFrame:SetScript("OnEvent",
function(self, event, addon)
if addon == "iWclPlayerScore" then
WP_Database = WP_Database or {}
WP_Database_1 = WP_Database_1 or {}
WP_Database_2 = WP_Database_2 or {}
WP_Database_3 = WP_Database_3 or {}
iWclPlayerScore:ScheduleTimer("InitCode", 5)
end
end)
local Chat_EventFrame = CreateFrame("Frame")
Chat_EventFrame:RegisterEvent("CHAT_MSG_SYSTEM")
Chat_EventFrame:SetScript("OnEvent",
function(self, event, message)
local name
name = Deformat(message, _G.WHO_LIST_FORMAT)
if name then
dstr = load_data(name)
if dstr then
print("|cFFFFFF00WCL " .. name .. ":" .. dstr )
end
end
end)
-- a dictionary of format to match entity
local FORMAT_SEQUENCES = {
["s"] = ".+",
["c"] = ".",
["%d*d"] = "%%-?%%d+",
["[fg]"] = "%%-?%%d+%%.?%%d*",
["%%%.%d[fg]"] = "%%-?%%d+%%.?%%d*",
}
-- a set of format sequences that are string-based, i.e. not numbers.
local STRING_BASED_SEQUENCES = {
["s"] = true,
["c"] = true,
}
local cache = setmetatable({}, {__mode='k'})
-- generate the deformat function for the pattern, or fetch from the cache.
local function get_deformat_function(pattern)
local func = cache[pattern]
if func then
return func
end
-- escape the pattern, so that string.match can use it properly
local unpattern = '^' .. pattern:gsub("([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1") .. '$'
-- a dictionary of index-to-boolean representing whether the index is a number rather than a string.
local number_indexes = {}
-- (if the pattern is a numbered format,) a dictionary of index-to-real index.
local index_translation = nil
-- the highest found index, also the number of indexes found.
local highest_index
if not pattern:find("%%1%$") then
-- not a numbered format
local i = 0
while true do
i = i + 1
local first_index
local first_sequence
for sequence in pairs(FORMAT_SEQUENCES) do
local index = unpattern:find("%%%%" .. sequence)
if index and (not first_index or index < first_index) then
first_index = index
first_sequence = sequence
end
end
if not first_index then
break
end
unpattern = unpattern:gsub("%%%%" .. first_sequence, "(" .. FORMAT_SEQUENCES[first_sequence] .. ")", 1)
number_indexes[i] = not STRING_BASED_SEQUENCES[first_sequence]
end
highest_index = i - 1
else
-- a numbered format
local i = 0
while true do
i = i + 1
local found_sequence
for sequence in pairs(FORMAT_SEQUENCES) do
if unpattern:find("%%%%" .. i .. "%%%$" .. sequence) then
found_sequence = sequence
break
end
end
if not found_sequence then
break
end
unpattern = unpattern:gsub("%%%%" .. i .. "%%%$" .. found_sequence, "(" .. FORMAT_SEQUENCES[found_sequence] .. ")", 1)
number_indexes[i] = not STRING_BASED_SEQUENCES[found_sequence]
end
highest_index = i - 1
i = 0
index_translation = {}
pattern:gsub("%%(%d)%$", function(w)
i = i + 1
index_translation[i] = tonumber(w)
end)
end
if highest_index == 0 then
cache[pattern] = do_nothing
else
--[=[
-- resultant function looks something like this:
local unpattern = ...
return function(text)
local a1, a2 = text:match(unpattern)
if not a1 then
return nil, nil
end
return a1+0, a2
end
-- or if it were a numbered pattern,
local unpattern = ...
return function(text)
local a2, a1 = text:match(unpattern)
if not a1 then
return nil, nil
end
return a1+0, a2
end
]=]
local t = {}
t[#t+1] = [=[
return function(text)
local ]=]
for i = 1, highest_index do
if i ~= 1 then
t[#t+1] = ", "
end
t[#t+1] = "a"
if not index_translation then
t[#t+1] = i
else
t[#t+1] = index_translation[i]
end
end
t[#t+1] = [=[ = text:match(]=]
t[#t+1] = ("%q"):format(unpattern)
t[#t+1] = [=[)
if not a1 then
return ]=]
for i = 1, highest_index do
if i ~= 1 then
t[#t+1] = ", "
end
t[#t+1] = "nil"
end
t[#t+1] = "\n"
t[#t+1] = [=[
end
]=]
t[#t+1] = "return "
for i = 1, highest_index do
if i ~= 1 then
t[#t+1] = ", "
end
t[#t+1] = "a"
t[#t+1] = i
if number_indexes[i] then
t[#t+1] = "+0"
end
end
t[#t+1] = "\n"
t[#t+1] = [=[
end
]=]
t = table.concat(t, "")
-- print(t)
cache[pattern] = assert(loadstring(t))()
end
return cache[pattern]
end
function Deformat(text, pattern)
if type(text) ~= "string" then
error(("Argument #1 to `Deformat' must be a string, got %s (%s)."):format(type(text), text), 2)
elseif type(pattern) ~= "string" then
error(("Argument #2 to `Deformat' must be a string, got %s (%s)."):format(type(pattern), pattern), 2)
end
return get_deformat_function(pattern)(text)
end