-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatTracker.lua
More file actions
106 lines (98 loc) · 2.98 KB
/
Copy pathChatTracker.lua
File metadata and controls
106 lines (98 loc) · 2.98 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
local keywords = {}
local banned = {}
local notifiedSenders = {}
local filterEnabled = true
function AddKeyword(word)
if not tContains(keywords, word) then
table.insert(keywords, word)
print("|cff00ff00[ChatTracker]|r Added keyword: " .. word)
end
end
function RemoveKeyword(word)
for i, v in ipairs(keywords) do
if v:lower() == word:lower() then
table.remove(keywords, i)
print("|cff00ff00[ChatTracker]|r Removed keyword: " .. word)
return
end
end
end
function AddBannedWord(word)
if not tContains(banned, word) then
table.insert(banned, word)
print("|cff00ff00[ChatTracker]|r Added banned word: " .. word)
end
end
function RemoveBannedWord(word)
for i, v in ipairs(banned) do
if v:lower() == word:lower() then
table.remove(banned, i)
print("|cff00ff00[ChatTracker]|r Removed banned word: " .. word)
return
end
end
end
function ToggleFilter(state)
if state == "on" then
filterEnabled = true
print("|cff00ff00[ChatTracker]|r Filter enabled.")
elseif state == "off" then
filterEnabled = false
print("|cff00ff00[ChatTracker]|r Filter disabled.")
end
end
-- Main initialization function
function ChatTracker(self, event, msg, sender, ...)
if not filterEnabled then return end
for _, kw in ipairs(keywords) do
local msg = msg:lower() or ""
if msg:find(kw:lower()) then
for _, ban in ipairs(banned) do
if msg:find(ban) then
return -- Ignore banned messages
end
end
if sender and not notifiedSenders[sender] then
print("\124cffff0000" .. sender .. ": " .. msg .. "\124r")
PlaySoundFile("Sound\\Interface\\RaidWarning.wav")
notifiedSenders[sender] = true
end
break
end
end
end
-- Slash command handler
SLASH_CHATTRACKER1 = "/track"
SlashCmdList["CHATTRACKER"] = function(msg)
local cmd, arg = msg:match("^(%S+)%s*(.-)$")
if cmd == "addkw" and arg ~= "" then
AddKeyword(arg)
elseif cmd == "rmkw" and arg ~= "" then
RemoveKeyword(arg)
elseif cmd == "addban" and arg ~= "" then
AddBannedWord(arg)
elseif cmd == "rmban" and arg ~= "" then
RemoveBannedWord(arg)
elseif cmd == "on" then
ToggleFilter("on")
elseif cmd == "off" then
ToggleFilter("off")
elseif cmd == "list" then
print("|cff00ff00[ChatTracker]|r Keywords: " .. table.concat(keywords, ", "))
print("|cff00ff00[ChatTracker]|r Banned words: " .. table.concat(banned, ", "))
elseif cmd == "clear" then
notifiedSenders = {}
print("|cff00ff00[ChatTracker]|r Cleared notified senders.")
elseif cmd == "reset" then
keywords = {}
banned = {}
notifiedSenders = {}
filterEnabled = true
print("|cff00ff00[ChatTracker]|r Reset all settings to default.")
else
print("|cff00ff00[ChatTracker]|r Usage:")
print("/track addkw <word>, rmkw <word>, addban <word>, rmban <word>, on, off, list, clear, reset")
end
end
-- Apply the filters to msg events
ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", ChatTracker)