-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImprovedIgnore.lua
288 lines (254 loc) · 8.38 KB
/
ImprovedIgnore.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
--[[
ImprovedIgnore.lua
by Yrys - Hellscream <yrysremove at twparemove dot net>
by Two - Updated to add unlimited ignore functionality
Improved functionality for ignore. Ignored players show up as red on
who lists, and sending a tell to a player on ignore will optionally either
auto-remove that player from your ignore list, or block the tell.
]]
-- Variables.
IIGNORE_VER = "1.12.1.2"
local SendChatMessage_Orig = nil
local defaultFrame = DEFAULT_CHAT_FRAME
local defaultWrite = DEFAULT_CHAT_FRAME.AddMessage
local log = function(text, r, g, b, group, holdTime)
defaultWrite(defaultFrame, tostring(text), r, g, b, group, holdTime)
end
local hookChatFrame = function(frame)
if (not frame) then return end
local original = frame.AddMessage
if (original) then
frame.AddMessage = function(t, message, ...)
local found, _, channel, player = string.find(message, "^%[([^%]]+)%].*|Hplayer:([^|]+)|h")
if (not found) then
found, _, player = string.find(message, "|Hplayer:([^|]+)|h.*"..STR_IIGNORE_LOCALIZATION_WHISPERS..":")
if (found) then
channel = STR_IIGNORE_CHANNEL_WHISPER
end
end
if (found and player and channel) then
if (ImprovedIgnore_IsPlayerIgnored(player) and not ImprovedIgnore_DoBypassChannel(channel)) then
return
end
end
original(t, message, unpack (arg))
end
else
log("Tried to hook non-chat frame")
end
end
local fixPlayerName = function(player)
local _, _, first, remaining = string.find(player, "^(.)(.+)")
return string.upper(first or "")..string.lower(remaining or "")
end
local guessChannelName = function(channel)
for c,s in pairs(ImprovedIgnore_BypassChannel) do
if (string.lower(c) == string.lower(channel)) then
return c
end
end
return channel
end
function ImprovedIgnore_IsPlayerIgnored(player)
if (player and ImprovedIgnore_List[fixPlayerName(player)]) then
return true
else
return false
end
end
function ImprovedIgnore_AddToIgnore(player, reason)
ImprovedIgnore_List[fixPlayerName(player)] = reason or ""
end
function ImprovedIgnore_RemoveFromIgnore(player)
ImprovedIgnore_List[fixPlayerName(player)] = nil
end
function ImprovedIgnore_SetBypassChannel(channel, setting)
if (channel and STR_IIGNORE_CHANNEL_SETTING[setting]) then
ImprovedIgnore_BypassChannel[guessChannelName(channel)] = setting
else
return nil
end
end
function ImprovedIgnore_DoBypassChannel(channel)
return (ImprovedIgnore_BypassChannel[channel] == STR_IIGNORE_ALLOW)
end
function ImprovedIgnore_OnLoad()
this:RegisterEvent("VARIABLES_LOADED")
-- Set up slash commands.
SlashCmdList["IMPROVEDIGNORE"] = ImprovedIgnore_CmdRelay
SLASH_IMPROVEDIGNORE1 = "/ii"
SLASH_IMPROVEDIGNORE2 = "/improvedignore"
end
local copyPlayerIgnoreEntries = function()
local ignoredPlayer
local numIgnores = GetNumIgnores()
local toDelete = {}
if numIgnores then
for n = 1, numIgnores do
ignoredPlayer = GetIgnoreName(n)
if (not ImprovedIgnore_IsPlayerIgnored(ignoredPlayer)) then
ImprovedIgnore_AddToIgnore(ignoredPlayer)
log(string.format(STR_IIGNORE_FUNC_COPYFROMLIST, tostring(ignoredPlayer)))
end
table.insert(toDelete, ignoredPlayer)
end
for n, name in ipairs(toDelete) do
DelIgnore(name)
end
end
end
local hookFunctions = function()
if SendChatMessage ~= ImprovedIgnore_SendChatMessage then
SendChatMessage_Orig = SendChatMessage
SendChatMessage = ImprovedIgnore_SendChatMessage
end
hookChatFrame(ChatFrame1)
hookChatFrame(ChatFrame2)
hookChatFrame(ChatFrame3)
hookChatFrame(ChatFrame4)
hookChatFrame(ChatFrame5)
hookChatFrame(ChatFrame6)
hookChatFrame(ChatFrame7)
end
local initialize = function()
ImprovedIgnore_List = ImprovedIgnore_List or {}
ImprovedIgnore_Settings = ImprovedIgnore_Settings or {
whisper = STR_IIGNORE_ALLOW
}
if (not STR_IIGNORE_WHISPER_SETTING[ImprovedIgnore_Settings.whisper]) then
ImprovedIgnore_Settings.whisper = STR_IIGNORE_ALLOW
end
ImprovedIgnore_BypassChannel = ImprovedIgnore_BypassChannel or {
[STR_IIGNORE_CHANNEL_PARTY] = STR_IIGNORE_ALLOW,
[STR_IIGNORE_CHANNEL_RAID] = STR_IIGNORE_ALLOW,
[STR_IIGNORE_CHANNEL_RAIDLEAD] = STR_IIGNORE_ALLOW,
[STR_IIGNORE_CHANNEL_OFFICER] = STR_IIGNORE_ALLOW,
}
copyPlayerIgnoreEntries()
hookFunctions()
log(string.format(STR_IIGNORE_FUNC_LOADED, IIGNORE_VER))
end
-- Event handler. Checks for non-WhoFrame /whos.
function ImprovedIgnore_OnEvent()
if (event == "VARIABLES_LOADED") then
initialize()
end
end
local printStatusWhispers = function()
log(STR_IIGNORE_STATUS_WHISPER.." "..STR_IIGNORE_WHISPER_SETTING[ImprovedIgnore_Settings.whisper])
end
local printStatusChannels = function()
log(STR_IIGNORE_STATUS_CHANNELS)
for channel, setting in ImprovedIgnore_BypassChannel do
log(string.format(" %s: %s", tostring(channel), setting))
end
end
local commands = setmetatable({
[STR_IIGNORE_COMMAND_STATUS] = function()
log(STR_IIGNORE_STATUS_HEADER)
printStatusWhispers()
printStatusChannels()
end,
[STR_IIGNORE_COMMAND_WHISPER] = function(args)
if (STR_IIGNORE_WHISPER_SETTING[args]) then
ImprovedIgnore_Settings.whisper = args
printStatusWhispers()
else
log(STR_IIGNORE_HELP_WHISPER)
end
end,
[STR_IIGNORE_COMMAND_ADD] = function(args)
local found, _, name, reason = string.find(args, "^%s*(%S+)%s?(.*)")
if (found) then
name = fixPlayerName(name)
ImprovedIgnore_AddToIgnore(name, reason)
log(string.format(STR_IIGNORE_STATUS_ADDED, name))
else
log(STR_IIGNORE_HELP_ADD)
end
end,
[STR_IIGNORE_COMMAND_REMOVE] = function(name)
if (name and not string.find(name, " ")) then
name = fixPlayerName(name)
if (ImprovedIgnore_IsPlayerIgnored(name)) then
ImprovedIgnore_RemoveFromIgnore(name)
log(string.format(STR_IIGNORE_STATUS_REMOVED, name))
else
log(string.format(STR_IIGNORE_STATUS_NOT_REMOVED, name))
end
else
log(STR_IIGNORE_HELP_REMOVE)
end
end,
[STR_IIGNORE_COMMAND_LIST] = function()
local ignoredWithoutReason = {}
log(STR_IIGNORE_STATUS_LIST)
for player, reason in pairs(ImprovedIgnore_List) do
if (reason and (string.len(reason) > 0)) then
log(player.." - "..reason)
else
table.insert(ignoredWithoutReason, player)
end
end
log(table.concat(ignoredWithoutReason, ", "))
end,
[STR_IIGNORE_COMMAND_ALLOW] = function(channel)
if (channel) then
channel = guessChannelName(channel)
ImprovedIgnore_SetBypassChannel(channel, STR_IIGNORE_ALLOW)
log(channel..": "..STR_IIGNORE_ALLOW)
else
log(STR_IIGNORE_HELP_ALLOW_CHANNEL)
end
end,
[STR_IIGNORE_COMMAND_DENY] = function(channel)
if (channel) then
channel = guessChannelName(channel)
ImprovedIgnore_SetBypassChannel(channel, STR_IIGNORE_DENY)
log(channel..": "..STR_IIGNORE_DENY)
else
log(STR_IIGNORE_HELP_DENY_CHANNEL)
end
end,
}, {
__index = function()
return function()
log(string.format(STR_IIGNORE_HELP_HEADER, IIGNORE_VER))
log(STR_IIGNORE_HELP_STATUS)
log(STR_IIGNORE_HELP_WHISPER)
log(STR_IIGNORE_HELP_ADD)
log(STR_IIGNORE_HELP_REMOVE)
log(STR_IIGNORE_HELP_LIST)
log(STR_IIGNORE_HELP_ALLOW_CHANNEL)
log(STR_IIGNORE_HELP_DENY_CHANNEL)
end
end
})
-- Command-line handler. Passes to other functions.
function ImprovedIgnore_CmdRelay(args)
if args then
_, _, cmd, subargs = string.find (args, "^([^ ]-) (.+)$")
if not cmd then
cmd = args
end
commands[string.lower(cmd)](subargs)
end
end
-- Check for ignored players on sending a whisper.
function ImprovedIgnore_SendChatMessage (msg, ...)
local system, language, player = unpack (arg)
if ImprovedIgnore_IsPlayerIgnored(player) then
if system == "WHISPER" and player then
if ImprovedIgnore_Settings.whisper == STR_IIGNORE_REMOVE then
log(string.format (STR_IIGNORE_WHISPER_REMOVE, player), 1.0, 0.2, 0.2)
ImprovedIgnore_RemoveFromIgnore(player)
elseif ImprovedIgnore_Settings.whisper == STR_IIGNORE_DENY then
log(string.format(STR_IIGNORE_WHISPER_DENY, player), 1.0, 0.3, 0.3)
return
elseif (ImprovedIgnore_Settings.whisper == STR_IIGNORE_ALLOW) then
log(string.format(STR_IIGNORE_WHISPER_ALLOW, player), 1.0, 0.3, 0.3)
end
end
end
SendChatMessage_Orig (msg, unpack (arg))
end