Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
1334 lines (1169 loc) · 48.5 KB
/
Copy pathCore.lua
File metadata and controls
1334 lines (1169 loc) · 48.5 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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- RskChatScanner Core
local addonName, addon = ...
-- Initialize addon with Ace3
addon.core = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceEvent-3.0", "AceTimer-3.0", "AceConsole-3.0")
local core = addon.core
-- Libraries (with fallbacks if missing)
local LSM = LibStub("LibSharedMedia-3.0", true) or {}
-- Add fallback methods if library is missing
if not LSM.Fetch then
LSM.Fetch = function(_, mediatype, key)
if mediatype == "statusbar" then
return "Interface\\TargetingFrame\\UI-StatusBar"
elseif mediatype == "font" then
return "Fonts\\FRIZQT__.TTF"
elseif mediatype == "sound" then
return "Sound\\Interface\\iTellMessage.ogg"
end
end
end
-- Expose activeBars globally so UI/Bars.lua can access it
addon.activeBars = addon.activeBars or {}
local activeBars = addon.activeBars
local barAnchors = {}
local matches = {}
local barsLocked = true
-- Function to create anchor if it doesn't exist
local function CreateAnchor()
if barAnchors[1] then
return barAnchors[1]
end
if not addon.Config or not addon.Config.db or not addon.Config.db.profile then
return nil
end
local appearance = addon.Config.db.profile.appearance
-- Create anchor frame
local anchor = CreateFrame("Frame", "RskChatScannerBarAnchor", UIParent, BackdropTemplateMixin and "BackdropTemplate")
anchor:SetSize(appearance.barWidth, appearance.barHeight)
anchor:SetPoint(appearance.barPosition.point,
UIParent,
appearance.barPosition.relativePoint,
appearance.barPosition.x,
appearance.barPosition.y)
anchor:SetMovable(true)
anchor:EnableMouse(false) -- Locked by default
anchor:RegisterForDrag("LeftButton")
-- Add visual background when unlocked
if anchor.SetBackdrop then
anchor:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
anchor:SetBackdropColor(0, 1, 0, 0.3)
anchor:SetBackdropBorderColor(0, 1, 0, 0.8)
end
-- Add text
anchor.text = anchor:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
anchor.text:SetPoint("CENTER")
anchor.text:SetText("Drag to move")
anchor.text:SetTextColor(1, 1, 1)
-- Hide anchor by default (locked)
anchor:Hide()
anchor:SetScript("OnDragStart", function(self) self:StartMoving() end)
anchor:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local point, _, relativePoint, x, y = self:GetPoint()
appearance.barPosition.point = point
appearance.barPosition.relativePoint = relativePoint
appearance.barPosition.x = x
appearance.barPosition.y = y
end)
barAnchors[1] = anchor
return anchor
end
-- Function to toggle lock/unlock bars
local function ToggleBarsLock()
barsLocked = not barsLocked
-- Create anchor if it doesn't exist
local anchor = CreateAnchor()
if anchor then
if barsLocked then
anchor:EnableMouse(false)
anchor:Hide()
print("|cff00ff00ChatScanner PRO:|r Bars locked")
else
anchor:EnableMouse(true)
anchor:Show()
print("|cff00ff00ChatScanner PRO:|r Bars unlocked - Drag the green anchor to move notifications")
end
else
print("|cff00ff00ChatScanner PRO:|r Error: Could not create anchor")
end
end
-- Function to reposition all active bars
local function RepositionBars()
if not addon.Config or not addon.Config.db or not addon.Config.db.profile then
return
end
local appearance = addon.Config.db.profile.appearance
local anchor = barAnchors[1]
if not anchor then return end
for i, bar in ipairs(activeBars) do
bar:ClearAllPoints()
local offset = (i - 1) * (appearance.barHeight + appearance.barSpacing)
if appearance.barGrowDirection == "UP" then
bar:SetPoint("BOTTOMLEFT", anchor, "TOPLEFT", 0, offset)
else
bar:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, -offset)
end
end
end
-- Parse comma-separated keywords with special syntax
function core.ParseKeywords(keywordString)
if not keywordString or keywordString == "" then
return { normal = {}, required = {}, groups = {} }
end
local result = {
normal = {}, -- Normal keywords (any one is enough)
required = {}, -- Required keywords (all must be present)
groups = {} -- Groups of keywords (all in a group must be present)
}
-- Process normal keywords (separated by commas)
for keyword in string.gmatch(keywordString, "([^,]+)") do
local trimmed = string.trim(keyword):lower()
-- Check for required keywords with + syntax
if string.match(trimmed, "^%+(.+)%+$") then
local required = string.match(trimmed, "^%+(.+)%+$")
table.insert(result.required, required)
-- Check for keyword groups with & syntax
elseif string.match(trimmed, "^%&(.+)%&$") then
local group = string.match(trimmed, "^%&(.+)%&$")
local groupWords = {}
for word in string.gmatch(group, "([^%s]+)") do
table.insert(groupWords, word:lower())
end
if #groupWords > 0 then
table.insert(result.groups, groupWords)
end
-- Normal keywords
else
table.insert(result.normal, trimmed:lower())
end
end
return result
end
-- Check if message matches keywords according to our flexible system
function core.MessageMatchesKeywords(message, keywords)
local lowerMessage = string.lower(message)
local matchedKeyword = nil
-- Check required keywords (all must be present)
if #keywords.required > 0 then
for _, keyword in ipairs(keywords.required) do
if not string.find(lowerMessage, keyword, 1, true) then
return false, nil -- Missing a required keyword
end
end
matchedKeyword = table.concat(keywords.required, "+")
end
-- Check keyword groups (all keywords in at least one group must be present)
local groupMatched = false
if #keywords.groups > 0 then
for _, group in ipairs(keywords.groups) do
local allInGroupFound = true
for _, word in ipairs(group) do
if not string.find(lowerMessage, word, 1, true) then
allInGroupFound = false
break
end
end
if allInGroupFound then
groupMatched = true
if not matchedKeyword then
matchedKeyword = table.concat(group, "&")
end
break
end
end
-- If we have groups but none matched, and no required keywords matched either,
-- then we need to check normal keywords
if not groupMatched and #keywords.required == 0 then
-- Continue to normal keywords check
elseif not groupMatched and #keywords.required > 0 then
-- Required keywords matched but no group matched
return true, matchedKeyword
else
-- A group matched
return true, matchedKeyword
end
end
-- If we have required keywords but no normal keywords, and required matched,
-- then we're done
if #keywords.required > 0 and #keywords.normal == 0 then
return true, matchedKeyword
end
-- Check normal keywords (any one is enough)
for _, keyword in ipairs(keywords.normal) do
if string.find(lowerMessage, keyword, 1, true) then
return true, keyword
end
end
-- If we have required keywords but no normal keywords matched,
-- we still consider it a match
if #keywords.required > 0 then
return true, matchedKeyword
end
-- No match found
return false, nil
end
-- Get player info (level, class, guild)
local function GetPlayerInfo(playerName)
local info = {
name = playerName,
level = nil,
class = nil,
classColor = nil,
guild = nil,
classIcon = nil
}
-- Try to get info from target/mouseover/party/raid
local unit = nil
if UnitName("target") == playerName then
unit = "target"
elseif UnitName("mouseover") == playerName then
unit = "mouseover"
else
-- Check party
for i = 1, 4 do
if UnitName("party" .. i) == playerName then
unit = "party" .. i
break
end
end
-- Check raid
if not unit then
for i = 1, 40 do
if UnitName("raid" .. i) == playerName then
unit = "raid" .. i
break
end
end
end
end
if unit then
info.level = UnitLevel(unit)
local _, class = UnitClass(unit)
info.class = class
-- Get class color
if class and RAID_CLASS_COLORS[class] then
info.classColor = RAID_CLASS_COLORS[class]
end
-- Get class icon
local classIcons = {
WARRIOR = "Interface\\Icons\\ClassIcon_Warrior",
PALADIN = "Interface\\Icons\\ClassIcon_Paladin",
HUNTER = "Interface\\Icons\\ClassIcon_Hunter",
ROGUE = "Interface\\Icons\\ClassIcon_Rogue",
PRIEST = "Interface\\Icons\\ClassIcon_Priest",
SHAMAN = "Interface\\Icons\\ClassIcon_Shaman",
MAGE = "Interface\\Icons\\ClassIcon_Mage",
WARLOCK = "Interface\\Icons\\ClassIcon_Warlock",
DRUID = "Interface\\Icons\\ClassIcon_Druid"
}
info.classIcon = classIcons[class]
-- Get guild
info.guild = GetGuildInfo(unit)
end
return info
end
-- Add player to blacklist
function core:AddToBlacklist(playerName, duration, reason)
if not addon.Config or not addon.Config.db or not addon.Config.db.profile.blacklist then
return
end
local blacklist = addon.Config.db.profile.blacklist.players
-- Check if player is already blacklisted
for _, entry in ipairs(blacklist) do
if entry.name == playerName then
print("|cffFF6B6BChatScanner PRO:|r " .. playerName .. " is already blacklisted")
return
end
end
-- Add to blacklist
table.insert(blacklist, {
name = playerName,
reason = reason or "No reason",
timestamp = time(),
duration = duration -- 0 = forever, otherwise seconds
})
local durationText = duration == 0 and "forever" or (duration == 3600 and "1 hour" or "24 hours")
print("|cffFF0000ChatScanner PRO:|r " .. playerName .. " added to blacklist for " .. durationText)
-- Close all notifications from this player
self:CloseNotificationsFromPlayer(playerName)
end
-- Close all notifications from a specific player
function core:CloseNotificationsFromPlayer(playerName)
if addon.Bars and addon.Bars.ClosePlayerBars then
addon.Bars:ClosePlayerBars(playerName)
end
end
-- Check if player is blacklisted
function core:IsBlacklisted(playerName)
if not addon.Config or not addon.Config.db or not addon.Config.db.profile.blacklist then
return false
end
local blacklist = addon.Config.db.profile.blacklist.players
local currentTime = time()
for i = #blacklist, 1, -1 do
local entry = blacklist[i]
if entry.name == playerName then
-- Check if temporary blacklist has expired
if entry.duration > 0 then
local expiresAt = entry.timestamp + entry.duration
if currentTime >= expiresAt then
-- Remove expired entry
table.remove(blacklist, i)
return false
end
end
return true
end
end
return false
end
-- Show template menu
function core:ShowTemplateMenu(playerName, parent)
if not addon.Config or not addon.Config.db or not addon.Config.db.profile then
return
end
local templates = addon.Config.db.profile.templates
if not templates or #templates == 0 then
print("|cffFF0000ChatScanner PRO:|r No templates available. Create templates in the Templates tab.")
ChatFrame_SendTell(playerName)
return
end
-- Get enabled templates
local enabledTemplates = {}
for _, template in ipairs(templates) do
if template.enabled then
table.insert(enabledTemplates, template)
end
end
if #enabledTemplates == 0 then
print("|cffFF0000ChatScanner PRO:|r No enabled templates")
ChatFrame_SendTell(playerName)
return
end
-- If only one template, send it directly
if #enabledTemplates == 1 then
local template = enabledTemplates[1]
SendChatMessage(template.text, "WHISPER", nil, playerName)
print("|cff00ff00ChatScanner PRO:|r Sent template '" .. template.name .. "' to " .. playerName)
return
end
-- Multiple templates: show selection dialog
StaticPopupDialogs["CHATSCANNER_SELECT_TEMPLATE"] = {
text = "Select template to send to " .. playerName .. ":",
button1 = "Cancel",
OnShow = function(self)
-- Create buttons for each template
local yOffset = -60
for i, template in ipairs(enabledTemplates) do
local btn = CreateFrame("Button", nil, self, "UIPanelButtonTemplate")
btn:SetSize(200, 25)
btn:SetPoint("TOP", self, "TOP", 0, yOffset)
btn:SetText(template.name)
btn:SetScript("OnClick", function()
SendChatMessage(template.text, "WHISPER", nil, playerName)
print("|cff00ff00ChatScanner PRO:|r Sent template '" .. template.name .. "' to " .. playerName)
self:Hide()
end)
yOffset = yOffset - 30
end
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3
}
StaticPopup_Show("CHATSCANNER_SELECT_TEMPLATE")
end
-- Create a notification bar
local function CreateBar(match)
-- Get settings
local settings = addon.Config.db.profile
local appearance = settings.appearance
-- Find filter
local filter
for _, f in ipairs(settings.filters) do
if f.name == match.filterName then
filter = f
break
end
end
if not filter then return end
-- Play sound if enabled (global and per-filter)
if settings.settings.soundEnabled and (filter.playSound ~= false) then
local soundFile = LSM:Fetch("sound", appearance.sound) or "Sound\\Interface\\iTellMessage.ogg"
PlaySoundFile(soundFile, "Master")
end
-- Create a frame for the notification bar
local bar = CreateFrame("Frame", nil, UIParent)
bar:SetSize(appearance.barWidth, appearance.barHeight)
-- Store match data for later reference (blacklist, etc.)
bar.match = match
-- Set initial opacity to 0 for fade-in animation
bar:SetAlpha(0)
-- Add main texture background using selected bar texture
bar.bg = bar:CreateTexture(nil, "BACKGROUND")
bar.bg:SetAllPoints(bar)
local barTexture = LSM:Fetch("statusbar", appearance.barTexture) or "Interface\\TargetingFrame\\UI-StatusBar"
bar.bg:SetTexture(barTexture)
bar.bg:SetVertexColor(filter.color.r, filter.color.g, filter.color.b, appearance.barOpacity or 0.9)
-- Add simple border
bar.border = CreateFrame("Frame", nil, bar, BackdropTemplateMixin and "BackdropTemplate")
bar.border:SetAllPoints(bar)
if bar.border.SetBackdrop then
bar.border:SetBackdrop({
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 12,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
})
bar.border:SetBackdropBorderColor(0, 0, 0, 0.8)
end
-- Get player info
local playerInfo = GetPlayerInfo(match.playerName)
-- Get font settings for later use
local fontPath = LSM:Fetch("font", appearance.font) or "Fonts\\FRIZQT__.TTF"
local fontSize = appearance.fontSize or 12
-- Add icon on the left (filter icon, class icon, or default)
bar.icon = bar:CreateTexture(nil, "ARTWORK")
local iconSize = appearance.barHeight - 6
bar.icon:SetSize(iconSize, iconSize)
bar.icon:SetPoint("LEFT", bar, "LEFT", 3, 0)
-- Priority: Filter icon > Class icon > Default icon
if filter.icon and filter.icon ~= "" then
bar.icon:SetTexture(filter.icon)
elseif playerInfo.classIcon then
bar.icon:SetTexture(playerInfo.classIcon)
else
bar.icon:SetTexture("Interface\\Icons\\INV_Misc_Note_01")
end
-- Create compact button container on the right (2 rows)
local buttonWidth = 60
local buttonHeight = (appearance.barHeight - 8) / 2 -- Split height in 2
local buttonSpacing = 2
-- Container frame for buttons
bar.buttonContainer = CreateFrame("Frame", nil, bar)
bar.buttonContainer:SetSize(buttonWidth * 2 + buttonSpacing, appearance.barHeight - 6)
bar.buttonContainer:SetPoint("RIGHT", bar, "RIGHT", -3, 0)
-- Top row: Reply and Invite
bar.replyButton = CreateFrame("Button", nil, bar.buttonContainer)
bar.replyButton:SetSize(buttonWidth, buttonHeight)
bar.replyButton:SetPoint("TOPLEFT", bar.buttonContainer, "TOPLEFT", 0, 0)
bar.replyButton.bg = bar.replyButton:CreateTexture(nil, "BACKGROUND")
bar.replyButton.bg:SetAllPoints()
bar.replyButton.bg:SetColorTexture(0.2, 0.6, 0.2, 0.8)
bar.replyButton.text = bar.replyButton:CreateFontString(nil, "OVERLAY")
bar.replyButton.text:SetPoint("CENTER")
bar.replyButton.text:SetFont(fontPath, math.max(fontSize - 2, 8), "OUTLINE")
bar.replyButton.text:SetText("Reply")
bar.replyButton.text:SetTextColor(1, 1, 1)
bar.replyButton:SetScript("OnEnter", function(self)
self.bg:SetColorTexture(0.3, 0.8, 0.3, 1)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:AddLine("Whisper " .. match.playerName)
if addon.Config.db.profile.templates and #addon.Config.db.profile.templates > 0 then
GameTooltip:AddLine("Right-click for templates", 0.5, 0.5, 1)
end
GameTooltip:Show()
end)
bar.replyButton:SetScript("OnLeave", function(self)
self.bg:SetColorTexture(0.2, 0.6, 0.2, 0.8)
GameTooltip:Hide()
end)
bar.replyButton:RegisterForClicks("LeftButtonUp", "RightButtonUp")
bar.replyButton:SetScript("OnClick", function(self, button)
if button == "LeftButton" then
ChatFrame_SendTell(match.playerName)
elseif button == "RightButton" then
core:ShowTemplateMenu(match.playerName, self)
end
end)
-- Invite button (top right)
bar.inviteButton = CreateFrame("Button", nil, bar.buttonContainer)
bar.inviteButton:SetSize(buttonWidth, buttonHeight)
bar.inviteButton:SetPoint("TOPRIGHT", bar.buttonContainer, "TOPRIGHT", 0, 0)
bar.inviteButton.bg = bar.inviteButton:CreateTexture(nil, "BACKGROUND")
bar.inviteButton.bg:SetAllPoints()
bar.inviteButton.bg:SetColorTexture(0.8, 0.6, 0.2, 0.8)
bar.inviteButton.text = bar.inviteButton:CreateFontString(nil, "OVERLAY")
bar.inviteButton.text:SetPoint("CENTER")
bar.inviteButton.text:SetFont(fontPath, math.max(fontSize - 2, 8), "OUTLINE")
bar.inviteButton.text:SetText("Invite")
bar.inviteButton.text:SetTextColor(1, 1, 1)
bar.inviteButton:SetScript("OnEnter", function(self)
self.bg:SetColorTexture(1, 0.8, 0.3, 1)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:AddLine("Invite to group")
GameTooltip:Show()
end)
bar.inviteButton:SetScript("OnLeave", function(self)
self.bg:SetColorTexture(0.8, 0.6, 0.2, 0.8)
GameTooltip:Hide()
end)
bar.inviteButton:SetScript("OnClick", function()
InviteUnit(match.playerName)
print("|cff00ff00ChatScanner PRO:|r Invited " .. match.playerName)
end)
-- Copy button (bottom left)
bar.copyButton = CreateFrame("Button", nil, bar.buttonContainer)
bar.copyButton:SetSize(buttonWidth, buttonHeight)
bar.copyButton:SetPoint("BOTTOMLEFT", bar.buttonContainer, "BOTTOMLEFT", 0, 0)
bar.copyButton.bg = bar.copyButton:CreateTexture(nil, "BACKGROUND")
bar.copyButton.bg:SetAllPoints()
bar.copyButton.bg:SetColorTexture(0.4, 0.4, 0.8, 0.8)
bar.copyButton.text = bar.copyButton:CreateFontString(nil, "OVERLAY")
bar.copyButton.text:SetPoint("CENTER")
bar.copyButton.text:SetFont(fontPath, math.max(fontSize - 2, 8), "OUTLINE")
bar.copyButton.text:SetText("Copy")
bar.copyButton.text:SetTextColor(1, 1, 1)
bar.copyButton:SetScript("OnEnter", function(self)
self.bg:SetColorTexture(0.5, 0.5, 1, 1)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:AddLine("Copy name")
GameTooltip:Show()
end)
bar.copyButton:SetScript("OnLeave", function(self)
self.bg:SetColorTexture(0.4, 0.4, 0.8, 0.8)
GameTooltip:Hide()
end)
bar.copyButton:SetScript("OnClick", function()
-- Create a popup dialog with the name to copy
StaticPopupDialogs["CHATSCANNER_COPY_NAME"] = {
text = "Copy this name (Ctrl+C):",
button1 = "Close",
hasEditBox = true,
OnShow = function(self)
self.editBox:SetText(match.playerName)
self.editBox:HighlightText()
self.editBox:SetFocus()
end,
OnAccept = function(self)
-- Nothing to do, just close
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3
}
StaticPopup_Show("CHATSCANNER_COPY_NAME")
end)
-- Ignore button (bottom right)
bar.ignoreButton = CreateFrame("Button", nil, bar.buttonContainer)
bar.ignoreButton:SetSize(buttonWidth, buttonHeight)
bar.ignoreButton:SetPoint("BOTTOMRIGHT", bar.buttonContainer, "BOTTOMRIGHT", 0, 0)
bar.ignoreButton.bg = bar.ignoreButton:CreateTexture(nil, "BACKGROUND")
bar.ignoreButton.bg:SetAllPoints()
bar.ignoreButton.bg:SetColorTexture(0.8, 0.2, 0.2, 0.8)
bar.ignoreButton.text = bar.ignoreButton:CreateFontString(nil, "OVERLAY")
bar.ignoreButton.text:SetPoint("CENTER")
bar.ignoreButton.text:SetFont(fontPath, math.max(fontSize - 2, 8), "OUTLINE")
bar.ignoreButton.text:SetText("Ignore")
bar.ignoreButton.text:SetTextColor(1, 1, 1)
bar.ignoreButton:SetScript("OnEnter", function(self)
self.bg:SetColorTexture(1, 0.3, 0.3, 1)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:AddLine("Ignore player")
GameTooltip:Show()
end)
bar.ignoreButton:SetScript("OnLeave", function(self)
self.bg:SetColorTexture(0.8, 0.2, 0.2, 0.8)
GameTooltip:Hide()
end)
bar.ignoreButton:SetScript("OnClick", function()
-- Show simple popup to choose ignore duration
StaticPopupDialogs["CHATSCANNER_IGNORE_PLAYER"] = {
text = "Ignore " .. match.playerName .. " for how long?",
button1 = "1 Hour",
button2 = "24 Hours",
button3 = "Forever",
OnAccept = function()
if addon.core then
addon.core:AddToBlacklist(match.playerName, 3600, "Ignored from notification")
end
end,
OnCancel = function()
if addon.core then
addon.core:AddToBlacklist(match.playerName, 86400, "Ignored from notification")
end
end,
OnAlt = function()
if addon.core then
addon.core:AddToBlacklist(match.playerName, 0, "Ignored from notification")
end
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3
}
StaticPopup_Show("CHATSCANNER_IGNORE_PLAYER")
end)
-- Build enriched player text
local playerText = match.playerName
-- Add level if available
if playerInfo.level and playerInfo.level > 0 then
playerText = playerText .. " [" .. playerInfo.level .. "]"
end
-- Add guild if available
if playerInfo.guild then
playerText = playerText .. " <" .. playerInfo.guild .. ">"
end
-- Add text next to icon (with space for action buttons)
bar.label = bar:CreateFontString(nil, "OVERLAY")
bar.label:SetPoint("LEFT", bar.icon, "RIGHT", 8, 0)
bar.label:SetPoint("RIGHT", bar.buttonContainer, "LEFT", -5, 0)
-- Apply custom font from settings
bar.label:SetFont(fontPath, fontSize, "OUTLINE")
bar.label:SetText(playerText)
-- Apply class color if available
if playerInfo.classColor then
bar.label:SetTextColor(playerInfo.classColor.r, playerInfo.classColor.g, playerInfo.classColor.b)
else
bar.label:SetTextColor(1, 1, 1)
end
bar.label:SetJustifyH("LEFT")
-- Enable mouse interaction
bar:EnableMouse(true)
-- Add tooltip and pause on hover
bar:SetScript("OnEnter", function(self)
-- Pause on hover functionality
if appearance.pauseOnHover then
self.isPaused = true
if self.hideTimer then
self.hideTimer:Cancel()
end
end
-- Show tooltip
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:AddLine("|cffFFD700ChatScanner PRO|r")
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine("Filter:", "|cffFFFFFF" .. match.filterName .. "|r")
GameTooltip:AddDoubleLine("Player:", playerText)
if playerInfo.class then
GameTooltip:AddDoubleLine("Class:", "|cff" ..
string.format("%02x%02x%02x",
playerInfo.classColor.r * 255,
playerInfo.classColor.g * 255,
playerInfo.classColor.b * 255) ..
playerInfo.class .. "|r")
end
GameTooltip:AddDoubleLine("Channel:", "|cffFF6B6B" .. match.channel .. "|r")
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Message:", 1, 1, 0)
GameTooltip:AddLine(match.message, 1, 1, 1, true)
GameTooltip:AddLine(" ")
GameTooltip:AddLine("|cff00FF00Click bar to whisper|r")
if appearance.pauseOnHover then
GameTooltip:AddLine("|cff888888(Timer paused while hovering)|r")
end
GameTooltip:Show()
end)
bar:SetScript("OnLeave", function(self)
-- Resume timer if pause on hover is enabled
if appearance.pauseOnHover then
self.isPaused = false
-- Restart timer
self.hideTimer = C_Timer.After(self.duration or 10, function()
if not self.isPaused then
self:Stop()
end
end)
end
GameTooltip:Hide()
end)
-- Add click handler
bar:SetScript("OnMouseDown", function()
ChatFrame_SendTell(match.playerName)
end)
-- Add methods to mimic LibCandyBar
bar.SetLabel = function(self, text)
self.label:SetText(text)
end
bar.SetDuration = function(self, duration)
self.duration = duration
end
bar.SetColor = function(self, r, g, b)
if self.SetBackdrop then
self:SetBackdropColor(r, g, b, 0.5)
end
end
bar.SetTextColor = function(self, r, g, b)
self.label:SetTextColor(r, g, b)
end
bar.SetTimeVisibility = function(self, visible) end
bar.SetIcon = function(self, icon)
self.icon:SetTexture(icon)
end
bar.Start = function(self)
self:Show()
-- Fade-in animation
local fadeInDuration = appearance.fadeInDuration or 0.3
if fadeInDuration > 0 then
local startTime = GetTime()
local fadeInFrame = CreateFrame("Frame")
fadeInFrame:SetScript("OnUpdate", function(frame)
local elapsed = GetTime() - startTime
local progress = math.min(elapsed / fadeInDuration, 1)
self:SetAlpha(progress)
if progress >= 1 then
frame:SetScript("OnUpdate", nil)
end
end)
else
self:SetAlpha(1)
end
-- Auto-hide after duration
self.hideTimer = C_Timer.After(self.duration or 10, function()
if not self.isPaused then
self:Stop()
end
end)
end
bar.Stop = function(self)
-- Fade-out animation
local fadeOutDuration = appearance.fadeOutDuration or 0.5
if fadeOutDuration > 0 then
local startAlpha = self:GetAlpha()
local startTime = GetTime()
local fadeOutFrame = CreateFrame("Frame")
fadeOutFrame:SetScript("OnUpdate", function(frame)
local elapsed = GetTime() - startTime
local progress = math.min(elapsed / fadeOutDuration, 1)
self:SetAlpha(startAlpha * (1 - progress))
if progress >= 1 then
frame:SetScript("OnUpdate", nil)
if self.onStopCallback then
self.onStopCallback()
end
self:Hide()
end
end)
else
if self.onStopCallback then
self.onStopCallback()
end
self:Hide()
end
end
bar.SetCallback = function(self, event, callback)
if event == "OnStop" then
self.onStopCallback = callback
end
end
-- Set properties
bar:SetLabel(match.playerName)
-- Use custom duration from settings
local duration = addon.Config.db.profile.settings.notificationDuration or 10
bar:SetDuration(duration)
bar:SetColor(filter.color.r, filter.color.g, filter.color.b)
bar:SetTextColor(1, 1, 1)
-- Les scripts sont déjà définis plus haut
-- Get or create anchor
local anchor = CreateAnchor()
if not anchor then
print("ChatScanner PRO: Error creating anchor")
return
end
-- Start the bar
bar:Start()
-- Add to active bars
table.insert(activeBars, bar)
-- Remove oldest bar if we have too many (use setting)
local maxBars = addon.Config.db.profile.settings.maxNotifications or 10
if #activeBars > maxBars then
local oldestBar = table.remove(activeBars, 1)
oldestBar:Stop()
end
-- Reposition all bars
RepositionBars()
-- Set callback for when the bar stops
bar:SetCallback("OnStop", function()
for i, activeBar in ipairs(activeBars) do
if activeBar == bar then
table.remove(activeBars, i)
-- Reposition remaining bars when one is removed
RepositionBars()
break
end
end
end)
return bar
end
-- Store a match
local function StoreMatch(playerName, message, filterName, matchedKeyword, channel)
local match = {
playerName = playerName,
message = message,
filterName = filterName,
matchedKeyword = matchedKeyword,
channel = channel,
timestamp = time(),
}
table.insert(matches, 1, match)
-- Keep only last 100 matches
while #matches > 100 do
table.remove(matches)
end
return match
end
-- Function to update chat event registrations
function core:UpdateChatEventRegistrations()
-- Unregister all chat events first
self:UnregisterEvent("CHAT_MSG_SAY")
self:UnregisterEvent("CHAT_MSG_YELL")
self:UnregisterEvent("CHAT_MSG_GUILD")
self:UnregisterEvent("CHAT_MSG_PARTY")
self:UnregisterEvent("CHAT_MSG_RAID")
self:UnregisterEvent("CHAT_MSG_CHANNEL")
self:UnregisterEvent("CHAT_MSG_WHISPER")
-- Register only enabled channels
if addon.Config and addon.Config.db and addon.Config.db.profile and addon.Config.db.profile.settings and addon.Config.db.profile.settings.chatChannels then
local channels = addon.Config.db.profile.settings.chatChannels
if channels.SAY then self:RegisterEvent("CHAT_MSG_SAY", ScanMessage) end
if channels.YELL then self:RegisterEvent("CHAT_MSG_YELL", ScanMessage) end
if channels.GUILD then self:RegisterEvent("CHAT_MSG_GUILD", ScanMessage) end
if channels.PARTY then self:RegisterEvent("CHAT_MSG_PARTY", ScanMessage) end
if channels.RAID then self:RegisterEvent("CHAT_MSG_RAID", ScanMessage) end
if channels.CHANNEL then self:RegisterEvent("CHAT_MSG_CHANNEL", ScanMessage) end
if channels.WHISPER then self:RegisterEvent("CHAT_MSG_WHISPER", ScanMessage) end
end
end
-- Anti-spam cache: stores recent messages to detect duplicates
local recentMessages = {}
local SPAM_WINDOW = 5 -- seconds
-- Main chat scanning function
local function ScanMessage(event, message, sender, _, channelName, _, _, _, channelNumber, ...)
-- Check if addon is enabled
if not addon.Config or not addon.Config.db or not addon.Config.db.profile or not addon.Config.db.profile.enabled then
return
end
-- Check if we should pause during combat
if addon.Config.db.profile.settings.pauseInCombat and InCombatLockdown() then
return
end
-- Remove realm from sender name
local playerName = sender and string.match(sender, "([^-]+)") or "Unknown"
-- Skip own messages if option is enabled
if addon.Config.db.profile.settings.ignoreOwnMessages and playerName == UnitName("player") then
return
end
-- Skip blacklisted players
if core:IsBlacklisted(playerName) then
return
end
-- Anti-spam: Check if this is a duplicate message from the same player
if addon.Config.db.profile.settings.antiSpam then
local messageKey = playerName .. ":" .. message
local currentTime = time()
-- Clean old entries
for key, timestamp in pairs(recentMessages) do
if currentTime - timestamp > SPAM_WINDOW then
recentMessages[key] = nil
end
end