-
Notifications
You must be signed in to change notification settings - Fork 40
/
CVRequestArchiver.user.js
4623 lines (4394 loc) · 266 KB
/
CVRequestArchiver.user.js
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
// ==UserScript==
// @name CV Request Archiver
// @namespace https://github.com/SO-Close-Vote-Reviewers/
// @version 3.5.0
// @description Moves messages or performs other actions on Chat messages. In some rooms, including SOCVR, it scans the chat transcript and checks all cv+delete+undelete+reopen+dupe requests and SD, FireAlarm, Queen, etc. reports for status, then moves the completed or expired ones.
// @author @TinyGiant @rene @Tunaki @Makyen
// @updateURL https://github.com/SO-Close-Vote-Reviewers/UserScripts/raw/master/CVRequestArchiver.user.js
// @downloadURL https://github.com/SO-Close-Vote-Reviewers/UserScripts/raw/master/CVRequestArchiver.user.js
// @include /https?:\/\/chat(\.meta)?\.stack(overflow|exchange).com\/(rooms|search|transcript|users)(\/|\?).*/
// @grant none
// ==/UserScript==
/* jshint -W097 */
/* jshint jquery: true */
/* jshint forin: false */
/* jshint curly: false */
/* jshint browser: true */
/* jshint devel: true */
/* jshint esversion: 6 */
/* jshint esnext: true */
/* globals CHAT, $, jQuery, popUp */ //eslint-disable-line no-redeclare
// You need to be a room owner for this script to work.
// In rooms where you are the owner, it adds a button to the bottom bar in chat
// (with the label "scan 3k") and on-hover decorations on all chat messages
// which allow you to manually move or otherwise manipulate them
// To add support for a new room, edit the targetRoomSets definition below
// (as of 2023-04-28, it starts on line 244)
(function() {
'use strict';
const lsPrefix = 'SOCVR-Archiver-'; //prefix to avoid clashes in localStorage
const getStorage = (key) => localStorage[lsPrefix + key];
const setStorage = (key, val) => (localStorage[lsPrefix + key] = val);
const setStorageJSON = (key, val) => (localStorage[lsPrefix + key] = JSON.stringify(val));
function getStorageJSON(key) {
const storageValue = getStorage(key);
try {
return JSON.parse(storageValue);
} catch (e) {
//Storage is not valid JSON
return null;
}
}
//Don't run in iframes
if (window !== window.top) {
return false;
}
let room;
let me;
let isChat = false;
const isSearch = /^\/+search/.test(window.location.pathname);
const isTranscript = /^\/+transcript\//.test(window.location.pathname);
const isUsersPage = /^\/+users\//.test(window.location.pathname);
const isInfoPage = /^\/rooms\/info\/\d+\//.test(window.location.pathname);
const isStarsPage = isInfoPage && /\btab=stars\b/.test(window.location.search);
const fkey = getFkey();
function getFkey() {
const fkeyFromFunction = window.fkey()?.fkey;
if (fkeyFromFunction && typeof fkeyFromFunction === 'string') {
return fkeyFromFunction;
} //else
//Try to get the fkey from the HTML. If not available, then get it from storage.
const $fkey = $('#fkey');
let alternateFkey = null;
if (isSearch || isUsersPage) {
//#fkey is not available in search and user pages, but is returned as a property value from window.fkey().
alternateFkey = getStorage('fkey');
} else {
if (!$fkey.length) {
return null;
}
alternateFkey = $fkey.val();
}
if (!alternateFkey) {
return null;
}
return alternateFkey;
}
setStorage('fkey', fkey);
function startup() {
if (typeof $ !== 'function') {
//jQuery doesn't exist yet. Try again later.
//Should put a limit on the number of times this is retried.
setTimeout(startup, 250);
return;
}
room = (/(?:chat(?:\.meta)?\.stack(?:overflow|exchange).com)\/rooms\/(?:info\/)?(\d+)/.exec(window.location.href) || [false, false])[1];
if (isInfoPage && !isStarsPage) {
//The only info page the Archiver does anything on is the stars page.
room = 0;
}
isChat = !!room;
if (isSearch) {
room = (/^.*\broom=(\d+)\b.*$/i.exec(window.location.search) || [false, false])[1];
}
if (isTranscript) {
const roomNameLink = $('#sidebar-content .room-mini .room-mini-header .room-name a');
if (roomNameLink.length) {
room = (/^(?:https?:)?(?:\/\/chat(?:\.meta)?\.stack(?:overflow|exchange)\.com)?\/rooms\/(\d+)/.exec(roomNameLink[0].href) || [false, false])[1];
}
}
room = +room;
if (!room && !isUsersPage && !isSearch) {
return false;
}
me = (/\d+/.exec($('#active-user').attr('class')) || [false])[0];
//Get me from localStorage. (transcript doesn't contain who you are).
me = me ? me : getStorage('me');
if (!me) {
return false;
}
//Save me in localStorage.
setStorage('me', me);
if (isUsersPage || (isSearch && !room)) {
//On user pages, we don't test for being the RO/mod.
cvRequestArchiver();
return;
}
getUserInfoInRoom(room, me).done(cvRequestArchiver);
}
function getUserInfoInRoom(inRoom, user) {
return $.ajax({
type: 'POST',
url: '/user/info?ids=' + user + '&roomId=' + inRoom,
});
}
function cvRequestArchiver(info) {
const roRooms = getStorageJSON('roRooms') || {};
let isModerator = false;
setIsModeratorRoRoomsByInfo(room, info);
if (!(isUsersPage || (isSearch && !room)) && !info.users[0].is_owner && !info.users[0].is_moderator) {
return false;
}
let totalEventsToFetch = 0;
let requests = [];
let messagesToMove = [];
let events = [];
let eventsByNum = {};
//A location to store the last room in which a message was which was added to the manual move list.
// This is really a hack that will work most of the time. What should really be done here is record
// the room that each message is in and move them separately by room.
// Looks like if they are not all from the same room, but at least one is in the declared move-from room
// then it will move the ones that are in the declared room and silently fail on those that are in any
// other rooms.
let roomForMostRecentlyAddedManualMove = getStorage('roomForMostRecentlyAddedManualMove') || 0;
const nodes = {};
let avatarList = getStorageJSON('avatarList') || {};
const $body = $(document.body);
const nKButtonEntriesToScan = 3000;
const soChat = 'chat.stackoverflow.com';
const seChat = 'chat.stackexchange.com';
const mseChat = 'chat.meta.stackexchange.com';
//User ID's are different on the 3 separate Chat servers.
// If a user ID is not defined here for a particular server, then the RequestTypes which use it will not perform that portion of the testing for that
// request type. This could result in erroneous operation.
const knownUserIdsByChatSite = {
[soChat]: {
fireAlarm: 6373379,
smokeDetector: 3735529,
queen: 6294609,
fox9000: 3671802,
yam: 5285668,
panta: 1413395,
},
[seChat]: {
fireAlarm: 212669,
smokeDetector: 120914,
queen: null, //No account found
fox9000: 118010,
yam: 323209,
panta: 141258,
},
[mseChat]: {
fireAlarm: 330041,
smokeDetector: 266345,
queen: null, //No account found
fox9000: 261079,
yam: 278816,
panta: 186472,
},
};
const parser = new DOMParser();
let replyNode = $();
//Define Target Room Sets
//const trashcanEmoji = String.fromCodePoint(0x1F5D1) + String.fromCodePoint(0xFE0F);
const trashcanEmoji = String.fromCodePoint(0x1F5D1);
function TargetRoom(_roomNumber, _chatServer, _fullName, _shortName, _displayed, _classInfo, _options) {
//A class for target rooms.
_options = (typeof _options === 'object' && _options !== null) ? _options : {};
this.roomNumber = _roomNumber;
this.chatServer = _chatServer;
this.fullName = _fullName;
this.shortName = _shortName;
this.displayed = _displayed;
this.classInfo = _classInfo;
this.showAsTarget = _options.showAsTarget;
this.showMeta = _options.showMeta;
this.showDeleted = _options.showDeleted;
this.showUI = _options.showUI;
}
function makeRoomsByNumberObject(roomArray) {
return roomArray.reduce((obj, roomObj) => {
obj[roomObj.roomNumber] = roomObj;
return obj;
}, {});
}
const commonRoomOptions = {
allTrue: {showAsTarget: true, showMeta: true, showDeleted: true, showUI: true},
notTarget: {showAsTarget: false, showMeta: true, showDeleted: true, showUI: true},
targetAndDeleted: {showAsTarget: true, showMeta: false, showDeleted: true, showUI: false},
noUI: {showAsTarget: true, showMeta: true, showDeleted: true, showUI: false},
onlyDeleted: {showAsTarget: false, showMeta: false, showDeleted: true, showUI: false},
};
const soChatScanning = {
//On Chat.SO the following are the same for all room sets.
//The following properties are needed to have the archiver semi-automatically scan for messages to archive.
mainSite: 'stackoverflow.com',
mainSiteSEApiParam: 'stackoverflow', //How to identify the main site to the SE API.
mainSiteRegExpText: 'stackoverflow\\.com',
regExp: {
//Various other RegExp are constructed and added to this list.
//chatMetaElimiation is used to remove chat and meta from detection by the RegExp looking for links to the main site.
// The meta site is most important here. This is used due to the lack of look-behind in JavaScript RegExp.
chatMetaElimiation: /(?:meta|chat)\.stackoverflow\.com\/?/g,
},
};
const targetRoomSets = [
//SO CHAT
{//SOCVR
name: 'SOCVR',
primeRoom: 41570,
chatServer: soChat,
defaultTargetRoom: 90230,
rooms: makeRoomsByNumberObject([
//SOCVR
new TargetRoom(41570, soChat, 'SOCVR', 'SOCVR', 'S', 'SOCVR', commonRoomOptions.allTrue),
//Graveyard
new TargetRoom(90230, soChat, 'SOCVR Request Graveyard', 'Graveyard', 'G', 'Grave', commonRoomOptions.allTrue),
//SOCVR /dev/null
new TargetRoom(126195, soChat, 'SOCVR /dev/null', 'Null', 'N', 'Null', commonRoomOptions.allTrue),
//Testing Facility
new TargetRoom(68414, soChat, 'SOCVR Testing Facility', 'Testing', 'Te', 'Test', commonRoomOptions.allTrue),
//The Ministry of Silly Hats
//The "М" in 'Мinistry' is not actual capital M to have the Ministry sorted to the end of the room order.
new TargetRoom(92764, soChat, 'The Ministry of Silly Hats', 'Мinistry', 'M', 'Minist', commonRoomOptions.noUI),
//Private for SD posts that have especially offensive content.
new TargetRoom(170175, soChat, 'Private Trash', 'Private', 'P', 'Private', commonRoomOptions.noUI),
]),
//Semi-auto scanning:
//On Chat.SO, many of the properties are common for all rooms. Those are in soChatScanning. However,
// includedRequestTypes and excludedRequestTypes may vary per room.
//An optional list of RequestTypes keys (String). If it exists, only the listed RequestTypes are included.
//includedRequestTypes: [],
//An optional list of RequestTypes keys (String). If it exists, these are excluded from RequestTypes used.
// The exclusion happens after inclusion, so keys listed here will not be included even if in includedRequestTypes.
excludedRequestTypes: [
],
useCrudeRequestTypes: false,
},
{//SOBotics
name: 'SOBotics',
primeRoom: 111347,
chatServer: soChat,
defaultTargetRoom: 170175,
rooms: makeRoomsByNumberObject([
//SOBotics
new TargetRoom(111347, soChat, 'SOBotics', 'Botics', 'B', 'Bot', commonRoomOptions.noUI),
//Private for SD posts that have especially offensive content.
new TargetRoom(170175, soChat, 'Private Trash', 'Private', 'P', 'Private', commonRoomOptions.noUI),
//Trash can
new TargetRoom(23262, soChat, 'Trash can', 'Trash', trashcanEmoji, 'Trash', commonRoomOptions.noUI),
]),
},
{//Python
name: 'Python',
primeRoom: 6,
chatServer: soChat,
defaultTargetRoom: 71097,
rooms: makeRoomsByNumberObject([
//SOBotics
new TargetRoom(6, soChat, 'Python', 'Python', 'P', 'Py', commonRoomOptions.noUI),
//Python Ouroboros - The Rotating Knives: The Python room's default trash bin.
new TargetRoom(71097, soChat, 'Python Ouroboros - The Rotating Knives', 'Ouroboros', 'O', 'Ouroboros', commonRoomOptions.noUI),
//Private for SD posts that have especially offensive content.
new TargetRoom(170175, soChat, 'Private Trash', 'Private', 'T', 'Private', commonRoomOptions.noUI),
//Trash can
new TargetRoom(23262, soChat, 'Trash can', 'Trash', trashcanEmoji, 'Trash', commonRoomOptions.noUI),
]),
},
{//SO Chat Default
name: 'SO Chat Default',
primeRoom: 99999999,
chatServer: soChat,
isSiteDefault: true,
defaultTargetRoom: 23262,
rooms: makeRoomsByNumberObject([
//Trash can
new TargetRoom(23262, soChat, 'Trash can', 'Trash', trashcanEmoji, 'Trash', commonRoomOptions.noUI),
//Private for SD posts that have especially offensive content.
new TargetRoom(170175, soChat, 'Private Trash', 'Private', 'P', 'Private', commonRoomOptions.noUI),
new TargetRoom(109494, soChat, 'friendly bin', 'friendly', 'f', 'friendly', commonRoomOptions.noUI),
]),
},
//SE CHAT
{//Charcoal HQ
name: 'Charcoal HQ',
primeRoom: 11540,
chatServer: seChat,
defaultTargetRoom: 82806,
rooms: makeRoomsByNumberObject([
//Charcoal HQ
new TargetRoom(11540, seChat, 'Charcoal HQ', 'Charcoal', 'C', 'CHQ', commonRoomOptions.noUI),
//Charcoal Test
new TargetRoom(65945, seChat, 'Charcoal Test', 'Test', 'CT', 'Test', commonRoomOptions.noUI),
//Trash (public; not frozen)
new TargetRoom(82806, seChat, 'Trash', 'Trash', 'Tr', 'Trash 82', commonRoomOptions.noUI),
//Trash 19718 (Gallery mode; ROs of other rooms are given explicit write access; currently frozen: 2021-10-28)
new TargetRoom(19718, seChat, 'Trash (requires access)', 'Trash', 'T', 'Trash 19', commonRoomOptions.noUI),
//trash
//Room is frozen
//new TargetRoom(57121, seChat, 'trash (room 57121)', 'trash', 't', 'trash 57', commonRoomOptions.noUI),
//Private for SD posts that have especially offensive content.
new TargetRoom(658, seChat, 'Private Trash (Trashcan; mod-private)', 'Private', 'P', 'Private', commonRoomOptions.noUI),
]),
},
{//CRCQR
name: 'CRCQR',
primeRoom: 85306,
chatServer: seChat,
defaultTargetRoom: 86076,
rooms: makeRoomsByNumberObject([
//CRCQR
new TargetRoom(85306, soChat, 'CRCQR', 'CRCQR', 'C', 'CRCQR', commonRoomOptions.allTrue),
//CRCQR Graveyard
new TargetRoom(86076, soChat, 'CRCQR Request Graveyard', 'Graveyard', 'G', 'Grave', commonRoomOptions.allTrue),
//CRCQR /dev/null
new TargetRoom(86077, soChat, 'CRCQR /dev/null', 'Null', 'N', 'Null', commonRoomOptions.allTrue),
//Private for SD posts that have especially offensive content.
new TargetRoom(658, seChat, 'Private Trash (Trashcan; mod-private)', 'Private', 'P', 'Private', commonRoomOptions.noUI),
]),
//Semi-auto scanning:
//The following properties are needed to have the archiver semi-automatically scan for messages to archive.
mainSite: 'codereview.stackexchange.com',
mainSiteSEApiParam: 'codereview', //How to identify the main site to the SE API.
mainSiteRegExpText: 'codereview\\.stackexchange\\.com',
regExp: {
//Various other RegExp are constructed and added to this list.
//chatMetaElimiation is used to remove chat and meta from detection by the RegExp looking for links to the main site.
// The meta site is most important here. This is used due to the lack of look-behind in JavaScript RegExp.
chatMetaElimiation: /meta\.codereview\.stackexchange\.com\/?/g, //This is the old meta domain, but is considered an alias by SE.
},
//An optional list of RequestTypes keys (String). If it exists, only the listed RequestTypes are included.
//includedRequestTypes: [],
//An optional list of RequestTypes keys (String). If it exists, these are excluded from RequestTypes used.
// The exclusion happens after inclusion, so keys listed here will not be included even if in includedRequestTypes.
excludedRequestTypes: [
],
useCrudeRequestTypes: false,
},
{//CRUDE
name: 'CRUDE',
primeRoom: 2165,
chatServer: seChat,
defaultTargetRoom: 88696,
rooms: makeRoomsByNumberObject([
//CRUDE
new TargetRoom(2165, soChat, 'CRUDE', 'CRUDE', 'C', 'CRUDE', commonRoomOptions.allTrue),
//CRUDE Archive
new TargetRoom(88696, soChat, 'CRUDE Archive', 'Archive', 'A', 'Archive', commonRoomOptions.allTrue),
//Trash
new TargetRoom(82806, seChat, 'Trash', 'Trash', 'Tr', 'Trash 82', commonRoomOptions.noUI),
//Private for SD posts that have especially offensive content.
new TargetRoom(658, seChat, 'Private Trash (Trashcan; mod-private)', 'Private', 'P', 'Private', commonRoomOptions.noUI),
]),
//Semi-auto scanning:
//The following properties are needed to have the archiver semi-automatically scan for messages to archive.
mainSite: 'math.stackexchange.com',
mainSiteSEApiParam: 'math', //How to identify the main site to the SE API.
mainSiteRegExpText: 'math\\.stackexchange\\.com',
regExp: {
//Various other RegExp are constructed and added to this list.
//chatMetaElimiation is used to remove chat and meta from detection by the RegExp looking for links to the main site.
// The meta site is most important here. This is used due to the lack of look-behind in JavaScript RegExp.
chatMetaElimiation: /meta\.math\.stackexchange\.com\/?/g, //This is the old meta domain, but is considered an alias by SE.
},
//An optional list of RequestTypes keys (String). If it exists, only the listed RequestTypes are included.
//includedRequestTypes: [],
//An optional list of RequestTypes keys (String). If it exists, these are excluded from RequestTypes used.
// The exclusion happens after inclusion, so keys listed here will not be included even if in includedRequestTypes.
excludedRequestTypes: [
],
useCrudeRequestTypes: true,
},
{//SE Chat Default
name: 'SE Chat Default',
primeRoom: 99999999,
chatServer: seChat,
isSiteDefault: true,
defaultTargetRoom: 19718,
rooms: makeRoomsByNumberObject([
//Trash
new TargetRoom(19718, soChat, 'Trash (requires access)', 'Trash', trashcanEmoji, 'Trash', commonRoomOptions.noUI), //User must have access.
//Trash
new TargetRoom(82806, seChat, 'Trash', 'Trash', 'Tr', 'Trash 82', commonRoomOptions.noUI),
//Private trash.
new TargetRoom(658, seChat, 'Private Trash (Trashcan; mod-private)', 'Private', 'P', 'Private', commonRoomOptions.noUI),
]),
},
//MSE CHAT
{//Tavern on the Meta
name: 'Tavern on the Meta',
primeRoom: 89,
chatServer: mseChat,
defaultTargetRoom: 1037,
rooms: makeRoomsByNumberObject([
//Tavern on the Meta
new TargetRoom(89, mseChat, 'Tavern on the Meta', 'Tavern', 'Ta', 'Tavern', commonRoomOptions.allTrue),
//Chimney
new TargetRoom(1037, mseChat, 'Chimney', 'Chimney', 'C', 'Chimney', commonRoomOptions.allTrue),
//Sandbox/Trash Bin/Something
new TargetRoom(1196, mseChat, 'Sandbox/Trash Bin/Something', 'Something', 'S', 'Something', commonRoomOptions.noUI),
//Trashcan
new TargetRoom(1251, mseChat, 'Trashcan', 'Trashcan', 'Tr', 'Trashcan', commonRoomOptions.noUI),
]),
//Semi-auto scanning:
//The following properties are needed to have the archiver semi-automatically scan for messages to archive.
mainSite: 'meta.stackexchange.com',
mainSiteSEApiParam: 'meta', //How to identify the main site to the SE API.
mainSiteRegExpText: 'meta\\.stackexchange\\.com',
regExp: {
//Various other RegExp are constructed and added to this list.
//chatMetaElimiation is used to remove chat and meta from detection by the RegExp looking for links to the main site.
// This is used due to the lack of look-behind in JavaScript RegExp.
chatMetaElimiation: /chat\.meta\.stackexchange\.com\/?/g, //This is the chat domain.
},
//An optional list of RequestTypes keys (String). If it exists, only the listed RequestTypes are included.
//includedRequestTypes: [],
//An optional list of RequestTypes keys (String). If it exists, these are excluded from RequestTypes used.
// The exclusion happens after inclusion, so keys listed here will not be included even if in includedRequestTypes.
excludedRequestTypes: [
],
useCrudeRequestTypes: false,
},
{//Meta SE Chat Default
name: 'Meta SE Chat Default',
primeRoom: 99999999,
chatServer: mseChat,
isSiteDefault: true,
defaultTargetRoom: 19718,
rooms: makeRoomsByNumberObject([
//Sandbox/Trash Bin/Something
new TargetRoom(1196, mseChat, 'Sandbox/Trash Bin/Something', 'Something', trashcanEmoji, 'Something', commonRoomOptions.noUI),
]),
},
];
targetRoomSets.forEach((roomSet) => {
if (roomSet.chatServer === soChat) {
Object.assign(roomSet, soChatScanning);
}
});
const defaultDisabledTargetRoomSet = {
primeRoom: 999999998,
chatServer: window.location.hostname,
defaultTargetRoom: 999999999,
rooms: makeRoomsByNumberObject([
//Nowhere
new TargetRoom(999999998, window.location.hostname, 'Disabled', 'Disabled', 'D', 'Disabled', commonRoomOptions.onlyDeleted),
new TargetRoom(999999999, window.location.hostname, 'Disabled', 'Disabled', 'D', 'Disabled', commonRoomOptions.onlyDeleted),
]),
};
const siteTargetRoomSets = targetRoomSets.filter(({chatServer}) => chatServer === window.location.hostname);
// Determine the set of target rooms to use.
const targetRoomSet = (siteTargetRoomSets.find((roomSet) => roomSet.rooms[room]) || siteTargetRoomSets.find(({isSiteDefault}) => isSiteDefault) || defaultDisabledTargetRoomSet);
const defaultTargetRoom = targetRoomSet.defaultTargetRoom;
const siteAllRooms = {};
//Reversing the order here gives priority to sets listed first, due to potentially overwriting an entry in siteAllRooms.
siteTargetRoomSets.reverse().forEach((roomSet) => {
roomSet.roomsOrder = Object.keys(roomSet.rooms).sort((a, b) => roomSet.rooms[a].shortName > roomSet.rooms[b].shortName);
const setRoomsOrder = roomSet.roomsOrder;
const setRoomsOrderOnlyTargets = setRoomsOrder.filter((key) => roomSet.rooms[key].showAsTarget);
setRoomsOrder.forEach((roomTarget) => {
const roomOrderWithoutCurrent = setRoomsOrderOnlyTargets.filter((key) => +key !== +roomTarget);
roomSet.rooms[roomTarget].metaHTML = makeMetaRoomTargetsHtmlByOrderAndRooms(roomOrderWithoutCurrent, roomSet.rooms);
siteAllRooms[roomTarget] = roomSet.rooms[roomTarget];
});
});
//Undo in-place reversal.
siteTargetRoomSets.reverse();
//Save the default target prior to it, potentially, being deleted.
const targetRoomsByRoomNumber = (isUsersPage || (isSearch && !room)) ? siteAllRooms : targetRoomSet.rooms;
const defaultTargetRoomObject = targetRoomsByRoomNumber[defaultTargetRoom];
//Save the current room prior to deleting it as a target.
const currentRoomTargetInfo = targetRoomsByRoomNumber[room] || new TargetRoom(room, window.location.hostname, 'Default', 'Default', 'D', 'Default', commonRoomOptions.noUI);
//The current room is not a valid room target.
delete targetRoomsByRoomNumber[room];
//Remove any group rooms which are not to be used as a target.
Object.keys(targetRoomsByRoomNumber).forEach((key) => {
if (!targetRoomsByRoomNumber[key].showAsTarget) {
delete targetRoomsByRoomNumber[key];
}
});
//The order in which we want to display the controls. As it happens, an alpha-sort based on shortName works well.
const targetRoomsByRoomNumberOrder = Object.keys(targetRoomsByRoomNumber).sort((a, b) => targetRoomsByRoomNumber[a].shortName > targetRoomsByRoomNumber[b].shortName);
const knownUserIds = knownUserIdsByChatSite[targetRoomSet.chatServer];
if (targetRoomSet.regExp) {
//Match and capture the ID for questions, answers, and posts URLs.
//e.g. /stackoverflow\.com\/(?:q[^\/]*|posts|a[^\/]*)\/+(\d+)/g
targetRoomSet.regExp.questionAnswerPostsId = new RegExp(`${targetRoomSet.mainSiteRegExpText}/(?:q[^/]*|posts|a[^/]*)/+(\\d+)`, 'g');
//The above will preferentially obtain questions over some answer URL formats: e.g.
// https://stackoverflow.com/questions/7654321/foo-my-baz/1234567#1234567
// That's good for cv-pls/reopen-pls, but for other types of requests we should be considering the answer instead, if the URL is the alternate answer URL.
//e.g. /(?:^|[\s"'])(?:(?:https?:)?(?:(?:\/\/)?(?:www\.|\/\/)?stackoverflow\.com\/))(?:q[^\/]*|posts)[^\s#]*#(\d+)(?:$|[\s"'])/g
targetRoomSet.regExp.answerIdFromQuestionUrl = new RegExp(`(?:^|[\\s\"\'])(?:(?:https?:)?(?:(?://)?(?:www\\.|//)?${targetRoomSet.mainSiteRegExpText}/))(?:q[^/]*|posts)[^\\s#]*#(\\d+)(?:$|[\\s"'])`, 'g'); // eslint-disable-line no-useless-escape
//Detect a comment URL
//e.g. /(?:^|[\s"'])(?:(?:https?:)?(?:(?:\/\/)?(?:www\.|\/\/)?stackoverflow\.com\/))(?:q[^\/]*|posts|a)[^\s#]*#comment(\d+)(?:$|[\s"'_])/g
targetRoomSet.regExp.commentIdFromUrl = new RegExp(`(?:^|[\\s\"\'])(?:(?:https?:)?(?:(?://)?(?:www\\.|//)?${targetRoomSet.mainSiteRegExpText}/))(?:q[^/]*|posts|a)[^\\s#]*#comment(\\d+)(?:$|[\\s\"\'_])`, 'g'); // eslint-disable-line no-useless-escape
}
//The UI doesn't currently function on sites other than chat.SO.
const roomGroupStringPropertyKeysRequiredForUI = [
'mainSite',
'mainSiteSEApiParam',
'mainSiteRegExpText',
];
const roomGroupRegExpPropertyKeysRequiredForUI = [
'chatMetaElimiation',
'questionAnswerPostsId',
'answerIdFromQuestionUrl',
'commentIdFromUrl',
];
//Only show the UI if the target room specifies it, it's chat and enough information exists and is minimally valid.
const showUI = currentRoomTargetInfo.showUI && isChat && targetRoomSet.regExp &&
roomGroupStringPropertyKeysRequiredForUI.every((key) => typeof targetRoomSet[key] === 'string') &&
roomGroupRegExpPropertyKeysRequiredForUI.every((key) => targetRoomSet.regExp[key] instanceof RegExp);
const showDeleted = currentRoomTargetInfo.showDeleted;
const showMeta = currentRoomTargetInfo.showMeta || isUsersPage || (isSearch && !room);
const addedMetaHtml = makeMetaRoomTargetsHtml();
if (isUsersPage || (isSearch && !room)) {
//There is no set room, so want to make sure we have user info for at least all the
// rooms for which we have in a room target set for this chatServer.
const additionalUserInfoFetches = [];
Object.keys(siteAllRooms).forEach((roomId, index) => {
if (typeof roRooms[roomId] !== 'boolean') {
additionalUserInfoFetches.push(delay(index * 500).then(() => getUserInfoInRoom(roomId, me)).then((userInfo) => {
setIsModeratorRoRoomsByInfo(roomId, userInfo, true);
}));
}
});
if (additionalUserInfoFetches.length) {
//jQuery.when is broken and does not work here. It immediately resolves,
// not waiting for the for the Promises to resolve.
//jQuery.when.apply(jQuery, additionalUserInfoFetches).then(() => {
Promise.all(additionalUserInfoFetches).then(() => {
addMoveToInMeta();
});
}
}
const SECONDS_IN_MINUTE = 60;
const SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
const SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR;
const timezoneOffsetMs = (new Date()).getTimezoneOffset() * SECONDS_IN_MINUTE * 1000;
//The SE Chat endpoint supports movePosts with up to 2048 messages.
// However, when the chunk size is larger than 100 it causes the chat interface to not properly
// delete moved messages from the chat display. Thus, the chunk size is kept at < 100 for moves of displayed messages.
// The size used is 100 for messages which would be still visible in the most recent chat instance for the user,
// then 2048 for the rest. The minimal number of moves is performed.
// Some messages are not moved (those without a user_id), as they cause an API error.
const bigChunkSize = 2048; //CHAT API movePosts maximum is 2048, higher numbers result in "Internal Server Error".
const smallChunkSize = 100;
const unclosedRequestReviewerButtons = $('.urrs-requests-button');
// REQUEST TYPES
/* Example request text:
<a href="//stackoverflow.com/questions/tagged/cv-pls"><span class="ob-post-tag" style="background-color: #E0EAF1; color: #3E6D8E; border-color: #3E6D8E; border-style: solid;">cv-pls</span></a> <a href="//stackoverflow.com/questions/tagged/entity-framework"><span class="ob-post-tag" style="background-color: #E0EAF1; color: #3E6D8E; border-color: #3E6D8E; border-style: solid;">entity-framework</span></a> Unclear ("I get error"-type of question) https://stackoverflow.com/q/46022628/861716
*/
//People can really mangle the -pls portion of the request. The RegExp has a known terminating character for the tag:
// " for matching the href URL and ] for plain text.
//Match if they get at least 2 characters of pls, just pl, or 1 extra character
const please = '(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)';
const hrefUrlTag = '(?:tagged\\/';
const endHrefToPlainText = '"|\\[(?:(?:meta-)?tag\\W?)?';
const endPlainTextToEndWithQuestion = `\\]).*?${targetRoomSet.mainSiteRegExpText}\\/(?:[qa][^\\/]*|posts)\\/+(\\d+)`;
const questionUrlToHrefTag = `${targetRoomSet.mainSiteRegExpText}\\/(?:[qa][^\\/]*|posts)\\/+(\\d+).*(?:tagged\\/`;
const endPlainTextToEndWithQuestionOrReview = `\\]).*?${targetRoomSet.mainSiteRegExpText}\\/(?:[qa][^\\/]*|posts|review\\/[\\w-]+)\\/+(\\d+)`;
const questionOrReviewUrlToHrefTag = `${targetRoomSet.mainSiteRegExpText}\\/(?:[qa][^\\/]*|posts|review\\/[\\w-]+)\\/+(\\d+).*(?:tagged\\/`;
const endPlainTextToEnd = '\\])';
const endHrefPrefixToSpanText = '[^>]*><span[^>]*>';
const endSpanTextToPlainText = '<\\/span>|\\[(?:(?:meta-)?tag\\W?)?';
function makeTagRegExArray(prefix, additional, includeReviews) {
prefix = typeof prefix === 'string' ? prefix : '';
additional = typeof additional === 'string' ? additional : '';
//We have multiple RegExp for each tag type. We are always checking all of them for any match. Thus, this is equivalent
// to using a single RegExp that is /(?:RegExp text1|RegExp text2|RegExp text3|RegExp text4)/. Testing against a single
// RegExp should be faster than 4.
const regexText = '(?:' + ([
//Tag before question
(hrefUrlTag + prefix + additional + endHrefToPlainText + prefix + additional + (includeReviews ? endPlainTextToEndWithQuestionOrReview : endPlainTextToEndWithQuestion)),
//Tag after question
((includeReviews ? questionOrReviewUrlToHrefTag : questionUrlToHrefTag) + prefix + additional + endHrefToPlainText + prefix + additional + endPlainTextToEnd),
//Tag before question: match tag in the <span>, not in the href (which could be encoded)
(hrefUrlTag + prefix + endHrefPrefixToSpanText + prefix + additional + endSpanTextToPlainText + prefix + additional + (includeReviews ? endPlainTextToEndWithQuestionOrReview : endPlainTextToEndWithQuestion)),
//Tag after question: match tag in the <span>, not in the href (which could be encoded)
((includeReviews ? questionOrReviewUrlToHrefTag : questionUrlToHrefTag) + prefix + endHrefPrefixToSpanText + prefix + additional + endSpanTextToPlainText + prefix + additional + endPlainTextToEnd),
].join('|')) + ')';
return [new RegExp(regexText, 'i')];
//Example produced from cv-pls (excludes the dup request types added to cvRegexes):
//2019-08-23: https://regex101.com/r/VbNPrg/1
//(?:(?:tagged\/(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)"|\[(?:(?:meta-)?tag\W?)?(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)\]).*?stackoverflow\.com\/(?:[qa][^\/]*|posts)\/+(\d+)|stackoverflow\.com\/(?:[qa][^\/]*|posts)\/+(\d+).*(?:tagged\/(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)"|\[(?:(?:meta-)?tag\W?)?(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)\])|(?:tagged\/(?:cv|closev?)-?[^>]*><span[^>]*>(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)<\/span>|\[(?:(?:meta-)?tag\W?)?(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)\]).*?stackoverflow\.com\/(?:[qa][^\/]*|posts)\/+(\d+)|stackoverflow\.com\/(?:[qa][^\/]*|posts)\/+(\d+).*(?:tagged\/(?:cv|closev?)-?[^>]*><span[^>]*>(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)<\/span>|\[(?:(?:meta-)?tag\W?)?(?:cv|closev?)-?(?:pl(?:ease|s|z)|p.?[sz]|.l[sz]|pl.?|.pl[sz]|p.l[sz]|pl.[sz]|pl[sz].)\]))/i
}
function makeActualTagWithoutQuestionmarkRegExArray(prefix, additional) {
prefix = typeof prefix === 'string' ? prefix : '';
additional = typeof additional === 'string' ? additional : '';
const regexText = '(?:' + ([
//https://regex101.com/r/akgdVi/2
'<span class="ob-post-tag"[^>]*>' + prefix + additional + '<\\/span><\\/a>\\s*(?![\\w ]*\\?)',
].join('|')) + ')';
return [new RegExp(regexText, 'i')];
}
const cvRegexes = makeTagRegExArray('(?:cv|closev?|cls)-?', please).concat(makeTagRegExArray('(?:dup(?:licate)?)-?', please), makeTagRegExArray('(?:dup(?:licate)?)-?'));
const deleteRegexes = makeTagRegExArray('d(?:el(?:ete|etion)?)?(?:v)?-?(?:vote)?-?', please);
const undeleteRegexes = makeTagRegExArray('un-?del(?:ete|etion)?(?:v)?-?(?:vote)?(?:-?answers?|-?questions?)?-?', please);
const reopenRegexes = makeTagRegExArray('(?:re-?)?open-?', please);
const duplicateRegexes = makeTagRegExArray('pos?sib(?:le|el)-dup(?:e|licate)?');
const flagRegexes = makeTagRegExArray('(?:re-?)?flag-?', please);
const flagAsTagRegexes = makeActualTagWithoutQuestionmarkRegExArray('(?:re-?)?flag-?', please);
const spamRegexes = makeTagRegExArray('spam');
const spamAsTagRegexes = makeActualTagWithoutQuestionmarkRegExArray('spam');
const offensiveRegexes = makeTagRegExArray('(?:off?en[cs]ive|rude|abb?u[cs]ive)');
const offensiveAsTagRegexes = makeActualTagWithoutQuestionmarkRegExArray('(?:off?en[cs]ive|rude|abb?u[cs]ive)');
const approveRejectRegexes = makeTagRegExArray('(?:app?rove?|reject|rev[ie]+w)-?(?:edit-?)?', please, true);
// FireAlarm reports
const faRegexes = [
/(?:\/\/stackapps\.com\/q\/7183\">FireAlarm(?:-Swift)?)/, // eslint-disable-line no-useless-escape
/(?:\[ <a href="\/\/github\.com\/SOBotics\/FireAlarm\/tree\/swift" rel="nofollow noopener noreferrer">FireAlarm-Swift<\/a> \])/,
];
//We need to choose if we want more SD commands to be archived.
//We probably don't want to archive: (?!blame|lick|wut|coffee|tea|brownie)
const sdBangBangCommandsRegEx = /^\s*(?:!!\/|sdc )(?:report|scan|feedback)/i;
// https://regex101.com/r/3M6xoA/1/
const sdFeedbacksRegEx = /^(?:@SmokeD?e?t?e?c?t?o?r?|\s*sd)(?:\s+\d*(?:k|v|n|naa|fp?|tp?|spam|rude|abus(?:iv)?e|offensive|v|vand|vandalism|notspam|true|false|ignore|del|delete|remove|gone|postgone|why\??|-)u?-?)+\s*.*$/i;
const editMonitorRegEx = /bad edit/i;
const crudeCloseRegexes = makeTagRegExArray('(?:cv|closev?)-?');
const aHrefQAPRtag = `<a href=\"(?:https?:)?\/\/${targetRoomSet.mainSiteRegExpText}/(?:[qa][^/]*|posts|review/[\\w-]+)/+(\\d+)[^>]*>`; // eslint-disable-line no-useless-escape
const aHrefQAPRtagWithS = aHrefQAPRtag + '\\s*';
const endOfCrudeXnRegex = '(?:\\d+|[a-z])(?:\\s*:\\s*</b>[^<]*)?</a>\\W*(?:<br/?>)?\\W*)+$';
//The CRUDE Xn regexes are based off of:
// https://regex101.com/r/GHYTaY/1
const crudeCloseCnRegexes = [
new RegExp(`^\\s*(?:for\\W*)?(?:close|closure)?\\W*(?:\\s*${aHrefQAPRtagWithS}(?:<b>)?\\s*(?:c(?:lose)?)${endOfCrudeXnRegex}`, 'i'), // eslint-disable-line no-useless-escape
];
const crudeReopenRegexes = makeTagRegExArray('re-?openv?-?');
const crudeReopenRnRegexes = [
new RegExp(`^\\s*(?:for\\W*)?(?:reopen|unclose)?\\W*(?:\\s*${aHrefQAPRtagWithS}(?:<b>)?\\s*(?:r(?:eopen)?)${endOfCrudeXnRegex}`, 'i'), // eslint-disable-line no-useless-escape
];
const crudeDeleteRegexes = makeTagRegExArray('d(?:el(?:ete|etion)?)?(?:v)?-?(?:vote)?-?');
const crudeDeleteDnRegexes = [
new RegExp(`^\\s*(?:for\\W*)?(?:delete|deletion)?\\W*(?:\\s*${aHrefQAPRtagWithS}(?:<b>)?\\s*(?:d(?:el(?:ete)?)?)${endOfCrudeXnRegex}`, 'i'), // eslint-disable-line no-useless-escape
];
const crudeUndeleteRegexes = makeTagRegExArray('un?-?d(?:el(?:ete|etion)?)?(?:v)?-?(?:vote)?-?');
const crudeUndeleteUnRegexes = [
new RegExp(`^\\s*(?:for\\W*)?(?:undelete|undeletion)?\\W*(?:\\s*${aHrefQAPRtagWithS}(?:<b>)?\\s*(?:un?-?(?:del(?:ete)?)?)${endOfCrudeXnRegex}`, 'i'), // eslint-disable-line no-useless-escape
];
/* The RequestTypes Object contains definitions for the detections which are used to determine if a message should be archived.
Each detection should be a separate key containing an Object which defines the detection. The keys within that Object define
how messages are matched to the detection and what criteria must be met in order for the message to be archived.
There are "primary" types of detections, which have some known criteria about the condition of the linked post/comment
which must be met for them to be archived prior to their `alwaysArchiveAfterSeconds` time expiring. Those types are:
DELETE: The post must be deleted (i.e. no data is received from the SE API).
REOPEN: The question must be open.
CLOSE: The question must be closed.
UNDELETE: The post must not be deleted (i.e. we must get data from the SE API).
FLAG_SPAM_OFFENSIVE
APPROVE_REJECT
Only primary types are permitted to be created by combining a reply with its parent.
The available keys to describe a detection are:
additionalRequestCompleteTests: Array of Function
An array of additional test functions which if any are passed, then the request is considered complete.
alwaysArchiveAfterSeconds: Number
If the request was posted more than this many seconds ago, then it is considered complete. Very small fractional values can be used to always archive.
andRegexes: Array of RegExp | RegExp
Additional RegExps which must also have a match. The RegExp are tested against the HTML with <code> removed.
archiveParentWithThis: Boolean (truthy)
If true, then parents (messages to which these are a direct reply) are archived with the matching messages.
archiveWithChildren: Boolean (truthy)
Archive this message when any direct response to it (it's children) are archived.
archiveWithNextFromUserId: userId (Number)
Archive this message when the next message which was posted by a specified userId.
archiveWithParent: Boolean (truthy)
Archive this message when the message to which it is a direct response (it's parent) is archived.
archiveWithPreviousFromUserId: userId (Number)
Archive this message when the previous message which was posted by a specified userId.
name: String
A human readable name for the type. This is not used in the code, but helps for debugging, as it's visible when viewing the type.
noContent: Boolean (truthy)
Match if there is no content (i.e. post is deleted)
onlyComments: Boolean (truthy)
The posts associated with this type can only point to comments.
onlyQuestions: Boolean (truthy)
The posts associated with this type can only point to questions. Any URLs which include information about both the question
and an answer, a comment or an answer and a comment will be reduced the the question. This does not, currently, look for questions
associated with answers when only the answer is specified in the URL (e.g. //stackoverflow.com/a/123456)
primary: Boolean (truthy)
This type is considered primary (not currently used, theses are manually defined, so there is a known order).
regexes: Array of RegExp | RegExp
An Array of RegExp where at least one must match the HTML for the message content (as delivered by the API, but with text in <code> removed).
replyToTypeKeys: Array of String
Matches if this is a reply to the specified type.
textRegexes: Array of RegExp | RegExp
At least one of which must match the `.text()` content of the message with all <code> removed, and all meta and chat links removed.
underAgeTypeKey: String (a RequestTypes key)
When the message is under the "alwaysArchiveAfterSeconds", treat matching messages as if they were of the specified type.
The RequestTypes is specified as the type's key.
userIdMatch: userId (Number)
Match if the message was posted by the specified userId.
*/
const RequestTypes = {
DELETE: {
name: 'Delete',
primary: true,
regexes: deleteRegexes,
alwaysArchiveAfterSeconds: 7 * SECONDS_IN_DAY, //7 days
},
REOPEN: {
name: 'Reopen',
primary: true,
regexes: reopenRegexes,
onlyQuestions: true,
alwaysArchiveAfterSeconds: 3 * SECONDS_IN_DAY, //3 days
},
CLOSE: {
name: 'Close',
primary: true,
regexes: cvRegexes,
onlyQuestions: true,
alwaysArchiveAfterSeconds: 3 * SECONDS_IN_DAY, //3 days
},
UNDELETE: {
name: 'Undelete',
primary: true,
regexes: undeleteRegexes,
alwaysArchiveAfterSeconds: 7 * SECONDS_IN_DAY, //7 days
},
FLAG_SPAM_OFFENSIVE: {
name: 'Flag, Spam and Offensive',
primary: true,
regexes: flagRegexes.concat(spamRegexes, offensiveRegexes),
//"spam" and "offensive" are too generic. We need to require that they are actually in tags.
andRegexes: flagAsTagRegexes.concat(spamAsTagRegexes, offensiveAsTagRegexes),
alwaysArchiveAfterSeconds: 2 * SECONDS_IN_HOUR, //2 hours
underAgeTypeKey: 'DELETE',
},
APPROVE_REJECT: {
name: 'Approve/Reject',
primary: true,
regexes: approveRejectRegexes,
alwaysArchiveAfterSeconds: 2 * SECONDS_IN_HOUR, //2 hours
//This really should have a separate call to the SE API to get review information, where possible.
underAgeTypeKey: 'DELETE',
},
QUEEN_SOCVFINDER: {//QUEEN: SOCVFinder
name: 'Queen: SOCVFinder',
regexes: duplicateRegexes,
alwaysArchiveAfterSeconds: 3 * SECONDS_IN_DAY, //3 days
underAgeTypeKey: 'CLOSE',
},
FIREALARM: {
name: 'FireAlarm',
regexes: faRegexes,
userIdMatch: knownUserIds.fireAlarm,
alwaysArchiveAfterSeconds: 30 * SECONDS_IN_MINUTE, //30 minutes
underAgeTypeKey: 'CLOSE',
archiveParentWithThis: true,
},
QUEEN_HEAT: {
name: 'Queen: HeatDetector',
alwaysArchiveAfterSeconds: 30 * SECONDS_IN_MINUTE, //30 minutes
userIdMatch: knownUserIds.queen,
regexes: [
/Heat Detector/,
],
underAgeTypeKey: 'DELETE',
onlyComments: true,
},
EDITMONITOR: {// Monitors edits in the suggested edit queue
name: 'Edit Monitor reports',
userIdMatch: knownUserIds.fox9000,
regexes: [editMonitorRegEx],
alwaysArchiveAfterSeconds: 2 * SECONDS_IN_HOUR, //2 hours
//This really should have a separate call to the SE API to get review information, where possible.
underAgeTypeKey: 'DELETE',
},
YAM: {// Monitors cv-pls requests for edits above a threshold.
name: 'Yam requested question change reports',
userIdMatch: knownUserIds.yam,
textRegexes: [/\d+%\s*changed\b/i],
alwaysArchiveAfterSeconds: 4 * SECONDS_IN_HOUR, //4 hours
},
SMOKEDETECTOR: {
name: 'SmokeDetector',
userIdMatch: knownUserIds.smokeDetector,
alwaysArchiveAfterSeconds: 4 * SECONDS_IN_HOUR, //4 hours
underAgeTypeKey: 'DELETE',
textRegexes: [
/\[\s*SmokeDetector\s*[|\]]/,
],
additionalRequestCompleteTests: [
// Take advantage of AIM, if installed, to get number of FP feedbacks.
function(event) {
//Expires SD reports with >= 1 false positive feedbacks.
return $('#message-' + event.message_id + ' > .ai-information .ai-feedback-info-fp').first().text() >= 1;
},
//Relies on AIM.
function(event) {
//Expires SD reports marked with the ai-deleted class (i.e. AIM thinks it's deleted).
return !!$('#message-' + event.message_id + ' > .content.ai-deleted').length;
},
//Relies on both AIM and an updated version of the Unclosed Request Review Script
function(event) {
//Expires SD reports with >= 1 tp- feedbacks that have been edited since the message was posted.
// e.g. a vandalism report that has been reverted.
const message = $('#message-' + event.message_id).first();
//Relies on an updated version of the Unclosed Request Generator
const requestInfo = $('.request-info a', message).first();
const aimHoverTpu = $('.meta .ai-information .ai-feedback-info-tpu', message);
if (!requestInfo.length || !aimHoverTpu.length) {
return false;
}
let lastEditDate = requestInfo[0].dataset.lastEditDate;
lastEditDate = lastEditDate ? +lastEditDate : 0;
const aimHoverTpuText = aimHoverTpu.text();
const aimHoverTpuTitle = aimHoverTpu.attr('title');
if (lastEditDate > event.time_stamp && aimHoverTpuText >= 1 && /^tp-?:/.test(aimHoverTpuTitle)) {
return true;
} // else
return false;
},
//NAA feedback is currently not considered, due to the MS API not raising NAA flags. Once FIRE does
// do so through the SE API, it'd be reasonable to expire them if the current user has sent such
// feedback through FIRE (implies that FIRE needs to indicate that).
],
},
SMOKEDETECTOR_NOCONTENT: {
name: 'SmokeDetector no content',
userIdMatch: knownUserIds.smokeDetector,
alwaysArchiveAfterSeconds: 0.01, //Always archive
noContent: true,
},
SMOKEDETECTOR_REPLYING: {
name: 'SmokeDetector replying',
userIdMatch: knownUserIds.smokeDetector,
alwaysArchiveAfterSeconds: 4 * SECONDS_IN_HOUR, //4 hours
replyToTypeKeys: [
'SMOKEDETECTOR_FEEDBACK',
'SMOKEDETECTOR_COMMAND',
],
archiveWithParent: true,
},
SMOKEDETECTOR_FEEDBACK: {
name: 'SmokeDetector feedback',
regexes: [sdFeedbacksRegEx],
alwaysArchiveAfterSeconds: 4 * SECONDS_IN_HOUR, //4 hours
archiveWithParent: true,
archiveWithPreviousFromUserId: knownUserIds.smokeDetector,
},
SMOKEDETECTOR_COMMAND: {
name: 'SmokeDetector commands',
regexes: [sdBangBangCommandsRegEx],
alwaysArchiveAfterSeconds: 4 * SECONDS_IN_HOUR, //4 hours
archiveWithNextFromUserId: knownUserIds.smokeDetector,
archiveWithChildren: true,
underAgeTypeKey: 'DELETE',
},
SMOKEDETECTOR_REPLY_TO_REPORT: {
name: 'SmokeDetector reply to report',
replyToTypeKeys: [
'SMOKEDETECTOR_NOCONTENT',
'SMOKEDETECTOR',
],
archiveWithParent: true,
},
PANTA_SMOKEDETECTOR_FEEDBACK_TRAINING: {
name: 'Panta SmokeDetector Training feedback',
userIdMatch: knownUserIds.panta,
regexes: [
//Regex modified from sdFeedbacksRegEx (above)
/^(?:\s*\d*(?:(?:k|v|n|naa|fp?|tp?|spam|rude|abus(?:iv)?e|offensive|v|vand|vandalism|notspam|true|false|ignore|del|delete|remove|gone|postgone|why))?u?-?)\s*(?:\s+\d*(?:(?:k|v|n|naa|fp?|tp?|spam|rude|abus(?:iv)?e|offensive|v|vand|vandalism|notspam|true|false|ignore|del|delete|remove|gone|postgone|why))?u?-?)*\s*$/i,
],
alwaysArchiveAfterSeconds: 4 * SECONDS_IN_HOUR, //4 hours
archiveWithParent: true,
archiveWithPreviousFromUserId: knownUserIds.smokeDetector,
},
CRUDE_CLOSE: {
name: 'CRUDE Close',
regexes: crudeCloseRegexes,
onlyQuestions: true,
alwaysArchiveAfterSeconds: 3 * SECONDS_IN_DAY, //3 days
underAgeTypeKey: 'CLOSE',
},
CRUDE_CLOSE_CN: {
name: 'CRUDE Close CN',
regexes: crudeCloseCnRegexes,
onlyQuestions: true,
alwaysArchiveAfterSeconds: 3 * SECONDS_IN_DAY, //3 days
underAgeTypeKey: 'CLOSE',
},
CRUDE_REOPEN: {
name: 'CRUDE Reopen',
regexes: crudeReopenRegexes,
onlyQuestions: true,
alwaysArchiveAfterSeconds: 3 * SECONDS_IN_DAY, //3 days
underAgeTypeKey: 'REOPEN',
},
CRUDE_REOPEN_RN: {
name: 'CRUDE Reopen RN',
regexes: crudeReopenRnRegexes,
onlyQuestions: true,
alwaysArchiveAfterSeconds: 3 * SECONDS_IN_DAY, //3 days
underAgeTypeKey: 'REOPEN',
},
CRUDE_DELETE: {
name: 'CRUDE Delete',
regexes: crudeDeleteRegexes,
alwaysArchiveAfterSeconds: 7 * SECONDS_IN_DAY, //7 days
underAgeTypeKey: 'DELETE',
},
CRUDE_DELETE_DN: {
name: 'CRUDE Delete DN',
regexes: crudeDeleteDnRegexes,
alwaysArchiveAfterSeconds: 7 * SECONDS_IN_DAY, //7 days
underAgeTypeKey: 'DELETE',
},
CRUDE_UNDELETE: {
name: 'CRUDE Undelete',
regexes: crudeUndeleteRegexes,
alwaysArchiveAfterSeconds: 7 * SECONDS_IN_DAY, //7 days
underAgeTypeKey: 'UNDELETE',
},
CRUDE_UNDELETE_UN: {
name: 'CRUDE Undelete UN',
regexes: crudeUndeleteUnRegexes,
alwaysArchiveAfterSeconds: 7 * SECONDS_IN_DAY, //7 days
underAgeTypeKey: 'UNDELETE',
},
};
//If the targetRoomSet has a includedRequestTypes list, limit the RequestTypes to that list.
if (Array.isArray(targetRoomSet.includedRequestTypes)) {
const includeList = targetRoomSet.includedRequestTypes;
Object.keys(RequestTypes).forEach((typeKey) => {
if (includeList.indexOf(typeKey) === -1 && !(targetRoomSet.useCrudeRequestTypes && typeKey.indexOf('CRUDE_') === 0)) {
//Keep it if it's in the include list, or using CRUDE RequestTypes and it is one.
delete RequestTypes[typeKey];
}
});
}
if (targetRoomSet.useCrudeRequestTypes === false) {
Object.keys(RequestTypes).forEach((typeKey) => {
if (typeKey.indexOf('CRUDE_') === 0) {
//If not using CRUDE RequestTypes and this one of them, then delete it.
delete RequestTypes[typeKey];
}
});
}
//If the targetRoomSet has a excludedRequestTypes list, remove those from the RequestTypes.
if (Array.isArray(targetRoomSet.excludedRequestTypes)) {
targetRoomSet.excludedRequestTypes.forEach((typeKey) => delete RequestTypes[typeKey]);