-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoster.lua
More file actions
134 lines (122 loc) · 3.7 KB
/
Copy pathRoster.lua
File metadata and controls
134 lines (122 loc) · 3.7 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
local ADDON_NAME, ns = ...
local Roster = {}
ns.Roster = Roster
local deDE = GetLocale() == "deDE"
-- Status constants.
Roster.UNCHECKED = "unchecked"
Roster.STALE = "stale"
Roster.CLEAN = "clean"
Roster.FLAGGED = "flagged"
local function isStale(record)
local ttl = ns.db.profile.cacheTTL or 0
if ttl <= 0 then
return false
end
return (time() - (record.time or 0)) > ttl
end
-- Walk the current group and return an ordered entry list plus a summary.
-- Each entry: { name, class, guid, unit, status, problems, time }
function Roster:Build()
local entries = {}
local cache = ns.db.global.cache
local function add(unit)
if not UnitExists(unit) or not UnitIsPlayer(unit) then
return
end
if UnitIsUnit(unit, "player") then
return -- never list yourself
end
local name = UnitName(unit)
local _, classFile = UnitClass(unit)
local guid = UnitGUID(unit)
local record = guid and cache[guid]
local status, problems, when
if not record then
status = Roster.UNCHECKED
elseif isStale(record) then
status = Roster.STALE
problems, when = record.problems, record.time
elseif record.problems and #record.problems > 0 then
status = Roster.FLAGGED
problems, when = record.problems, record.time
else
status = Roster.CLEAN
when = record.time
end
entries[#entries + 1] = {
name = name,
class = classFile,
guid = guid,
unit = unit,
status = status,
problems = problems,
time = when,
spec = record and record.talents and record.talents.spec,
record = record,
whispered = guid and ns.db.global.whispered[guid] or false,
}
end
if IsInRaid() then
for i = 1, GetNumGroupMembers() do
add("raid" .. i)
end
elseif IsInGroup() then
add("player")
for i = 1, GetNumGroupMembers() - 1 do
add("party" .. i)
end
else
add("player")
end
-- Sort: unchecked/stale first, then flagged, then clean; alpha within.
local rank = { [Roster.UNCHECKED] = 1, [Roster.STALE] = 2, [Roster.FLAGGED] = 3, [Roster.CLEAN] = 4 }
table.sort(entries, function(a, b)
if rank[a.status] ~= rank[b.status] then
return rank[a.status] < rank[b.status]
end
return (a.name or "") < (b.name or "")
end)
return entries
end
function Roster:Summary(entries)
entries = entries or self:Build()
local checked, flagged = 0, 0
for _, e in ipairs(entries) do
if e.status == Roster.CLEAN or e.status == Roster.FLAGGED then
checked = checked + 1
end
if e.status == Roster.FLAGGED then
flagged = flagged + 1
end
end
return checked, #entries, flagged
end
-- Whisper a single flagged player their issue list. No-op if not flagged, already
-- whispered, or whispering is disabled. Returns true if a message was sent.
function Roster:Whisper(entry)
if not ns.db.profile.whisperOnFlag then
return false
end
if not entry or entry.status ~= Roster.FLAGGED or not entry.problems or #entry.problems == 0 then
return false
end
if entry.guid and ns.db.global.whispered[entry.guid] then
return false -- already notified; never double-whisper
end
local prefix = deDE and "Scry: dir fehlt - " or "Scry: you're missing - "
SendChatMessage(prefix .. table.concat(entry.problems, ", "), "WHISPER", nil, entry.name)
if entry.guid then
ns.db.global.whispered[entry.guid] = true
end
return true
end
-- Bulk path (slash command): whisper every still-un-whispered flagged player.
function Roster:WhisperFlagged()
local sent = 0
for _, e in ipairs(self:Build()) do
if self:Whisper(e) then
sent = sent + 1
end
end
ns.Addon:Print((deDE and "%d Spieler angeflüstert." or "Whispered %d player(s)."):format(sent))
end