forked from IceyPop/GlobalIgnoreListClassic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobalIgnoreList.lua
2430 lines (1814 loc) · 57.3 KB
/
GlobalIgnoreList.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
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
----------------------------------
-- Global Ignore List Variables --
----------------------------------
-- SUGGESTED FEATURES TO ADD OR THINGS TO DO
-- History tab for last 50 or so filtered messages
-- History tab for last 50 or so ignore add/removals
-- Option to open the ignore window only when the ignore tab is selected
-- Chat filter tag for person's level [level=60] or maybe even basic math like "[level<60]"
-- Create a GitHub account (or similar?) to maintain the project and allow people to submit changes
-- Create scanner for repeat messages example: LF2M for RFD spammed 3 times back to back maybe chould show just one of them
-- Create a scrolling options panel? Or a way to add more options (out of space!)
GIL_Loaded = false
GIL_SyncOK = false
GIL_SyncTried = false
lastFilterError = false
local _, L = ...
local GILFRAME = nil
local gotLoaded = false
local gotEntering = false
local safeToLoad = false
local doLoginIgnore = true
local faction = nil
local maxIgnoreSize = 50
local maxSyncTries = 2
local maxHistorySize = 100
local firstClear = false
local firstPrune = false
local pruneDays = 0
local timer = 0
local loadedTime = GetTime()
local lastSentIgnore = ""
local lastFilterMsg = ""
local lastFilterResult = ""
local filterDefDesc = {}
local filterDefFilter = {}
local filterDefActive = {}
local needPartyClose = false
local gotGroup = IsInGroup()
local partyNameUI = ""
local groupWarning = {}
local MSG_LOGOFF = ERR_FRIEND_OFFLINE_S:gsub("%%s", ".+")
local MSG_LOGON = ERR_FRIEND_ONLINE_SS:gsub("|Hplayer:%%s|h%[%%s%]|h", "|Hplayer:.+|h%%[.+%%]|h")
local filterLoginMsgs = true
--print ("DEBUG gotGroup=" .. (tostring(gotGroup) or "NIL"))
local BlizzardAddIgnore = nil
local BlizzardDelIgnore = nil
local BlizzardDelIgnoreByIndex = nil
local BlizzardAddOrDelIgnore = nil
local BlizzardInviteUnit = nil
----------------------------------
-- Global Ignore List Functions --
----------------------------------
function ShowMsg (msg)
print ("|cff33ff99Global Ignore: |cffffffff" .. (msg or "Critical error"))
end
local function OnOff (value)
if value == nil or value == false then
return "|cffffff00" .. L["OFF"] .. "|cffffffff"
elseif value == true then
return "|cffffff00" .. L["ON"] .. "|cffffffff"
else
return "|cffff0000nil"
end
end
function dayString (value)
if value == 1 then
return L["DAY"]
else
return L["DAYS"]
end
end
local function AddToList(newname, newfaction, newnote, newtype)
local index = #GlobalIgnoreDB.ignoreList+1
GlobalIgnoreDB.ignoreList[index] = newname
GlobalIgnoreDB.factionList[index] = newfaction
GlobalIgnoreDB.dateList[index] = date("%d %b %Y")
GlobalIgnoreDB.notes[index] = (newnote or "")
GlobalIgnoreDB.expList[index] = GlobalIgnoreDB.defexpire
GlobalIgnoreDB.typeList[index] = (newtype or "player")
GlobalIgnoreDB.syncInfo[index] = {}
end
local function RemoveFromList(index)
if index <= #GlobalIgnoreDB.ignoreList then
table.remove(GlobalIgnoreDB.ignoreList, index)
table.remove(GlobalIgnoreDB.factionList, index)
table.remove(GlobalIgnoreDB.dateList, index)
table.remove(GlobalIgnoreDB.notes, index)
table.remove(GlobalIgnoreDB.expList, index)
table.remove(GlobalIgnoreDB.typeList, index)
table.remove(GlobalIgnoreDB.syncInfo, index)
end
end
local function getSyncValue (index)
-- value, index of syncInfo data
local s = ""
local p = ""
local v = 0
for c = 1, #GlobalIgnoreDB.syncInfo[index] do
s = GlobalIgnoreDB.syncInfo[index][c]
p = string.find(s, "@", 1, true)
if p > 0 then
v = tonumber(string.sub(s, p + 1))
s = string.sub(s, 1, p - 1)
if playerName == s then
return v, c
end
end
end
return 0, 0
end
local function setSyncValue (index)
local val,idx = getSyncValue(index)
if idx == 0 then
idx = #GlobalIgnoreDB.syncInfo[index] + 1
end
val = val + 1
GlobalIgnoreDB.syncInfo[index][idx] = playerName .. "@" .. val
end
local function isServerMatch (server1, server2)
return Proper(server1) == Proper(server2)
end
local function hasIgnored (name)
local result = 0
name = Proper(addServer(name))
for count = 1, C_FriendList.GetNumIgnores() do
if name == Proper(addServer(C_FriendList.GetIgnoreName(count))) then
result = count
break
end
end
return result
end
function hasNPCIgnored (name)
if not name then return 0 end
for count = 1, #GlobalIgnoreDB.ignoreList do
if GlobalIgnoreDB.ignoreList[count] == name and GlobalIgnoreDB.typeList[count] == "npc" then
return count
end
end
return 0
end
local function hasServerIgnored (name)
if not name then return 0 end
for count = 1, #GlobalIgnoreDB.ignoreList do
if GlobalIgnoreDB.ignoreList[count] == name and GlobalIgnoreDB.typeList[count] == "server" then
return count
end
end
return 0
end
function hasGroupWarning (name)
if not name then return 0 end
for count = 1, #groupWarning do
if groupWarning[count] == name then
return count
end
end
return 0
end
function hasGlobalIgnored (name)
if not name then return 0 end
for count = 1, #GlobalIgnoreDB.ignoreList do
if GlobalIgnoreDB.ignoreList[count] == name and GlobalIgnoreDB.typeList[count] == "player" then
return count
end
end
return 0
end
function hasAnyIgnored (name)
if not name then return 0 end
for count = 1, #GlobalIgnoreDB.ignoreList do
if GlobalIgnoreDB.ignoreList[count] == name then
return count
end
end
return 0
end
local function hasDeleted (name)
if not name then return 0 end
for count = 1, #GlobalIgnoreDB.delList do
if GlobalIgnoreDB.delList[count] == name then
return count
end
end
return 0
end
local function addDeleted (name)
local idx = hasDeleted(name)
if idx == 0 then
if #GlobalIgnoreDB.delList >= maxHistorySize then
table.remove(GlobalIgnoreDB.delList, 1)
end
GlobalIgnoreDB.delList[#GlobalIgnoreDB.delList + 1] = name
end
end
local function removeDeleted (name)
local idx = hasDeleted(name)
if idx > 0 then
table.remove(GlobalIgnoreDB.delList, idx)
end
end
local function ShowIgnoreList (param)
local days = tonumber(param)
local sName = ""
if not days then
days = 0
sName = param
if not sName then
sName = ""
end
end
if days > 0 then
ShowMsg("|cffffff00" .. format(L["LIST_1"], days))
else
if sName ~= "" then
sName = Proper(sName)
if sName == "Npc" then
ShowMsg("|cffffff00".. L["LIST_2"])
else
if sName == "Server" then
sName = serverName
end
ShowMsg("|cffffff00" .. format(L["LIST_3"], sName))
end
else
ShowMsg("|cffffff00" .. L["LIST_4"])
end
end
local count = 0
for key,value in pairs(GlobalIgnoreDB.ignoreList) do
local ok = true
local type = "P"
if GlobalIgnoreDB.typeList[key] == "npc" then
type = "N"
elseif GlobalIgnoreDB.typeList[key] == "server" then
type = "S"
end
if days > 0 then
ok = daysFromToday(GlobalIgnoreDB.dateList[key]) >= days
elseif sName ~= "" then
ok = (type == "N" and sName == "Npc") or (type == "P" and isServerMatch(sName, getServer(value))) or (type == "S" and isServerMatch(sName, value))
end
if ok then
local str = " (" .. key .. ") [" .. type.. "] " .. value .. " (" .. (GlobalIgnoreDB.factionList[key] or "Unknown") .. ") " .. "[".. daysFromToday(GlobalIgnoreDB.dateList[key]) .. " "..L["DAYS"] .. "]"
if GlobalIgnoreDB.notes[key] ~= "" then
str = str .." (" .. GlobalIgnoreDB.notes[key] .. ")"
end
ShowMsg(str)
count = count + 1
end
end
ShowMsg("|cffffff00" .. format(L["LIST_5"], count))
end
function ResetSpamFilters()
GlobalIgnoreDB.filterList = {}
GlobalIgnoreDB.filterDesc = {}
GlobalIgnoreDB.filterCount = {}
GlobalIgnoreDB.filterActive = {}
GlobalIgnoreDB.invertSpam = false
GlobalIgnoreDB.spamFilter = true
GlobalIgnoreDB.autoUpdate = true
for count = 1, #filterDefDesc do
GlobalIgnoreDB.filterDesc[count] = filterDefDesc[count]
GlobalIgnoreDB.filterList[count] = filterDefFilter[count]
GlobalIgnoreDB.filterActive[count] = filterDefActive[count]
GlobalIgnoreDB.filterCount[count] = 0
end
end
local function ResetIgnoreDB()
GlobalIgnoreDB = {
chatmsg = true,
sameserver = true,
samefaction = true,
openWithFriends = true,
attachFriends = true,
trackChanges = true,
filterMailbox = false,
spamFilter = true,
invertSpam = true,
autoIgnore = true,
autoUpdate = true,
autoCount = 3,
autoTime = 600,
defexpire = 0,
ignoreList = {},
factionList = {},
dateList = {},
notes = {},
expList = {},
typeList = {},
delList = {},
syncInfo = {},
filterTotal = 0,
filterCount = {},
filterDesc = {},
filterList = {},
skipGuild = true,
skipParty = false,
skipPrivate = true
}
GlobalIgnoreImported = false
ResetSpamFilters()
end
local function isValidList()
if C_FriendList.GetNumIgnores() > 0 then
local str
local found = 0
for count = 1, C_FriendList.GetNumIgnores() do
str = removeServer(C_FriendList.GetIgnoreName(count), true)
if str ~= nil and str ~= UNKNOWN then
break
end
found = found + 1
end
if str == nil or str == UNKNOWN then
if GlobalIgnoreDB.loginMessages then
ShowMsg(format(L["LOAD_5"], found, UNKNOWN))
end
return false
end
end
return true
end
function SyncIgnoreList (silent)
if silent == nil then
silent = false
end
if GlobalIgnoreDB.loginMessages then
ShowMsg(L["LOAD_4"])
end
if isValidList() == false then
return
end
-- import ignore list if first time sync
if GlobalIgnoreImported == nil or GlobalIgnoreImported ~= true then
local ignores = C_FriendList.GetNumIgnores()
local added = 0
local name
if (ignores > 0) and (silent == false) and GlobalIgnoreDB.loginMessages then
ShowMsg(L["LOAD_2"])
end
for count = 1, ignores do
name = C_FriendList.GetIgnoreName(count)
if name ~= nil then
if removeServer(name, true) ~= UNKNOWN then
name = Proper(addServer(name))
if hasGlobalIgnored(name) == 0 then
added = added + 1
AddToList(name, faction)
if silent == false and GlobalIgnoreDB.loginMessages then
ShowMsg (format(L["LOAD_3"], name))
end
end
end
end
end
GlobalIgnoreImported = true
end
-- first remove expired entries
local count = 0
while count < #GlobalIgnoreDB.dateList do
count = count + 1
if GlobalIgnoreDB.expList[count] > 0 and daysFromToday(GlobalIgnoreDB.dateList[count]) >= GlobalIgnoreDB.expList[count] then
local name = addServer(GlobalIgnoreDB.ignoreList[count])
C_FriendList.DelIgnore(name)
count = 0
end
end
-- find account ignores that aren't on global ignore and do things
for count = 1, C_FriendList.GetNumIgnores() do
local name = addServer(C_FriendList.GetIgnoreName(count))
local skipRemove = false
local globIdx = hasGlobalIgnored(name)
if globIdx == 0 then
if GlobalIgnoreDB.trackChanges == true then
local idx = hasDeleted(name)
if idx == 0 then
skipRemove = true
C_FriendList.AddIgnore(name, true)
end
end
if skipRemove == false then
if not silent then
ShowMsg (format(L["SYNC_1"], name))
end
BlizzardDelIgnoreByIndex (hasIgnored(name))
end
else
GlobalIgnoreDB.syncInfo[globIdx] = {}
end
end
if GlobalIgnoreDB.trackChanges == true then
local listCount = 0
while listCount <= #GlobalIgnoreDB.ignoreList do
if GlobalIgnoreDB.typeList[listCount] == "player" then
local tries = getSyncValue(listCount)
if tries >= maxSyncTries then
C_FriendList.DelIgnore(removeServer(GlobalIgnoreDB.ignoreList[listCount]))
listCount = listCount - 1
end
end
listCount = listCount + 1
end
end
-- local ignoreCount = C_FriendList.GetNumIgnores()
--
-- if ignore list is larger than our max we must remove players until it gets to max
-- if ignoreCount > maxIgnoreSize then
-- if ignoreCount > maxIgnoreSize then
-- local name = C_FriendList.GetIgnoreName(ignoreCount)
-- print("DEBUG Reducing Max account ignore: "..name)
-- BlizzardDelIgnore(ignoreCount)
-- print("DEBUG Readding to global ignore")
-- AddIgnore(name, true)
-- ignoreCount = C_FriendList.GetNumIgnores()
-- end
-- end
-- move qualified players to account wide ignore if there is room for it
local ignoreCount = C_FriendList.GetNumIgnores()
if ignoreCount < maxIgnoreSize then
for key,value in pairs(GlobalIgnoreDB.ignoreList) do
if GlobalIgnoreDB.typeList[key] == "player" then
local name = addServer(value)
--print("DEBUG processing: ".. name .. " ignored? ".. hasIgnored(name));
if hasIgnored(name) == 0 then
-- should we add an option to not always samefaction sync?
local ok = (GlobalIgnoreDB.factionList[key] == faction)
if ok then
ok = (isServerMatch(serverName, getServer(name))) or (GlobalIgnoreDB.sameserver == false)
end
if ok then
ignoreCount = ignoreCount + 1
setSyncValue(key)
name = removeServer(name)
if not silent then
ShowMsg (format(L["SYNC_2"], name))
end
BlizzardAddIgnore(name)
end
end
end
if ignoreCount >= maxIgnoreSize then
break
end
end
end
GIL_SyncOK = true
end
local function PruneIgnoreList (days, doit)
if days == nil or days <= 0 then
return 0
end
local targets = 0
local count = 0
while count < #GlobalIgnoreDB.dateList do
count = count + 1
if daysFromToday(GlobalIgnoreDB.dateList[count]) >= days then
targets = targets + 1
local name = addServer(GlobalIgnoreDB.ignoreList[count])
--if doit ~= true then
-- ShowMsg("Prune will remove: "..name)
--end
if doit == true then
if GlobalIgnoreDB.typeList[count] == "player" then
C_FriendList.DelIgnore(name)
else
RemoveFromList(count)
end
count = 0
end
end
end
return targets
end
local function ApplicationStartup(self)
if GIL_Loaded == true or safeToLoad == false then
return
end
if GlobalIgnoreDB.loginMessages then
ShowMsg(L["LOAD_1"])
end
-- Set filter defaults
filterDefDesc[#filterDefDesc + 1] = "Filter \"Anal\" Spammers"
filterDefFilter[#filterDefFilter + 1] = "([word=anal] or [contains=analan]) and ([link] or [words=2])"
filterDefActive[#filterDefActive + 1] = true
filterDefDesc[#filterDefDesc + 1] = "Filter Thunderfury linking"
filterDefFilter[#filterDefFilter + 1] = "[item=19019]"
filterDefActive[#filterDefActive + 1] = true
filterDefDesc[#filterDefDesc + 1] = "Filter Gold Spam #1"
filterDefFilter[#filterDefFilter + 1] = "([contains=.c0m] or [contains=.c.0.m] or [contains=,com] or ([contains=.com] and ([contains=code] or [contains=usd] or [contains=+15]))"
filterDefActive[#filterDefActive + 1] = true
filterDefDesc[#filterDefDesc + 1] = "Filter Gold Spam #2"
filterDefFilter[#filterDefFilter + 1] = "([contains=░] or [contains=▒] or [contains=▓] or [contains=█]) and ([contains=wts] or [contains=sell] or [contains=gold] or [contains=share]))"
filterDefActive[#filterDefActive + 1] = true
filterDefDesc[#filterDefDesc + 1] = "Filter Gold Spam #3"
filterDefFilter[#filterDefFilter + 1] = "([contains=deliver] or [contains=delivery] or [contains=gold] or [contains=delievery] or [contains=sale]) and ([contains=.com] or [contains=,com] or [contains=c0m])"
filterDefActive[#filterDefActive + 1] = true
filterDefDesc[#filterDefDesc + 1] = "Filter Gold Spam #4"
filterDefFilter[#filterDefFilter + 1] = "([contains=wts] or [contains=sell]) and [contains=share] and ([contains=account] or [contains=acc]))"
filterDefActive[#filterDefActive + 1] = true
filterDefDesc[#filterDefDesc + 1] = "Filter Guild Recruitment"
filterDefFilter[#filterDefFilter + 1] = "(([contains=<] and [contains=>]) or ([contains=\\[] and [contains=\\]]) or ([contains=\\(] and [contains=\\)])) and ([contains=recruit] or [contains=progress] or [contains=raid] or [contains=guild] or [contains=seek] or [contains=mythic])"
filterDefActive[#filterDefActive + 1] = false
filterDefDesc[#filterDefDesc + 1] = "Filter Community Recruitment"
filterDefFilter[#filterDefFilter + 1] = "[community]"
filterDefActive[#filterDefActive + 1] = false
filterDefDesc[#filterDefDesc + 1] = "Filter WTS"
filterDefFilter[#filterDefFilter + 1] = "[contains=WTS] or [contains=WTB]"
filterDefActive[#filterDefActive + 1] = false
filterDefDesc[#filterDefDesc + 1] = "Filter Chinese/Korean/Japanese"
filterDefFilter[#filterDefFilter + 1] = "[nonlatin]"
filterDefActive[#filterDefActive + 1] = false
faction = UnitFactionGroup("player")
if GlobalIgnoreDB == nil then
ResetIgnoreDB()
end
-- set missing defaults or upgrade if needed
if GlobalIgnoreDB.skipPrivate == nil then
GlobalIgnoreDB.skipPrivate = true
end
if GlobalIgnoreDB.skipParty == nil then
GlobalIgnoreDB.skipParty = false
end
if GlobalIgnoreDB.skipGuild == nil then
GlobalIgnoreDB.skipGuild = true
end
if GlobalIgnoreDB.filterTotal == nil then
GlobalIgnoreDB.filterTotal = 0
end
if GlobalIgnoreDB.spamFilter == nil then
GlobalIgnoreDB.spamFilter = true
end
if GlobalIgnoreDB.invertSpam == nil then
GlobalIgnoreDB.invertSpam = false
end
if GlobalIgnoreDB.autoIgnore == nil then
GlobalIgnoreDB.autoIgnore = true
end
if GlobalIgnoreDB.autoUpdate == nil then
GlobalIgnoreDB.autoUpdate = true
end
if GlobalIgnoreDB.autoCount == nil then
GlobalIgnoreDB.autoCount = 3
end
if GlobalIgnoreDB.autoTime == nil then
GlobalIgnoreDB.autoTime = 600
end
if GlobalIgnoreDB.filterList == nil or GlobalIgnoreDB.filterDesc == nil or GlobalIgnoreDB.filterCount == nil then
ResetSpamFilters()
end
if GlobalIgnoreDB.delList == nil then
GlobalIgnoreDB.delList = {}
end
if GlobalIgnoreDB.defexpire == nil then
GlobalIgnoreDB.defexpire = 0
end
if not tonumber(GlobalIgnoreDB.defexpire) then
GlobalIgnoreDB.defexpire = 0
end
if GlobalIgnoreDB.trackChanges == nil then
GlobalIgnoreDB.trackChanges = true
end
if GlobalIgnoreDB.filterMailbox == nil then
GlobalIgnoreDB.filterMailbox = false
end
if GlobalIgnoreDB.openWithFriends == nil then
GlobalIgnoreDB.openWithFriends = true
end
if not GlobalIgnoreDB.attachFriends == nil then
GlobalIgnoreDB.attachFriends = true
end
if GlobalIgnoreDB.asknote == nil then
GlobalIgnoreDB.asknote = true
end
if GlobalIgnoreDB.expList == nil then
GlobalIgnoreDB.expList = {}
for count = 1, #GlobalIgnoreDB.ignoreList do
GlobalIgnoreDB.expList[count] = 0
end
end
if GlobalIgnoreDB.syncList then
GlobalIgnoreDB.syncList = nil
end
if GlobalIgnoreDB.syncInfo == nil then
GlobalIgnoreDB.syncInfo = {}
for count = 1, #GlobalIgnoreDB.ignoreList do
GlobalIgnoreDB.syncInfo[count] = {}
end
end
if GlobalIgnoreDB.typeList == nil then
GlobalIgnoreDB.typeList = {}
for count = 1, #GlobalIgnoreDB.ignoreList do
GlobalIgnoreDB.typeList[count] = "player"
end
end
if GlobalIgnoreDB.revision == nil then
GlobalIgnoreDB.revision = 1
for count = 1, #GlobalIgnoreDB.ignoreList do
GlobalIgnoreDB.ignoreList[count] = Proper(GlobalIgnoreDB.ignoreList[count])
end
end
if GlobalIgnoreDB.filterActive == nil then
GlobalIgnoreDB.filterActive = {}
for count = 1, #GlobalIgnoreDB.filterDesc do
GlobalIgnoreDB.filterActive[count] = true
end
end
loadedTime = GetTime()
SyncIgnoreList(GlobalIgnoreDB.chatmsg == nil or GlobalIgnoreDB.chatmsg == false)
GIL_Loaded = true
self:UnregisterEvent("IGNORELIST_UPDATE")
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
self:UnregisterEvent("ADDON_LOADED")
-- Synchronize spam filters with defaults, if enabled
if GlobalIgnoreDB.autoUpdate == true then
for count = 1, #filterDefDesc do
local found = false
for count2 = 1, #GlobalIgnoreDB.filterDesc do
if GlobalIgnoreDB.filterDesc[count2] == filterDefDesc[count] then
found = true
GlobalIgnoreDB.filterList[count2] = filterDefFilter[count]
break
end
end
if found == false then
ShowMsg("Adding new spam filter: " .. filterDefDesc[count])
GlobalIgnoreDB.filterDesc[#GlobalIgnoreDB.filterDesc + 1] = filterDefDesc[count]
GlobalIgnoreDB.filterList[#GlobalIgnoreDB.filterList + 1] = filterDefFilter[count]
GlobalIgnoreDB.filterActive[#GlobalIgnoreDB.filterActive + 1] = filterDefActive[count]
GlobalIgnoreDB.filterCount[#GlobalIgnoreDB.filterCount + 1] = 0
end
end
end
end
-------------------
-- EVENT HANDLER --
-------------------
local function EventHandler (self, event, sender, arg1, ...)
--print ("DEBUG event=".. (event or "nil"))
--print ("DEBUG event=".. (event or "nil") .. " sender=" .. (sender or "nil"))
--if (event == "CHANNEL_INVITE_REQUEST") or (event == "CHAT_MSG_CHANNEL_NOTICE_USER") then
-- print ("DEBUG RECEIVED CHANNEL INVITE REQUEST: " .. (arg1 or "nil"))
--end
if (event == "ADDON_LOADED") and (sender == "GlobalIgnoreList") then
gotLoaded = true
end
if event == "IGNORELIST_UPDATE" then
gotUpdate = true
end
if event == "PLAYER_ENTERING_WORLD" then
gotEntering = true
end
if event == "GROUP_ROSTER_UPDATE" then
if gotGroup == true and not IsInGroup() then
gotGroup = false
groupWarning = {}
elseif gotGroup == false and IsInGroup() then
gotGroup = true
elseif gotGroup == true then
local prefix = IsInRaid() and "raid" or "party"
local name = ""
local doWarn = false
for count = 1, GetNumGroupMembers() do
name = GetUnitName(prefix..count, true)
if name then
name = addServer(name)
if hasGlobalIgnored(name) > 0 and hasGroupWarning(name) == 0 then
doWarn = true
groupWarning[#groupWarning + 1] = name
end
end
end
if doWarn then
local nameList = ""
for count = 1, #groupWarning do
nameList = nameList .. "\n" .. groupWarning[count]
end
ShowMsg(format(L["CHAT_1"], #groupWarning, nameList))
StaticPopup_Show("GIL_PARTYWARN", #groupWarning, nameList)
end
end
end
if event == "PARTY_INVITE_REQUEST" and GIL_Loaded == true then
sender = addServer(sender)
if hasGlobalIgnored(sender) > 0 then
DeclineGroup()
ShowMsg("Automatically declined invite from " .. sender)
StaticPopup_Hide("PARTY_INVITE")
end
return
end
if event == "DUEL_REQUESTED" and GIL_Loaded == true then
sender = addServer(sender)
if hasGlobalIgnored(sender) > 0 then
CancelDuel()
ShowMsg("Automatically declined duel from " .. sender)
end
return
end
if (event == "MAIL_INBOX_UPDATE") then
if not GlobalIgnoreDB.filterMailbox then
return
end
for index = 1, select(1, GetInboxNumItems()) do
_, _, sender, subject, money, CODAmount, _, hasItem, _, _, _, _, isGM = GetInboxHeaderInfo(index)
check = true
if sender == nil or money > 0 or CODAmount > 0 or hasItem ~= nil or isGM then
check = false
end
if check then
body = select(1, GetInboxText(index))
if subject ~= nil then
subjectResult, subjectFilterNum = filterComplex(nil, string.lower(subject), nil)
if subjectResult == true then
DeleteInboxItem(index)
GlobalIgnoreDB.filterTotal = GlobalIgnoreDB.filterTotal + 1
GlobalIgnoreDB.filterCount[subjectFilterNum] = GlobalIgnoreDB.filterCount[subjectFilterNum] + 1
end
end
if body ~= nil then
bodyResult, bodyFilterNum = filterComplex(nil, string.lower(body))
if bodyResult == true then
DeleteInboxItem(index)
GlobalIgnoreDB.filterTotal = GlobalIgnoreDB.filterTotal + 1
GlobalIgnoreDB.filterCount[bodyFilterNum] = GlobalIgnoreDB.filterCount[bodyFilterNum] + 1
end
end
if subjectResult == true or bodyResult == true then
-- C_ReportSystem.OpenReportPlayerDialog(PLAYER_REPORT_TYPE_SPAM, sender, PlayerLocation:CreateFromUnit(sender))
-- C_ReportSystem.SetPendingReportTarget(sender)
end
end
end
end
if gotLoaded == true and gotEntering == true then
if safeToLoad ~= true and gotUpdate ~= true then
timer = 0
self:SetScript("OnUpdate", function(Self, elapsed)
timer = timer + elapsed
if timer < 5 then