-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReport.lua
More file actions
636 lines (551 loc) · 20.1 KB
/
Report.lua
File metadata and controls
636 lines (551 loc) · 20.1 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
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
local addonName, BBT = ...
BBT = BBT or _G.BigBotTracker or {}
_G.BigBotTracker = BBT
BBT.Report = BBT.Report or {}
local Report = BBT.Report
local Util = BBT.Util
local REPORT_COMMENT_LIMIT = 127
local unpack = unpack or table.unpack
Report.REPORT_COMMENT_LIMIT = REPORT_COMMENT_LIMIT
local function truncate(value, limit)
value = tostring(value or "")
limit = limit or REPORT_COMMENT_LIMIT
if #value <= limit then
return value
end
return value:sub(1, math.max(0, limit - 3)) .. "..."
end
local function formatDurationCompact(seconds)
seconds = math.max(0, math.floor((tonumber(seconds) or 0) + 0.5))
if seconds < 60 then
return tostring(seconds) .. "s"
end
if seconds < 3600 then
local minutes = math.floor(seconds / 60)
local remainder = seconds % 60
if remainder == 0 then
return tostring(minutes) .. "m"
end
return string.format("%dm%02ds", minutes, remainder)
end
if seconds < 86400 then
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
if minutes == 0 then
return tostring(hours) .. "h"
end
return string.format("%dh%02dm", hours, minutes)
end
local days = math.floor(seconds / 86400)
local hours = math.floor((seconds % 86400) / 3600)
if hours == 0 then
return tostring(days) .. "d"
end
return string.format("%dd%02dh", days, hours)
end
local function getActiveSpan(candidate)
local behavior = candidate and candidate.behavior or {}
if (behavior.activeSpan or 0) > 0 then
return behavior.activeSpan
end
if candidate and candidate.firstSeen and candidate.lastSeen and candidate.lastSeen > candidate.firstSeen then
return candidate.lastSeen - candidate.firstSeen
end
return 0
end
local function getBestRate(candidate)
local behavior = candidate and candidate.behavior or {}
local timing = candidate and candidate.timing or {}
local rate = behavior.postsPerHour or 0
for _, summary in pairs(timing.windowSummaries or {}) do
rate = math.max(rate, summary.postsPerHour or 0)
end
return rate
end
local function getDominantBucket(candidate)
local timing = candidate and candidate.timing or {}
return timing.dominantBuckets and timing.dominantBuckets[1] or nil
end
local function buildIntervalFragment(candidate)
local timing = candidate and candidate.timing or {}
local baseline = candidate and candidate.baseline or {}
local topBucket = getDominantBucket(candidate)
local interval = topBucket and topBucket.bucket or timing.medianInterval or timing.averageInterval or 0
local cadenceClass = timing.cadenceClass or timing.intervalConsistency
if topBucket and (topBucket.percent or 0) >= 60 and interval > 0 then
return string.format("~%s interval", formatDurationCompact(interval))
end
local regularCadence = cadenceClass == "Fixed Cadence"
or cadenceClass == "Dominant Active-Run Cadence"
or cadenceClass == "Dominant Cadence"
or cadenceClass == "Jittered Cadence"
or cadenceClass == "Mixed Cadence"
or cadenceClass == "Mixed Regular"
if regularCadence then
if interval > 0 then
return string.format("~%s interval", formatDurationCompact(interval))
end
return "regular posting interval"
end
if (baseline.regularityPercentile or 0) >= 95 then
return "highly regular timing"
end
return nil
end
local function buildVolumeFragment(candidate)
local messages = candidate and candidate.totalMessages or 0
if messages <= 0 then
return nil
end
local span = getActiveSpan(candidate)
if span >= 60 then
return string.format("%d posts in %s", messages, formatDurationCompact(span))
end
return tostring(messages) .. " posts"
end
local function buildReuseFragment(candidate)
local content = candidate and candidate.content or {}
local templateReuse = content.templateReusePercent or 0
local shingleReuse = content.shingleReusePercent or 0
local nearDuplicates = content.nearDuplicateCount or 0
if templateReuse >= 40 then
return string.format("%d%% reused text", math.floor(templateReuse + 0.5))
end
if shingleReuse >= 55 then
return string.format("%d%% similar wording", math.floor(shingleReuse + 0.5))
end
if nearDuplicates > 0 then
return tostring(nearDuplicates) .. " near-dupes"
end
return nil
end
local function buildPersistenceFragment(candidate)
local dayCount = Util.CountMap(candidate and candidate.daysSeen)
if dayCount >= 2 then
return string.format("observed %d days", dayCount)
end
return nil
end
local function buildRateFragment(candidate)
local rate = getBestRate(candidate)
if rate >= 15 then
return string.format("about %.0f posts/hr", rate)
end
return nil
end
local function buildLocalEvidenceFragment(candidate)
local score = candidate and candidate.score or {}
local localEvidence = score.confidence or 0
if localEvidence > 0 then
return string.format("%d%% local evidence", math.floor(localEvidence + 0.5))
end
return nil
end
local function addPart(parts, value)
if value and value ~= "" then
parts[#parts + 1] = value
end
end
local function renderReportComment(base, parts, confidencePart)
local allParts = {}
for _, part in ipairs(parts) do
allParts[#allParts + 1] = part
end
if confidencePart then
allParts[#allParts + 1] = confidencePart
end
if #allParts == 0 then
return base .. "."
end
return base .. ": " .. table.concat(allParts, ", ") .. "."
end
local function composeReportComment(parts, confidencePart)
local base = "Big Bot Tracker: Repeated advertising pattern"
local kept = {}
for _, part in ipairs(parts) do
kept[#kept + 1] = part
local candidate = renderReportComment(base, kept, confidencePart)
if #candidate > REPORT_COMMENT_LIMIT then
table.remove(kept)
end
end
local comment = renderReportComment(base, kept, confidencePart)
while #comment > REPORT_COMMENT_LIMIT and #kept > 0 do
table.remove(kept)
comment = renderReportComment(base, kept, confidencePart)
end
if #comment <= REPORT_COMMENT_LIMIT then
return comment
end
return truncate(comment, REPORT_COMMENT_LIMIT)
end
local function addEvidenceBullet(bullets, seen, text)
if not text or text == "" or #bullets >= 4 then
return
end
if seen[text] then
return
end
seen[text] = true
bullets[#bullets + 1] = text
end
local function plural(value, singular, pluralText)
return tostring(value) .. " " .. (value == 1 and singular or pluralText)
end
local function getReportEnums()
local enum = _G.Enum or {}
local reportType = enum.ReportType or {}
local majorCategory = enum.ReportMajorCategory or {}
local minorCategory = enum.ReportMinorCategory or {}
return {
inWorld = reportType.InWorld,
cheating = majorCategory.Cheating,
botting = minorCategory.Botting,
}
end
local function tableContains(list, value)
if value == nil or type(list) ~= "table" then
return false
end
for _, item in ipairs(list) do
if item == value then
return true
end
end
return false
end
local function safeCall(fn, ...)
if type(fn) ~= "function" then
return false, nil, "missing"
end
local ok, first, second = pcall(fn, ...)
if not ok then
return false, nil, tostring(first)
end
return true, first, second
end
local function createLocation(methodName, ...)
if not PlayerLocation or type(PlayerLocation[methodName]) ~= "function" then
return nil, "missing"
end
local args = { ... }
local ok, location = pcall(function()
return PlayerLocation[methodName](PlayerLocation, unpack(args))
end)
if not ok then
return nil, tostring(location)
end
return location, nil
end
local function isLocationValid(location)
if not location or type(location.IsValid) ~= "function" then
return false
end
local ok, valid = pcall(function()
return location:IsValid()
end)
return ok and valid == true
end
local function canReportLocation(location)
if not isLocationValid(location) then
return false, nil
end
if not C_ReportSystem or type(C_ReportSystem.CanReportPlayer) ~= "function" then
return false, "missing"
end
local ok, canReport = pcall(C_ReportSystem.CanReportPlayer, location)
if not ok then
return false, tostring(canReport)
end
return canReport == true, nil
end
local function getTargetFullName()
if not UnitExists or not UnitExists("target") then
return nil
end
local name, realm
if UnitFullName then
name, realm = UnitFullName("target")
end
if (not name or name == "") and UnitName then
name, realm = UnitName("target")
end
if not name or name == "" then
return nil
end
if not realm or realm == "" then
realm = Util.GetPlayerRealm()
end
return name .. "-" .. realm
end
local function targetMatchesCandidate(candidate)
local fullName = getTargetFullName()
if not fullName or not candidate then
return false, fullName
end
local targetIdentity = Util.NormalizeIdentity(fullName)
return targetIdentity.fullKey == candidate.fullKey, targetIdentity.displayName
end
local function checkInWorldBottingCategory()
local enums = getReportEnums()
local status = {
hasReportType = enums.inWorld ~= nil,
hasCheating = false,
hasBotting = false,
error = nil,
}
if not status.hasReportType or not C_ReportSystem then
return status
end
local okMajor, majorCategories, majorError = safeCall(C_ReportSystem.GetMajorCategoriesForReportType, enums.inWorld)
if not okMajor then
status.error = majorError
return status
end
status.hasCheating = tableContains(majorCategories, enums.cheating)
if not status.hasCheating then
return status
end
local okMinor, minorCategories, minorError =
safeCall(C_ReportSystem.GetMinorCategoriesForReportTypeAndMajorCategory, enums.inWorld, enums.cheating)
if not okMinor then
status.error = minorError
return status
end
status.hasBotting = tableContains(minorCategories, enums.botting)
return status
end
local function writeDiagnostic(candidate, diagnostic)
if not candidate or type(diagnostic) ~= "table" then
return
end
candidate.lastReportDiagnostic = {
checkedAt = diagnostic.checkedAt,
isCritical = diagnostic.isCritical,
hasGuid = diagnostic.hasGuid,
hasLineID = diagnostic.hasLineID,
targetMatches = diagnostic.targetMatches,
targetLocationValid = diagnostic.targetLocationValid,
targetCanReport = diagnostic.targetCanReport,
guidLocationValid = diagnostic.guidLocationValid,
guidCanReport = diagnostic.guidCanReport,
chatLineValid = diagnostic.chatLineValid,
chatLineCanReport = diagnostic.chatLineCanReport,
inWorldHasCheating = diagnostic.inWorldHasCheating,
inWorldHasBotting = diagnostic.inWorldHasBotting,
canOpen = diagnostic.canOpen,
source = diagnostic.source,
reason = diagnostic.reason,
}
end
function Report.IsCriticalCandidate(candidate)
local score = candidate and candidate.score or {}
return score.status == "Very Strong Pattern" or score.tier == "Very Strong Pattern"
end
function Report.BuildReportComment(candidate)
local parts = {}
addPart(parts, buildIntervalFragment(candidate))
addPart(parts, buildVolumeFragment(candidate))
addPart(parts, buildReuseFragment(candidate))
addPart(parts, buildPersistenceFragment(candidate))
addPart(parts, buildRateFragment(candidate))
return composeReportComment(parts, buildLocalEvidenceFragment(candidate))
end
function Report.BuildReportAssist(candidate)
local timing = candidate and candidate.timing or {}
local content = candidate and candidate.content or {}
local score = candidate and candidate.score or {}
local bullets = {}
local seen = {}
local topBucket = getDominantBucket(candidate)
if topBucket and (topBucket.percent or 0) > 0 then
addEvidenceBullet(
bullets,
seen,
string.format(
"Observed timing: %d%% of intervals were near %s.",
math.floor((topBucket.percent or 0) + 0.5),
formatDurationCompact(topBucket.bucket or timing.medianInterval or timing.averageInterval or 0)
)
)
elseif buildIntervalFragment(candidate) then
addEvidenceBullet(bullets, seen, "Observed timing: " .. buildIntervalFragment(candidate) .. ".")
end
local messages = candidate and candidate.totalMessages or 0
local activeSpan = getActiveSpan(candidate)
if messages > 0 then
local observed = string.format("Observed volume: %s", plural(messages, "message", "messages"))
if activeSpan >= 60 then
observed = observed .. " over " .. formatDurationCompact(activeSpan)
end
local dayCount = Util.CountMap(candidate and candidate.daysSeen)
if dayCount >= 2 then
observed = observed .. " across " .. plural(dayCount, "day", "days")
end
addEvidenceBullet(bullets, seen, observed .. ".")
end
local reuseDetails = {}
if (content.templateReusePercent or 0) >= 40 then
reuseDetails[#reuseDetails + 1] =
string.format("%d%% reused text", math.floor((content.templateReusePercent or 0) + 0.5))
end
if (content.shingleReusePercent or 0) >= 55 then
reuseDetails[#reuseDetails + 1] =
string.format("%d%% similar wording", math.floor((content.shingleReusePercent or 0) + 0.5))
end
if (content.nearDuplicateCount or 0) > 0 then
reuseDetails[#reuseDetails + 1] = plural(content.nearDuplicateCount or 0, "near-dupe", "near-dupes")
end
if #reuseDetails > 0 then
addEvidenceBullet(bullets, seen, "Repeated wording: " .. table.concat(reuseDetails, ", ") .. ".")
end
local rate = getBestRate(candidate)
if rate >= 15 then
addEvidenceBullet(bullets, seen, string.format("Posting rate: %.1f/hr in active windows.", rate))
end
for _, reason in ipairs(score.reasons or {}) do
addEvidenceBullet(bullets, seen, "Observed signal: " .. tostring(reason))
end
if #bullets < 2 then
addEvidenceBullet(
bullets,
seen,
string.format(
"Model context: local timing and repeated-ad evidence reached %d%% local evidence.",
math.floor((score.confidence or 0) + 0.5)
)
)
end
return {
comment = Report.BuildReportComment(candidate),
commentLimit = REPORT_COMMENT_LIMIT,
instruction = "If you report this in Blizzard's window, select Cheating > Botting.",
bullets = bullets,
}
end
function Report.GetDiagnostics(candidate)
local categoryStatus = checkInWorldBottingCategory()
local diagnostic = {
checkedAt = Util.GetNow(),
candidate = candidate and candidate.displayName or nil,
isCritical = Report.IsCriticalCandidate(candidate),
hasGuid = candidate and candidate.lastGuid ~= nil and candidate.lastGuid ~= "",
hasLineID = candidate and candidate.lastLineID ~= nil,
targetMatches = false,
targetName = nil,
targetLocationValid = false,
targetCanReport = false,
guidLocationValid = false,
guidCanReport = false,
chatLineValid = false,
chatLineCanReport = false,
inWorldHasCheating = categoryStatus.hasCheating,
inWorldHasBotting = categoryStatus.hasBotting,
canOpen = false,
source = "none",
reason = "No candidate selected.",
}
if not candidate then
return diagnostic
end
local selectedLocation = nil
diagnostic.targetMatches, diagnostic.targetName = targetMatchesCandidate(candidate)
if diagnostic.targetMatches then
local targetLocation = createLocation("CreateFromUnit", "target")
diagnostic.targetLocationValid = isLocationValid(targetLocation)
diagnostic.targetCanReport = canReportLocation(targetLocation)
if diagnostic.targetCanReport then
selectedLocation = targetLocation
diagnostic.source = "target"
end
end
if not selectedLocation and diagnostic.hasGuid then
local guidLocation = createLocation("CreateFromGUID", candidate.lastGuid)
diagnostic.guidLocationValid = isLocationValid(guidLocation)
diagnostic.guidCanReport = canReportLocation(guidLocation)
if diagnostic.guidCanReport then
selectedLocation = guidLocation
diagnostic.source = "guid"
end
end
if diagnostic.hasLineID then
local validChatLine = false
if C_ChatInfo and type(C_ChatInfo.IsValidChatLine) == "function" then
local ok, result = pcall(C_ChatInfo.IsValidChatLine, candidate.lastLineID)
validChatLine = ok and result == true
end
diagnostic.chatLineValid = validChatLine
if validChatLine then
local chatLocation = createLocation("CreateFromChatLineID", candidate.lastLineID)
diagnostic.chatLineCanReport = canReportLocation(chatLocation)
end
end
diagnostic._selectedLocation = selectedLocation
if not diagnostic.isCritical then
diagnostic.reason = "Candidate is not Very Strong Pattern."
elseif not diagnostic.inWorldHasBotting then
diagnostic.reason = "In-world Botting category unavailable."
elseif not selectedLocation then
diagnostic.reason = "No reportable in-world player location."
else
diagnostic.canOpen = true
diagnostic.reason = "Ready."
end
writeDiagnostic(candidate, diagnostic)
return diagnostic
end
local function loadReportFrame()
if ReportFrame and ReportFrame.InitiateReport then
return true
end
if C_AddOns and type(C_AddOns.LoadAddOn) == "function" then
local ok = pcall(C_AddOns.LoadAddOn, "Blizzard_ReportFrame")
return ok and ReportFrame and ReportFrame.InitiateReport
end
if type(LoadAddOn) == "function" then
local ok = pcall(LoadAddOn, "Blizzard_ReportFrame")
return ok and ReportFrame and ReportFrame.InitiateReport
end
return false
end
function Report.OpenBottingReport(candidate)
local diagnostic = Report.GetDiagnostics(candidate)
if not diagnostic.canOpen then
return false, diagnostic
end
if not loadReportFrame() then
diagnostic.canOpen = false
diagnostic.reason = "Blizzard report frame unavailable."
writeDiagnostic(candidate, diagnostic)
return false, diagnostic
end
if not ReportInfo or type(ReportInfo.CreateReportInfoFromType) ~= "function" then
diagnostic.canOpen = false
diagnostic.reason = "ReportInfo API unavailable."
writeDiagnostic(candidate, diagnostic)
return false, diagnostic
end
local enums = getReportEnums()
local reportInfo = ReportInfo:CreateReportInfoFromType(enums.inWorld)
if not reportInfo then
diagnostic.canOpen = false
diagnostic.reason = "Could not create in-world report info."
writeDiagnostic(candidate, diagnostic)
return false, diagnostic
end
local ok, err = pcall(function()
ReportFrame:InitiateReport(reportInfo, candidate.displayName, diagnostic._selectedLocation)
end)
if not ok then
diagnostic.canOpen = false
diagnostic.reason = tostring(err)
writeDiagnostic(candidate, diagnostic)
return false, diagnostic
end
diagnostic.reason = "Opened Blizzard report frame."
writeDiagnostic(candidate, diagnostic)
if BBT.Storage and BBT.Storage.MarkReported then
BBT.Storage.MarkReported(candidate, Util.GetNow(), true)
end
return true, diagnostic
end