Skip to content

Commit bc7eff8

Browse files
committed
Merge branch 'edge'
2 parents d695453 + 80c11b2 commit bc7eff8

36 files changed

+1653
-615
lines changed

src/Action/index.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Comment, Submission} from "snoowrap";
22
import {Logger} from "winston";
33
import {RuleResult} from "../Rule";
4-
import {SubredditResources} from "../Subreddit/SubredditResources";
4+
import {checkAuthorFilter, SubredditResources} from "../Subreddit/SubredditResources";
55
import {ActionProcessResult, ActionResult, ChecksActivityState, TypedActivityStates} from "../Common/interfaces";
66
import Author, {AuthorOptions} from "../Author/Author";
77
import {mergeArr} from "../util";
@@ -28,6 +28,7 @@ export abstract class Action {
2828
subredditName,
2929
dryRun = false,
3030
authorIs: {
31+
excludeCondition = 'OR',
3132
include = [],
3233
exclude = [],
3334
} = {},
@@ -42,6 +43,7 @@ export abstract class Action {
4243
this.logger = logger.child({labels: [`Action ${this.getActionUniqueName()}`]}, mergeArr);
4344

4445
this.authorIs = {
46+
excludeCondition,
4547
exclude: exclude.map(x => new Author(x)),
4648
include: include.map(x => new Author(x)),
4749
}
@@ -72,27 +74,10 @@ export abstract class Action {
7274
actRes.runReason = `Activity did not pass 'itemIs' test, Action not run`;
7375
return actRes;
7476
}
75-
if (this.authorIs.include !== undefined && this.authorIs.include.length > 0) {
76-
for (const auth of this.authorIs.include) {
77-
if (await this.resources.testAuthorCriteria(item, auth)) {
78-
actRes.run = true;
79-
const results = await this.process(item, ruleResults, runtimeDryrun);
80-
return {...actRes, ...results};
81-
}
82-
}
83-
this.logger.verbose('Inclusive author criteria not matched, Action not run');
84-
actRes.runReason = 'Inclusive author criteria not matched';
85-
return actRes;
86-
} else if (this.authorIs.exclude !== undefined && this.authorIs.exclude.length > 0) {
87-
for (const auth of this.authorIs.exclude) {
88-
if (await this.resources.testAuthorCriteria(item, auth, false)) {
89-
actRes.run = true;
90-
const results = await this.process(item, ruleResults, runtimeDryrun);
91-
return {...actRes, ...results};
92-
}
93-
}
94-
this.logger.verbose('Exclusive author criteria not matched, Action not run');
95-
actRes.runReason = 'Exclusive author criteria not matched';
77+
const [authFilterResult, authFilterType] = await checkAuthorFilter(item, this.authorIs, this.resources, this.logger);
78+
if(!authFilterResult) {
79+
this.logger.verbose(`${authFilterType} author criteria not matched, Action not run`);
80+
actRes.runReason = `${authFilterType} author criteria not matched`;
9681
return actRes;
9782
}
9883

src/Author/Author.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {UserNoteCriteria} from "../Rule";
2-
import {CompareValue, CompareValueOrPercent, DurationComparor} from "../Common/interfaces";
2+
import {CompareValue, CompareValueOrPercent, DurationComparor, JoinOperands} from "../Common/interfaces";
33
import {parseStringToRegex} from "../util";
44

55
/**
@@ -12,7 +12,17 @@ export interface AuthorOptions {
1212
* */
1313
include?: AuthorCriteria[];
1414
/**
15-
* Only runs if `include` is not present. Will "pass" if any of set of the AuthorCriteria **does not** pass
15+
* * OR => if ANY exclude condition "does not" pass then the exclude test passes
16+
* * AND => if ALL exclude conditions "do not" pass then the exclude test passes
17+
*
18+
* Defaults to OR
19+
* @default OR
20+
* */
21+
excludeCondition?: JoinOperands
22+
/**
23+
* Only runs if `include` is not present. Each AuthorCriteria is comprised of conditions that the Author being checked must "not" pass. See excludeCondition for set behavior
24+
*
25+
* EX: `isMod: true, name: Automoderator` => Will pass if the Author IS NOT a mod and IS NOT named Automoderator
1626
* */
1727
exclude?: AuthorCriteria[];
1828
}

0 commit comments

Comments
 (0)