@fsvreddit/bot-bouncer-evaluation 0.7.42 → 0.7.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,11 @@ class EvaluateBadDisplayName extends UserEvaluatorBase_js_1.UserEvaluatorBase {
15
15
  this.banContentThreshold = 0;
16
16
  }
17
17
  getBadDisplayNameRegexes() {
18
- this.badDisplayNameRegexes ?? (this.badDisplayNameRegexes = this.getVariable("regexes", []));
18
+ if (this.badDisplayNameRegexes === undefined) {
19
+ const bannableDisplayNameRegexes = this.getVariable("regexes", []);
20
+ const ignoredDisplayNameRegexes = this.getVariable("ignoredRegexes", []);
21
+ this.badDisplayNameRegexes = bannableDisplayNameRegexes.filter(regex => !ignoredDisplayNameRegexes.includes(regex));
22
+ }
19
23
  return this.badDisplayNameRegexes;
20
24
  }
21
25
  isBadDisplayName(displayName) {
@@ -14,7 +14,11 @@ class EvaluateBioText extends UserEvaluatorBase_js_1.UserEvaluatorBase {
14
14
  this.banContentThreshold = 0;
15
15
  }
16
16
  getBioText() {
17
- this.bioText ?? (this.bioText = this.getVariable("bantext", []));
17
+ if (this.bioText === undefined) {
18
+ const bannableBioText = this.getVariable("bantext", []);
19
+ const ignoredBanText = this.getVariable("ignoredBanText", []);
20
+ this.bioText = bannableBioText.filter(bioText => !ignoredBanText.includes(bioText));
21
+ }
18
22
  return this.bioText;
19
23
  }
20
24
  validateVariables() {
@@ -79,24 +83,7 @@ class EvaluateBioText extends UserEvaluatorBase_js_1.UserEvaluatorBase {
79
83
  return this.getCompiledRegexes().some(regex => user.userDescription && regex.test(user.userDescription));
80
84
  }
81
85
  evaluate(user) {
82
- let matchedRegex;
83
- if (this.verboseLogging) {
84
- matchedRegex = this.getCompiledRegexes().find((regex) => {
85
- if (!user.userDescription) {
86
- return false;
87
- }
88
- const start = Date.now();
89
- const result = regex.test(user.userDescription);
90
- const end = Date.now();
91
- if (end - start > this.regexWarnThreshold) {
92
- console.log(`${this.name}: Regex took ${end - start}ms for regex: ${regex.source}`);
93
- }
94
- return result;
95
- });
96
- }
97
- else {
98
- matchedRegex = this.getCompiledRegexes().find(regex => user.userDescription && regex.test(user.userDescription));
99
- }
86
+ const matchedRegex = this.getCompiledRegexes().find(regex => user.userDescription && regex.test(user.userDescription));
100
87
  if (matchedRegex) {
101
88
  this.canAutoBan = true;
102
89
  this.addHitReason(`Bio text matched regex: ${(0, markdown_escape_1.default)(matchedRegex.source)}`);
@@ -479,20 +479,7 @@ class EvaluateBotGroupAdvanced extends UserEvaluatorBase_js_1.UserEvaluatorBase
479
479
  return compiledRegex;
480
480
  }
481
481
  anyRegexMatches(input, regexes) {
482
- if (this.verboseLogging) {
483
- return regexes.some((regex) => {
484
- const start = Date.now();
485
- const result = this.getCompiledRegex(regex).test(input);
486
- const end = Date.now();
487
- if (end - start > this.regexWarnThreshold) {
488
- console.warn(`Evaluation: Regex took ${end - start}ms: ${regex}`);
489
- }
490
- return result;
491
- });
492
- }
493
- else {
494
- return regexes.some(regex => this.getCompiledRegex(regex).test(input));
495
- }
482
+ return regexes.some(regex => this.getCompiledRegex(regex).test(input));
496
483
  }
497
484
  getBotGroups() {
498
485
  const groups = this.getAllVariables("group");
@@ -767,9 +754,6 @@ class EvaluateBotGroupAdvanced extends UserEvaluatorBase_js_1.UserEvaluatorBase
767
754
  continue;
768
755
  }
769
756
  if (!group.criteria) {
770
- if (this.verboseLogging) {
771
- console.log(`Pre-evaluation: Comment ${comment.comment.id} for ${comment.author.name} matches bot group with no criteria ${group.name}`);
772
- }
773
757
  return true;
774
758
  }
775
759
  ;
@@ -46,7 +46,8 @@ class EvaluatePostTitle extends UserEvaluatorBase_js_1.UserEvaluatorBase {
46
46
  return false;
47
47
  }
48
48
  getTitles() {
49
- return this.getVariable("bantext", []);
49
+ const prefixesToIgnore = this.getVariable("ignoredRegexPrefixes", []);
50
+ return this.getVariable("bantext", []).filter(title => !prefixesToIgnore.some(prefix => title.startsWith(prefix)));
50
51
  }
51
52
  getTitleRegexes() {
52
53
  this.titleRegexes ?? (this.titleRegexes = this.getTitles().map(title => new RegExp(title, "u")));
@@ -78,21 +79,7 @@ class EvaluatePostTitle extends UserEvaluatorBase_js_1.UserEvaluatorBase {
78
79
  if (nonMatchingTitles.has(title)) {
79
80
  continue;
80
81
  }
81
- let matchedBanRegex;
82
- if (this.verboseLogging) {
83
- matchedBanRegex = regexes.find((regex) => {
84
- const start = Date.now();
85
- const result = regex.test(title);
86
- const end = Date.now();
87
- if (end - start > this.regexWarnThreshold) {
88
- console.warn(`Evaluation: Regex took ${end - start}ms: ${regex.source}`);
89
- }
90
- return result;
91
- });
92
- }
93
- else {
94
- matchedBanRegex = regexes.find(regex => regex.test(title));
95
- }
82
+ const matchedBanRegex = regexes.find(regex => regex.test(title));
96
83
  if (!matchedBanRegex) {
97
84
  nonMatchingTitles.add(title);
98
85
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fsvreddit/bot-bouncer-evaluation",
3
- "version": "0.7.42",
3
+ "version": "0.7.44",
4
4
  "description": "Evaluation code for Bot Bouncer, a Dev Platform app designed to hunt bots on Reddit",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {