-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrChat_Spam.lua
More file actions
365 lines (304 loc) · 10.8 KB
/
rChat_Spam.lua
File metadata and controls
365 lines (304 loc) · 10.8 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
rChat = rChat or {}
local SF = LibSFUtils
-- the spam table from the saved variables
local config = {}
function rChat.setSpamConfig(cfgtable)
config = cfgtable or {}
end
local spammableChannels = {
[CHAT_CHANNEL_ZONE_LANGUAGE_1 + 1] = true,
[CHAT_CHANNEL_ZONE_LANGUAGE_2 + 1] = true,
[CHAT_CHANNEL_ZONE_LANGUAGE_3 + 1] = true,
[CHAT_CHANNEL_ZONE_LANGUAGE_4 + 1] = true,
[CHAT_CHANNEL_ZONE_LANGUAGE_5 + 1] = true,
[CHAT_CHANNEL_ZONE_LANGUAGE_6 + 1] = true,
[CHAT_CHANNEL_ZONE_LANGUAGE_7 + 1] = true,
[CHAT_CHANNEL_SAY + 1] = true,
[CHAT_CHANNEL_YELL + 1] = true,
[CHAT_CHANNEL_ZONE + 1] = true,
[CHAT_CHANNEL_EMOTE + 1] = true,
}
local function IsSpammableChannel(chanCode)
if chanCode == nil then return nil end
return spammableChannels[chanCode + 1]
end
-- Return true/false if text is a flood
local function SpamFlood(from, text, spamChanCode)
local db = rChat.save
-- 2+ messages identical in less than 30 seconds on Character channels = spam
local previousLine = rChatData.getChatCacheSize()
if previousLine == 0 then return false end
local ourMessageTimestamp = GetTimeStamp()
local checkSpam = true
while checkSpam do
local entry = rChatData.getCacheEntry(previousLine)
-- Previous line can be a ChanSystem one
if entry and entry.channel ~= CHAT_CHANNEL_SYSTEM then
if (type(entry.timestamp) == "number") and
((ourMessageTimestamp - entry.timestamp) < config.floodGracePeriod) then
-- if our message is sent by our chatter / will be break by "Character" channels and "UserID" Channels
if from == entry.rawT.from then
-- if our message is eq of last message
if text == entry.rawT.text then
-- Previous and current must be in zone(s), yell, say, emote (Character Channels except party)
if IsSpammableChannel(spamChanCode) and IsSpammableChannel(entry.channel) then
-- Spam
return true
end
end
end
else
-- > 30s, stop analysis
checkSpam = false
end
end
if previousLine > 1 then
previousLine = previousLine - 1
else
checkSpam = false
end
end
return false
end
-- Return true/false if text is a LFG message
local function SpamLookingFor(text)
local spamStrings = {
[1] = "l[%s.]?f[%s.]?[%d]?[%s.]?[mgtdh]", -- (m)ember, (g)roup
[2] = "l[%s.]?f[%s.]?[%d]?[%s.]?heal", -- heal
[3] = "l[%s.]?f[%s.]?[%d]?[%s.]?dd", -- dd
[4] = "l[%s.]?f[%s.]?[%d]?[%s.]?dps", -- dps
[5] = "l[%s.]?f[%s.]?[%d]?[%s.]?tank", -- tank
[6] = "l[%s.]?f[%s.]?[%d]?[%s.]?daily", -- daily
[7] = "l[%s.]?f[%s.]?[%d]?[%s.]?boss", -- world boss
[8] = "l[%s.]?f[%s.]?[%d]?[%s.]?dungeon", -- dungeon
}
local lowertext = string.lower(text)
if string.find(text,"^lf") then
for _, spamString in ipairs(spamStrings) do
if string.find(lowertext, spamString) then
return true
end
end
end
return false
end
-- Return true/false if text is a WTT message
local function SpamWantTo(text)
local hasItemLink = string.find(text, "|H(.-):item:(.-)|h(.-)|h")
local hasWantTo = string.find(text, "[wW][%s.]?[tT][%s.]?[bBsStT] ")
-- "W.T S"
if hasItemLink and hasWantTo then
return true
elseif hasWantTo and string.find(text, "[Bb][Ii][Tt][Ee]") then
-- Werewolf/Vampire Bite
return true
-- Crowns
elseif string.find(text, "[Cc][Rr][Oo][Ww][Nn][Ss]") then
-- Match
return true
elseif hasItemLink and string.find(text,"[sS]elling") then
return true
end
return false
end
-- Return true/false if text is a WTT message
local function SpamPriceCheck(text)
-- "PC"
if string.find(text, "[pP][cC]") then -- price check 1
-- Item Handler
if string.find(text, "|H(.-):item:(.-)|h(.-)|h") then
-- Match
return true
end
elseif string.find(text, "[pP]rice [cC]heck") then -- price check 2
-- Item Handler
if string.find(text, "|H(.-):item:(.-)|h(.-)|h") then
-- Match
return true
end
elseif string.find(text, "^TTC ") then -- response TTC
return true
elseif string.find(text,"^MM ") then -- response Master Merchant
return true
end
return false
end
-- Return true/false if text is a Guild recruitment one
local function SpamGuildRecruit(text)
-- look for guild link in message
local validLinkTypes = {
[GUILD_LINK_TYPE] = true,
}
local linksTable = {} -- returned
ZO_ExtractLinksFromText(text, validLinkTypes, linksTable)
if next(linksTable) ~= nil then
return true
end
return false
end
-- Return true/false if anti spam is enabled for a certain category
-- Categories must be : Flood, LookingFor, WantTo, GuildRecruit
local function IsSpamEnabledForCategory(category)
local rChatData = rChat.data
if category == "Flood" then
-- Enabled in Options?
if config.floodProtect then
-- AntiSpam is enabled
return true
end
-- AntiSpam is disabled
return false
-- LFG
elseif category == "LookingFor" then
-- Enabled in Options?
if config.lookingForProtect then
-- Enabled in reality?
if rChatData.spamLookingForEnabled then
-- AntiSpam is enabled
return true
else
-- AntiSpam is disabled .. since -/+ grace time ?
if GetTimeStamp() - rChatData.spamTempLookingForStopTimestamp > (config.spamGracePeriod * 60) then
-- Grace period outdatted -> we need to re-enable it
rChatData.spamLookingForEnabled = true
return true
end
end
end
-- AntiSpam is disabled
return false
-- PC
elseif category == "Price" then
-- Enabled in Options?
if config.priceCheckProtect then
-- Enabled in reality?
if rChatData.spamPriceCheckEnabled then
-- AntiSpam is enabled
return true
else
-- AntiSpam is disabled .. since -/+ grace time ?
if GetTimeStamp() - rChatData.spamTempPriceStopTimestamp > (config.spamGracePeriod * 60) then
-- Grace period outdated -> we need to re-enable it
rChatData.spamPriceCheckEnabled = true
return true
end
end
end
-- AntiSpam is disabled
return false
-- WTT
elseif category == "WantTo" then
-- Enabled in Options?
if config.wantToProtect then
-- Enabled in reality?
if rChatData.spamWantToEnabled then
-- AntiSpam is enabled
return true
else
-- AntiSpam is disabled .. since -/+ grace time ?
if GetTimeStamp() - rChatData.spamTempWantToStopTimestamp > (config.spamGracePeriod * 60) then
-- Grace period outdated -> we need to re-enable it
rChatData.spamWantToEnabled = true
return true
end
end
end
-- AntiSpam is disabled
return false
-- Join my Awesome guild
elseif category == "GuildRecruit" then
-- Enabled in Options?
if config.guildProtect then
-- Enabled in reality?
if rChatData.spamGuildRecruitEnabled then
-- AntiSpam is enabled
return true
else
-- AntiSpam is disabled .. since -/+ grace time ?
if GetTimeStamp() - rChatData.spamTempGuildRecruitStopTimestamp > (config.spamGracePeriod * 60) then
-- Grace period outdated -> we need to re-enable it
rChatData.spamGuildRecruitEnabled = true
return true
end
end
end
-- AntiSpam is disabled
return false
end
end
-- Return true is message is a spam depending on MANY parameters
function rChat.SpamFilter(chanCode, from, text, isCS)
-- ZOS GM are NEVER blocked
if isCS then return false end
if not IsSpammableChannel(chanCode) then return false end
local rChatData = rChat.data
-- 4 options for spam : Spam flood (multiple messages) ; LFM/LFG ; WT(T/S/B) ; Guild Recruitment
rChat_Logger():Debug("Looking for spam in "..chanCode.." text = "..text)
-- Spam (I'm not allowed to flood even for testing)
if IsSpamEnabledForCategory("Flood") then
rChat_Logger():Debug("Looking for flood")
if SpamFlood(from, text, chanCode) then
rChat_Logger():Debug("found")
return true
end
end
-- But "I" can have other exceptions (useful for testing)
local isMe = false
if zo_strformat(SI_UNIT_NAME, from) == GetUnitName("player") or from == GetDisplayName() then
-- I'm allowed to do spammable things
isMe = true
end
-- Looking For
if IsSpamEnabledForCategory("LookingFor") then
if SpamLookingFor(text) then
rChat_Logger():Debug("found Looking for")
if isMe == false then
return true
else
rChatData.spamTempLookingForStopTimestamp = GetTimeStamp()
rChatData.spamLookingForEnabled = false
return false
end
end
end
-- Want To
if IsSpamEnabledForCategory("WantTo") then
if SpamWantTo(text) then
rChat_Logger():Debug("found Want To")
if isMe == false then
return true
else
rChatData.spamTempWantToStopTimestamp = GetTimeStamp()
rChatData.spamWantToStop = true
return false
end
end
end
-- Price Check
if IsSpamEnabledForCategory("Price") then
if SpamPriceCheck(text) then
rChat_Logger():Debug("found Price Check")
if isMe == false then
return true
else
rChatData.spamTempPriceStopTimestamp = GetTimeStamp()
rChatData.spamPriceCheck = true
return false
end
end
end
-- Guild Recruit
if IsSpamEnabledForCategory("GuildRecruit") then
if SpamGuildRecruit(text, chanCode) then
rChat_Logger():Debug("found GuildRecruit")
if isMe == false then
return true
else
rChatData.spamTempGuildRecruitStopTimestamp = GetTimeStamp()
rChatData.spamGuildRecruitStop = true
return false
end
end
end
return false
end