Compare commits
48 Commits
redisCache
...
0.12.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
296f1c8dee | ||
|
|
e32ac60db5 | ||
|
|
859680dca8 | ||
|
|
ffa1e423b2 | ||
|
|
09cb08492c | ||
|
|
d9ab81ab8c | ||
|
|
98691bd19c | ||
|
|
8123c34463 | ||
|
|
3292d011fa | ||
|
|
661a0ae440 | ||
|
|
05f477b67d | ||
|
|
1317a5916c | ||
|
|
e9135ec1ef | ||
|
|
e58a0f8f21 | ||
|
|
f7cebc013b | ||
|
|
ae8e11feb4 | ||
|
|
e07b8cc291 | ||
|
|
fc51928054 | ||
|
|
e2590e50f8 | ||
|
|
aaed0d3419 | ||
|
|
bc7eff8928 | ||
|
|
d6954533a0 | ||
|
|
ba53233640 | ||
|
|
1ac7ad4724 | ||
|
|
2a282a0d6f | ||
|
|
fd5a92758d | ||
|
|
39daa11f2d | ||
|
|
dac6541e28 | ||
|
|
97906281e6 | ||
|
|
487f13f704 | ||
|
|
631e21452c | ||
|
|
4f3685a1f5 | ||
|
|
d2d945db2c | ||
|
|
910f7f79ef | ||
|
|
a11b667d5e | ||
|
|
885e3fa765 | ||
|
|
465c3c9acf | ||
|
|
161251a943 | ||
|
|
ce4cb96d9a | ||
|
|
c317f95953 | ||
|
|
d0e0515990 | ||
|
|
cdddd8de48 | ||
|
|
f598215d88 | ||
|
|
0c7218571c | ||
|
|
acc7c49e0e | ||
|
|
01839512d5 | ||
|
|
4680640b0c | ||
|
|
b813ebdd96 |
1
.github/FUNDING.yml
vendored
@@ -1,3 +1,2 @@
|
||||
github: [FoxxMD]
|
||||
patreon: FoxxMD
|
||||
custom: ["bitcoincash:qqmpsh365r8n9jhp4p8ks7f7qdr7203cws4kmkmr8q"]
|
||||
|
||||
@@ -31,8 +31,6 @@ Feature Highlights for **Moderators:**
|
||||
* [**Web interface**](#web-ui-and-screenshots) for monitoring, administration, and oauth bot authentication
|
||||
* [**Placeholders**](/docs/subreddit/actionTemplating.md) (like automoderator) can be configured via a wiki page or raw text and supports [mustache](https://mustache.github.io) templating
|
||||
* [**Partial Configurations**](/docs/subreddit/components/README.md#partial-configurations) -- offload parts of your configuration to shared locations to consolidate logic between multiple subreddits
|
||||
* [Guest Access](/docs/subreddit/README.md#guest-access) enables collaboration and easier setup by allowing temporary access
|
||||
* [Toxic content prediction](/docs/subreddit/components/README.md#moderatehatespeechcom-predictions) using [moderatehatespeech.com](https://moderatehatespeech.com) machine learning model
|
||||
|
||||
Feature highlights for **Developers and Hosting (Operators):**
|
||||
|
||||
@@ -136,10 +134,6 @@ Moderator view/invite and authorization:
|
||||
|
||||

|
||||
|
||||
A similar helper and invitation experience is available for adding **subreddits to an existing bot.**
|
||||
|
||||

|
||||
|
||||
### Configuration Editor
|
||||
|
||||
A built-in editor using [monaco-editor](https://microsoft.github.io/monaco-editor/) makes editing configurations easy:
|
||||
|
||||
@@ -152,7 +152,6 @@ An **Action** is some action the bot can take against the checked Activity (comm
|
||||
|
||||
* For **Operator/Bot maintainers** see **[Operation Guide](/docs/operator/README.md)**
|
||||
* For **Moderators**
|
||||
* Start with the [Subreddit/Moderator docs](/docs/subreddit/README.md) or [Moderator Getting Started guide](/docs/subreddit/gettingStarted.md)
|
||||
* Refer to the [Subreddit Components Documentation](/docs/subreddit/components) or the [subreddit-ready examples](/docs/subreddit/components/subredditReady)
|
||||
* as well as the [schema](https://json-schema.app/view/%23?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Fcontext-mod%2Fmaster%2Fsrc%2FSchema%2FApp.json) which has
|
||||
* fully annotated configuration data/structure
|
||||
|
||||
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 125 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 137 KiB After Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 226 KiB |
|
Before Width: | Height: | Size: 141 KiB |
|
Before Width: | Height: | Size: 225 KiB After Width: | Height: | Size: 479 KiB |
@@ -1,95 +0,0 @@
|
||||
This section is for **reddit moderators**. It covers how to use a CM bot for your subreddit.
|
||||
|
||||
If you are trying to run a ContextMod instance (the actual software) please refer to the [operator section](/docs/operator/README.md).
|
||||
|
||||
# Table of Contents
|
||||
|
||||
* [Overview](#overview)
|
||||
* [Your Relationship to CM](#your-relationship-to-cm)
|
||||
* [Operator](#operator)
|
||||
* [Your Bot](#your-bot)
|
||||
* [Getting Started](#getting-started)
|
||||
* [Accessing The Bot](#accessing-the-bot)
|
||||
* [Editing The Bot](#editing-the-bot)
|
||||
* [Configuration](#configuration)
|
||||
* [Guest Access](#guest-access)
|
||||
|
||||
# Overview
|
||||
|
||||
The Context Mod **software** can manage multiple **bots** (reddit accounts used as bots, like `/u/MyCMBot`). Each bot can manage (run) multiple **subreddits** which is determined by the subreddits the account is a moderator of.
|
||||
|
||||
You, the moderator of a subreddit a CM bot runs in, can access/manage the Bot using the CM software's [web interface](/docs/images/subredditStatus.jpg) and control its behavior using the [web editor.](/docs/images/editor.jpg)
|
||||
|
||||
## Your Relationship to CM
|
||||
|
||||
It is important to understand the relationship between you (the moderator), the bot, and the operator (the person running the CM software).
|
||||
|
||||
The easiest way to think about this is in relation to how you use Automoderator and interact with Reddit as a moderator. As an analogy:
|
||||
|
||||
### Operator
|
||||
|
||||
The operator is the person running the actual server/machine the Context Mod software is on.
|
||||
|
||||
They are best thought of as **Reddit:**
|
||||
|
||||
* Mostly hands-off when it comes to the bot and interacting with your subreddit
|
||||
* You must interact with Reddit first before you can use automoderator (login, create a subreddit, etc...)
|
||||
|
||||
Unlike reddit, though, there is a greater level of trust required between you and the Operator because what you make the Bot do ultimately affects the Operator since they are the ones actually running your Bot and making API calls to reddit.
|
||||
|
||||
### Your Bot
|
||||
|
||||
Your bot is like an **invite-only version of Automoderator**:
|
||||
|
||||
* Unlike automoderator, you **must** interact with the Operator in order to get the bot working. It is not public for anyone to use.
|
||||
* Like automoderator, you **must** create a [configuration](/docs/subreddit/components/README.md) for it do anything.
|
||||
* The bot does not come pre-configured for you. It is a blank slate and requires user input to be useful.
|
||||
* Also like automoderator, you are **entirely in control of the bot.**
|
||||
* You can start, stop, and edit its behavior at any time without needing to communicate with the Operator.
|
||||
* CM provides you _tools_, different ways the Bot can detect patterns in your subreddit/users as well as actions it can, and you can decide to use them however you want.
|
||||
* Your bot is **only accessible to moderators of your subreddit.**
|
||||
|
||||
# Getting Started
|
||||
|
||||
The [Getting Started](/docs/subreddit/gettingStarted.md) guide lays out the steps needed to go from nothing to a working Bot. If you are a moderator new to Context Mod this is where you want to begin.
|
||||
|
||||
# Accessing The Bot
|
||||
|
||||
All bot management and editing is done through the [web interface.](/docs/images/subredditStatus.jpg) The URL used for accessing this interface is given to you by the **Operator** once they have agreed to host your bot/subreddit.
|
||||
|
||||
NOTE: This interface is **only access to moderators of your subreddit** and [guests.](#guest-access) You must login to the web interface **with your moderator account** in order to access it.
|
||||
|
||||
A **guided tour** that helps show how to manage the bot at a high-level is available on the web interface by clicking the **Help** button in the top-right of the page.
|
||||
|
||||
## Editing The Bot
|
||||
|
||||
Find the [editor in the web interface](/docs/webInterface.md#editingupdating-your-config) to access the built-in editor for the bot.
|
||||
|
||||
[The editor](/docs/images/editor.jpg) should be your all-in-one location for viewing and editing your bot's behavior. **It is equivalent to Automoderator's editor page.**
|
||||
|
||||
The editor features:
|
||||
|
||||
* syntax validation and highlighting
|
||||
* configuration auto-complete and documentation (hover over properties)
|
||||
* built-in validation using Microsoft Word "squiggly lines" indicators and an error list at the bottom of the window
|
||||
* built-in saving (at the top of the window)
|
||||
|
||||
# Configuration
|
||||
|
||||
Use the [Configuration Reference](/docs/subreddit/components/README.md) to learn about all the different components available for building a CM configuration.
|
||||
|
||||
Additionally, refer to [How It Works](/docs/README.md#how-it-works) and [Core Concepts](/docs/README.md#concepts) to learn the basic of CM configuration.
|
||||
|
||||
After you have the basics under your belt you could use the [subreddit-reddit example configurations](/docs/subreddit/components/subredditReady) to familiarize yourself with a complete configuration and ways to use CM.
|
||||
|
||||
# Guest Access
|
||||
|
||||
CM supports **Guest Access**. Reddit users who are given Guest Access to your bot are allowed to access the web interface even though they are not moderators.
|
||||
|
||||
Additionally, they can edit the subreddit's config using the bot. If a Guest edits your config their username will be mentioned in the wiki page edit reason.
|
||||
|
||||
Guests can do everything a regular mod can except view/add/remove Guest. They can be removed at any time or set with an expiration date that their access is removed on.
|
||||
|
||||
**Guests are helpful if you are new to CM and know reddit users that can help you get started.**
|
||||
|
||||
[Add guests from the Subreddit tab in the main interface.](/docs/images/guests.jpg)
|
||||
@@ -22,7 +22,6 @@ This list is not exhaustive. [For complete documentation on a subreddit's config
|
||||
* [Regex](#regex)
|
||||
* [Repost](#repost)
|
||||
* [Sentiment Analysis](#sentiment-analysis)
|
||||
* [Toxic Content Prediction](#moderatehatespeechcom-predictions)
|
||||
* [Rule Sets](#rule-sets)
|
||||
* [Actions](#actions)
|
||||
* [Named Actions](#named-actions)
|
||||
@@ -378,12 +377,6 @@ This rule is for searching **all of Reddit** for reposts, as opposed to just the
|
||||
|
||||
The **Sentiment Rule** is used to determine the overall emotional intent (negative, neutral, positive) of a Submission or Comment by analyzing the actual text content of the Activity.
|
||||
|
||||
### ModerateHateSpeech.com Predictions
|
||||
|
||||
[**Full Documentation**](/docs/subreddit/components/mhs)
|
||||
|
||||
ContextMod integrates with [moderatehatespeech.com](https://moderatehatespeech.com/) (MHS) [toxic content machine learning model](https://moderatehatespeech.com/framework/) through their API. This rule sends an Activity's content (title or body) to MHS which returns a prediction on whether the content is toxic and actionable by a moderator. Their model is [specifically trained for reddit content.](https://www.reddit.com/r/redditdev/comments/xdscbo/updated_bot_backed_by_moderationoriented_ml_for/)
|
||||
|
||||
# Rule Sets
|
||||
|
||||
The `rules` list on a `Check` can contain both `Rule` objects and `RuleSet` objects.
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
// if the nested rules pass the condition then the Rule Set triggers the Check
|
||||
//
|
||||
// AND = all nested rules must be triggered to make the Rule Set trigger
|
||||
// OR = any of the nested Rules will be the Rule Set trigger
|
||||
// AND = any of the nested Rules will be the Rule Set trigger
|
||||
"condition": "AND",
|
||||
// in this check we use an Attribution >10% on ONLY submissions, which is a lower requirement then the above attribution rule
|
||||
// and combine it with a History rule looking for low comment engagement
|
||||
|
||||
@@ -22,7 +22,7 @@ runs:
|
||||
# if the nested rules pass the condition then the Rule Set triggers the Check
|
||||
#
|
||||
# AND = all nested rules must be triggered to make the Rule Set trigger
|
||||
# OR = any of the nested Rules will be the Rule Set trigger
|
||||
# AND = any of the nested Rules will be the Rule Set trigger
|
||||
- condition: AND
|
||||
# in this check we use an Attribution >10% on ONLY submissions, which is a lower requirement then the above attribution rule
|
||||
# and combine it with a History rule looking for low comment engagement
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
// for this to pass the Author of the Submission must not have the flair "Supreme Memer" and have the name "user1" or "user2"
|
||||
{
|
||||
"flairText": ["Supreme Memer"],
|
||||
"names": ["user1","user2"]
|
||||
"name": ["user1","user2"]
|
||||
},
|
||||
{
|
||||
// for this to pass the Author of the Submission must not have the flair "Decent Memer"
|
||||
|
||||
@@ -30,7 +30,7 @@ runs:
|
||||
# for this to pass the Author of the Submission must not have the flair "Supreme Memer" and have the name "user1" or "user2"
|
||||
- flairText:
|
||||
- Supreme Memer
|
||||
names:
|
||||
name:
|
||||
- user1
|
||||
- user2
|
||||
# for this to pass the Author of the Submission must not have the flair "Decent Memer"
|
||||
|
||||
@@ -5,45 +5,9 @@ The **History** rule can check an Author's submission/comment statistics over a
|
||||
* Submission total or percentage of All Activity
|
||||
* Comment total or percentage of all Activity
|
||||
* Comments made as OP (commented in their own Submission) total or percentage of all Comments
|
||||
* Ratio of activities against another window of activities
|
||||
|
||||
Consult the [schema](https://json-schema.app/view/%23%2Fdefinitions%2FHistoryJSONConfig?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Fcontext-mod%2Fmaster%2Fsrc%2FSchema%2FApp.json) for a complete reference of the rule's properties.
|
||||
|
||||
## Ratio
|
||||
|
||||
Use the `ratio` property in Criteria to test the [number of activities](/docs/subreddit/activitiesWindow.md) found in the parent criteria against the number of activities from _another_ [activity window](/docs/subreddit/activitiesWindow.md) defined in the ratio.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
- kind: history
|
||||
criteria:
|
||||
# "parent" criteria, returns all activities, in the last 100 from user's history, that occurred in r/mealtimevideos
|
||||
- window:
|
||||
count: 100
|
||||
filterOn:
|
||||
post:
|
||||
subreddits:
|
||||
include:
|
||||
- mealtimevideos
|
||||
ratio:
|
||||
# "ratio" criteria, returns all activities, in the last 100 from user's history, that occurred in r/redditdev
|
||||
window:
|
||||
count: 100
|
||||
filterOn:
|
||||
post:
|
||||
subreddits:
|
||||
include:
|
||||
- redditdev
|
||||
# test (number of parent criteria activities) / (number of ratio critieria activities)
|
||||
threshold: '> 1.2'
|
||||
```
|
||||
|
||||
`threshold` may be a number or percentage `(number * 100)`
|
||||
|
||||
* EX `> 1.2` => There are 1.2 activities from parent criteria for every 1 ratio activities
|
||||
* EX `<= 75%` => There are equal to or less than 0.75 activities from parent criteria for every 1 ratio activities
|
||||
|
||||
### Examples
|
||||
|
||||
* Low Comment Engagement [YAML](/docs/subreddit/componentscomponents/history/lowEngagement.yaml) | [JSON](/docs/subreddit/componentscomponents/history/lowEngagement.json5) - Check if Author is submitting much more than they comment.
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
# Table of Contents
|
||||
|
||||
* [Overview](#overview)
|
||||
* [MHS Predictions](#mhs-predictions)
|
||||
* [Flagged](#flagged)
|
||||
* [Confidence](#confidence)
|
||||
* [Usage](#usage)
|
||||
* [Minimal/Default Config](#minimaldefault-config)
|
||||
* [Full Config](#full-config)
|
||||
* [Historical Matching](#historical-matching)
|
||||
* [Examples](#examples)
|
||||
|
||||
# Overview
|
||||
|
||||
[moderatehatespeech.com](https://moderatehatespeech.com/) (MHS) is a [non-profit initiative](https://moderatehatespeech.com/about/) to identify and fight toxic and hateful content online using programmatic technology such as machine learning models.
|
||||
|
||||
They offer a [toxic content prediction model](https://moderatehatespeech.com/framework/) specifically trained on and for [reddit content](https://www.reddit.com/r/redditdev/comments/xdscbo/updated_bot_backed_by_moderationoriented_ml_for/) as well as partnering [directly with subreddits.](https://moderatehatespeech.com/research/subreddit-program/).
|
||||
|
||||
Context Mod leverages their [API](https://moderatehatespeech.com/docs/) for toxic content predictions in the **MHS Rule.**
|
||||
|
||||
The **MHS Rule** sends an Activity's content (title or body) to MHS which returns a prediction on whether the content is toxic and actionable by a moderator.
|
||||
|
||||
## MHS Predictions
|
||||
|
||||
MHS's toxic content predictions return two indicators about the content it analyzed. Both are available as test conditions in ContextMod.
|
||||
|
||||
### Flagged
|
||||
|
||||
MHS returns a straight "Toxic or Normal" **flag** based on how it classifies the content.
|
||||
|
||||
Example
|
||||
|
||||
* `Normal` - "I love those pineapples"
|
||||
* `Toxic` - "why are we having all these people from shithole countries coming here"
|
||||
|
||||
### Confidence
|
||||
|
||||
MHS returns how **confident** it is of the flag classification on a scale of 0 to 100.
|
||||
|
||||
Example
|
||||
|
||||
"why are we having all these people from shithole countries coming here"
|
||||
|
||||
* Flag = `Toxic`
|
||||
* Confidence = `97.12` -> The model is 97% confident the content is `Toxic`
|
||||
|
||||
# Usage
|
||||
|
||||
**An MHS Api Key is required to use this Rule**. An API Key can be acquired, for free, by creating an account at [moderatehatespeech.com](https://moderatehatespeech.com).
|
||||
|
||||
The Key can be provided by the bot's Operator in the [bot config credentials](https://json-schema.app/view/%23/%23%2Fdefinitions%2FBotInstanceJsonConfig/%23%2Fdefinitions%2FBotCredentialsJsonConfig?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Fcontext-mod%2Fedge%2Fsrc%2FSchema%2FOperatorConfig.json) or in the subreddit's config in the top-level `credentials` property like this:
|
||||
|
||||
```yaml
|
||||
credentials:
|
||||
mhs:
|
||||
apiKey: 'myMHSApiKey'
|
||||
|
||||
# the rest of your config below
|
||||
polling:
|
||||
# ...
|
||||
runs:
|
||||
# ...
|
||||
```
|
||||
|
||||
### Minimal/Default Config
|
||||
|
||||
ContextMod provides a reasonable default configuration for the MHS Rule if you do not wish to configure it yourself. The default configuration will trigger the rule if the MHS prediction:
|
||||
|
||||
* flags as `toxic`
|
||||
* with `90% or greater` confidence
|
||||
|
||||
Example
|
||||
|
||||
```yaml
|
||||
rules:
|
||||
- kind: mhs
|
||||
|
||||
# rest of your rules here...
|
||||
```
|
||||
|
||||
### Full Config
|
||||
|
||||
|
||||
| Property | Type | Description | Default |
|
||||
|--------------|---------|-------------------------------------------------------------------------------------------|---------|
|
||||
| `flagged` | boolean | Test whether content is flagged as toxic (true) or normal (false) | `true` |
|
||||
| `confidence` | string | Comparison against a number 0 to 100 representing how confident MHS is in the prediction | `>= 90` |
|
||||
| `testOn` | array | Which parts of the Activity to send to MHS. Options: `title` and/or `body` | `body` |
|
||||
|
||||
Example
|
||||
|
||||
```yaml
|
||||
rules:
|
||||
- kind: mhs
|
||||
criteria:
|
||||
flagged: true # triggers if MHs flags the content as toxic AND
|
||||
confidence: '> 66' # MHS is 66% or more confident in its prediction
|
||||
testOn: # send the body of the activity to the MHS prediction service
|
||||
- body
|
||||
```
|
||||
|
||||
#### Historical Matching
|
||||
|
||||
Like the [Sentiment](/docs/subreddit/components/sentiment#historical) and [Regex](/docs/subreddit/components/regex#historical) rules CM can also use MHS predictions to check content from the Author's history.
|
||||
|
||||
Example
|
||||
|
||||
```yaml
|
||||
rules:
|
||||
- kind: mhs
|
||||
# ...same config as above but can include below...
|
||||
historical:
|
||||
mustMatchCurrent: true # if true then CM will not check author's history unless current Activity matches MHS prediction criteria
|
||||
totalMatching: '> 1' # comparison for how many activities in history must match to trigger the rule
|
||||
window: 10 # specify the range of activities to check in author's history
|
||||
criteria: #... if specified, overrides parent-level criteria
|
||||
```
|
||||
|
||||
# Examples
|
||||
|
||||
Report if MHS flags as toxic
|
||||
|
||||
```yaml
|
||||
rules:
|
||||
- kind: mhs
|
||||
actions:
|
||||
- kind: report
|
||||
content: 'MHS flagged => {{rules.mhs.summary}}'
|
||||
```
|
||||
|
||||
Report if MHS flags as toxic with 95% confidence
|
||||
|
||||
```yaml
|
||||
rules:
|
||||
- kind: mhs
|
||||
confidence: '>= 95'
|
||||
actions:
|
||||
- kind: report
|
||||
content: 'MHS flagged => {{rules.mhs.summary}}'
|
||||
```
|
||||
|
||||
Report if MHS flags as toxic and at least 3 recent activities in last 10 from author's history are also toxic
|
||||
|
||||
```yaml
|
||||
rules:
|
||||
- kind: mhs
|
||||
historical:
|
||||
window: 10
|
||||
mustMatchCurrent: true
|
||||
totalMatching: '>= 3'
|
||||
actions:
|
||||
- kind: report
|
||||
content: 'MHS flagged => {{rules.mhs.summary}}'
|
||||
```
|
||||
|
||||
Approve if MHS flags as NOT toxic with 95% confidence
|
||||
|
||||
```yaml
|
||||
rules:
|
||||
- kind: mhs
|
||||
confidence: '>= 95'
|
||||
flagged: false
|
||||
actions:
|
||||
- kind: approve
|
||||
```
|
||||
@@ -43,7 +43,7 @@
|
||||
// remove this after confirming behavior is acceptable
|
||||
{
|
||||
"kind": "report",
|
||||
"content": "Remove=> {{rules.freekarma.totalCount}} activities in freekarma subs"
|
||||
"content": "Remove=> {{rules.newtube.totalCount}} activities in freekarma subs"
|
||||
},
|
||||
//
|
||||
//
|
||||
|
||||
@@ -25,7 +25,7 @@ runs:
|
||||
actions:
|
||||
- kind: report
|
||||
enable: true
|
||||
content: 'Remove=> {{rules.freekarma.totalCount}} activities in freekarma subs'
|
||||
content: 'Remove=> {{rules.newtube.totalCount}} activities in freekarma subs'
|
||||
- kind: remove
|
||||
enable: true
|
||||
- kind: comment
|
||||
|
||||
344
package-lock.json
generated
@@ -11,10 +11,9 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@awaitjs/express": "^0.8.0",
|
||||
"@datasert/cronjs-matcher": "^1.2.0",
|
||||
"@googleapis/youtube": "^2.0.0",
|
||||
"@influxdata/influxdb-client": "^1.31.0",
|
||||
"@influxdata/influxdb-client-apis": "^1.31.0",
|
||||
"@influxdata/influxdb-client": "^1.27.0",
|
||||
"@influxdata/influxdb-client-apis": "^1.27.0",
|
||||
"@nlpjs/core": "^4.23.4",
|
||||
"@nlpjs/lang-de": "^4.23.4",
|
||||
"@nlpjs/lang-en": "^4.23.4",
|
||||
@@ -29,7 +28,7 @@
|
||||
"autolinker": "^3.14.3",
|
||||
"body-parser": "^1.19.0",
|
||||
"cache-manager": "^3.4.4",
|
||||
"cache-manager-redis-store": "^3.0.1",
|
||||
"cache-manager-redis-store": "^2.0.0",
|
||||
"commander": "^8.0.0",
|
||||
"comment-json": "^4.1.1",
|
||||
"connect-typeorm": "^2.0.0",
|
||||
@@ -95,6 +94,7 @@
|
||||
"@tsconfig/node14": "^1.0.0",
|
||||
"@types/async": "^3.2.7",
|
||||
"@types/cache-manager": "^3.4.2",
|
||||
"@types/cache-manager-redis-store": "^2.0.0",
|
||||
"@types/chai": "^4.3.0",
|
||||
"@types/chai-as-promised": "^7.1.5",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
@@ -137,7 +137,7 @@
|
||||
"typescript-json-schema": "~0.53"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.18.0"
|
||||
"node": ">=16"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"better-sqlite3": "^7.5.0",
|
||||
@@ -656,20 +656,6 @@
|
||||
"kuler": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@datasert/cronjs-matcher": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@datasert/cronjs-matcher/-/cronjs-matcher-1.2.0.tgz",
|
||||
"integrity": "sha512-ht6Vwwa3qssMn/9bphypjG/U8w0DV3GtTS2C6kbAy39rerQFTRzmml9xZNlot1K13gm9K/EEq3DLPEOsH++ICw==",
|
||||
"dependencies": {
|
||||
"@datasert/cronjs-parser": "^1.2.0",
|
||||
"luxon": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@datasert/cronjs-parser": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@datasert/cronjs-parser/-/cronjs-parser-1.2.0.tgz",
|
||||
"integrity": "sha512-7kzYh7F5V3ElX+k3W9w6SKS6WdjqJQ2gIY1y0evldnjAwZxnFzR/Yu9Mv9OeDaCQX+mGAq2MvEnJbwu9oj3CXQ=="
|
||||
},
|
||||
"node_modules/@googleapis/youtube": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@googleapis/youtube/-/youtube-2.0.0.tgz",
|
||||
@@ -682,14 +668,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@influxdata/influxdb-client": {
|
||||
"version": "1.31.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.31.0.tgz",
|
||||
"integrity": "sha512-8DVT3ZB/VeCK5Nn+BxhgMrAMSTseQAEgV20AK+ZMO5Fcup9XWsA9L2zE+3eBFl0Y+lF3UeKiASkiKMQvws35GA=="
|
||||
"version": "1.27.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.27.0.tgz",
|
||||
"integrity": "sha512-hOBi+ApIurDd8jFWo+eYjMWWsDRp3wih/U/NOVRoHaTOE8ihSQthi9wfMD4YeVqt4pCN6ygIwo7lEKFXwNuwcA=="
|
||||
},
|
||||
"node_modules/@influxdata/influxdb-client-apis": {
|
||||
"version": "1.31.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.31.0.tgz",
|
||||
"integrity": "sha512-6ALGNLxtfffhICobOdj13Z6vj6gdQVOzVXPoPNd+w7V60zrbGhTqzXHV1KMZ/lzOb6YkRTRODbxz4W/b/7N5hg==",
|
||||
"version": "1.27.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.27.0.tgz",
|
||||
"integrity": "sha512-a4gd7CwNRXSsSVt9tm8GzGxuPXngEmQucMdoTZ0YYeWSbKUXz3B/3u9/EqMGEbtq5MdbbB2OKA611hu205UiNg==",
|
||||
"peerDependencies": {
|
||||
"@influxdata/influxdb-client": "*"
|
||||
}
|
||||
@@ -978,59 +964,6 @@
|
||||
"resolved": "https://registry.npmjs.org/@nlpjs/slot/-/slot-4.22.17.tgz",
|
||||
"integrity": "sha512-cNYcxf9DKB+fnRa2NxT5wbWq5j57R1WCTXLWI/1Cyycr227IP7GN7qaD4RbkzotBFFB8wm63UHod9frzmuiXxg=="
|
||||
},
|
||||
"node_modules/@redis/bloom": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.0.2.tgz",
|
||||
"integrity": "sha512-EBw7Ag1hPgFzdznK2PBblc1kdlj5B5Cw3XwI9/oG7tSn85/HKy3X9xHy/8tm/eNXJYHLXHJL/pkwBpFMVVefkw==",
|
||||
"peerDependencies": {
|
||||
"@redis/client": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@redis/client": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.3.0.tgz",
|
||||
"integrity": "sha512-XCFV60nloXAefDsPnYMjHGtvbtHR8fV5Om8cQ0JYqTNbWcQo/4AryzJ2luRj4blveWazRK/j40gES8M7Cp6cfQ==",
|
||||
"dependencies": {
|
||||
"cluster-key-slot": "1.1.0",
|
||||
"generic-pool": "3.8.2",
|
||||
"yallist": "4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@redis/graph": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.0.1.tgz",
|
||||
"integrity": "sha512-oDE4myMCJOCVKYMygEMWuriBgqlS5FqdWerikMoJxzmmTUErnTRRgmIDa2VcgytACZMFqpAOWDzops4DOlnkfQ==",
|
||||
"peerDependencies": {
|
||||
"@redis/client": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@redis/json": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.4.tgz",
|
||||
"integrity": "sha512-LUZE2Gdrhg0Rx7AN+cZkb1e6HjoSKaeeW8rYnt89Tly13GBI5eP4CwDVr+MY8BAYfCg4/N15OUrtLoona9uSgw==",
|
||||
"peerDependencies": {
|
||||
"@redis/client": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@redis/search": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.0.tgz",
|
||||
"integrity": "sha512-NyFZEVnxIJEybpy+YskjgOJRNsfTYqaPbK/Buv6W2kmFNaRk85JiqjJZA5QkRmWvGbyQYwoO5QfDi2wHskKrQQ==",
|
||||
"peerDependencies": {
|
||||
"@redis/client": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@redis/time-series": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.3.tgz",
|
||||
"integrity": "sha512-OFp0q4SGrTH0Mruf6oFsHGea58u8vS/iI5+NpYdicaM+7BgqBZH8FFvNZ8rYYLrUO/QRqMq72NpXmxLVNcdmjA==",
|
||||
"peerDependencies": {
|
||||
"@redis/client": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@sindresorhus/is": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
|
||||
@@ -1215,6 +1148,16 @@
|
||||
"integrity": "sha512-71aBXoFYXZW4TnDHHH8gExw2lS28BZaWeKefgsiJI7QYZeJfUEbMKw6CQtzGjlYQcGIWwB76hcCrkVA3YHSvsw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/cache-manager-redis-store": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/cache-manager-redis-store/-/cache-manager-redis-store-2.0.1.tgz",
|
||||
"integrity": "sha512-8QuccvcPieh1xM/5kReE76SfdcIdEB0ePc+54ah/NBuK2eG+6O50SX4WKoJX81UxGdW3sh/WlDaDNqjnqxWNsA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/cache-manager": "*",
|
||||
"@types/redis": "^2.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/cacheable-request": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",
|
||||
@@ -1498,6 +1441,15 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz",
|
||||
"integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw=="
|
||||
},
|
||||
"node_modules/@types/redis": {
|
||||
"version": "2.8.32",
|
||||
"resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.32.tgz",
|
||||
"integrity": "sha512-7jkMKxcGq9p242exlbsVzuJb57KqHRhNl4dHoQu2Y5v9bCAbtIXXH0R3HleSQW4CTOqpHIYUW3t6tpUj4BVQ+w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/responselike": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz",
|
||||
@@ -2383,14 +2335,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/cache-manager-redis-store": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cache-manager-redis-store/-/cache-manager-redis-store-3.0.1.tgz",
|
||||
"integrity": "sha512-o560kw+dFqusC9lQJhcm6L2F2fMKobJ5af+FoR2PdnMVdpQ3f3Bz6qzvObTGyvoazQJxjQNWgMQeChP4vRTuXQ==",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cache-manager-redis-store/-/cache-manager-redis-store-2.0.0.tgz",
|
||||
"integrity": "sha512-bWLWlUg6nCYHiJLCCYxY2MgvwvKnvlWwrbuynrzpjEIhfArD2GC9LtutIHFEPeyGVQN6C+WEw+P3r+BFBwhswg==",
|
||||
"dependencies": {
|
||||
"redis": "^4.3.1"
|
||||
"redis": "^3.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16.18.0"
|
||||
"node": ">= 8.3"
|
||||
}
|
||||
},
|
||||
"node_modules/cacheable-lookup": {
|
||||
@@ -2674,14 +2626,6 @@
|
||||
"mimic-response": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cluster-key-slot": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
|
||||
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw==",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
||||
@@ -3251,6 +3195,14 @@
|
||||
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/denque": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
|
||||
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||
@@ -4199,14 +4151,6 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/generic-pool": {
|
||||
"version": "3.8.2",
|
||||
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.8.2.tgz",
|
||||
"integrity": "sha512-nGToKy6p3PAbYQ7p1UlWl6vSPwfwU6TMSWK7TTu+WUY4ZjyZQGniGGt2oNVvyNSpyZYSB43zMXVLcBm08MTMkg==",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/gensync": {
|
||||
"version": "1.0.0-beta.2",
|
||||
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||
@@ -5852,14 +5796,6 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/luxon": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-2.5.0.tgz",
|
||||
"integrity": "sha512-IDkEPB80Rb6gCAU+FEib0t4FeJ4uVOuX1CQ9GsvU3O+JAGIgu0J7sf1OarXKaKDygTZIoJyU6YdZzTFRu+YR0A==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/make-dir": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
|
||||
@@ -7839,16 +7775,45 @@
|
||||
}
|
||||
},
|
||||
"node_modules/redis": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-4.3.1.tgz",
|
||||
"integrity": "sha512-cM7yFU5CA6zyCF7N/+SSTcSJQSRMEKN0k0Whhu6J7n9mmXRoXugfWDBo5iOzGwABmsWKSwGPTU5J4Bxbl+0mrA==",
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
|
||||
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
|
||||
"dependencies": {
|
||||
"@redis/bloom": "1.0.2",
|
||||
"@redis/client": "1.3.0",
|
||||
"@redis/graph": "1.0.1",
|
||||
"@redis/json": "1.0.4",
|
||||
"@redis/search": "1.1.0",
|
||||
"@redis/time-series": "1.0.3"
|
||||
"denque": "^1.5.0",
|
||||
"redis-commands": "^1.7.0",
|
||||
"redis-errors": "^1.2.0",
|
||||
"redis-parser": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/node-redis"
|
||||
}
|
||||
},
|
||||
"node_modules/redis-commands": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
|
||||
"integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
|
||||
},
|
||||
"node_modules/redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=",
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/redis-parser": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
|
||||
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
|
||||
"dependencies": {
|
||||
"redis-errors": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/reflect-metadata": {
|
||||
@@ -10847,20 +10812,6 @@
|
||||
"kuler": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"@datasert/cronjs-matcher": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@datasert/cronjs-matcher/-/cronjs-matcher-1.2.0.tgz",
|
||||
"integrity": "sha512-ht6Vwwa3qssMn/9bphypjG/U8w0DV3GtTS2C6kbAy39rerQFTRzmml9xZNlot1K13gm9K/EEq3DLPEOsH++ICw==",
|
||||
"requires": {
|
||||
"@datasert/cronjs-parser": "^1.2.0",
|
||||
"luxon": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"@datasert/cronjs-parser": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@datasert/cronjs-parser/-/cronjs-parser-1.2.0.tgz",
|
||||
"integrity": "sha512-7kzYh7F5V3ElX+k3W9w6SKS6WdjqJQ2gIY1y0evldnjAwZxnFzR/Yu9Mv9OeDaCQX+mGAq2MvEnJbwu9oj3CXQ=="
|
||||
},
|
||||
"@googleapis/youtube": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@googleapis/youtube/-/youtube-2.0.0.tgz",
|
||||
@@ -10870,14 +10821,14 @@
|
||||
}
|
||||
},
|
||||
"@influxdata/influxdb-client": {
|
||||
"version": "1.31.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.31.0.tgz",
|
||||
"integrity": "sha512-8DVT3ZB/VeCK5Nn+BxhgMrAMSTseQAEgV20AK+ZMO5Fcup9XWsA9L2zE+3eBFl0Y+lF3UeKiASkiKMQvws35GA=="
|
||||
"version": "1.27.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.27.0.tgz",
|
||||
"integrity": "sha512-hOBi+ApIurDd8jFWo+eYjMWWsDRp3wih/U/NOVRoHaTOE8ihSQthi9wfMD4YeVqt4pCN6ygIwo7lEKFXwNuwcA=="
|
||||
},
|
||||
"@influxdata/influxdb-client-apis": {
|
||||
"version": "1.31.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.31.0.tgz",
|
||||
"integrity": "sha512-6ALGNLxtfffhICobOdj13Z6vj6gdQVOzVXPoPNd+w7V60zrbGhTqzXHV1KMZ/lzOb6YkRTRODbxz4W/b/7N5hg==",
|
||||
"version": "1.27.0",
|
||||
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client-apis/-/influxdb-client-apis-1.27.0.tgz",
|
||||
"integrity": "sha512-a4gd7CwNRXSsSVt9tm8GzGxuPXngEmQucMdoTZ0YYeWSbKUXz3B/3u9/EqMGEbtq5MdbbB2OKA611hu205UiNg==",
|
||||
"requires": {}
|
||||
},
|
||||
"@istanbuljs/load-nyc-config": {
|
||||
@@ -11127,46 +11078,6 @@
|
||||
"resolved": "https://registry.npmjs.org/@nlpjs/slot/-/slot-4.22.17.tgz",
|
||||
"integrity": "sha512-cNYcxf9DKB+fnRa2NxT5wbWq5j57R1WCTXLWI/1Cyycr227IP7GN7qaD4RbkzotBFFB8wm63UHod9frzmuiXxg=="
|
||||
},
|
||||
"@redis/bloom": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.0.2.tgz",
|
||||
"integrity": "sha512-EBw7Ag1hPgFzdznK2PBblc1kdlj5B5Cw3XwI9/oG7tSn85/HKy3X9xHy/8tm/eNXJYHLXHJL/pkwBpFMVVefkw==",
|
||||
"requires": {}
|
||||
},
|
||||
"@redis/client": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.3.0.tgz",
|
||||
"integrity": "sha512-XCFV60nloXAefDsPnYMjHGtvbtHR8fV5Om8cQ0JYqTNbWcQo/4AryzJ2luRj4blveWazRK/j40gES8M7Cp6cfQ==",
|
||||
"requires": {
|
||||
"cluster-key-slot": "1.1.0",
|
||||
"generic-pool": "3.8.2",
|
||||
"yallist": "4.0.0"
|
||||
}
|
||||
},
|
||||
"@redis/graph": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.0.1.tgz",
|
||||
"integrity": "sha512-oDE4myMCJOCVKYMygEMWuriBgqlS5FqdWerikMoJxzmmTUErnTRRgmIDa2VcgytACZMFqpAOWDzops4DOlnkfQ==",
|
||||
"requires": {}
|
||||
},
|
||||
"@redis/json": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.4.tgz",
|
||||
"integrity": "sha512-LUZE2Gdrhg0Rx7AN+cZkb1e6HjoSKaeeW8rYnt89Tly13GBI5eP4CwDVr+MY8BAYfCg4/N15OUrtLoona9uSgw==",
|
||||
"requires": {}
|
||||
},
|
||||
"@redis/search": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.0.tgz",
|
||||
"integrity": "sha512-NyFZEVnxIJEybpy+YskjgOJRNsfTYqaPbK/Buv6W2kmFNaRk85JiqjJZA5QkRmWvGbyQYwoO5QfDi2wHskKrQQ==",
|
||||
"requires": {}
|
||||
},
|
||||
"@redis/time-series": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.3.tgz",
|
||||
"integrity": "sha512-OFp0q4SGrTH0Mruf6oFsHGea58u8vS/iI5+NpYdicaM+7BgqBZH8FFvNZ8rYYLrUO/QRqMq72NpXmxLVNcdmjA==",
|
||||
"requires": {}
|
||||
},
|
||||
"@sindresorhus/is": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
|
||||
@@ -11266,6 +11177,16 @@
|
||||
"integrity": "sha512-71aBXoFYXZW4TnDHHH8gExw2lS28BZaWeKefgsiJI7QYZeJfUEbMKw6CQtzGjlYQcGIWwB76hcCrkVA3YHSvsw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/cache-manager-redis-store": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/cache-manager-redis-store/-/cache-manager-redis-store-2.0.1.tgz",
|
||||
"integrity": "sha512-8QuccvcPieh1xM/5kReE76SfdcIdEB0ePc+54ah/NBuK2eG+6O50SX4WKoJX81UxGdW3sh/WlDaDNqjnqxWNsA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/cache-manager": "*",
|
||||
"@types/redis": "^2.8.0"
|
||||
}
|
||||
},
|
||||
"@types/cacheable-request": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",
|
||||
@@ -11549,6 +11470,15 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz",
|
||||
"integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw=="
|
||||
},
|
||||
"@types/redis": {
|
||||
"version": "2.8.32",
|
||||
"resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.32.tgz",
|
||||
"integrity": "sha512-7jkMKxcGq9p242exlbsVzuJb57KqHRhNl4dHoQu2Y5v9bCAbtIXXH0R3HleSQW4CTOqpHIYUW3t6tpUj4BVQ+w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/responselike": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz",
|
||||
@@ -12286,11 +12216,11 @@
|
||||
}
|
||||
},
|
||||
"cache-manager-redis-store": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cache-manager-redis-store/-/cache-manager-redis-store-3.0.1.tgz",
|
||||
"integrity": "sha512-o560kw+dFqusC9lQJhcm6L2F2fMKobJ5af+FoR2PdnMVdpQ3f3Bz6qzvObTGyvoazQJxjQNWgMQeChP4vRTuXQ==",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cache-manager-redis-store/-/cache-manager-redis-store-2.0.0.tgz",
|
||||
"integrity": "sha512-bWLWlUg6nCYHiJLCCYxY2MgvwvKnvlWwrbuynrzpjEIhfArD2GC9LtutIHFEPeyGVQN6C+WEw+P3r+BFBwhswg==",
|
||||
"requires": {
|
||||
"redis": "^4.3.1"
|
||||
"redis": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"cacheable-lookup": {
|
||||
@@ -12503,11 +12433,6 @@
|
||||
"mimic-response": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"cluster-key-slot": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
|
||||
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw=="
|
||||
},
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
||||
@@ -12971,6 +12896,11 @@
|
||||
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=",
|
||||
"optional": true
|
||||
},
|
||||
"denque": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
|
||||
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw=="
|
||||
},
|
||||
"depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||
@@ -13708,11 +13638,6 @@
|
||||
"json-bigint": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"generic-pool": {
|
||||
"version": "3.8.2",
|
||||
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.8.2.tgz",
|
||||
"integrity": "sha512-nGToKy6p3PAbYQ7p1UlWl6vSPwfwU6TMSWK7TTu+WUY4ZjyZQGniGGt2oNVvyNSpyZYSB43zMXVLcBm08MTMkg=="
|
||||
},
|
||||
"gensync": {
|
||||
"version": "1.0.0-beta.2",
|
||||
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||
@@ -14961,11 +14886,6 @@
|
||||
"yallist": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"luxon": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-2.5.0.tgz",
|
||||
"integrity": "sha512-IDkEPB80Rb6gCAU+FEib0t4FeJ4uVOuX1CQ9GsvU3O+JAGIgu0J7sf1OarXKaKDygTZIoJyU6YdZzTFRu+YR0A=="
|
||||
},
|
||||
"make-dir": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
|
||||
@@ -16493,16 +16413,32 @@
|
||||
}
|
||||
},
|
||||
"redis": {
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-4.3.1.tgz",
|
||||
"integrity": "sha512-cM7yFU5CA6zyCF7N/+SSTcSJQSRMEKN0k0Whhu6J7n9mmXRoXugfWDBo5iOzGwABmsWKSwGPTU5J4Bxbl+0mrA==",
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
|
||||
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
|
||||
"requires": {
|
||||
"@redis/bloom": "1.0.2",
|
||||
"@redis/client": "1.3.0",
|
||||
"@redis/graph": "1.0.1",
|
||||
"@redis/json": "1.0.4",
|
||||
"@redis/search": "1.1.0",
|
||||
"@redis/time-series": "1.0.3"
|
||||
"denque": "^1.5.0",
|
||||
"redis-commands": "^1.7.0",
|
||||
"redis-errors": "^1.2.0",
|
||||
"redis-parser": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"redis-commands": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
|
||||
"integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
|
||||
},
|
||||
"redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60="
|
||||
},
|
||||
"redis-parser": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
|
||||
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
|
||||
"requires": {
|
||||
"redis-errors": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"reflect-metadata": {
|
||||
|
||||
10
package.json
@@ -24,17 +24,16 @@
|
||||
"initMigration": "npm run typeorm -- migration:generate -t 1642180264563 -d ormconfig.js \"src/Common/Migrations/Database/init\""
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.18.0"
|
||||
"node": ">=16"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@awaitjs/express": "^0.8.0",
|
||||
"@datasert/cronjs-matcher": "^1.2.0",
|
||||
"@googleapis/youtube": "^2.0.0",
|
||||
"@influxdata/influxdb-client": "^1.31.0",
|
||||
"@influxdata/influxdb-client-apis": "^1.31.0",
|
||||
"@influxdata/influxdb-client": "^1.27.0",
|
||||
"@influxdata/influxdb-client-apis": "^1.27.0",
|
||||
"@nlpjs/core": "^4.23.4",
|
||||
"@nlpjs/lang-de": "^4.23.4",
|
||||
"@nlpjs/lang-en": "^4.23.4",
|
||||
@@ -49,7 +48,7 @@
|
||||
"autolinker": "^3.14.3",
|
||||
"body-parser": "^1.19.0",
|
||||
"cache-manager": "^3.4.4",
|
||||
"cache-manager-redis-store": "^3.0.1",
|
||||
"cache-manager-redis-store": "^2.0.0",
|
||||
"commander": "^8.0.0",
|
||||
"comment-json": "^4.1.1",
|
||||
"connect-typeorm": "^2.0.0",
|
||||
@@ -115,6 +114,7 @@
|
||||
"@tsconfig/node14": "^1.0.0",
|
||||
"@types/async": "^3.2.7",
|
||||
"@types/cache-manager": "^3.4.2",
|
||||
"@types/cache-manager-redis-store": "^2.0.0",
|
||||
"@types/chai": "^4.3.0",
|
||||
"@types/chai-as-promised": "^7.1.5",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
import {ActionJson, ActionConfig, ActionOptions} from "./index";
|
||||
import Action from "./index";
|
||||
import {Comment} from "snoowrap";
|
||||
import {renderContent} from "../Utils/SnoowrapUtils";
|
||||
import Submission from "snoowrap/dist/objects/Submission";
|
||||
import {ActionProcessResult, RichContent} from "../Common/interfaces";
|
||||
import {buildFilterCriteriaSummary, normalizeModActionCriteria, toModNoteLabel} from "../util";
|
||||
import {toModNoteLabel} from "../util";
|
||||
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
|
||||
import {runCheckOptions} from "../Subreddit/Manager";
|
||||
import {
|
||||
ActionTypes,
|
||||
ModUserNoteLabel,
|
||||
} from "../Common/Infrastructure/Atomic";
|
||||
import {ActionTypes, ModUserNoteLabel} from "../Common/Infrastructure/Atomic";
|
||||
import {ModNote} from "../Subreddit/ModNotes/ModNote";
|
||||
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
|
||||
import {ModNoteCriteria} from "../Common/Infrastructure/Filters/FilterCriteria";
|
||||
|
||||
|
||||
export class ModNoteAction extends Action {
|
||||
content: string;
|
||||
type?: string;
|
||||
existingNoteCheck?: ModNoteCriteria
|
||||
allowDuplicate: boolean;
|
||||
referenceActivity: boolean
|
||||
|
||||
constructor(options: ModNoteActionOptions) {
|
||||
super(options);
|
||||
const {type, content = '', existingNoteCheck = true, referenceActivity = true} = options;
|
||||
const {type, content = '', allowDuplicate = false, referenceActivity = true} = options;
|
||||
this.type = type;
|
||||
this.content = content;
|
||||
this.allowDuplicate = allowDuplicate;
|
||||
this.referenceActivity = referenceActivity;
|
||||
this.existingNoteCheck = typeof existingNoteCheck === 'boolean' ? this.generateModLogCriteriaFromDuplicateConvenience(existingNoteCheck) : normalizeModActionCriteria(existingNoteCheck);
|
||||
}
|
||||
|
||||
getKind(): ActionTypes {
|
||||
@@ -37,7 +35,7 @@ export class ModNoteAction extends Action {
|
||||
return {
|
||||
content: this.content,
|
||||
type: this.type,
|
||||
existingNoteCheck: this.existingNoteCheck,
|
||||
allowDuplicate: this.allowDuplicate,
|
||||
referenceActivity: this.referenceActivity,
|
||||
}
|
||||
}
|
||||
@@ -50,30 +48,27 @@ export class ModNoteAction extends Action {
|
||||
const renderedContent = await this.renderContent(this.content, item, ruleResults, actionResults);
|
||||
this.logger.verbose(`Note:\r\n(${this.type}) ${renderedContent}`);
|
||||
|
||||
let noteCheckPassed: boolean = true;
|
||||
let noteCheckResult: undefined | string;
|
||||
|
||||
if(this.existingNoteCheck === undefined) {
|
||||
// nothing to do!
|
||||
noteCheckResult = 'existingNoteCheck=false so no existing note checks were performed.';
|
||||
} else {
|
||||
const noteCheckCriteriaResult = await this.resources.isAuthor(item, {
|
||||
modActions: [this.existingNoteCheck]
|
||||
});
|
||||
noteCheckPassed = noteCheckCriteriaResult.passed;
|
||||
const {details} = buildFilterCriteriaSummary(noteCheckCriteriaResult);
|
||||
noteCheckResult = `${noteCheckPassed ? 'Existing note check condition succeeded' : 'Will not add note because existing note check condition failed'} -- ${details.join(' ')}`;
|
||||
}
|
||||
|
||||
this.logger.info(noteCheckResult);
|
||||
if (!noteCheckPassed) {
|
||||
return {
|
||||
dryRun,
|
||||
success: false,
|
||||
result: noteCheckResult
|
||||
};
|
||||
}
|
||||
|
||||
// TODO see what changes are made for bulk fetch of notes before implementing this
|
||||
// https://www.reddit.com/r/redditdev/comments/t8w861/new_mod_notes_api/
|
||||
// if (!this.allowDuplicate) {
|
||||
// const notes = await this.resources.userNotes.getUserNotes(item.author);
|
||||
// let existingNote = notes.find((x) => x.link !== null && x.link.includes(item.id));
|
||||
// if(existingNote === undefined && notes.length > 0) {
|
||||
// const lastNote = notes[notes.length - 1];
|
||||
// // possibly notes don't have a reference link so check if last one has same text
|
||||
// if(lastNote.link === null && lastNote.text === renderedContent) {
|
||||
// existingNote = lastNote;
|
||||
// }
|
||||
// }
|
||||
// if (existingNote !== undefined && existingNote.noteType === this.type) {
|
||||
// this.logger.info(`Will not add note because one already exists for this Activity (${existingNote.time.local().format()}) and allowDuplicate=false`);
|
||||
// return {
|
||||
// dryRun,
|
||||
// success: false,
|
||||
// result: `Will not add note because one already exists for this Activity (${existingNote.time.local().format()}) and allowDuplicate=false`
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
if (!dryRun) {
|
||||
await this.resources.addModNote({
|
||||
label: modLabel,
|
||||
@@ -89,36 +84,15 @@ export class ModNoteAction extends Action {
|
||||
result: `${modLabel !== undefined ? `(${modLabel})` : ''} ${renderedContent}`
|
||||
}
|
||||
}
|
||||
|
||||
generateModLogCriteriaFromDuplicateConvenience(val: boolean): ModNoteCriteria | undefined {
|
||||
if(val) {
|
||||
return {
|
||||
noteType: this.type !== undefined ? [toModNoteLabel(this.type)] : undefined,
|
||||
note: this.content !== '' ? [this.content] : undefined,
|
||||
referencesCurrentActivity: this.referenceActivity ? true : undefined,
|
||||
search: 'current',
|
||||
count: '< 1'
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ModNoteActionConfig extends ActionConfig, RichContent {
|
||||
/**
|
||||
* Check if there is an existing Note matching some criteria before adding the Note.
|
||||
*
|
||||
* If this check passes then the Note is added. The value may be a boolean or ModNoteCriteria.
|
||||
*
|
||||
* Boolean convenience:
|
||||
*
|
||||
* * If `true` or undefined then CM generates a ModNoteCriteria that passes only if there is NO existing note matching note criteria
|
||||
* * If `false` then no check is performed and Note is always added
|
||||
*
|
||||
* @examples [true]
|
||||
* @default true
|
||||
* Add Note even if a Note already exists for this Activity
|
||||
* @examples [false]
|
||||
* @default false
|
||||
* */
|
||||
existingNoteCheck?: boolean | ModNoteCriteria,
|
||||
allowDuplicate?: boolean,
|
||||
type?: ModUserNoteLabel
|
||||
referenceActivity?: boolean
|
||||
}
|
||||
|
||||
246
src/Bot/index.ts
@@ -1,5 +1,4 @@
|
||||
import Snoowrap, {Comment, ConfigOptions, RedditUser, Submission} from "snoowrap";
|
||||
import {Subreddit} from "snoowrap/dist/objects"
|
||||
import Snoowrap, {Comment, ConfigOptions, RedditUser, Submission, Subreddit} from "snoowrap";
|
||||
import {Logger} from "winston";
|
||||
import dayjs, {Dayjs} from "dayjs";
|
||||
import {Duration} from "dayjs/plugin/duration";
|
||||
@@ -28,15 +27,7 @@ import {CommentStream, ModQueueStream, SPoll, SubmissionStream, UnmoderatedStrea
|
||||
import {BotResourcesManager} from "../Subreddit/SubredditResources";
|
||||
import LoggedError from "../Utils/LoggedError";
|
||||
import pEvent from "p-event";
|
||||
import {
|
||||
SimpleError,
|
||||
isRateLimitError,
|
||||
isRequestError,
|
||||
isScopeError,
|
||||
isStatusError,
|
||||
CMError,
|
||||
ISeriousError, definesSeriousError
|
||||
} from "../Utils/Errors";
|
||||
import {SimpleError, isRateLimitError, isRequestError, isScopeError, isStatusError, CMError} from "../Utils/Errors";
|
||||
import {ErrorWithCause} from "pony-cause";
|
||||
import {DataSource, Repository} from "typeorm";
|
||||
import {Bot as BotEntity} from '../Common/Entities/Bot';
|
||||
@@ -52,17 +43,10 @@ import {FilterCriteriaDefaults} from "../Common/Infrastructure/Filters/FilterSha
|
||||
import {snooLogWrapper} from "../Utils/loggerFactory";
|
||||
import {InfluxClient} from "../Common/Influx/InfluxClient";
|
||||
import {Point} from "@influxdata/influxdb-client";
|
||||
import {
|
||||
BotInstanceFunctions, HydratedSubredditInviteData,
|
||||
NormalizedManagerResponse,
|
||||
SubredditInviteData,
|
||||
SubredditInviteDataPersisted, SubredditOnboardingReadiness
|
||||
} from "../Web/Common/interfaces";
|
||||
import {BotInstanceFunctions, NormalizedManagerResponse} from "../Web/Common/interfaces";
|
||||
import {AuthorEntity} from "../Common/Entities/AuthorEntity";
|
||||
import {Guest, GuestEntityData} from "../Common/Entities/Guest/GuestInterfaces";
|
||||
import {guestEntitiesToAll, guestEntityToApiGuest} from "../Common/Entities/Guest/GuestEntity";
|
||||
import {SubredditInvite} from "../Common/Entities/SubredditInvite";
|
||||
import {dayjsDTFormat} from "../Common/defaults";
|
||||
|
||||
class Bot implements BotInstanceFunctions {
|
||||
|
||||
@@ -77,7 +61,6 @@ class Bot implements BotInstanceFunctions {
|
||||
excludeSubreddits: string[];
|
||||
filterCriteriaDefaults?: FilterCriteriaDefaults
|
||||
subManagers: Manager[] = [];
|
||||
moderatedSubreddits: Subreddit[] = []
|
||||
heartbeatInterval: number;
|
||||
nextHeartbeat: Dayjs = dayjs();
|
||||
heartBeating: boolean = false;
|
||||
@@ -122,8 +105,6 @@ class Bot implements BotInstanceFunctions {
|
||||
runTypeRepo: Repository<RunStateType>;
|
||||
managerRepo: Repository<ManagerEntity>;
|
||||
authorRepo: Repository<AuthorEntity>;
|
||||
subredditInviteRepo: Repository<SubredditInvite>
|
||||
botRepo: Repository<BotEntity>
|
||||
botEntity!: BotEntity
|
||||
|
||||
getBotName = () => {
|
||||
@@ -187,8 +168,6 @@ class Bot implements BotInstanceFunctions {
|
||||
this.runTypeRepo = this.database.getRepository(RunStateType);
|
||||
this.managerRepo = this.database.getRepository(ManagerEntity);
|
||||
this.authorRepo = this.database.getRepository(AuthorEntity);
|
||||
this.subredditInviteRepo = this.database.getRepository(SubredditInvite)
|
||||
this.botRepo = this.database.getRepository(BotEntity)
|
||||
this.config = config;
|
||||
this.dryRun = parseBool(dryRun) === true ? true : undefined;
|
||||
this.softLimit = softLimit;
|
||||
@@ -427,27 +406,18 @@ class Bot implements BotInstanceFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
async getModeratedSubreddits(refresh = false) {
|
||||
|
||||
if(this.moderatedSubreddits.length > 0 && !refresh) {
|
||||
return this.moderatedSubreddits;
|
||||
}
|
||||
|
||||
let subListing = await this.client.getModeratedSubreddits({count: 100});
|
||||
while (!subListing.isFinished) {
|
||||
subListing = await subListing.fetchMore({amount: 100});
|
||||
}
|
||||
const availSubs = subListing.filter(x => x.display_name !== `u_${this.botUser?.name}`);
|
||||
this.moderatedSubreddits = availSubs;
|
||||
return availSubs;
|
||||
}
|
||||
|
||||
async buildManagers(subreddits: string[] = []) {
|
||||
await this.init();
|
||||
|
||||
this.logger.verbose('Syncing subreddits to moderate with managers...');
|
||||
|
||||
const availSubs = await this.getModeratedSubreddits(true);
|
||||
let availSubs: Subreddit[] = [];
|
||||
|
||||
let subListing = await this.client.getModeratedSubreddits({count: 100});
|
||||
while(!subListing.isFinished) {
|
||||
subListing = await subListing.fetchMore({amount: 100});
|
||||
}
|
||||
availSubs = subListing.filter(x => x.display_name !== `u_${this.botUser?.name}`);
|
||||
|
||||
this.logger.verbose(`${this.botAccount} is a moderator of these subreddits: ${availSubs.map(x => x.display_name_prefixed).join(', ')}`);
|
||||
|
||||
@@ -529,7 +499,7 @@ class Bot implements BotInstanceFunctions {
|
||||
for (const sub of subsToRun) {
|
||||
if(!this.subManagers.some(x => x.subreddit.display_name === sub.display_name)) {
|
||||
subManagersChanged = true;
|
||||
this.logger.info(`Manager for ${sub.display_name_prefixed} not found in loaded managers. Loading now...`);
|
||||
this.logger.info(`Manager for ${sub.display_name_prefixed} not found in existing managers. Creating now...`);
|
||||
subsToInit.push(sub.display_name);
|
||||
try {
|
||||
this.subManagers.push(await this.createManager(sub));
|
||||
@@ -665,7 +635,7 @@ class Bot implements BotInstanceFunctions {
|
||||
await manager.parseConfiguration('system', true, {suppressNotification: true, suppressChangeEvent: true});
|
||||
} catch (err: any) {
|
||||
if(err.logged !== true) {
|
||||
const normalizedError = new ErrorWithCause(`Bot could not initialize manager`, {cause: err});
|
||||
const normalizedError = new ErrorWithCause(`Bot could not initialize manager because config was not valid`, {cause: err});
|
||||
// @ts-ignore
|
||||
this.logger.error(normalizedError, {subreddit: manager.subreddit.display_name_prefixed});
|
||||
} else {
|
||||
@@ -743,9 +713,6 @@ class Bot implements BotInstanceFunctions {
|
||||
eventsState: new EventsRunState({invokee, runType}),
|
||||
managerState: new ManagerRunState({invokee, runType})
|
||||
}));
|
||||
this.logger.info(`Created new Manager (${managerEntity.id}) for ${subVal.display_name}`);
|
||||
} else {
|
||||
this.logger.info(`Found existing Manager (${managerEntity.id}) for ${subVal.display_name}`);
|
||||
}
|
||||
|
||||
const manager = new Manager(sub, this.client, this.logger, this.cacheManager, {
|
||||
@@ -793,50 +760,21 @@ class Bot implements BotInstanceFunctions {
|
||||
}
|
||||
|
||||
async checkModInvites() {
|
||||
this.logger.debug('Checking onboarding invites...');
|
||||
const expired = this.botEntity.getSubredditInvites().filter(x => x.expiresAt !== undefined && x.expiresAt.isSameOrBefore(dayjs()));
|
||||
for (const exp of expired) {
|
||||
this.logger.debug(`Onboarding invite for ${exp.subreddit} expired at ${exp.expiresAt?.format(dayjsDTFormat)}`);
|
||||
await this.deleteSubredditInvite(exp);
|
||||
}
|
||||
|
||||
for (const subInvite of this.botEntity.getSubredditInvites()) {
|
||||
if (subInvite.canAutomaticallyAccept()) {
|
||||
try {
|
||||
await this.acceptModInvite(subInvite);
|
||||
await this.deleteSubredditInvite(subInvite);
|
||||
} catch (err: any) {
|
||||
if(definesSeriousError(err) && !err.isSerious) {
|
||||
this.logger.warn(err);
|
||||
} else {
|
||||
this.logger.error(err);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.logger.debug(`Cannot try to automatically accept mod invite for ${subInvite.subreddit} because it has additional settings that require moderator approval`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async acceptModInvite(invite: SubredditInvite) {
|
||||
const {subreddit: name} = invite;
|
||||
try {
|
||||
// @ts-ignore
|
||||
await this.client.getSubreddit(name).acceptModeratorInvite();
|
||||
this.logger.info(`Accepted moderator invite for r/${name}!`);
|
||||
} catch (err: any) {
|
||||
if (err.message.includes('NO_INVITE_FOUND')) {
|
||||
throw new SimpleError(`No pending moderation invite for r/${name} was found`, {isSerious: false});
|
||||
} else if (isStatusError(err) && err.statusCode === 403) {
|
||||
let msg = `Error occurred while checking r/${name} for a pending moderation invite.`;
|
||||
if(!this.client.scope.includes('modself')) {
|
||||
msg = `${msg} This bot must have the 'modself' oauth permission in order to accept invites.`;
|
||||
const subs: string[] = await this.cacheManager.getPendingSubredditInvites();
|
||||
for (const name of subs) {
|
||||
try {
|
||||
// @ts-ignore
|
||||
await this.client.getSubreddit(name).acceptModeratorInvite();
|
||||
this.logger.info(`Accepted moderator invite for r/${name}!`);
|
||||
await this.cacheManager.deletePendingSubredditInvite(name);
|
||||
} catch (err: any) {
|
||||
if (err.message.includes('NO_INVITE_FOUND')) {
|
||||
this.logger.warn(`No pending moderation invite for r/${name} was found`);
|
||||
} else if (isStatusError(err) && err.statusCode === 403) {
|
||||
this.logger.error(`Error occurred while checking r/${name} for a pending moderation invite. It is likely that this bot does not have the 'modself' oauth permission. Error: ${err.message}`);
|
||||
} else {
|
||||
msg = `${msg} If this subreddit is private it is likely no moderation invite exists.`;
|
||||
this.logger.error(`Error occurred while checking r/${name} for a pending moderation invite. Error: ${err.message}`);
|
||||
}
|
||||
throw new CMError(msg, {cause: err})
|
||||
} else {
|
||||
throw new CMError(`Error occurred while checking r/${name} for a pending moderation invite.`, {cause: err});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1298,140 +1236,6 @@ class Bot implements BotInstanceFunctions {
|
||||
|
||||
return newGuests;
|
||||
}
|
||||
|
||||
async addSubredditInvite(data: HydratedSubredditInviteData){
|
||||
let sub: Subreddit;
|
||||
let name: string;
|
||||
if (data.subreddit instanceof Subreddit) {
|
||||
sub = data.subreddit;
|
||||
name = sub.display_name;
|
||||
} else {
|
||||
try {
|
||||
const maybeName = parseRedditEntity(data.subreddit);
|
||||
name = maybeName.name;
|
||||
} catch (e: any) {
|
||||
throw new SimpleError(`Value '${data.subreddit}' is not a valid subreddit name`);
|
||||
}
|
||||
try {
|
||||
const [exists, foundSub] = await this.client.subredditExists(name);
|
||||
if (!exists) {
|
||||
throw new SimpleError(`No subreddit with the name ${name} exists`);
|
||||
}
|
||||
if (foundSub !== undefined) {
|
||||
name = foundSub.display_name;
|
||||
}
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if((await this.subredditInviteRepo.findOneBy({subreddit: name}))) {
|
||||
throw new CMError(`Invite for ${name} already exists`);
|
||||
}
|
||||
const invite = new SubredditInvite({
|
||||
subreddit: name,
|
||||
initialConfig: data.initialConfig,
|
||||
guests: data.guests,
|
||||
bot: this.botEntity
|
||||
})
|
||||
await this.subredditInviteRepo.save(invite);
|
||||
this.botEntity.addSubredditInvite(invite);
|
||||
return invite;
|
||||
}
|
||||
|
||||
getSubredditInvites(): SubredditInviteDataPersisted[] {
|
||||
if(this.botEntity !== undefined) {
|
||||
return this.botEntity.getSubredditInvites().map(x => x.toSubredditInviteData());
|
||||
}
|
||||
this.logger.warn('No bot entity found');
|
||||
return [];
|
||||
}
|
||||
|
||||
getInvite(id: string): SubredditInvite | undefined {
|
||||
if(this.botEntity !== undefined) {
|
||||
return this.botEntity.getSubredditInvites().find(x => x.id === id);
|
||||
}
|
||||
this.logger.warn('No bot entity found');
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getOnboardingReadiness(invite: SubredditInvite): SubredditOnboardingReadiness {
|
||||
const hasManager = this.subManagers.some(x => x.subreddit.display_name.toLowerCase() === invite.subreddit.toLowerCase());
|
||||
const isMod = this.moderatedSubreddits.some(x => x.display_name.toLowerCase() === invite.subreddit.toLowerCase());
|
||||
return {
|
||||
hasManager,
|
||||
isMod
|
||||
};
|
||||
}
|
||||
|
||||
async finishOnboarding(invite: SubredditInvite) {
|
||||
const readiness = this.getOnboardingReadiness(invite);
|
||||
if (readiness.hasManager || readiness.isMod) {
|
||||
this.logger.info(`Bot is already a mod of ${invite.subreddit}. Finishing onboarding early.`);
|
||||
await this.deleteSubredditInvite(invite);
|
||||
}
|
||||
try {
|
||||
await this.acceptModInvite(invite);
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
// rebuild managers to get new subreddit
|
||||
await this.buildManagers();
|
||||
const manager = this.subManagers.find(x => x.subreddit.display_name.toLowerCase() === invite.subreddit.toLowerCase());
|
||||
if (manager === undefined) {
|
||||
throw new CMError('Accepted moderator invitation but could not find manager after rebuilding??');
|
||||
}
|
||||
const {guests = [], initialConfig} = invite;
|
||||
|
||||
// add guests
|
||||
if (guests.length > 0) {
|
||||
await this.addGuest(guests, dayjs().add(1, 'day'), manager.subreddit.display_name);
|
||||
}
|
||||
|
||||
// set initial config
|
||||
if (initialConfig !== undefined) {
|
||||
let data: string;
|
||||
try {
|
||||
const res = await manager.resources.getExternalResource(initialConfig);
|
||||
data = res.val;
|
||||
} catch (e: any) {
|
||||
throw new CMError(`Accepted moderator invitation but error occurred while trying to fetch config from Initial Config value (${initialConfig})`, {cause: e});
|
||||
}
|
||||
try {
|
||||
await manager.writeConfig(data, 'Generated by Initial Config during onboarding')
|
||||
} catch (e: any) {
|
||||
throw new CMError(`Accepted moderator invitation but error occurred while trying to set wiki config value from initial config (${initialConfig})`, {cause: e});
|
||||
}
|
||||
|
||||
// it's ok if this fails because we've already done all the onboarding steps. user can still access the dashboard and all settings have been applied (even if they were invalid IE config)
|
||||
manager.parseConfiguration('system', true).catch((err: any) => {
|
||||
if(err.logged !== true) {
|
||||
this.logger.error(err, {subreddit: manager.displayLabel});
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch(e: any) {
|
||||
throw e;
|
||||
} finally {
|
||||
await this.deleteSubredditInvite(invite);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSubredditInvite(val: string | SubredditInvite) {
|
||||
let invite: SubredditInvite;
|
||||
if(val instanceof SubredditInvite) {
|
||||
invite = val;
|
||||
} else {
|
||||
const maybeInvite = this.botEntity.getSubredditInvites().find(x => x.subreddit === val);
|
||||
if(maybeInvite === undefined) {
|
||||
throw new CMError(`No invite for subreddit ${val} exists for this Bot`);
|
||||
}
|
||||
invite = maybeInvite;
|
||||
}
|
||||
await this.subredditInviteRepo.delete({id: invite.id});
|
||||
this.botEntity.removeSubredditInvite(invite);
|
||||
}
|
||||
}
|
||||
|
||||
export default Bot;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import {ActivitySourceData, ActivitySourceTypes} from "./Infrastructure/Atomic";
|
||||
import {strToActivitySourceData} from "../util";
|
||||
|
||||
export class ActivitySource {
|
||||
type: ActivitySourceTypes
|
||||
identifier?: string
|
||||
|
||||
constructor(data: string | ActivitySourceData) {
|
||||
if (typeof data === 'string') {
|
||||
const {type, identifier} = strToActivitySourceData(data);
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
} else {
|
||||
this.type = data.type;
|
||||
this.identifier = data.identifier;
|
||||
}
|
||||
}
|
||||
|
||||
matches(desired: ActivitySource): boolean {
|
||||
if(desired.type !== this.type) {
|
||||
return false;
|
||||
}
|
||||
// if this source does not have an identifier (we have already matched type) then it is broad enough to match
|
||||
if(this.identifier === undefined) {
|
||||
return true;
|
||||
}
|
||||
// at this point we know this source has an identifier but desired DOES NOT so this source is more restrictive and does not match
|
||||
if(desired.identifier === undefined) {
|
||||
return false;
|
||||
}
|
||||
// otherwise sources match if identifiers are the same
|
||||
return this.identifier.toLowerCase() === desired.identifier.toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import {CacheOptions} from "../interfaces";
|
||||
import cacheManager, {Cache} from "cache-manager";
|
||||
import {redisStore} from "cache-manager-redis-store";
|
||||
import {create as createMemoryStore} from "../../Utils/memoryStore";
|
||||
import {CacheProvider} from "../Infrastructure/Atomic";
|
||||
import {cacheOptDefaults} from "../defaults";
|
||||
|
||||
export const buildCacheOptionsFromProvider = (provider: CacheProvider | any): CacheOptions => {
|
||||
if (typeof provider === 'string') {
|
||||
return {
|
||||
store: provider as CacheProvider,
|
||||
...cacheOptDefaults
|
||||
}
|
||||
}
|
||||
return {
|
||||
store: 'memory',
|
||||
...cacheOptDefaults,
|
||||
...provider,
|
||||
}
|
||||
}
|
||||
export const createCacheManager = async (options: CacheOptions): Promise<Cache> => {
|
||||
const {store, max, ttl = 60, host = 'localhost', port, auth_pass, db, ...rest} = options;
|
||||
switch (store) {
|
||||
case 'none':
|
||||
return cacheManager.caching({store: 'none', max, ttl});
|
||||
case 'redis':
|
||||
const rStore = await redisStore(
|
||||
{
|
||||
socket: {
|
||||
host,
|
||||
port
|
||||
},
|
||||
password: auth_pass,
|
||||
database: db,
|
||||
}
|
||||
);
|
||||
return cacheManager.caching({
|
||||
store: rStore,
|
||||
ttl,
|
||||
...rest,
|
||||
});
|
||||
case 'memory':
|
||||
default:
|
||||
//return cacheManager.caching({store: 'memory', max, ttl});
|
||||
return cacheManager.caching({store: {create: createMemoryStore}, max, ttl, shouldCloneBeforeSet: false});
|
||||
}
|
||||
}
|
||||
@@ -65,26 +65,4 @@ export class Bot extends RandomIdBaseEntity implements HasGuests {
|
||||
this.guests = []
|
||||
return [];
|
||||
}
|
||||
|
||||
getSubredditInvites(): SubredditInvite[] {
|
||||
if(this.subredditInvites === undefined) {
|
||||
return [];
|
||||
}
|
||||
return this.subredditInvites;
|
||||
}
|
||||
|
||||
addSubredditInvite(invite: SubredditInvite) {
|
||||
if(this.subredditInvites === undefined) {
|
||||
this.subredditInvites = [];
|
||||
}
|
||||
this.subredditInvites.push(invite);
|
||||
}
|
||||
|
||||
removeSubredditInvite(invite: SubredditInvite) {
|
||||
if(this.subredditInvites === undefined) {
|
||||
return;
|
||||
}
|
||||
const index = this.subredditInvites.findIndex(x => x.id === invite.id);
|
||||
this.subredditInvites.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import Submission from "snoowrap/dist/objects/Submission";
|
||||
import Comment from "snoowrap/dist/objects/Comment";
|
||||
import {ColumnDurationTransformer} from "./Transformers";
|
||||
import { RedditUser } from "snoowrap/dist/objects";
|
||||
import {ActivitySourceTypes, DurationVal, NonDispatchActivitySourceValue, onExistingFoundBehavior} from "../Infrastructure/Atomic";
|
||||
import {ActivitySourceTypes, DurationVal, NonDispatchActivitySource, onExistingFoundBehavior} from "../Infrastructure/Atomic";
|
||||
|
||||
@Entity({name: 'DispatchedAction'})
|
||||
export class DispatchedEntity extends TimeAwareRandomBaseEntity {
|
||||
@@ -53,7 +53,7 @@ export class DispatchedEntity extends TimeAwareRandomBaseEntity {
|
||||
identifier?: string
|
||||
|
||||
@Column("varchar", {nullable: true, length: 200})
|
||||
cancelIfQueued?: boolean | NonDispatchActivitySourceValue | NonDispatchActivitySourceValue[]
|
||||
cancelIfQueued?: boolean | NonDispatchActivitySource | NonDispatchActivitySource[]
|
||||
|
||||
@Column({nullable: true})
|
||||
onExistingFound?: onExistingFoundBehavior
|
||||
@@ -127,7 +127,7 @@ export class DispatchedEntity extends TimeAwareRandomBaseEntity {
|
||||
} else if (cVal === 'false') {
|
||||
this.cancelIfQueued = false;
|
||||
} else if (cVal.includes('[')) {
|
||||
this.cancelIfQueued = JSON.parse(cVal) as NonDispatchActivitySourceValue[];
|
||||
this.cancelIfQueued = JSON.parse(cVal) as NonDispatchActivitySource[];
|
||||
}
|
||||
}
|
||||
if(this.goto === null) {
|
||||
|
||||
@@ -43,7 +43,7 @@ export class ManagerEntity extends RandomIdBaseEntity implements RunningStateEnt
|
||||
@Column("varchar", {length: 200})
|
||||
name!: string;
|
||||
|
||||
@ManyToOne(type => Bot, sub => sub.managers, {eager: true})
|
||||
@ManyToOne(type => Bot, sub => sub.managers, {cascade: ['insert'], eager: true})
|
||||
bot!: Bot;
|
||||
|
||||
@ManyToOne(type => Subreddit, sub => sub.activities, {cascade: ['insert'], eager: true})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {AfterLoad, Column, Entity, JoinColumn, ManyToOne, PrimaryColumn} from "typeorm";
|
||||
import {InviteData, SubredditInviteData, SubredditInviteDataPersisted} from "../../Web/Common/interfaces";
|
||||
import {Column, Entity, JoinColumn, ManyToOne, PrimaryColumn} from "typeorm";
|
||||
import {InviteData, SubredditInviteData} from "../../Web/Common/interfaces";
|
||||
import dayjs, {Dayjs} from "dayjs";
|
||||
import {TimeAwareRandomBaseEntity} from "./Base/TimeAwareRandomBaseEntity";
|
||||
import {AuthorEntity} from "./AuthorEntity";
|
||||
@@ -8,7 +8,6 @@ import {Bot} from "./Bot";
|
||||
@Entity()
|
||||
export class SubredditInvite extends TimeAwareRandomBaseEntity implements SubredditInviteData {
|
||||
|
||||
@PrimaryColumn("varchar", {length: 255})
|
||||
subreddit!: string;
|
||||
|
||||
@Column("simple-json", {nullable: true})
|
||||
@@ -17,9 +16,6 @@ export class SubredditInvite extends TimeAwareRandomBaseEntity implements Subred
|
||||
@Column("text")
|
||||
initialConfig?: string
|
||||
|
||||
@PrimaryColumn("varchar", {length: 200})
|
||||
messageId?: string
|
||||
|
||||
@ManyToOne(type => Bot, bot => bot.subredditInvites, {nullable: false, orphanedRowAction: 'delete'})
|
||||
@JoinColumn({name: 'botId', referencedColumnName: 'id'})
|
||||
bot!: Bot;
|
||||
@@ -42,13 +38,12 @@ export class SubredditInvite extends TimeAwareRandomBaseEntity implements Subred
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data?: SubredditInviteData & { expiresIn?: number, bot: Bot }) {
|
||||
constructor(data?: SubredditInviteData & { expiresIn?: number }) {
|
||||
super();
|
||||
if (data !== undefined) {
|
||||
this.subreddit = data.subreddit;
|
||||
this.initialConfig = data.initialConfig === null ? undefined : data.initialConfig;
|
||||
this.guests = data.guests === null || data.guests === undefined ? [] : data.guests;
|
||||
this.bot = data.bot;
|
||||
this.initialConfig = data.initialConfig;
|
||||
this.guests = data.guests;
|
||||
|
||||
|
||||
if (data.expiresIn !== undefined && data.expiresIn !== 0) {
|
||||
@@ -56,44 +51,4 @@ export class SubredditInvite extends TimeAwareRandomBaseEntity implements Subred
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toSubredditInviteData(): SubredditInviteDataPersisted {
|
||||
return {
|
||||
id: this.id,
|
||||
subreddit: this.subreddit,
|
||||
initialConfig: this.getInitialConfig(),
|
||||
guests: this.getGuests(),
|
||||
expiresAt: this.expiresAt !== undefined ? this.expiresAt.unix() : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
getGuests(): string[] {
|
||||
if(this.guests === null || this.guests === undefined) {
|
||||
return [];
|
||||
}
|
||||
return this.guests;
|
||||
}
|
||||
|
||||
getInitialConfig(): string | undefined {
|
||||
if(this.initialConfig === null) {
|
||||
return undefined;
|
||||
}
|
||||
return this.initialConfig;
|
||||
}
|
||||
|
||||
canAutomaticallyAccept() {
|
||||
return this.getGuests().length === 0 && this.getInitialConfig() === undefined;
|
||||
// TODO setup inbox checking to look for reply to messageId (eventually!)
|
||||
}
|
||||
|
||||
@AfterLoad()
|
||||
fixNullable() {
|
||||
if(this.guests === null) {
|
||||
this.guests = undefined;
|
||||
}
|
||||
if(this.initialConfig === null) {
|
||||
this.initialConfig = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +1,16 @@
|
||||
import {InfluxConfig} from "./interfaces";
|
||||
import {InfluxDB, Point, WriteApi, setLogger, DEFAULT_WriteOptions, ClientOptions, DEFAULT_RetryDelayStrategyOptions, Logger as InfluxLogger} from "@influxdata/influxdb-client";
|
||||
import {InfluxDB, Point, WriteApi, setLogger} from "@influxdata/influxdb-client";
|
||||
import {HealthAPI} from "@influxdata/influxdb-client-apis";
|
||||
import dayjs, {Dayjs} from "dayjs";
|
||||
import {Logger} from "winston";
|
||||
import {mergeArr} from "../../util";
|
||||
import {CMError} from "../../Utils/Errors";
|
||||
import {Agent} from 'http';
|
||||
import {WriteOptions} from "@influxdata/influxdb-client/dist";
|
||||
|
||||
export interface InfluxClientConfig extends InfluxConfig {
|
||||
client?: InfluxDB
|
||||
ready?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppress non-error write failures
|
||||
*
|
||||
* These have not yet hit the max retry. On max retry failure Influx logs as ERROR.
|
||||
* The non-error failures are super noisy in the log so suppress them UNLESS debug is turned on
|
||||
*
|
||||
* https://github.com/influxdata/influxdb-client-js/blob/master/packages/core/src/impl/WriteApiImpl.ts#L221
|
||||
* */
|
||||
const extendLogger = (logger: Logger, suppressWriteWarnings = true): InfluxLogger => {
|
||||
return {
|
||||
...logger,
|
||||
error: (message: string, err?: any) => logger.error(message, err),
|
||||
warn: (message: string, err?: any) => {
|
||||
if(suppressWriteWarnings && !message.includes('Write to InfluxDB failed (attempt')) {
|
||||
logger.warn(message, err);
|
||||
} else if(!suppressWriteWarnings) {
|
||||
logger.warn(message, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class InfluxClient {
|
||||
config: InfluxConfig;
|
||||
client: InfluxDB;
|
||||
@@ -58,14 +34,13 @@ export class InfluxClient {
|
||||
|
||||
this.config = rest;
|
||||
this.ready = ready;
|
||||
if (client !== undefined) {
|
||||
if(client !== undefined) {
|
||||
this.client = client;
|
||||
} else {
|
||||
this.client = InfluxClient.createClient(this.config);
|
||||
setLogger(extendLogger(this.logger, !(rest.debug ?? false)));
|
||||
this.client = InfluxClient.createClient(this.config);
|
||||
setLogger(this.logger);
|
||||
}
|
||||
|
||||
this.write = this.client.getWriteApi(config.credentials.org, config.credentials.bucket, 'ms', InfluxClient.createWriteOptions(this.config, this.logger));
|
||||
this.write = this.client.getWriteApi(config.credentials.org, config.credentials.bucket, 'ms');
|
||||
this.tags = tags;
|
||||
this.write.useDefaultTags(tags);
|
||||
this.health = new HealthAPI(this.client);
|
||||
@@ -121,62 +96,13 @@ export class InfluxClient {
|
||||
}
|
||||
|
||||
static createClient(config: InfluxConfig): InfluxDB {
|
||||
const {
|
||||
credentials,
|
||||
useKeepAliveAgent = true,
|
||||
} = config;
|
||||
|
||||
const clientOptions: ClientOptions = {
|
||||
url: credentials.url,
|
||||
token: credentials.token,
|
||||
writeOptions: InfluxClient.createWriteOptions(config),
|
||||
}
|
||||
if (useKeepAliveAgent) {
|
||||
// reusing connection
|
||||
// https://github.com/influxdata/influxdb-client-js/issues/393#issuecomment-985272866
|
||||
const agent = new Agent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 20 * 1000, // 20 seconds keep alive
|
||||
})
|
||||
process.on('exit', () => agent.destroy())
|
||||
clientOptions.transportOptions = {agent};
|
||||
}
|
||||
return new InfluxDB(clientOptions);
|
||||
}
|
||||
|
||||
static createWriteOptions(config: InfluxConfig, logger?: Logger): Partial<WriteOptions> {
|
||||
const {
|
||||
return new InfluxDB({
|
||||
url: config.credentials.url,
|
||||
token: config.credentials.token,
|
||||
writeOptions: {
|
||||
defaultTags: userDefinedDefaultTags = {},
|
||||
...restUserWriteOptions
|
||||
} = {
|
||||
batchSize: 500,
|
||||
maxRetries: 5,
|
||||
// 30 seconds
|
||||
flushInterval: 30000
|
||||
},
|
||||
defaultTags: legacyDefaultTags = {},
|
||||
debug = false,
|
||||
} = config;
|
||||
|
||||
const allUserDefinedTags = {...legacyDefaultTags, ...userDefinedDefaultTags};
|
||||
|
||||
const writeOptions: Partial<WriteOptions> = {
|
||||
...DEFAULT_WriteOptions,
|
||||
...restUserWriteOptions,
|
||||
defaultTags: allUserDefinedTags
|
||||
}
|
||||
|
||||
if (debug && logger !== undefined) {
|
||||
writeOptions.writeSuccess = (lines: Array<string>) => {
|
||||
logger.debug(`Flushed ${lines.length} lines to server`);
|
||||
};
|
||||
writeOptions.writeRetrySkipped = (entry: { lines: Array<string>; expires: number }) => {
|
||||
logger.warn(`Skipped flushing ${entry.lines.length} lines due to full buffer`);
|
||||
defaultTags: config.defaultTags
|
||||
}
|
||||
}
|
||||
|
||||
return writeOptions;
|
||||
});
|
||||
}
|
||||
|
||||
childClient(logger: Logger, tags: Record<string, string> = {}) {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {InfluxDB, WriteApi, WriteOptions} from "@influxdata/influxdb-client/dist";
|
||||
import {InfluxDB, WriteApi} from "@influxdata/influxdb-client/dist";
|
||||
|
||||
export interface InfluxConfig {
|
||||
credentials: InfluxCredentials
|
||||
defaultTags?: Record<string, string>
|
||||
writeOptions?: WriteOptions
|
||||
useKeepAliveAgent?: boolean
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
export interface InfluxCredentials {
|
||||
|
||||
@@ -17,22 +17,6 @@ import {ActivityType} from "./Reddit";
|
||||
|
||||
export type DurationComparor = string;
|
||||
|
||||
/**
|
||||
* A relative datetime description
|
||||
*
|
||||
* May be either:
|
||||
*
|
||||
* * day of the week (monday, tuesday, etc...)
|
||||
* * cron expression IE `* * 15 *`
|
||||
*
|
||||
* See https://crontab.guru/ for generating expressions
|
||||
*
|
||||
* https://regexr.com/6u3cc
|
||||
*
|
||||
* @pattern ((?:(?:(?:(?:\d+,)+\d+|(?:\d+(?:\/|-|#)\d+)|\d+L?|\*(?:\/\d+)?|L(?:-\d+)?|\?|[A-Z]{3}(?:-[A-Z]{3})?) ?){5,7})$)|(mon|tues|wed|thurs|fri|sat|sun){1}
|
||||
* */
|
||||
export type RelativeDateTimeMatch = string;
|
||||
|
||||
/**
|
||||
* A string containing a comparison operator and a value to compare against
|
||||
*
|
||||
@@ -41,7 +25,7 @@ export type RelativeDateTimeMatch = string;
|
||||
* * EX `> 100` => greater than 100
|
||||
* * EX `<= 75%` => less than or equal to 75%
|
||||
*
|
||||
* @pattern ^\s*(>|>=|<|<=)\s*((?:\d+)(?:(?:(?:.|,)\d+)+)?)\s*(%?)(.*)$
|
||||
* @pattern ^\s*(>|>=|<|<=)\s*(\d+)\s*(%?)(.*)$
|
||||
* */
|
||||
export type CompareValueOrPercent = string;
|
||||
export type StringOperator = '>' | '>=' | '<' | '<=';
|
||||
@@ -168,16 +152,9 @@ export type onExistingFoundBehavior = 'replace' | 'skip' | 'ignore';
|
||||
export type ActionTarget = 'self' | 'parent';
|
||||
export type ArbitraryActionTarget = ActionTarget | string;
|
||||
export type InclusiveActionTarget = ActionTarget | 'any';
|
||||
export const SOURCE_POLL = 'poll';
|
||||
export type SourcePollStr = 'poll';
|
||||
export const SOURCE_DISPATCH = 'dispatch';
|
||||
export type SourceDispatchStr = 'dispatch';
|
||||
export const SOURCE_USER = 'user';
|
||||
export type SourceUserStr = 'user';
|
||||
|
||||
export type DispatchSourceValue = SourceDispatchStr | `dispatch:${string}`;
|
||||
export type NonDispatchActivitySourceValue = SourcePollStr | `poll:${PollOn}` | SourceUserStr | `user:${string}`;
|
||||
export type ActivitySourceTypes = SourcePollStr | SourceDispatchStr | SourceUserStr; // TODO
|
||||
export type DispatchSource = 'dispatch' | `dispatch:${string}`;
|
||||
export type NonDispatchActivitySource = 'poll' | `poll:${PollOn}` | 'user' | `user:${string}`;
|
||||
export type ActivitySourceTypes = 'poll' | 'dispatch' | 'user'; // TODO
|
||||
// https://github.com/YousefED/typescript-json-schema/issues/426
|
||||
// https://github.com/YousefED/typescript-json-schema/issues/425
|
||||
// @pattern ^(((poll|dispatch)(:\w+)?)|user)$
|
||||
@@ -195,12 +172,7 @@ export type ActivitySourceTypes = SourcePollStr | SourceDispatchStr | SourceUser
|
||||
*
|
||||
*
|
||||
* */
|
||||
export type ActivitySourceValue = NonDispatchActivitySourceValue | DispatchSourceValue;
|
||||
|
||||
export interface ActivitySourceData {
|
||||
type: ActivitySourceTypes
|
||||
identifier?: string
|
||||
}
|
||||
export type ActivitySource = NonDispatchActivitySource | DispatchSource;
|
||||
|
||||
export type ConfigFormat = 'json' | 'yaml';
|
||||
export type ActionTypes =
|
||||
|
||||
@@ -35,8 +35,8 @@ export const asGenericComparison = (val: any): val is GenericComparison => {
|
||||
return typeof val === 'object' && 'value' in val;
|
||||
}
|
||||
|
||||
export const GENERIC_VALUE_COMPARISON = /^\s*(?<opStr>>|>=|<|<=)\s*(?<value>-?(?:\d+)(?:(?:(?:.|,)\d+)+)?)(?<extra>\s+.*)*$/
|
||||
export const GENERIC_VALUE_COMPARISON_URL = 'https://regexr.com/6vama';
|
||||
export const GENERIC_VALUE_COMPARISON = /^\s*(?<opStr>>|>=|<|<=)\s*(?<value>-?\d?\.?\d+)(?<extra>\s+.*)*$/
|
||||
export const GENERIC_VALUE_COMPARISON_URL = 'https://regexr.com/60dq4';
|
||||
export const parseGenericValueComparison = (val: string, options?: {
|
||||
requireDuration?: boolean,
|
||||
reg?: RegExp
|
||||
@@ -107,8 +107,8 @@ export const parseGenericValueComparison = (val: string, options?: {
|
||||
durationText,
|
||||
}
|
||||
}
|
||||
const GENERIC_VALUE_PERCENT_COMPARISON = /^\s*(?<opStr>>|>=|<|<=)\s*(?<value>(?:\d+)(?:(?:(?:.|,)\d+)+)?)\s*(?<percent>%)?(?<extra>.*)$/
|
||||
const GENERIC_VALUE_PERCENT_COMPARISON_URL = 'https://regexr.com/6valr';
|
||||
const GENERIC_VALUE_PERCENT_COMPARISON = /^\s*(?<opStr>>|>=|<|<=)\s*(?<value>\d+)\s*(?<percent>%)?(?<extra>.*)$/
|
||||
const GENERIC_VALUE_PERCENT_COMPARISON_URL = 'https://regexr.com/60a16';
|
||||
export const parseGenericValueOrPercentComparison = (val: string, options?: {requireDuration: boolean}): GenericComparison => {
|
||||
return parseGenericValueComparison(val, {...(options ?? {}), reg: GENERIC_VALUE_PERCENT_COMPARISON});
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ import {
|
||||
DurationComparor,
|
||||
ModeratorNameCriteria,
|
||||
ModeratorNames, ModActionType,
|
||||
ModUserNoteLabel, RelativeDateTimeMatch
|
||||
ModUserNoteLabel
|
||||
} from "../Atomic";
|
||||
import {ActivityType, MaybeActivityType} from "../Reddit";
|
||||
import {ActivityType} from "../Reddit";
|
||||
import {GenericComparison, parseGenericValueComparison} from "../Comparisons";
|
||||
import {parseStringToRegexOrLiteralSearch} from "../../../util";
|
||||
import { Submission, Comment } from "snoowrap";
|
||||
|
||||
/**
|
||||
* Different attributes a `Subreddit` can be in. Only include a property if you want to check it.
|
||||
@@ -123,14 +122,13 @@ export interface UserNoteCriteria extends UserSubredditHistoryCriteria {
|
||||
|
||||
export interface ModActionCriteria extends UserSubredditHistoryCriteria {
|
||||
type?: ModActionType | ModActionType[]
|
||||
activityType?: MaybeActivityType | MaybeActivityType[]
|
||||
referencesCurrentActivity?: boolean
|
||||
activityType?: ActivityType | ActivityType[]
|
||||
}
|
||||
|
||||
export interface FullModActionCriteria extends Omit<ModActionCriteria, 'count'> {
|
||||
type?: ModActionType[]
|
||||
count?: GenericComparison
|
||||
activityType?: MaybeActivityType[]
|
||||
activityType?: ActivityType[]
|
||||
}
|
||||
|
||||
export interface ModNoteCriteria extends ModActionCriteria {
|
||||
@@ -169,7 +167,6 @@ export const toFullModNoteCriteria = (val: ModNoteCriteria): FullModNoteCriteria
|
||||
break;
|
||||
case 'activityType':
|
||||
case 'noteType':
|
||||
case 'referencesCurrentActivity':
|
||||
acc[k] = rawVal;
|
||||
break;
|
||||
case 'note':
|
||||
@@ -222,7 +219,6 @@ export const toFullModLogCriteria = (val: ModLogCriteria): FullModLogCriteria =>
|
||||
break;
|
||||
case 'activityType':
|
||||
case 'type':
|
||||
case 'referencesCurrentActivity':
|
||||
acc[k as keyof FullModLogCriteria] = rawVal;
|
||||
break;
|
||||
case 'action':
|
||||
@@ -445,21 +441,6 @@ export interface ActivityState {
|
||||
* */
|
||||
reports?: string
|
||||
age?: DurationComparor
|
||||
|
||||
/**
|
||||
* A relative datetime description to match the date the Activity was created
|
||||
*
|
||||
* May be either:
|
||||
*
|
||||
* * day of the week (monday, tuesday, etc...)
|
||||
* * cron expression IE `* * 15 *`
|
||||
*
|
||||
* See https://crontab.guru/ for generating expressions
|
||||
*
|
||||
* https://regexr.com/6u3cc
|
||||
*
|
||||
* */
|
||||
createdOn?: RelativeDateTimeMatch | RelativeDateTimeMatch[]
|
||||
/**
|
||||
* Test whether the activity is present in dispatched/delayed activities
|
||||
*
|
||||
@@ -489,33 +470,6 @@ export interface ActivityState {
|
||||
*
|
||||
* */
|
||||
source?: string | string[]
|
||||
|
||||
/**
|
||||
* * If `true` then passes if ANY flair
|
||||
* * If `false` then passes if NO flair
|
||||
* * If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes.
|
||||
* */
|
||||
authorFlairText?: boolean | string | string[]
|
||||
/**
|
||||
* * If `true` then passes if ANY flair
|
||||
* * If `false` then passes if NO flair
|
||||
* * If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes.
|
||||
* */
|
||||
authorFlairTemplateId?: boolean | string | string[]
|
||||
|
||||
/**
|
||||
* * If `true` then passes if ANY class
|
||||
* * If `false` then passes if NO class
|
||||
* * If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes.
|
||||
* */
|
||||
authorFlairCssClass?: boolean | string | string[]
|
||||
|
||||
/**
|
||||
* * If `true` then passes if ANY color
|
||||
* * If `false` then passes if NO color
|
||||
* * If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes.
|
||||
* */
|
||||
authorFlairBackgroundColor?: boolean | string | string[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,22 +492,13 @@ export interface SubmissionState extends ActivityState {
|
||||
/**
|
||||
* * If `true` then passes if flair has ANY text
|
||||
* * If `false` then passes if flair has NO text
|
||||
* * If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes.
|
||||
* */
|
||||
link_flair_text?: boolean | string | string[]
|
||||
/**
|
||||
* * If `true` then passes if flair has ANY css
|
||||
* * If `false` then passes if flair has NO css
|
||||
* * If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes.
|
||||
* */
|
||||
link_flair_css_class?: boolean | string | string[]
|
||||
|
||||
/**
|
||||
* * If `true` then passes if ANY color
|
||||
* * If `false` then passes if NO color
|
||||
* * If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes.
|
||||
* */
|
||||
link_flair_background_color?: boolean | string | string[]
|
||||
/**
|
||||
* * If `true` then passes if there is ANY flair template id
|
||||
* * If `false` then passes if there is NO flair template id
|
||||
@@ -577,16 +522,6 @@ export interface SubmissionState extends ActivityState {
|
||||
upvoteRatio?: number | CompareValue
|
||||
}
|
||||
|
||||
export const cmToSnoowrapActivityMap: Record<string, keyof (Submission & Comment)> = {
|
||||
authorFlairText: 'author_flair_text',
|
||||
flairText: 'author_flair_text',
|
||||
authorFlairTemplateId: 'author_flair_template_id',
|
||||
authorFlairCssClass: 'author_flair_css_class',
|
||||
authorFlairBackgroundColor: 'author_flair_background_color',
|
||||
flairTemplate: 'link_flair_template_id',
|
||||
flairCssClass: 'author_flair_css_class',
|
||||
}
|
||||
|
||||
export const cmActivityProperties = ['submissionState', 'score', 'reports', 'removed', 'deleted', 'filtered', 'age', 'title'];
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {Comment, Submission} from "snoowrap/dist/objects";
|
||||
|
||||
export type ActivityType = 'submission' | 'comment';
|
||||
export type MaybeActivityType = ActivityType | false;
|
||||
export type FullNameTypes = ActivityType | 'user' | 'subreddit' | 'message';
|
||||
|
||||
export interface RedditThing {
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import {MigrationInterface, QueryRunner, Table, TableColumn} from "typeorm"
|
||||
|
||||
export class subredditInvite1663001719622 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const table = await queryRunner.getTable('SubredditInvite') as Table;
|
||||
|
||||
await queryRunner.addColumns(table, [
|
||||
new TableColumn( {
|
||||
name: 'messageId',
|
||||
type: 'varchar',
|
||||
length: '200',
|
||||
isUnique: true,
|
||||
isNullable: true
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
import {RuleType} from "../../../Entities/RuleType";
|
||||
|
||||
export class mhs1663609045418 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.manager.getRepository(RuleType).save([
|
||||
new RuleType('mhs'),
|
||||
]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
}
|
||||
|
||||
}
|
||||
6
src/Common/Typings/support.d.ts
vendored
@@ -163,9 +163,3 @@ declare module 'wink-sentiment' {
|
||||
|
||||
export default sentiment;
|
||||
}
|
||||
|
||||
declare module 'cache-manager-redis-store' {
|
||||
import {RedisClientOptions} from "@redis/client";
|
||||
import {Cache, CachingConfig} from "cache-manager";
|
||||
export async function redisStore(config: RedisClientOptions & Partial<CachingConfig>): Cache;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@ import {HistoricalStatsDisplay} from "./interfaces";
|
||||
import path from "path";
|
||||
import {FilterCriteriaDefaults} from "./Infrastructure/Filters/FilterShapes";
|
||||
|
||||
export const dayjsDTFormat = 'YYYY-MM-DD HH:mm:ssZ';
|
||||
export const dayjsTimeFormat = 'HH:mm:ss z';
|
||||
|
||||
export const cacheOptDefaults = {ttl: 60, max: 500, checkPeriod: 600};
|
||||
export const cacheTTLDefaults = {
|
||||
authorTTL: 60,
|
||||
@@ -45,4 +42,4 @@ export const filterCriteriaDefault: FilterCriteriaDefaults = {
|
||||
export const defaultDataDir = path.resolve(__dirname, '../..');
|
||||
export const defaultConfigFilenames = ['config.json', 'config.yaml'];
|
||||
|
||||
export const VERSION = '0.13.1';
|
||||
export const VERSION = '0.12.2';
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
DurationVal,
|
||||
EventRetentionPolicyRange,
|
||||
JoinOperands,
|
||||
NonDispatchActivitySourceValue,
|
||||
NonDispatchActivitySource,
|
||||
NotificationEventType,
|
||||
NotificationProvider,
|
||||
onExistingFoundBehavior,
|
||||
@@ -1585,9 +1585,6 @@ export interface ThirdPartyCredentialsJsonConfig {
|
||||
youtube?: {
|
||||
apiKey: string
|
||||
}
|
||||
mhs?: {
|
||||
apiKey: string
|
||||
}
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
@@ -1967,7 +1964,7 @@ export type RequiredItemCrit = Required<(CommentState & SubmissionState)>;
|
||||
|
||||
export interface ActivityDispatchConfig {
|
||||
identifier?: string
|
||||
cancelIfQueued?: boolean | NonDispatchActivitySourceValue | NonDispatchActivitySourceValue[]
|
||||
cancelIfQueued?: boolean | NonDispatchActivitySource | NonDispatchActivitySource[]
|
||||
goto?: string
|
||||
onExistingFound?: onExistingFoundBehavior
|
||||
tardyTolerant?: boolean | DurationVal
|
||||
|
||||
@@ -19,11 +19,10 @@ import {DispatchActionJson} from "../Action/DispatchAction";
|
||||
import {CancelDispatchActionJson} from "../Action/CancelDispatchAction";
|
||||
import {ContributorActionJson} from "../Action/ContributorAction";
|
||||
import {SentimentRuleJSONConfig} from "../Rule/SentimentRule";
|
||||
import {MHSRuleJSONConfig} from "../Rule/MHSRule";
|
||||
import {ModNoteActionJson} from "../Action/ModNoteAction";
|
||||
import {IncludesData} from "./Infrastructure/Includes";
|
||||
import { SubmissionActionJson } from "../Action/SubmissionAction";
|
||||
|
||||
export type RuleObjectJsonTypes = RecentActivityRuleJSONConfig | RepeatActivityJSONConfig | AuthorRuleJSONConfig | AttributionJSONConfig | HistoryJSONConfig | RegexRuleJSONConfig | RepostRuleJSONConfig | SentimentRuleJSONConfig | MHSRuleJSONConfig
|
||||
export type RuleObjectJsonTypes = RecentActivityRuleJSONConfig | RepeatActivityJSONConfig | AuthorRuleJSONConfig | AttributionJSONConfig | HistoryJSONConfig | RegexRuleJSONConfig | RepostRuleJSONConfig | SentimentRuleJSONConfig
|
||||
|
||||
export type ActionJson = CommentActionJson | SubmissionActionJson | FlairActionJson | ReportActionJson | LockActionJson | RemoveActionJson | ApproveActionJson | BanActionJson | UserNoteActionJson | MessageActionJson | UserFlairActionJson | DispatchActionJson | CancelDispatchActionJson | ContributorActionJson | ModNoteActionJson | string | IncludesData;
|
||||
|
||||
@@ -81,23 +81,6 @@ export interface HistoryCriteria {
|
||||
|
||||
window: ActivityWindowConfig
|
||||
|
||||
ratio?: {
|
||||
window: ActivityWindowConfig
|
||||
/**
|
||||
* A string containing a comparison operator and a value to compare number of parent criteria activities against number of "ratio" activities
|
||||
*
|
||||
* This comparison is always done as (number of parent criteria activities) / (number of ratio activities)
|
||||
*
|
||||
* The syntax is `(< OR > OR <= OR >=) <number>[percent sign]`
|
||||
*
|
||||
* * EX `> 1.2` => There are 1.2 activities from parent criteria for every 1 ratio activities
|
||||
* * EX `<= 75%` => There are equal to or less than 0.75 activities from parent criteria for every 1 ratio activities
|
||||
*
|
||||
* @pattern ^\s*(>|>=|<|<=)\s*((?:\d+)(?:(?:(?:.|,)\d+)+)?)\s*(%?)(.*)$
|
||||
* */
|
||||
threshold: CompareValueOrPercent
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimum number of **filtered** activities that must exist from the `window` results for this criteria to run
|
||||
* @default 5
|
||||
@@ -187,7 +170,7 @@ export class HistoryRule extends Rule {
|
||||
|
||||
for (const criteria of this.criteria) {
|
||||
|
||||
const {comment, window, submission, total, ratio, minActivityCount = 5} = criteria;
|
||||
const {comment, window, submission, total, minActivityCount = 5} = criteria;
|
||||
|
||||
const {pre: activities, post: filteredActivities} = await this.resources.getAuthorActivitiesWithFilter(item.author, window);
|
||||
|
||||
@@ -268,24 +251,6 @@ export class HistoryRule extends Rule {
|
||||
}
|
||||
}
|
||||
|
||||
let foundRatio = undefined;
|
||||
let ratioTrigger = undefined;
|
||||
if(ratio !== undefined) {
|
||||
const { window: ratioWindow, threshold: ratioThreshold } = ratio;
|
||||
const {operator, value, isPercent, extra = ''} = parseGenericValueOrPercentComparison(ratioThreshold);
|
||||
const ratioWindowConfig = windowConfigToWindowCriteria(ratioWindow);
|
||||
const {post: ratioActivities} = await this.resources.getAuthorActivitiesWithFilter(item.author, ratioWindowConfig);
|
||||
|
||||
const ratioVal = filteredActivities.length / ratioActivities.length;
|
||||
foundRatio = formatNumber(ratioVal);
|
||||
if(isPercent) {
|
||||
const per = value / 100;
|
||||
ratioTrigger = comparisonTextOp(ratioVal, operator, per);
|
||||
} else {
|
||||
ratioTrigger = comparisonTextOp(ratioVal, operator, value);
|
||||
}
|
||||
}
|
||||
|
||||
const firstActivity = activities[0];
|
||||
const lastActivity = activities[activities.length - 1];
|
||||
|
||||
@@ -298,13 +263,11 @@ export class HistoryRule extends Rule {
|
||||
submissionTotal: fSubmissionTotal,
|
||||
commentTotal: fCommentTotal,
|
||||
opTotal: fOpTotal,
|
||||
foundRatio,
|
||||
filteredTotal: filteredActivities.length,
|
||||
submissionTrigger,
|
||||
commentTrigger,
|
||||
totalTrigger,
|
||||
ratioTrigger,
|
||||
triggered: (submissionTrigger === undefined || submissionTrigger === true) && (commentTrigger === undefined || commentTrigger === true) && (totalTrigger === undefined || totalTrigger === true) && (ratioTrigger === undefined || ratioTrigger === true),
|
||||
triggered: (submissionTrigger === undefined || submissionTrigger === true) && (commentTrigger === undefined || commentTrigger === true) && (totalTrigger === undefined || totalTrigger === true),
|
||||
subredditBreakdown: getSubredditBreakdownByActivityType(!asOp ? filteredActivities : filteredActivities.filter(x => asSubmission(x) || x.is_submitter))
|
||||
});
|
||||
}
|
||||
@@ -337,12 +300,6 @@ export class HistoryRule extends Rule {
|
||||
|
||||
this.logger.verbose(`${PASS} ${resultData.result}`);
|
||||
return Promise.resolve([true, this.getResult(true, resultData)]);
|
||||
} else {
|
||||
// log failures for easier debugging
|
||||
for(const res of criteriaResults) {
|
||||
const resultData = this.generateResultDataFromCriteria(res);
|
||||
this.logger.verbose(`${FAIL} ${resultData.result}`);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve([false, this.getResult(false, {result: failCriteriaResult})]);
|
||||
@@ -355,13 +312,11 @@ export class HistoryRule extends Rule {
|
||||
submissionTotal,
|
||||
commentTotal,
|
||||
filteredTotal,
|
||||
foundRatio,
|
||||
opTotal,
|
||||
criteria: {
|
||||
comment,
|
||||
submission,
|
||||
total,
|
||||
ratio,
|
||||
window,
|
||||
},
|
||||
criteria,
|
||||
@@ -369,7 +324,6 @@ export class HistoryRule extends Rule {
|
||||
submissionTrigger,
|
||||
commentTrigger,
|
||||
totalTrigger,
|
||||
ratioTrigger,
|
||||
subredditBreakdown,
|
||||
} = results;
|
||||
|
||||
@@ -378,7 +332,6 @@ export class HistoryRule extends Rule {
|
||||
submissionTotal,
|
||||
commentTotal,
|
||||
filteredTotal,
|
||||
foundRatio,
|
||||
opTotal,
|
||||
commentPercent: formatNumber((commentTotal/activityTotal)*100),
|
||||
submissionPercent: formatNumber((submissionTotal/activityTotal)*100),
|
||||
@@ -390,7 +343,6 @@ export class HistoryRule extends Rule {
|
||||
submissionTrigger,
|
||||
commentTrigger,
|
||||
totalTrigger,
|
||||
ratioTrigger,
|
||||
subredditBreakdown
|
||||
};
|
||||
|
||||
@@ -398,7 +350,6 @@ export class HistoryRule extends Rule {
|
||||
let totalSummary;
|
||||
let submissionSummary;
|
||||
let commentSummary;
|
||||
let ratioSummary;
|
||||
if(total !== undefined) {
|
||||
const {operator, value, isPercent, displayText} = parseGenericValueOrPercentComparison(total);
|
||||
const suffix = !isPercent ? 'Items' : `(${formatNumber((filteredTotal/activityTotal)*100)}%) of ${activityTotal} Total`;
|
||||
@@ -423,13 +374,6 @@ export class HistoryRule extends Rule {
|
||||
data.commentSummary = commentSummary;
|
||||
thresholdSummary.push(commentSummary);
|
||||
}
|
||||
if(ratio !== undefined) {
|
||||
const {threshold} = ratio;
|
||||
const {operator, value, isPercent, displayText, extra = ''} = parseGenericValueOrPercentComparison(threshold);
|
||||
ratioSummary = `${includePassFailSymbols ? `${submissionTrigger ? PASS : FAIL} ` : ''}Activity Ratio of (${foundRatio}) ${ratioTrigger ? 'passed' : 'did not pass'} test of ${displayText}`;
|
||||
data.ratioSummary = ratioSummary;
|
||||
thresholdSummary.push(ratioSummary);
|
||||
}
|
||||
|
||||
data.thresholdSummary = thresholdSummary.join(' and ');
|
||||
|
||||
|
||||
@@ -1,420 +0,0 @@
|
||||
import {Rule, RuleJSONConfig, RuleOptions} from "./index";
|
||||
import {Comment} from "snoowrap";
|
||||
import Submission from "snoowrap/dist/objects/Submission";
|
||||
import {
|
||||
asComment, boolToString,
|
||||
formatNumber,
|
||||
triggeredIndicator, windowConfigToWindowCriteria
|
||||
} from "../util";
|
||||
import got, {HTTPError} from 'got';
|
||||
import dayjs from 'dayjs';
|
||||
import {map as mapAsync} from 'async';
|
||||
import {
|
||||
comparisonTextOp,
|
||||
GenericComparison,
|
||||
parseGenericValueOrPercentComparison,
|
||||
} from "../Common/Infrastructure/Comparisons";
|
||||
import {ActivityWindowConfig, ActivityWindowCriteria} from "../Common/Infrastructure/ActivityWindow";
|
||||
import {RuleResult} from "../Common/interfaces";
|
||||
import {SnoowrapActivity} from "../Common/Infrastructure/Reddit";
|
||||
import {CMError} from "../Utils/Errors";
|
||||
import objectHash from "object-hash";
|
||||
|
||||
const formatConfidence = (val: number) => formatNumber(val * 100, {
|
||||
suffix: '%',
|
||||
toFixed: 2
|
||||
});
|
||||
|
||||
export class MHSRule extends Rule {
|
||||
|
||||
criteria: MHSCriteria
|
||||
|
||||
historical?: HistoricalMHS;
|
||||
|
||||
ogConfig: MHSConfig
|
||||
|
||||
constructor(options: MHSRuleOptions) {
|
||||
super(options);
|
||||
|
||||
if (this.resources.thirdPartyCredentials.mhs?.apiKey === undefined) {
|
||||
throw new CMError(`MHS (moderatehatespeech.com) API Key has not been specified. It must be present in the bot config or top-level subreddit 'credentials' property.`);
|
||||
}
|
||||
|
||||
const {
|
||||
criteria,
|
||||
historical,
|
||||
} = options;
|
||||
|
||||
this.ogConfig = {
|
||||
criteria,
|
||||
historical
|
||||
};
|
||||
|
||||
const {
|
||||
flagged = true,
|
||||
confidence = '>= 90',
|
||||
testOn = ['body']
|
||||
} = criteria || {};
|
||||
|
||||
this.criteria = {
|
||||
flagged,
|
||||
confidence: confidence !== undefined ? parseGenericValueOrPercentComparison(confidence) : undefined,
|
||||
testOn,
|
||||
}
|
||||
|
||||
if (options.historical !== undefined) {
|
||||
const {
|
||||
window,
|
||||
criteria: historyCriteria,
|
||||
mustMatchCurrent = false,
|
||||
totalMatching = '> 0',
|
||||
} = options.historical
|
||||
|
||||
let usedCriteria: MHSCriteria;
|
||||
if (historyCriteria === undefined) {
|
||||
usedCriteria = this.criteria;
|
||||
} else {
|
||||
const {
|
||||
flagged: historyFlagged = true,
|
||||
confidence: historyConfidence = '>= 90',
|
||||
testOn: historyTestOn = ['body']
|
||||
} = historyCriteria || {};
|
||||
usedCriteria = {
|
||||
flagged: historyFlagged,
|
||||
confidence: historyConfidence !== undefined ? parseGenericValueOrPercentComparison(historyConfidence) : undefined,
|
||||
testOn: historyTestOn,
|
||||
}
|
||||
}
|
||||
|
||||
this.historical = {
|
||||
criteria: usedCriteria,
|
||||
window: windowConfigToWindowCriteria(window),
|
||||
mustMatchCurrent,
|
||||
totalMatching: parseGenericValueOrPercentComparison(totalMatching),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
getKind(): string {
|
||||
return 'mhs';
|
||||
}
|
||||
|
||||
getSpecificPremise(): object {
|
||||
return this.ogConfig;
|
||||
}
|
||||
|
||||
protected async process(item: Submission | Comment): Promise<[boolean, RuleResult]> {
|
||||
|
||||
let ogResult = await this.testActivity(item, this.criteria);
|
||||
let historicResults: MHSCriteriaResult[] | undefined;
|
||||
let historicalCriteriaTest: string | undefined;
|
||||
|
||||
if (this.historical !== undefined && (!this.historical.mustMatchCurrent || ogResult.passed)) {
|
||||
const {
|
||||
criteria,
|
||||
window,
|
||||
} = this.historical;
|
||||
const history = await this.resources.getAuthorActivities(item.author, window);
|
||||
|
||||
historicResults = await mapAsync(history, async (x: SnoowrapActivity) => await this.testActivity(x, criteria)); // history.map(x => this.testActivity(x, sentiment));
|
||||
}
|
||||
|
||||
const logSummary: string[] = [];
|
||||
|
||||
let triggered = false;
|
||||
let humanWindow: string | undefined;
|
||||
let historicalPassed: string | undefined;
|
||||
let totalMatchingText: string | undefined;
|
||||
|
||||
if (historicResults === undefined) {
|
||||
triggered = ogResult.passed;
|
||||
logSummary.push(`Current Activity MHS Test: ${ogResult.summary}`);
|
||||
if (!triggered && this.historical !== undefined && this.historical.mustMatchCurrent) {
|
||||
logSummary.push(`Did not check Historical because 'mustMatchCurrent' is true`);
|
||||
}
|
||||
} else {
|
||||
const {
|
||||
totalMatching,
|
||||
criteria,
|
||||
} = this.historical as HistoricalMHS;
|
||||
|
||||
historicalCriteriaTest = mhsCriteriaTestDisplay(criteria);
|
||||
|
||||
totalMatchingText = totalMatching.displayText;
|
||||
const allResults = historicResults
|
||||
const passed = allResults.filter(x => x.passed);
|
||||
|
||||
const firstActivity = allResults[0].activity;
|
||||
const lastActivity = allResults[allResults.length - 1].activity;
|
||||
|
||||
const humanRange = dayjs.duration(dayjs(firstActivity.created_utc * 1000).diff(dayjs(lastActivity.created_utc * 1000))).humanize();
|
||||
|
||||
humanWindow = `${allResults.length} Activities (${humanRange})`;
|
||||
|
||||
const {operator, value, isPercent} = totalMatching;
|
||||
if (isPercent) {
|
||||
const passPercentVal = passed.length / allResults.length
|
||||
triggered = comparisonTextOp(passPercentVal, operator, (value / 100));
|
||||
historicalPassed = `${passed.length} (${formatNumber(passPercentVal)}%)`;
|
||||
} else {
|
||||
triggered = comparisonTextOp(passed.length, operator, value);
|
||||
historicalPassed = `${passed.length}`;
|
||||
}
|
||||
logSummary.push(`${triggeredIndicator(triggered)} ${historicalPassed} historical activities of ${humanWindow} passed MHS criteria '${historicalCriteriaTest}' which ${triggered ? 'MET' : 'DID NOT MEET'} threshold '${totalMatching.displayText}'`);
|
||||
}
|
||||
|
||||
const result = logSummary.join(' || ');
|
||||
this.logger.verbose(result);
|
||||
|
||||
return Promise.resolve([triggered, this.getResult(triggered, {
|
||||
result,
|
||||
data: {
|
||||
results: {
|
||||
triggered,
|
||||
criteriaTest: mhsCriteriaTestDisplay(this.criteria),
|
||||
historicalCriteriaTest,
|
||||
window: humanWindow,
|
||||
totalMatching: totalMatchingText
|
||||
}
|
||||
}
|
||||
})]);
|
||||
}
|
||||
|
||||
protected async testActivity(a: SnoowrapActivity, criteria: MHSCriteria): Promise<MHSCriteriaResult> {
|
||||
const content = [];
|
||||
if (asComment(a)) {
|
||||
content.push(a.body);
|
||||
} else {
|
||||
if (criteria.testOn.includes('title')) {
|
||||
content.push(a.title);
|
||||
}
|
||||
if (criteria.testOn.includes('body') && a.is_self) {
|
||||
content.push(a.selftext);
|
||||
}
|
||||
}
|
||||
const mhsResult = await this.getMHSResponse(content.join(' '));
|
||||
|
||||
const {
|
||||
flagged,
|
||||
confidence
|
||||
} = criteria;
|
||||
|
||||
let flaggedPassed: boolean | undefined;
|
||||
let confPassed: boolean | undefined;
|
||||
|
||||
let summary = [];
|
||||
|
||||
if (confidence !== undefined) {
|
||||
const {operator, value} = confidence;
|
||||
confPassed = comparisonTextOp(mhsResult.confidence * 100, operator, value);
|
||||
summary.push(`Confidence test (${confidence.displayText}) ${confPassed ? 'PASSED' : 'DID NOT PASS'} MHS confidence of ${formatConfidence(mhsResult.confidence)}`)
|
||||
}
|
||||
|
||||
if (flagged !== undefined) {
|
||||
flaggedPassed = flagged ? mhsResult.class === 'flag' : mhsResult.class === 'normal';
|
||||
summary.push(`Flagged pass condition of ${flagged} (${flagged ? 'toxic' : 'normal'}) ${flaggedPassed ? 'MATCHED' : 'DID NOT MATCH'} MHS flag '${mhsResult.class === 'flag' ? 'toxic' : 'normal'}' ${confidence === undefined ? ` (${formatConfidence(mhsResult.confidence)} confidence)` : ''}`);
|
||||
}
|
||||
|
||||
const passed = (flaggedPassed === undefined || flaggedPassed) && (confPassed === undefined || confPassed);
|
||||
|
||||
return {
|
||||
activity: a,
|
||||
criteria,
|
||||
mhsResult,
|
||||
passed,
|
||||
summary: `${triggeredIndicator(passed)} ${summary.join(' | ')}`
|
||||
}
|
||||
}
|
||||
|
||||
protected async getMHSResponse(content: string): Promise<MHSResponse> {
|
||||
const hash = objectHash.sha1({content});
|
||||
const key = `mhs-${hash}`;
|
||||
if (this.resources.wikiTTL !== false) {
|
||||
let res = await this.resources.cache.get(key) as undefined | null | MHSResponse;
|
||||
if(res !== undefined && res !== null) {
|
||||
// don't cache bad responses
|
||||
if(res.response.toLowerCase() === 'success')
|
||||
{
|
||||
return res;
|
||||
}
|
||||
}
|
||||
res = await this.callMHS(content);
|
||||
if(res.response.toLowerCase() === 'success') {
|
||||
await this.resources.cache.set(key, res, {ttl: this.resources.wikiTTL});
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return this.callMHS(content);
|
||||
}
|
||||
|
||||
protected async callMHS(content: string): Promise<MHSResponse> {
|
||||
try {
|
||||
return await got.post(`https://api.moderatehatespeech.com/api/v1/moderate/`, {
|
||||
headers: {
|
||||
'Content-Type': `application/json`,
|
||||
},
|
||||
json: {
|
||||
token: this.resources.thirdPartyCredentials.mhs?.apiKey,
|
||||
text: content
|
||||
},
|
||||
}).json() as MHSResponse;
|
||||
} catch (err: any) {
|
||||
let error: string | undefined = undefined;
|
||||
if (err instanceof HTTPError) {
|
||||
error = err.response.statusMessage;
|
||||
if (typeof err.response.body === 'string') {
|
||||
error = `(${err.response.statusCode}) ${err.response.body}`;
|
||||
}
|
||||
}
|
||||
throw new CMError(`MHS request failed${error !== undefined ? ` with error: ${error}` : ''}`, {cause: err});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mhsCriteriaTestDisplay = (criteria: MHSCriteria) => {
|
||||
const summary = [];
|
||||
if (criteria.flagged !== undefined) {
|
||||
summary.push(`${criteria.flagged ? 'IS FLAGGED' : 'IS NOT FLAGGED'} as toxic`);
|
||||
}
|
||||
if (criteria.confidence !== undefined) {
|
||||
summary.push(`MHS confidence is ${criteria.confidence.displayText}`);
|
||||
}
|
||||
return summary.join(' AND ');
|
||||
}
|
||||
|
||||
interface MHSResponse {
|
||||
confidence: number
|
||||
response: string
|
||||
class: 'flag' | 'normal'
|
||||
}
|
||||
|
||||
interface MHSCriteriaResult {
|
||||
mhsResult: MHSResponse
|
||||
criteria: MHSCriteria
|
||||
passed: boolean
|
||||
summary: string,
|
||||
activity: SnoowrapActivity
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the content of Activities from the Author history against MHS criteria
|
||||
*
|
||||
* If this is defined then the `totalMatching` threshold must pass for the Rule to trigger
|
||||
*
|
||||
* If `criteria` is defined here it overrides the top-level `criteria` value
|
||||
*
|
||||
* */
|
||||
interface HistoricalMHSConfig {
|
||||
window: ActivityWindowConfig
|
||||
|
||||
criteria?: MHSCriteriaConfig
|
||||
|
||||
/**
|
||||
* When `true` the original Activity being checked MUST pass its criteria before the Rule considers any history
|
||||
*
|
||||
* @default false
|
||||
* */
|
||||
mustMatchCurrent?: boolean
|
||||
|
||||
/**
|
||||
* A string containing a comparison operator and a value to compare Activities from history that pass the given `criteria` test
|
||||
*
|
||||
* The syntax is `(< OR > OR <= OR >=) <number>[percent sign]`
|
||||
*
|
||||
* * EX `> 12` => greater than 12 activities passed given `criteria` test
|
||||
* * EX `<= 10%` => less than 10% of all Activities from history passed given `criteria` test
|
||||
*
|
||||
* @pattern ^\s*(>|>=|<|<=)\s*(\d+)\s*(%?)(.*)$
|
||||
* @default "> 0"
|
||||
* @examples ["> 0","> 10%"]
|
||||
* */
|
||||
totalMatching: string
|
||||
}
|
||||
|
||||
interface HistoricalMHS extends Omit<HistoricalMHSConfig, | 'window' | 'totalMatching' | 'criteria'> {
|
||||
window: ActivityWindowCriteria
|
||||
criteria: MHSCriteria
|
||||
totalMatching: GenericComparison
|
||||
}
|
||||
|
||||
/**
|
||||
* Criteria used to trigger based on MHS results
|
||||
*
|
||||
* If both `flagged` and `confidence` are specified then both conditions must pass.
|
||||
*
|
||||
* By default, only `flagged` is defined as `true`
|
||||
* */
|
||||
interface MHSCriteriaConfig {
|
||||
/**
|
||||
* Test if MHS considers content flagged as toxic or not
|
||||
*
|
||||
* @default true
|
||||
* */
|
||||
flagged?: boolean
|
||||
|
||||
/**
|
||||
* A string containing a comparison operator and a value to compare against the confidence returned from MHS
|
||||
*
|
||||
* The syntax is `(< OR > OR <= OR >=) <number>`
|
||||
*
|
||||
* * EX `> 50` => MHS confidence is greater than 50%
|
||||
*
|
||||
* @pattern ^\s*(>|>=|<|<=)\s*(\d+)\s*(%?)(.*)$
|
||||
* @examples ["> 50"]
|
||||
* */
|
||||
confidence?: string
|
||||
/**
|
||||
* Which content from an Activity to send to MHS
|
||||
*
|
||||
* Only used if the Activity being tested is a Submission -- Comments can be only tested against their body
|
||||
*
|
||||
* If more than one type of content is specified then all text is tested together as one string
|
||||
*
|
||||
* @default ["body"]
|
||||
* */
|
||||
testOn?: ('title' | 'body')[]
|
||||
}
|
||||
|
||||
interface MHSCriteria extends Omit<MHSCriteriaConfig, 'confidence'> {
|
||||
confidence?: GenericComparison
|
||||
testOn: ('title' | 'body')[]
|
||||
}
|
||||
|
||||
interface MHSConfig {
|
||||
|
||||
criteria?: MHSCriteriaConfig
|
||||
|
||||
/**
|
||||
* run MHS on Activities from the Author history
|
||||
*
|
||||
* If this is defined then the `totalMatching` threshold must pass for the Rule to trigger
|
||||
*
|
||||
* If `criteria` is defined here it overrides the top-level `criteria` value
|
||||
*
|
||||
* */
|
||||
historical?: HistoricalMHSConfig
|
||||
}
|
||||
|
||||
export interface MHSRuleOptions extends MHSConfig, RuleOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test content of an Activity against the MHS toxicity model for reddit content
|
||||
*
|
||||
* Running this Rule with no configuration will use a default configuration that will cause the Rule to trigger if MHS flags the content of the Activity as toxic.
|
||||
*
|
||||
* More info:
|
||||
*
|
||||
* * https://moderatehatespeech.com/docs/
|
||||
* * https://moderatehatespeech.com/
|
||||
*
|
||||
* */
|
||||
export interface MHSRuleJSONConfig extends MHSConfig, RuleJSONConfig {
|
||||
/**
|
||||
* @examples ["mhs"]
|
||||
* @default mhs
|
||||
* */
|
||||
kind: 'mhs'
|
||||
}
|
||||
|
||||
export default MHSRule;
|
||||
@@ -44,7 +44,6 @@ import {ActivityWindow, ActivityWindowConfig} from "../Common/Infrastructure/Act
|
||||
import {comparisonTextOp, parseGenericValueOrPercentComparison} from "../Common/Infrastructure/Comparisons";
|
||||
import {ImageHashCacheData} from "../Common/Infrastructure/Atomic";
|
||||
import {getSubredditBreakdownByActivityType} from "../Utils/SnoowrapUtils";
|
||||
import {CMError} from "../Utils/Errors";
|
||||
|
||||
const parseLink = parseUsableLinkIdentifier();
|
||||
|
||||
@@ -189,10 +188,8 @@ export class RecentActivityRule extends Rule {
|
||||
if (inferredSubmissionAsRef) {
|
||||
if (!asSubmission(item)) {
|
||||
this.logger.warn('Cannot use post as reference because triggered item is not a Submission');
|
||||
viableActivity = [];
|
||||
} else if (item.is_self) {
|
||||
this.logger.warn('Cannot use post as reference because triggered Submission is not a link type');
|
||||
viableActivity = [];
|
||||
} else {
|
||||
const itemId = item.id;
|
||||
const referenceUrl = await item.url;
|
||||
@@ -316,7 +313,7 @@ export class RecentActivityRule extends Rule {
|
||||
}
|
||||
} catch (err: any) {
|
||||
if(!err.message.includes('did not end with a valid image extension')) {
|
||||
this.logger.warn(new CMError(`Will not compare image from Submission ${x.id} due to error while parsing image URL`, {cause: err}));
|
||||
this.logger.warn(`Will not compare image from Submission ${x.id} due to error while parsing image URL => ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import {RepostRule, RepostRuleJSONConfig} from "./RepostRule";
|
||||
import {StructuredFilter} from "../Common/Infrastructure/Filters/FilterShapes";
|
||||
import {SentimentRule, SentimentRuleJSONConfig} from "./SentimentRule";
|
||||
import {StructuredRuleConfigObject} from "../Common/Infrastructure/RuleShapes";
|
||||
import {MHSRuleJSONConfig, MHSRule} from "./MHSRule";
|
||||
|
||||
export function ruleFactory
|
||||
(config: StructuredRuleConfigObject, logger: Logger, subredditName: string, resources: SubredditResources, client: Snoowrap): Rule {
|
||||
@@ -43,9 +42,6 @@ export function ruleFactory
|
||||
case 'sentiment':
|
||||
cfg = config as StructuredFilter<SentimentRuleJSONConfig>;
|
||||
return new SentimentRule({...cfg, logger, subredditName, resources, client});
|
||||
case 'mhs':
|
||||
cfg = config as StructuredFilter<MHSRuleJSONConfig>;
|
||||
return new MHSRule({...cfg, logger, subredditName, resources, client});
|
||||
default:
|
||||
throw new Error(`Rule with kind '${config.kind}' was not recognized.`);
|
||||
}
|
||||
|
||||
@@ -185,5 +185,5 @@ export interface RuleJSONConfig extends IRule {
|
||||
* The kind of rule to run
|
||||
* @examples ["recentActivity", "repeatActivity", "author", "attribution", "history"]
|
||||
*/
|
||||
kind: 'recentActivity' | 'repeatActivity' | 'author' | 'attribution' | 'history' | 'regex' | 'repost' | 'sentiment' | 'mhs'
|
||||
kind: 'recentActivity' | 'repeatActivity' | 'author' | 'attribution' | 'history' | 'regex' | 'repost' | 'sentiment'
|
||||
}
|
||||
|
||||
@@ -764,88 +764,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1785,18 +1703,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1835,9 +1753,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -1884,6 +1799,14 @@
|
||||
"ModNoteActionJson": {
|
||||
"description": "Add a Toolbox User Note to the Author of this Activity",
|
||||
"properties": {
|
||||
"allowDuplicate": {
|
||||
"default": false,
|
||||
"description": "Add Note even if a Note already exists for this Activity",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -1934,21 +1857,6 @@
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"existingNoteCheck": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModNoteCriteria"
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
],
|
||||
"default": true,
|
||||
"description": "Check if there is an existing Note matching some criteria before adding the Note.\n\nIf this check passes then the Note is added. The value may be a boolean or ModNoteCriteria.\n\nBoolean convenience:\n\n* If `true` or undefined then CM generates a ModNoteCriteria that passes only if there is NO existing note matching note criteria\n* If `false` then no check is performed and Note is always added",
|
||||
"examples": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -2021,18 +1929,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2091,9 +1999,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -2603,88 +2508,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -2735,23 +2558,6 @@
|
||||
"is_self": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"link_flair_background_color": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"link_flair_css_class": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -2767,7 +2573,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
|
||||
},
|
||||
"link_flair_text": {
|
||||
"anyOf": [
|
||||
@@ -2784,7 +2590,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
|
||||
},
|
||||
"locked": {
|
||||
"type": "boolean"
|
||||
|
||||
@@ -28,88 +28,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1718,9 +1636,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/RuleSetConfigData"
|
||||
},
|
||||
@@ -1772,88 +1687,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -2921,55 +2754,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalMHSConfig": {
|
||||
"description": "Test the content of Activities from the Author history against MHS criteria\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value",
|
||||
"properties": {
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"mustMatchCurrent": {
|
||||
"default": false,
|
||||
"description": "When `true` the original Activity being checked MUST pass its criteria before the Rule considers any history",
|
||||
"type": "boolean"
|
||||
},
|
||||
"totalMatching": {
|
||||
"default": "> 0",
|
||||
"description": "A string containing a comparison operator and a value to compare Activities from history that pass the given `criteria` test\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities passed given `criteria` test\n* EX `<= 10%` => less than 10% of all Activities from history passed given `criteria` test",
|
||||
"examples": [
|
||||
"> 0",
|
||||
"> 10%"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"totalMatching",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalSentimentConfig": {
|
||||
"description": "Test the Sentiment of Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `sentiment` is defined here it overrides the top-level `sentiment` value",
|
||||
"properties": {
|
||||
@@ -3040,40 +2824,6 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"ratio": {
|
||||
"properties": {
|
||||
"threshold": {
|
||||
"description": "A string containing a comparison operator and a value to compare number of parent criteria activities against number of \"ratio\" activities\n\nThis comparison is always done as (number of parent criteria activities) / (number of ratio activities)\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 1.2` => There are 1.2 activities from parent criteria for every 1 ratio activities\n* EX `<= 75%` => There are equal to or less than 0.75 activities from parent criteria for every 1 ratio activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*((?:\\d+)(?:(?:(?:.|,)\\d+)+)?)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threshold",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"submission": {
|
||||
"description": "A string containing a comparison operator and a value to compare **filtered** (using `include` or `exclude`, if present) submissions against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 100` => greater than 100 filtered submissions\n* EX `<= 75%` => filtered submissions are equal to or less than 75% of unfiltered Activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
@@ -3473,126 +3223,6 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MHSCriteriaConfig": {
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`",
|
||||
"properties": {
|
||||
"confidence": {
|
||||
"description": "A string containing a comparison operator and a value to compare against the confidence returned from MHS\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 50` => MHS confidence is greater than 50%",
|
||||
"examples": [
|
||||
"> 50"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"flagged": {
|
||||
"default": true,
|
||||
"description": "Test if MHS considers content flagged as toxic or not",
|
||||
"type": "boolean"
|
||||
},
|
||||
"testOn": {
|
||||
"default": [
|
||||
"body"
|
||||
],
|
||||
"description": "Which content from an Activity to send to MHS\n\nOnly used if the Activity being tested is a Submission -- Comments can be only tested against their body\n\nIf more than one type of content is specified then all text is tested together as one string",
|
||||
"items": {
|
||||
"enum": [
|
||||
"body",
|
||||
"title"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"MHSRuleJSONConfig": {
|
||||
"description": "Test content of an Activity against the MHS toxicity model for reddit content\n\nRunning this Rule with no configuration will use a default configuration that will cause the Rule to trigger if MHS flags the content of the Activity as toxic.\n\nMore info:\n\n* https://moderatehatespeech.com/docs/\n* https://moderatehatespeech.com/",
|
||||
"properties": {
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AuthorCriteria"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<AuthorCriteria>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<AuthorCriteria>"
|
||||
}
|
||||
],
|
||||
"description": "If present then these Author criteria are checked before running the Check. If criteria fails then the Check will fail."
|
||||
},
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"historical": {
|
||||
"$ref": "#/definitions/HistoricalMHSConfig",
|
||||
"description": "run MHS on Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value"
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/SubmissionState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/CommentState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<TypedActivityState>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<TypedActivityState>"
|
||||
}
|
||||
],
|
||||
"description": "A list of criteria to test the state of the `Activity` against before running the check.\n\nIf any set of criteria passes the Check will be run. If the criteria fails then the Check will fail.\n\n* @examples [[{\"over_18\": true, \"removed': false}]]"
|
||||
},
|
||||
"kind": {
|
||||
"default": "mhs",
|
||||
"description": "The kind of rule to run",
|
||||
"enum": [
|
||||
"mhs"
|
||||
],
|
||||
"examples": [
|
||||
"mhs"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "An optional, but highly recommended, friendly name for this rule. If not present will default to `kind`.\n\nCan only contain letters, numbers, underscore, spaces, and dashes\n\nname is used to reference Rule result data during Action content templating. See CommentAction or ReportAction for more details.",
|
||||
"examples": [
|
||||
"myNewRule"
|
||||
],
|
||||
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"kind"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MessageActionJson": {
|
||||
"description": "Send a private message to the Author of the Activity.",
|
||||
"properties": {
|
||||
@@ -3744,18 +3374,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -3794,9 +3424,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -3843,6 +3470,14 @@
|
||||
"ModNoteActionJson": {
|
||||
"description": "Add a Toolbox User Note to the Author of this Activity",
|
||||
"properties": {
|
||||
"allowDuplicate": {
|
||||
"default": false,
|
||||
"description": "Add Note even if a Note already exists for this Activity",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3893,21 +3528,6 @@
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"existingNoteCheck": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModNoteCriteria"
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
],
|
||||
"default": true,
|
||||
"description": "Check if there is an existing Note matching some criteria before adding the Note.\n\nIf this check passes then the Note is added. The value may be a boolean or ModNoteCriteria.\n\nBoolean convenience:\n\n* If `true` or undefined then CM generates a ModNoteCriteria that passes only if there is NO existing note matching note criteria\n* If `false` then no check is performed and Note is always added",
|
||||
"examples": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3980,18 +3600,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -4050,9 +3670,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -5551,9 +5168,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
@@ -6347,9 +5961,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/RuleSetConfigData"
|
||||
},
|
||||
@@ -6401,88 +6012,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -6533,23 +6062,6 @@
|
||||
"is_self": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"link_flair_background_color": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"link_flair_css_class": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -6565,7 +6077,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
|
||||
},
|
||||
"link_flair_text": {
|
||||
"anyOf": [
|
||||
@@ -6582,7 +6094,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
|
||||
},
|
||||
"locked": {
|
||||
"type": "boolean"
|
||||
@@ -6711,17 +6223,6 @@
|
||||
"ThirdPartyCredentialsJsonConfig": {
|
||||
"additionalProperties": {},
|
||||
"properties": {
|
||||
"mhs": {
|
||||
"properties": {
|
||||
"apiKey": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"apiKey"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"youtube": {
|
||||
"properties": {
|
||||
"apiKey": {
|
||||
|
||||
@@ -42,88 +42,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1541,9 +1459,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/RuleSetConfigData"
|
||||
},
|
||||
@@ -1595,88 +1510,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -2635,55 +2468,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalMHSConfig": {
|
||||
"description": "Test the content of Activities from the Author history against MHS criteria\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value",
|
||||
"properties": {
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"mustMatchCurrent": {
|
||||
"default": false,
|
||||
"description": "When `true` the original Activity being checked MUST pass its criteria before the Rule considers any history",
|
||||
"type": "boolean"
|
||||
},
|
||||
"totalMatching": {
|
||||
"default": "> 0",
|
||||
"description": "A string containing a comparison operator and a value to compare Activities from history that pass the given `criteria` test\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities passed given `criteria` test\n* EX `<= 10%` => less than 10% of all Activities from history passed given `criteria` test",
|
||||
"examples": [
|
||||
"> 0",
|
||||
"> 10%"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"totalMatching",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalSentimentConfig": {
|
||||
"description": "Test the Sentiment of Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `sentiment` is defined here it overrides the top-level `sentiment` value",
|
||||
"properties": {
|
||||
@@ -2754,40 +2538,6 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"ratio": {
|
||||
"properties": {
|
||||
"threshold": {
|
||||
"description": "A string containing a comparison operator and a value to compare number of parent criteria activities against number of \"ratio\" activities\n\nThis comparison is always done as (number of parent criteria activities) / (number of ratio activities)\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 1.2` => There are 1.2 activities from parent criteria for every 1 ratio activities\n* EX `<= 75%` => There are equal to or less than 0.75 activities from parent criteria for every 1 ratio activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*((?:\\d+)(?:(?:(?:.|,)\\d+)+)?)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threshold",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"submission": {
|
||||
"description": "A string containing a comparison operator and a value to compare **filtered** (using `include` or `exclude`, if present) submissions against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 100` => greater than 100 filtered submissions\n* EX `<= 75%` => filtered submissions are equal to or less than 75% of unfiltered Activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
@@ -3187,126 +2937,6 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MHSCriteriaConfig": {
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`",
|
||||
"properties": {
|
||||
"confidence": {
|
||||
"description": "A string containing a comparison operator and a value to compare against the confidence returned from MHS\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 50` => MHS confidence is greater than 50%",
|
||||
"examples": [
|
||||
"> 50"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"flagged": {
|
||||
"default": true,
|
||||
"description": "Test if MHS considers content flagged as toxic or not",
|
||||
"type": "boolean"
|
||||
},
|
||||
"testOn": {
|
||||
"default": [
|
||||
"body"
|
||||
],
|
||||
"description": "Which content from an Activity to send to MHS\n\nOnly used if the Activity being tested is a Submission -- Comments can be only tested against their body\n\nIf more than one type of content is specified then all text is tested together as one string",
|
||||
"items": {
|
||||
"enum": [
|
||||
"body",
|
||||
"title"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"MHSRuleJSONConfig": {
|
||||
"description": "Test content of an Activity against the MHS toxicity model for reddit content\n\nRunning this Rule with no configuration will use a default configuration that will cause the Rule to trigger if MHS flags the content of the Activity as toxic.\n\nMore info:\n\n* https://moderatehatespeech.com/docs/\n* https://moderatehatespeech.com/",
|
||||
"properties": {
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AuthorCriteria"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<AuthorCriteria>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<AuthorCriteria>"
|
||||
}
|
||||
],
|
||||
"description": "If present then these Author criteria are checked before running the Check. If criteria fails then the Check will fail."
|
||||
},
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"historical": {
|
||||
"$ref": "#/definitions/HistoricalMHSConfig",
|
||||
"description": "run MHS on Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value"
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/SubmissionState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/CommentState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<TypedActivityState>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<TypedActivityState>"
|
||||
}
|
||||
],
|
||||
"description": "A list of criteria to test the state of the `Activity` against before running the check.\n\nIf any set of criteria passes the Check will be run. If the criteria fails then the Check will fail.\n\n* @examples [[{\"over_18\": true, \"removed': false}]]"
|
||||
},
|
||||
"kind": {
|
||||
"default": "mhs",
|
||||
"description": "The kind of rule to run",
|
||||
"enum": [
|
||||
"mhs"
|
||||
],
|
||||
"examples": [
|
||||
"mhs"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "An optional, but highly recommended, friendly name for this rule. If not present will default to `kind`.\n\nCan only contain letters, numbers, underscore, spaces, and dashes\n\nname is used to reference Rule result data during Action content templating. See CommentAction or ReportAction for more details.",
|
||||
"examples": [
|
||||
"myNewRule"
|
||||
],
|
||||
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"kind"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MessageActionJson": {
|
||||
"description": "Send a private message to the Author of the Activity.",
|
||||
"properties": {
|
||||
@@ -3458,18 +3088,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -3508,9 +3138,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -3557,6 +3184,14 @@
|
||||
"ModNoteActionJson": {
|
||||
"description": "Add a Toolbox User Note to the Author of this Activity",
|
||||
"properties": {
|
||||
"allowDuplicate": {
|
||||
"default": false,
|
||||
"description": "Add Note even if a Note already exists for this Activity",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3607,21 +3242,6 @@
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"existingNoteCheck": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModNoteCriteria"
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
],
|
||||
"default": true,
|
||||
"description": "Check if there is an existing Note matching some criteria before adding the Note.\n\nIf this check passes then the Note is added. The value may be a boolean or ModNoteCriteria.\n\nBoolean convenience:\n\n* If `true` or undefined then CM generates a ModNoteCriteria that passes only if there is NO existing note matching note criteria\n* If `false` then no check is performed and Note is always added",
|
||||
"examples": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3694,18 +3314,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -3764,9 +3384,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -5125,9 +4742,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
@@ -5791,9 +5405,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/RuleSetConfigData"
|
||||
},
|
||||
@@ -5845,88 +5456,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -5977,23 +5506,6 @@
|
||||
"is_self": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"link_flair_background_color": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"link_flair_css_class": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -6009,7 +5521,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
|
||||
},
|
||||
"link_flair_text": {
|
||||
"anyOf": [
|
||||
@@ -6026,7 +5538,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
|
||||
},
|
||||
"locked": {
|
||||
"type": "boolean"
|
||||
|
||||
@@ -187,17 +187,6 @@
|
||||
},
|
||||
"BotCredentialsJsonConfig": {
|
||||
"properties": {
|
||||
"mhs": {
|
||||
"properties": {
|
||||
"apiKey": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"apiKey"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"reddit": {
|
||||
"$ref": "#/definitions/RedditCredentials"
|
||||
},
|
||||
@@ -534,88 +523,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1028,7 +935,7 @@
|
||||
"file": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"options\"|\"dirname\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">"
|
||||
"$ref": "#/definitions/Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"dirname\"|\"options\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
@@ -1133,18 +1040,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1183,9 +1090,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -1237,18 +1141,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1307,9 +1211,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -1481,7 +1382,7 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"options\"|\"dirname\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">": {
|
||||
"Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"dirname\"|\"options\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">": {
|
||||
"properties": {
|
||||
"auditFile": {
|
||||
"description": "A string representing the name of the name of the audit file. (default: './hash-audit.json')",
|
||||
@@ -1934,88 +1835,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -2066,23 +1885,6 @@
|
||||
"is_self": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"link_flair_background_color": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"link_flair_css_class": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -2098,7 +1900,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
|
||||
},
|
||||
"link_flair_text": {
|
||||
"anyOf": [
|
||||
@@ -2115,7 +1917,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
|
||||
},
|
||||
"locked": {
|
||||
"type": "boolean"
|
||||
@@ -2247,17 +2049,6 @@
|
||||
"ThirdPartyCredentialsJsonConfig": {
|
||||
"additionalProperties": {},
|
||||
"properties": {
|
||||
"mhs": {
|
||||
"properties": {
|
||||
"apiKey": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"apiKey"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"youtube": {
|
||||
"properties": {
|
||||
"apiKey": {
|
||||
|
||||
@@ -28,9 +28,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
@@ -63,88 +60,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -849,88 +764,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1484,55 +1317,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalMHSConfig": {
|
||||
"description": "Test the content of Activities from the Author history against MHS criteria\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value",
|
||||
"properties": {
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"mustMatchCurrent": {
|
||||
"default": false,
|
||||
"description": "When `true` the original Activity being checked MUST pass its criteria before the Rule considers any history",
|
||||
"type": "boolean"
|
||||
},
|
||||
"totalMatching": {
|
||||
"default": "> 0",
|
||||
"description": "A string containing a comparison operator and a value to compare Activities from history that pass the given `criteria` test\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities passed given `criteria` test\n* EX `<= 10%` => less than 10% of all Activities from history passed given `criteria` test",
|
||||
"examples": [
|
||||
"> 0",
|
||||
"> 10%"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"totalMatching",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalSentimentConfig": {
|
||||
"description": "Test the Sentiment of Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `sentiment` is defined here it overrides the top-level `sentiment` value",
|
||||
"properties": {
|
||||
@@ -1603,40 +1387,6 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"ratio": {
|
||||
"properties": {
|
||||
"threshold": {
|
||||
"description": "A string containing a comparison operator and a value to compare number of parent criteria activities against number of \"ratio\" activities\n\nThis comparison is always done as (number of parent criteria activities) / (number of ratio activities)\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 1.2` => There are 1.2 activities from parent criteria for every 1 ratio activities\n* EX `<= 75%` => There are equal to or less than 0.75 activities from parent criteria for every 1 ratio activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*((?:\\d+)(?:(?:(?:.|,)\\d+)+)?)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threshold",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"submission": {
|
||||
"description": "A string containing a comparison operator and a value to compare **filtered** (using `include` or `exclude`, if present) submissions against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 100` => greater than 100 filtered submissions\n* EX `<= 75%` => filtered submissions are equal to or less than 75% of unfiltered Activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
@@ -1944,126 +1694,6 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MHSCriteriaConfig": {
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`",
|
||||
"properties": {
|
||||
"confidence": {
|
||||
"description": "A string containing a comparison operator and a value to compare against the confidence returned from MHS\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 50` => MHS confidence is greater than 50%",
|
||||
"examples": [
|
||||
"> 50"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"flagged": {
|
||||
"default": true,
|
||||
"description": "Test if MHS considers content flagged as toxic or not",
|
||||
"type": "boolean"
|
||||
},
|
||||
"testOn": {
|
||||
"default": [
|
||||
"body"
|
||||
],
|
||||
"description": "Which content from an Activity to send to MHS\n\nOnly used if the Activity being tested is a Submission -- Comments can be only tested against their body\n\nIf more than one type of content is specified then all text is tested together as one string",
|
||||
"items": {
|
||||
"enum": [
|
||||
"body",
|
||||
"title"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"MHSRuleJSONConfig": {
|
||||
"description": "Test content of an Activity against the MHS toxicity model for reddit content\n\nRunning this Rule with no configuration will use a default configuration that will cause the Rule to trigger if MHS flags the content of the Activity as toxic.\n\nMore info:\n\n* https://moderatehatespeech.com/docs/\n* https://moderatehatespeech.com/",
|
||||
"properties": {
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AuthorCriteria"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<AuthorCriteria>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<AuthorCriteria>"
|
||||
}
|
||||
],
|
||||
"description": "If present then these Author criteria are checked before running the Check. If criteria fails then the Check will fail."
|
||||
},
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"historical": {
|
||||
"$ref": "#/definitions/HistoricalMHSConfig",
|
||||
"description": "run MHS on Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value"
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/SubmissionState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/CommentState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<TypedActivityState>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<TypedActivityState>"
|
||||
}
|
||||
],
|
||||
"description": "A list of criteria to test the state of the `Activity` against before running the check.\n\nIf any set of criteria passes the Check will be run. If the criteria fails then the Check will fail.\n\n* @examples [[{\"over_18\": true, \"removed': false}]]"
|
||||
},
|
||||
"kind": {
|
||||
"default": "mhs",
|
||||
"description": "The kind of rule to run",
|
||||
"enum": [
|
||||
"mhs"
|
||||
],
|
||||
"examples": [
|
||||
"mhs"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "An optional, but highly recommended, friendly name for this rule. If not present will default to `kind`.\n\nCan only contain letters, numbers, underscore, spaces, and dashes\n\nname is used to reference Rule result data during Action content templating. See CommentAction or ReportAction for more details.",
|
||||
"examples": [
|
||||
"myNewRule"
|
||||
],
|
||||
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"kind"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ModLogCriteria": {
|
||||
"properties": {
|
||||
"action": {
|
||||
@@ -2085,18 +1715,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2135,9 +1765,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -2189,18 +1816,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2259,9 +1886,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -3618,88 +3242,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -3750,23 +3292,6 @@
|
||||
"is_self": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"link_flair_background_color": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"link_flair_css_class": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3782,7 +3307,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
|
||||
},
|
||||
"link_flair_text": {
|
||||
"anyOf": [
|
||||
@@ -3799,7 +3324,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
|
||||
},
|
||||
"locked": {
|
||||
"type": "boolean"
|
||||
|
||||
@@ -28,88 +28,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -814,88 +732,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1449,55 +1285,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalMHSConfig": {
|
||||
"description": "Test the content of Activities from the Author history against MHS criteria\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value",
|
||||
"properties": {
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"mustMatchCurrent": {
|
||||
"default": false,
|
||||
"description": "When `true` the original Activity being checked MUST pass its criteria before the Rule considers any history",
|
||||
"type": "boolean"
|
||||
},
|
||||
"totalMatching": {
|
||||
"default": "> 0",
|
||||
"description": "A string containing a comparison operator and a value to compare Activities from history that pass the given `criteria` test\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities passed given `criteria` test\n* EX `<= 10%` => less than 10% of all Activities from history passed given `criteria` test",
|
||||
"examples": [
|
||||
"> 0",
|
||||
"> 10%"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"totalMatching",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalSentimentConfig": {
|
||||
"description": "Test the Sentiment of Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `sentiment` is defined here it overrides the top-level `sentiment` value",
|
||||
"properties": {
|
||||
@@ -1568,40 +1355,6 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"ratio": {
|
||||
"properties": {
|
||||
"threshold": {
|
||||
"description": "A string containing a comparison operator and a value to compare number of parent criteria activities against number of \"ratio\" activities\n\nThis comparison is always done as (number of parent criteria activities) / (number of ratio activities)\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 1.2` => There are 1.2 activities from parent criteria for every 1 ratio activities\n* EX `<= 75%` => There are equal to or less than 0.75 activities from parent criteria for every 1 ratio activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*((?:\\d+)(?:(?:(?:.|,)\\d+)+)?)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threshold",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"submission": {
|
||||
"description": "A string containing a comparison operator and a value to compare **filtered** (using `include` or `exclude`, if present) submissions against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 100` => greater than 100 filtered submissions\n* EX `<= 75%` => filtered submissions are equal to or less than 75% of unfiltered Activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
@@ -1909,126 +1662,6 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MHSCriteriaConfig": {
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`",
|
||||
"properties": {
|
||||
"confidence": {
|
||||
"description": "A string containing a comparison operator and a value to compare against the confidence returned from MHS\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 50` => MHS confidence is greater than 50%",
|
||||
"examples": [
|
||||
"> 50"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"flagged": {
|
||||
"default": true,
|
||||
"description": "Test if MHS considers content flagged as toxic or not",
|
||||
"type": "boolean"
|
||||
},
|
||||
"testOn": {
|
||||
"default": [
|
||||
"body"
|
||||
],
|
||||
"description": "Which content from an Activity to send to MHS\n\nOnly used if the Activity being tested is a Submission -- Comments can be only tested against their body\n\nIf more than one type of content is specified then all text is tested together as one string",
|
||||
"items": {
|
||||
"enum": [
|
||||
"body",
|
||||
"title"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"MHSRuleJSONConfig": {
|
||||
"description": "Test content of an Activity against the MHS toxicity model for reddit content\n\nRunning this Rule with no configuration will use a default configuration that will cause the Rule to trigger if MHS flags the content of the Activity as toxic.\n\nMore info:\n\n* https://moderatehatespeech.com/docs/\n* https://moderatehatespeech.com/",
|
||||
"properties": {
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AuthorCriteria"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<AuthorCriteria>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<AuthorCriteria>"
|
||||
}
|
||||
],
|
||||
"description": "If present then these Author criteria are checked before running the Check. If criteria fails then the Check will fail."
|
||||
},
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"historical": {
|
||||
"$ref": "#/definitions/HistoricalMHSConfig",
|
||||
"description": "run MHS on Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value"
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/SubmissionState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/CommentState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<TypedActivityState>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<TypedActivityState>"
|
||||
}
|
||||
],
|
||||
"description": "A list of criteria to test the state of the `Activity` against before running the check.\n\nIf any set of criteria passes the Check will be run. If the criteria fails then the Check will fail.\n\n* @examples [[{\"over_18\": true, \"removed': false}]]"
|
||||
},
|
||||
"kind": {
|
||||
"default": "mhs",
|
||||
"description": "The kind of rule to run",
|
||||
"enum": [
|
||||
"mhs"
|
||||
],
|
||||
"examples": [
|
||||
"mhs"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "An optional, but highly recommended, friendly name for this rule. If not present will default to `kind`.\n\nCan only contain letters, numbers, underscore, spaces, and dashes\n\nname is used to reference Rule result data during Action content templating. See CommentAction or ReportAction for more details.",
|
||||
"examples": [
|
||||
"myNewRule"
|
||||
],
|
||||
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"kind"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"ModLogCriteria": {
|
||||
"properties": {
|
||||
"action": {
|
||||
@@ -2050,18 +1683,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2100,9 +1733,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -2154,18 +1784,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -2224,9 +1854,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -3583,88 +3210,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -3715,23 +3260,6 @@
|
||||
"is_self": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"link_flair_background_color": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"link_flair_css_class": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3747,7 +3275,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
|
||||
},
|
||||
"link_flair_text": {
|
||||
"anyOf": [
|
||||
@@ -3764,7 +3292,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
|
||||
},
|
||||
"locked": {
|
||||
"type": "boolean"
|
||||
@@ -3982,9 +3510,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
|
||||
@@ -39,88 +39,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -1538,9 +1456,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/RuleSetConfigData"
|
||||
},
|
||||
@@ -1592,88 +1507,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -2702,55 +2535,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalMHSConfig": {
|
||||
"description": "Test the content of Activities from the Author history against MHS criteria\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value",
|
||||
"properties": {
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"mustMatchCurrent": {
|
||||
"default": false,
|
||||
"description": "When `true` the original Activity being checked MUST pass its criteria before the Rule considers any history",
|
||||
"type": "boolean"
|
||||
},
|
||||
"totalMatching": {
|
||||
"default": "> 0",
|
||||
"description": "A string containing a comparison operator and a value to compare Activities from history that pass the given `criteria` test\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities passed given `criteria` test\n* EX `<= 10%` => less than 10% of all Activities from history passed given `criteria` test",
|
||||
"examples": [
|
||||
"> 0",
|
||||
"> 10%"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"totalMatching",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"HistoricalSentimentConfig": {
|
||||
"description": "Test the Sentiment of Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `sentiment` is defined here it overrides the top-level `sentiment` value",
|
||||
"properties": {
|
||||
@@ -2821,40 +2605,6 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"ratio": {
|
||||
"properties": {
|
||||
"threshold": {
|
||||
"description": "A string containing a comparison operator and a value to compare number of parent criteria activities against number of \"ratio\" activities\n\nThis comparison is always done as (number of parent criteria activities) / (number of ratio activities)\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 1.2` => There are 1.2 activities from parent criteria for every 1 ratio activities\n* EX `<= 75%` => There are equal to or less than 0.75 activities from parent criteria for every 1 ratio activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*((?:\\d+)(?:(?:(?:.|,)\\d+)+)?)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"window": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DurationObject"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FullActivityWindowConfig"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "A value to define the range of Activities to retrieve.\n\nAcceptable values:\n\n**`ActivityWindowCriteria` object**\n\nAllows specify multiple range properties and more specific behavior\n\n**A `number` of Activities to retrieve**\n\n* EX `100` => 100 Activities\n\n*****\n\nAny of the below values that specify the amount of time to subtract from `NOW` to create a time range IE `NOW <---> [duration] ago`\n\nAcceptable values:\n\n**A `string` consisting of a value and a [Day.js](https://day.js.org/docs/en/durations/creating#list-of-all-available-units) time UNIT**\n\n* EX `9 days` => Range is `NOW <---> 9 days ago`\n\n**A [Day.js](https://day.js.org/docs/en/durations/creating) `object`**\n\n* EX `{\"days\": 90, \"minutes\": 15}` => Range is `NOW <---> 90 days and 15 minutes ago`\n\n**An [ISO 8601 duration](https://en.wikipedia.org/wiki/ISO_8601#Durations) `string`**\n\n* EX `PT15M` => 15 minutes => Range is `NOW <----> 15 minutes ago`",
|
||||
"examples": [
|
||||
"90 days"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"threshold",
|
||||
"window"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"submission": {
|
||||
"description": "A string containing a comparison operator and a value to compare **filtered** (using `include` or `exclude`, if present) submissions against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 100` => greater than 100 filtered submissions\n* EX `<= 75%` => filtered submissions are equal to or less than 75% of unfiltered Activities",
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
@@ -3254,126 +3004,6 @@
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MHSCriteriaConfig": {
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`",
|
||||
"properties": {
|
||||
"confidence": {
|
||||
"description": "A string containing a comparison operator and a value to compare against the confidence returned from MHS\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 50` => MHS confidence is greater than 50%",
|
||||
"examples": [
|
||||
"> 50"
|
||||
],
|
||||
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
|
||||
"type": "string"
|
||||
},
|
||||
"flagged": {
|
||||
"default": true,
|
||||
"description": "Test if MHS considers content flagged as toxic or not",
|
||||
"type": "boolean"
|
||||
},
|
||||
"testOn": {
|
||||
"default": [
|
||||
"body"
|
||||
],
|
||||
"description": "Which content from an Activity to send to MHS\n\nOnly used if the Activity being tested is a Submission -- Comments can be only tested against their body\n\nIf more than one type of content is specified then all text is tested together as one string",
|
||||
"items": {
|
||||
"enum": [
|
||||
"body",
|
||||
"title"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"MHSRuleJSONConfig": {
|
||||
"description": "Test content of an Activity against the MHS toxicity model for reddit content\n\nRunning this Rule with no configuration will use a default configuration that will cause the Rule to trigger if MHS flags the content of the Activity as toxic.\n\nMore info:\n\n* https://moderatehatespeech.com/docs/\n* https://moderatehatespeech.com/",
|
||||
"properties": {
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AuthorCriteria"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<AuthorCriteria>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<AuthorCriteria>"
|
||||
}
|
||||
],
|
||||
"description": "If present then these Author criteria are checked before running the Check. If criteria fails then the Check will fail."
|
||||
},
|
||||
"criteria": {
|
||||
"$ref": "#/definitions/MHSCriteriaConfig",
|
||||
"description": "Criteria used to trigger based on MHS results\n\nIf both `flagged` and `confidence` are specified then both conditions must pass.\n\nBy default, only `flagged` is defined as `true`"
|
||||
},
|
||||
"historical": {
|
||||
"$ref": "#/definitions/HistoricalMHSConfig",
|
||||
"description": "run MHS on Activities from the Author history\n\nIf this is defined then the `totalMatching` threshold must pass for the Rule to trigger\n\nIf `criteria` is defined here it overrides the top-level `criteria` value"
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/SubmissionState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/CommentState"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NamedCriteria<TypedActivityState>"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/FilterOptionsJson<TypedActivityState>"
|
||||
}
|
||||
],
|
||||
"description": "A list of criteria to test the state of the `Activity` against before running the check.\n\nIf any set of criteria passes the Check will be run. If the criteria fails then the Check will fail.\n\n* @examples [[{\"over_18\": true, \"removed': false}]]"
|
||||
},
|
||||
"kind": {
|
||||
"default": "mhs",
|
||||
"description": "The kind of rule to run",
|
||||
"enum": [
|
||||
"mhs"
|
||||
],
|
||||
"examples": [
|
||||
"mhs"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "An optional, but highly recommended, friendly name for this rule. If not present will default to `kind`.\n\nCan only contain letters, numbers, underscore, spaces, and dashes\n\nname is used to reference Rule result data during Action content templating. See CommentAction or ReportAction for more details.",
|
||||
"examples": [
|
||||
"myNewRule"
|
||||
],
|
||||
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"kind"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"MessageActionJson": {
|
||||
"description": "Send a private message to the Author of the Activity.",
|
||||
"properties": {
|
||||
@@ -3525,18 +3155,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -3575,9 +3205,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -3624,6 +3251,14 @@
|
||||
"ModNoteActionJson": {
|
||||
"description": "Add a Toolbox User Note to the Author of this Activity",
|
||||
"properties": {
|
||||
"allowDuplicate": {
|
||||
"default": false,
|
||||
"description": "Add Note even if a Note already exists for this Activity",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"authorIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3674,21 +3309,6 @@
|
||||
],
|
||||
"type": "boolean"
|
||||
},
|
||||
"existingNoteCheck": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModNoteCriteria"
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
],
|
||||
"default": true,
|
||||
"description": "Check if there is an existing Note matching some criteria before adding the Note.\n\nIf this check passes then the Note is added. The value may be a boolean or ModNoteCriteria.\n\nBoolean convenience:\n\n* If `true` or undefined then CM generates a ModNoteCriteria that passes only if there is NO existing note matching note criteria\n* If `false` then no check is performed and Note is always added",
|
||||
"examples": [
|
||||
true
|
||||
]
|
||||
},
|
||||
"itemIs": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -3761,18 +3381,18 @@
|
||||
"items": {
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"comment",
|
||||
false,
|
||||
"submission"
|
||||
]
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -3831,9 +3451,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"referencesCurrentActivity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search": {
|
||||
"default": "current",
|
||||
"description": "How to test the Toolbox Notes or Mod Actions for this Author:\n\n### current\n\nOnly the most recent note is checked for criteria\n\n### total\n\n`count` comparison of mod actions/notes must be found within all history\n\n* EX `count: > 3` => Must have more than 3 notes of `type`, total\n* EX `count: <= 25%` => Must have 25% or less of notes of `type`, total\n* EX: `count: > 3 in 1 week` => Must have more than 3 notes within the last week\n\n### consecutive\n\nThe `count` **number** of mod actions/notes must be found in a row.\n\nYou may also specify the time-based order in which to search the notes by specifying `ascending (asc)` or `descending (desc)` in the `count` value. Default is `descending`\n\n* EX `count: >= 3` => Must have 3 or more notes of `type` consecutively, in descending order\n* EX `count: < 2` => Must have less than 2 notes of `type` consecutively, in descending order\n* EX `count: > 4 asc` => Must have greater than 4 notes of `type` consecutively, in ascending order",
|
||||
@@ -5192,9 +4809,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
@@ -5988,9 +5602,6 @@
|
||||
{
|
||||
"$ref": "#/definitions/SentimentRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MHSRuleJSONConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/RuleSetConfigData"
|
||||
},
|
||||
@@ -6042,88 +5653,6 @@
|
||||
],
|
||||
"description": "* true/false => test whether Activity is approved or not\n* string or list of strings => test which moderator approved this Activity"
|
||||
},
|
||||
"authorFlairBackgroundColor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairCssClass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY class\n* If `false` then passes if NO class\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairTemplateId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then template id is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"authorFlairText": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY flair\n* If `false` then passes if NO flair\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"createdOn": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"description": "A relative datetime description to match the date the Activity was created\n\nMay be either:\n\n* day of the week (monday, tuesday, etc...)\n* cron expression IE `* * 15 *`\n\nSee https://crontab.guru/ for generating expressions\n\nhttps://regexr.com/6u3cc"
|
||||
},
|
||||
"deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
@@ -6174,23 +5703,6 @@
|
||||
"is_self": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"link_flair_background_color": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"boolean"
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if ANY color\n* If `false` then passes if NO color\n* If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes."
|
||||
},
|
||||
"link_flair_css_class": {
|
||||
"anyOf": [
|
||||
{
|
||||
@@ -6206,7 +5718,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css\n* If string or list of strings then class is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
|
||||
},
|
||||
"link_flair_text": {
|
||||
"anyOf": [
|
||||
@@ -6223,7 +5735,7 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text\n* If string or list of strings then text is matched, case-insensitive. String may also be a regular expression enclosed in forward slashes."
|
||||
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
|
||||
},
|
||||
"locked": {
|
||||
"type": "boolean"
|
||||
|
||||
@@ -9,15 +9,8 @@ import {
|
||||
createRetryHandler,
|
||||
determineNewResults,
|
||||
findLastIndex,
|
||||
formatNumber,
|
||||
frequencyEqualOrLargerThanMin,
|
||||
generateFullWikiUrl,
|
||||
getActivityAuthorName,
|
||||
isComment,
|
||||
isSubmission,
|
||||
likelyJson5,
|
||||
mergeArr,
|
||||
normalizeName,
|
||||
formatNumber, frequencyEqualOrLargerThanMin, getActivityAuthorName, isComment, isSubmission, likelyJson5,
|
||||
mergeArr, normalizeName,
|
||||
parseRedditEntity,
|
||||
pollingInfo,
|
||||
resultsSummary,
|
||||
@@ -74,7 +67,7 @@ import {
|
||||
isRateLimitError,
|
||||
isSeriousError,
|
||||
isStatusError,
|
||||
RunProcessingError, SimpleError
|
||||
RunProcessingError
|
||||
} from "../Utils/Errors";
|
||||
import {ErrorWithCause, stackWithCauses} from "pony-cause";
|
||||
import {Run} from "../Run";
|
||||
@@ -94,7 +87,8 @@ import {InvokeeType} from "../Common/Entities/InvokeeType";
|
||||
import {RunStateType} from "../Common/Entities/RunStateType";
|
||||
import {EntityRunState} from "../Common/Entities/EntityRunState/EntityRunState";
|
||||
import {
|
||||
ActivitySourceValue,
|
||||
ActivitySource,
|
||||
DispatchSource,
|
||||
EventRetentionPolicyRange,
|
||||
Invokee,
|
||||
PollOn,
|
||||
@@ -127,7 +121,7 @@ export interface runCheckOptions {
|
||||
force?: boolean,
|
||||
gotoContext?: string
|
||||
maxGotoDepth?: number
|
||||
source: ActivitySourceValue
|
||||
source: ActivitySource
|
||||
initialGoto?: string
|
||||
activitySource: ActivitySourceData
|
||||
disableDispatchDelays?: boolean
|
||||
@@ -601,34 +595,6 @@ export class Manager extends EventEmitter implements RunningStates {
|
||||
return this.runs.map(x => x.commentChecks);
|
||||
}
|
||||
|
||||
async setResourceManager(config: Partial<SubredditResourceConfig> = {}) {
|
||||
const {
|
||||
footer,
|
||||
logger = this.logger,
|
||||
subreddit = this.subreddit,
|
||||
caching,
|
||||
credentials,
|
||||
client = this.client,
|
||||
botEntity = this.botEntity,
|
||||
managerEntity = this.managerEntity,
|
||||
statFrequency = this.statDefaults.minFrequency,
|
||||
retention = this.retentionOverride,
|
||||
} = config;
|
||||
|
||||
this.resources = await this.cacheManager.set(this.subreddit.display_name, {
|
||||
footer: footer === undefined && this.resources !== undefined ? this.resources.footer : footer,
|
||||
logger,
|
||||
subreddit,
|
||||
caching,
|
||||
credentials,
|
||||
client,
|
||||
botEntity,
|
||||
managerEntity,
|
||||
statFrequency,
|
||||
retention,
|
||||
});
|
||||
}
|
||||
|
||||
protected async parseConfigurationFromObject(configObj: object, suppressChangeEvent: boolean = false) {
|
||||
try {
|
||||
const configBuilder = new ConfigBuilder({logger: this.logger});
|
||||
@@ -654,6 +620,10 @@ export class Manager extends EventEmitter implements RunningStates {
|
||||
|
||||
this.displayLabel = nickname || `${this.subreddit.display_name_prefixed}`;
|
||||
|
||||
if (footer !== undefined) {
|
||||
this.resources.footer = footer;
|
||||
}
|
||||
|
||||
this.subMaxWorkers = maxWorkers;
|
||||
const realMax = this.getMaxWorkers(this.subMaxWorkers);
|
||||
if(realMax !== this.queue.concurrency) {
|
||||
@@ -690,13 +660,9 @@ export class Manager extends EventEmitter implements RunningStates {
|
||||
statFrequency: realStatFrequency,
|
||||
retention: this.retentionOverride ?? retention
|
||||
};
|
||||
await this.setResourceManager(resourceConfig);
|
||||
this.resources = await this.cacheManager.set(this.subreddit.display_name, resourceConfig);
|
||||
this.resources.setLogger(this.logger);
|
||||
|
||||
if (footer !== undefined && this.resources !== undefined) {
|
||||
this.resources.footer = footer;
|
||||
}
|
||||
|
||||
this.logger.info('Subreddit-specific options updated');
|
||||
this.logger.info('Building Runs and Checks...');
|
||||
|
||||
@@ -814,17 +780,39 @@ export class Manager extends EventEmitter implements RunningStates {
|
||||
try {
|
||||
try {
|
||||
// @ts-ignore
|
||||
wiki = await this.getWikiPage();
|
||||
wiki = await this.subreddit.getWikiPage(this.wikiLocation).fetch();
|
||||
} catch (err: any) {
|
||||
if(err.cause !== undefined && isStatusError(err.cause) && err.cause.statusCode === 404) {
|
||||
// try to create it
|
||||
try {
|
||||
wiki = await this.writeConfig('', 'Empty configuration created for ContextMod');
|
||||
} catch (e: any) {
|
||||
throw new CMError(`Parsing config from wiki page failed because ${err.message} AND creating empty page failed`, {cause: e});
|
||||
if(isStatusError(err) && err.statusCode === 404) {
|
||||
// see if we can create the page
|
||||
if (!this.client.scope.includes('wikiedit')) {
|
||||
throw new ErrorWithCause(`Page does not exist and could not be created because Bot does not have oauth permission 'wikiedit'`, {cause: err});
|
||||
}
|
||||
const modPermissions = await this.getModPermissions();
|
||||
if (!modPermissions.includes('all') && !modPermissions.includes('wiki')) {
|
||||
throw new ErrorWithCause(`Page does not exist and could not be created because Bot not have mod permissions for creating wiki pages. Must have 'all' or 'wiki'`, {cause: err});
|
||||
}
|
||||
if(!this.client.scope.includes('modwiki')) {
|
||||
throw new ErrorWithCause(`Bot COULD create wiki config page but WILL NOT because it does not have the oauth permissions 'modwiki' which is required to set page visibility and editing permissions. Safety first!`, {cause: err});
|
||||
}
|
||||
// @ts-ignore
|
||||
wiki = await this.subreddit.getWikiPage(this.wikiLocation).edit({
|
||||
text: '',
|
||||
reason: 'Empty configuration created for ContextMod'
|
||||
});
|
||||
this.logger.info(`Wiki page at ${this.wikiLocation} did not exist so bot created it!`);
|
||||
|
||||
// 0 = use subreddit wiki permissions
|
||||
// 1 = only approved wiki contributors
|
||||
// 2 = only mods may edit and view
|
||||
// @ts-ignore
|
||||
await this.subreddit.getWikiPage(this.wikiLocation).editSettings({
|
||||
permissionLevel: 2,
|
||||
// don't list this page on r/[subreddit]/wiki/pages
|
||||
listed: false,
|
||||
});
|
||||
this.logger.info('Bot set wiki page visibility to MODS ONLY');
|
||||
} else {
|
||||
throw new CMError('Reading config from wiki failed', {cause: err});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
const revisionDate = dayjs.unix(wiki.revision_date);
|
||||
@@ -853,7 +841,12 @@ export class Manager extends EventEmitter implements RunningStates {
|
||||
this.lastWikiRevision = revisionDate;
|
||||
sourceData = await wiki.content_md;
|
||||
} catch (err: any) {
|
||||
throw err;
|
||||
let hint = '';
|
||||
if(isStatusError(err) && err.statusCode === 403) {
|
||||
hint = ` -- HINT: Either the page is restricted to mods only and the bot's reddit account does have the mod permission 'all' or 'wiki' OR the bot does not have the 'wikiread' oauth permission`;
|
||||
}
|
||||
const msg = `Could not read wiki configuration. Please ensure the page https://reddit.com${this.subreddit.url}wiki/${this.wikiLocation} exists and is readable${hint}`;
|
||||
throw new ErrorWithCause(msg, {cause: err});
|
||||
}
|
||||
|
||||
if (sourceData.replace('\r\n', '').trim() === '') {
|
||||
@@ -887,13 +880,12 @@ export class Manager extends EventEmitter implements RunningStates {
|
||||
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
if(this.resources === undefined) {
|
||||
// if we fail to get a valid config and there is no existing resource then just create a default one
|
||||
// -- also ensures that if one already exists we don't overwrite it
|
||||
await this.setResourceManager()
|
||||
}
|
||||
const error = new ErrorWithCause('Failed to parse subreddit configuration', {cause: err});
|
||||
// @ts-ignore
|
||||
//error.logged = true;
|
||||
this.logger.error(error);
|
||||
this.validConfigLoaded = false;
|
||||
throw new ErrorWithCause('Failed to parse subreddit configuration', {cause: err});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1807,104 +1799,6 @@ export class Manager extends EventEmitter implements RunningStates {
|
||||
}
|
||||
}
|
||||
|
||||
async setWikiPermissions(location: string = this.wikiLocation) {
|
||||
if(!this.client.scope.includes('modwiki')) {
|
||||
throw new SimpleError(`Cannot check or set permissions for wiki because bot does not have the 'modwiki' oauth permission`);
|
||||
}
|
||||
|
||||
const settings = await this.subreddit.getWikiPage(location).getSettings();
|
||||
const reasons = [];
|
||||
if(settings.listed) {
|
||||
reasons.push(`Page is listed (visible from r/${this.subreddit.display_name}/wiki/pages) but should be delisted.`)
|
||||
}
|
||||
// 0 = use subreddit wiki permissions
|
||||
// 1 = only approved wiki contributors
|
||||
// 2 = only mods may edit and view
|
||||
if(settings.permissionLevel === 0) {
|
||||
reasons.push(`Page editing level is set to 'inherit from general wiki settings' but should be set to contributors/mods only`);
|
||||
}
|
||||
if (reasons.length > 0) {
|
||||
this.logger.debug(`Updating wiki page permissions because: ${reasons.join(' | ')}`)
|
||||
// @ts-ignore
|
||||
await this.subreddit.getWikiPage(location).editSettings({
|
||||
permissionLevel: 2,
|
||||
// don't list this page on r/[subreddit]/wiki/pages
|
||||
listed: false,
|
||||
});
|
||||
this.logger.info('Bot set wiki page visibility to MODS ONLY and delisted the page');
|
||||
}
|
||||
}
|
||||
|
||||
async writeConfig(data: string, reason?: string, location: string = this.wikiLocation) {
|
||||
|
||||
const oauthErrors = [];
|
||||
if (!this.client.scope.includes('wikiedit')) {
|
||||
oauthErrors.push(`missing oauth permission 'wikiedit' is required to edit wiki pages`);
|
||||
}
|
||||
if (!this.client.scope.includes('modwiki')) {
|
||||
oauthErrors.push(`missing oauth permission 'modwiki' which is required to set page visibility and editing permissions.`);
|
||||
}
|
||||
|
||||
if(oauthErrors.length > 0) {
|
||||
throw new SimpleError(`Cannot edit wiki page ${generateFullWikiUrl(this.subreddit, location)} because: ${oauthErrors.join(' | ')}`);
|
||||
}
|
||||
|
||||
try {
|
||||
// @ts-ignore
|
||||
const wiki = await this.subreddit.getWikiPage(location).edit({
|
||||
text: data,
|
||||
reason: reason,
|
||||
});
|
||||
this.logger.debug(`Wrote config to ${location}`);
|
||||
try {
|
||||
await this.setWikiPermissions(location);
|
||||
} catch (e: any) {
|
||||
if (e.message.includes('modwiki')) {
|
||||
this.logger.warn(e);
|
||||
} else {
|
||||
throw new CMError(`Successfully edited wiki page ${generateFullWikiUrl(this.subreddit, location)} but an error occurred while checking/setting page permissions`, {cause: e});
|
||||
}
|
||||
}
|
||||
return wiki;
|
||||
} catch (err: any) {
|
||||
if (isStatusError(err)) {
|
||||
const modPermissions = await this.getModPermissions();
|
||||
if (!modPermissions.includes('all') && !modPermissions.includes('wiki')) {
|
||||
throw new ErrorWithCause(`Could not create wiki page ${generateFullWikiUrl(this.subreddit, location)} because Bot not have mod permissions for creating wiki pages. Must have 'all' or 'wiki'`, {cause: err});
|
||||
}
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async getWikiPage(location: string = this.wikiLocation) {
|
||||
let wiki: WikiPage;
|
||||
try {
|
||||
// @ts-ignore
|
||||
wiki = await this.subreddit.getWikiPage(location).fetch();
|
||||
} catch (err: any) {
|
||||
if (isStatusError(err)) {
|
||||
const error = err.statusCode === 404 ? 'does not exist' : 'is not accessible';
|
||||
let reasons = [];
|
||||
if (!this.client.scope.includes('wikiread')) {
|
||||
reasons.push(`Bot does not have 'wikiread' oauth permission`);
|
||||
} else {
|
||||
const modPermissions = await this.getModPermissions();
|
||||
if (!modPermissions.includes('all') && !modPermissions.includes('wiki')) {
|
||||
reasons.push(`Bot does not have required mod permissions ('all' or 'wiki') to read restricted wiki pages`);
|
||||
}
|
||||
}
|
||||
|
||||
throw new CMError(`Wiki page ${generateFullWikiUrl(this.subreddit, location)} ${error} (${err.statusCode})${reasons.length > 0 ? ` because: ${reasons.join(' | ')}` : '.'}`, {cause: err});
|
||||
} else {
|
||||
throw new CMError(`Wiki page ${generateFullWikiUrl(this.subreddit, location)} could not be read`, {cause: err});
|
||||
}
|
||||
}
|
||||
return wiki;
|
||||
}
|
||||
|
||||
toNormalizedManager(): NormalizedManagerResponse {
|
||||
return {
|
||||
name: this.displayLabel,
|
||||
|
||||
@@ -14,8 +14,10 @@ import {
|
||||
asActivity,
|
||||
asSubmission,
|
||||
asUserNoteCriteria,
|
||||
buildCacheOptionsFromProvider,
|
||||
buildCachePrefix,
|
||||
cacheStats,
|
||||
createCacheManager,
|
||||
escapeRegex,
|
||||
FAIL,
|
||||
fetchExternalResult,
|
||||
@@ -39,6 +41,7 @@ import {
|
||||
redisScanIterator,
|
||||
removeUndefinedKeys,
|
||||
shouldCacheSubredditStateCriteriaResult,
|
||||
strToActivitySource,
|
||||
subredditStateIsNameOnly,
|
||||
testMaybeStringRegex,
|
||||
toStrongSubredditState,
|
||||
@@ -55,7 +58,7 @@ import {
|
||||
filterByTimeRequirement,
|
||||
asSubreddit,
|
||||
modActionCriteriaSummary,
|
||||
parseRedditFullname, asStrongImageHashCache, matchesRelativeDateTime, generateFullWikiUrl
|
||||
parseRedditFullname, asStrongImageHashCache
|
||||
} from "../util";
|
||||
import LoggedError from "../Utils/LoggedError";
|
||||
import {
|
||||
@@ -110,29 +113,18 @@ import cloneDeep from "lodash/cloneDeep";
|
||||
import {
|
||||
asModLogCriteria,
|
||||
asModNoteCriteria,
|
||||
AuthorCriteria,
|
||||
cmToSnoowrapActivityMap,
|
||||
CommentState,
|
||||
ModLogCriteria,
|
||||
ModNoteCriteria,
|
||||
orderedAuthorCriteriaProps,
|
||||
RequiredAuthorCrit,
|
||||
StrongSubredditCriteria,
|
||||
SubmissionState,
|
||||
SubredditCriteria,
|
||||
toFullModLogCriteria,
|
||||
toFullModNoteCriteria,
|
||||
TypedActivityState,
|
||||
TypedActivityStates,
|
||||
AuthorCriteria, CommentState, ModLogCriteria, ModNoteCriteria, orderedAuthorCriteriaProps, RequiredAuthorCrit,
|
||||
StrongSubredditCriteria, SubmissionState,
|
||||
SubredditCriteria, toFullModLogCriteria, toFullModNoteCriteria, TypedActivityState, TypedActivityStates,
|
||||
UserNoteCriteria
|
||||
} from "../Common/Infrastructure/Filters/FilterCriteria";
|
||||
import {
|
||||
ActivitySourceValue, ConfigFragmentValidationFunc, DurationVal,
|
||||
ActivitySource, ConfigFragmentValidationFunc, DurationVal,
|
||||
EventRetentionPolicyRange, ImageHashCacheData,
|
||||
JoinOperands,
|
||||
ModActionType,
|
||||
ModeratorNameCriteria, ModUserNoteLabel, RelativeDateTimeMatch, statFrequencies, StatisticFrequency,
|
||||
StatisticFrequencyOption, WikiContext
|
||||
ModeratorNameCriteria, ModUserNoteLabel, statFrequencies, StatisticFrequency,
|
||||
StatisticFrequencyOption
|
||||
} from "../Common/Infrastructure/Atomic";
|
||||
import {
|
||||
AuthorOptions, FilterCriteriaPropertyResult,
|
||||
@@ -153,7 +145,7 @@ import {
|
||||
|
||||
ActivityType,
|
||||
AuthorHistorySort,
|
||||
CachedFetchedActivitiesResult, FetchedActivitiesResult, MaybeActivityType,
|
||||
CachedFetchedActivitiesResult, FetchedActivitiesResult,
|
||||
SnoowrapActivity, SubredditRemovalReason
|
||||
} from "../Common/Infrastructure/Reddit";
|
||||
import {AuthorCritPropHelper} from "../Common/Infrastructure/Filters/AuthorCritPropHelper";
|
||||
@@ -170,10 +162,8 @@ import {parseFromJsonOrYamlToObject} from "../Common/Config/ConfigUtil";
|
||||
import ConfigParseError from "../Utils/ConfigParseError";
|
||||
import {ActivityReport} from "../Common/Entities/ActivityReport";
|
||||
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
|
||||
import {ActivitySource} from "../Common/ActivitySource";
|
||||
import {buildCacheOptionsFromProvider, createCacheManager} from "../Common/Cache";
|
||||
|
||||
export const DEFAULT_FOOTER = '\r\n*****\r\nThis action was performed by [a bot.]({{botLink}}) Mention a moderator or [send a modmail]({{modmailLink}}) if you have any ideas, questions, or concerns about this action.';
|
||||
export const DEFAULT_FOOTER = '\r\n*****\r\nThis action was performed by [a bot.]({{botLink}}) Mention a moderator or [send a modmail]({{modmailLink}}) if you any ideas, questions, or concerns about this action.';
|
||||
|
||||
/**
|
||||
* Only used for migrating stats from cache to db
|
||||
@@ -233,7 +223,7 @@ export class SubredditResources {
|
||||
protected useSubredditAuthorCache!: boolean;
|
||||
protected authorTTL: number | false = cacheTTLDefaults.authorTTL;
|
||||
protected subredditTTL: number | false = cacheTTLDefaults.subredditTTL;
|
||||
public wikiTTL: number | false = cacheTTLDefaults.wikiTTL;
|
||||
protected wikiTTL: number | false = cacheTTLDefaults.wikiTTL;
|
||||
protected submissionTTL: number | false = cacheTTLDefaults.submissionTTL;
|
||||
protected commentTTL: number | false = cacheTTLDefaults.commentTTL;
|
||||
protected filterCriteriaTTL: number | false = cacheTTLDefaults.filterCriteriaTTL;
|
||||
@@ -1151,18 +1141,6 @@ export class SubredditResources {
|
||||
return mods;
|
||||
}
|
||||
|
||||
async getSubredditModeratorPermissions(rawUserVal: RedditUser | string, rawSubredditVal?: Subreddit | string): Promise<string[]> {
|
||||
const mods = await this.getSubredditModerators(rawSubredditVal);
|
||||
const user = rawUserVal instanceof RedditUser ? rawUserVal.name : rawUserVal;
|
||||
|
||||
const mod = mods.find(x => x.name.toLowerCase() === user.toLowerCase());
|
||||
if(mod === undefined) {
|
||||
return [];
|
||||
}
|
||||
// @ts-ignore
|
||||
return mod.mod_permissions as string[];
|
||||
}
|
||||
|
||||
async getSubredditContributors(): Promise<RedditUser[]> {
|
||||
const subName = this.subreddit.display_name;
|
||||
const hash = `sub-${subName}-contributors`;
|
||||
@@ -1231,156 +1209,6 @@ export class SubredditResources {
|
||||
return false;
|
||||
}
|
||||
|
||||
filterAuthorModActions(modActions: ModNote[], actionCriteria: (ModNoteCriteria | ModLogCriteria), referenceItem: SnoowrapActivity) {
|
||||
const {search = 'current', count = '>= 1'} = actionCriteria;
|
||||
|
||||
const {
|
||||
value,
|
||||
operator,
|
||||
isPercent,
|
||||
duration,
|
||||
extra = ''
|
||||
} = parseGenericValueOrPercentComparison(count);
|
||||
|
||||
const cutoffDate = duration === undefined ? undefined : dayjs().subtract(duration);
|
||||
|
||||
let actionsToUse: ModNote[] = [];
|
||||
if(asModNoteCriteria(actionCriteria)) {
|
||||
actionsToUse = modActions.filter(x => x.type === 'NOTE');
|
||||
} else {
|
||||
actionsToUse = modActions;
|
||||
}
|
||||
|
||||
if(search === 'current' && actionsToUse.length > 0) {
|
||||
actionsToUse = [actionsToUse[0]];
|
||||
}
|
||||
|
||||
let validActions: ModNote[] = [];
|
||||
if (asModLogCriteria(actionCriteria)) {
|
||||
const fullCrit = toFullModLogCriteria(actionCriteria);
|
||||
const fullCritEntries = Object.entries(fullCrit);
|
||||
validActions = actionsToUse.filter(x => {
|
||||
|
||||
// filter out any notes that occur before time range
|
||||
if(cutoffDate !== undefined && x.createdAt.isBefore(cutoffDate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const [k, v] of fullCritEntries) {
|
||||
const key = k.toLocaleLowerCase();
|
||||
if (['count', 'search'].includes(key)) {
|
||||
continue;
|
||||
}
|
||||
switch (key) {
|
||||
case 'type':
|
||||
if (!v.includes((x.type as ModActionType))) {
|
||||
return false
|
||||
}
|
||||
break;
|
||||
case 'activitytype':
|
||||
const anyMatch = v.some((a: MaybeActivityType) => {
|
||||
switch (a) {
|
||||
case 'submission':
|
||||
return isSubmission(x.action.actedOn);
|
||||
case 'comment':
|
||||
return isComment(x.action.actedOn);
|
||||
case false:
|
||||
return x.action.actedOn === undefined || (!asSubmission(x.action.actedOn) && !asComment(x.action.actedOn));
|
||||
}
|
||||
});
|
||||
if (!anyMatch) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'description':
|
||||
case 'action':
|
||||
case 'details':
|
||||
const actionPropVal = x.action[key] as string;
|
||||
if (actionPropVal === undefined) {
|
||||
return false;
|
||||
}
|
||||
const anyPropMatch = v.some((y: RegExp) => y.test(actionPropVal));
|
||||
if (!anyPropMatch) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'referencescurrentactivity':
|
||||
const isCurrentActivity = x.action.actedOn !== undefined && referenceItem !== undefined && x.action.actedOn.name === referenceItem.name;
|
||||
if((v === true && !isCurrentActivity) || (v === false && isCurrentActivity)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
} // case end
|
||||
|
||||
} // for each end
|
||||
|
||||
return true;
|
||||
}); // filter end
|
||||
} else if(asModNoteCriteria(actionCriteria)) {
|
||||
const fullCrit = toFullModNoteCriteria(actionCriteria as ModNoteCriteria);
|
||||
const fullCritEntries = Object.entries(fullCrit);
|
||||
validActions = actionsToUse.filter(x => {
|
||||
|
||||
// filter out any notes that occur before time range
|
||||
if(cutoffDate !== undefined && x.createdAt.isBefore(cutoffDate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const [k, v] of fullCritEntries) {
|
||||
const key = k.toLocaleLowerCase();
|
||||
if (['count', 'search'].includes(key)) {
|
||||
continue;
|
||||
}
|
||||
switch (key) {
|
||||
case 'notetype':
|
||||
if (!v.map((x: ModUserNoteLabel) => x.toUpperCase()).includes((x.note.label as ModUserNoteLabel))) {
|
||||
return false
|
||||
}
|
||||
break;
|
||||
case 'note':
|
||||
const actionPropVal = x.note.note;
|
||||
if (actionPropVal === undefined) {
|
||||
return false;
|
||||
}
|
||||
const anyPropMatch = v.some((y: RegExp) => y.test(actionPropVal));
|
||||
if (!anyPropMatch) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'activitytype':
|
||||
const anyMatch = v.some((a: MaybeActivityType) => {
|
||||
switch (a) {
|
||||
case 'submission':
|
||||
return isSubmission(x.action.actedOn);
|
||||
case 'comment':
|
||||
return isComment(x.action.actedOn);
|
||||
case false:
|
||||
return x.action.actedOn === undefined || (!asSubmission(x.action.actedOn) && !asComment(x.action.actedOn));
|
||||
}
|
||||
});
|
||||
if (!anyMatch) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'referencescurrentactivity':
|
||||
const isCurrentActivity = x.action.actedOn !== undefined && referenceItem !== undefined && x.action.actedOn.id === referenceItem.name;
|
||||
if((v === true && !isCurrentActivity) || (v === false && isCurrentActivity)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
} // case end
|
||||
|
||||
} // for each end
|
||||
|
||||
return true;
|
||||
}); // filter end
|
||||
} else {
|
||||
throw new SimpleError(`Could not determine if a modActions criteria was for Mod Log or Mod Note. Given: ${JSON.stringify(actionCriteria)}`);
|
||||
}
|
||||
|
||||
return [validActions, actionsToUse];
|
||||
}
|
||||
|
||||
async getAuthorModNotesByActivityAuthor(activity: Comment | Submission) {
|
||||
const author = activity.author instanceof RedditUser ? activity.author : getActivityAuthorName(activity.author);
|
||||
if (activity.subreddit.display_name !== this.subreddit.display_name) {
|
||||
@@ -1857,31 +1685,21 @@ export class SubredditResources {
|
||||
return filteredListing;
|
||||
}
|
||||
|
||||
async getExternalResource(val: string, subredditArg?: Subreddit, defaultTo: 'url' | 'wiki' | undefined = undefined): Promise<{ val: string, fromCache: boolean, response?: Response, hash?: string }> {
|
||||
let wikiContext = parseWikiContext(val);
|
||||
|
||||
let extUrl = wikiContext === undefined ? parseExternalUrl(val) : undefined;
|
||||
|
||||
if (extUrl === undefined && wikiContext === undefined) {
|
||||
if (defaultTo === 'url') {
|
||||
extUrl = val;
|
||||
} else if (defaultTo === 'wiki') {
|
||||
wikiContext = {wiki: val};
|
||||
}
|
||||
}
|
||||
|
||||
async getExternalResource(val: string, subredditArg?: Subreddit): Promise<{val: string, fromCache: boolean, response?: Response, hash?: string}> {
|
||||
const subreddit = subredditArg || this.subreddit;
|
||||
let cacheKey;
|
||||
const wikiContext = parseWikiContext(val);
|
||||
if (wikiContext !== undefined) {
|
||||
return await this.getWikiPage(wikiContext, subredditArg !== undefined ? subredditArg.display_name : undefined);
|
||||
cacheKey = `${subreddit.display_name}-content-${wikiContext.wiki}${wikiContext.subreddit !== undefined ? `|${wikiContext.subreddit}` : ''}`;
|
||||
}
|
||||
const extUrl = wikiContext === undefined ? parseExternalUrl(val) : undefined;
|
||||
if (extUrl !== undefined) {
|
||||
return await this.getCachedUrlResult(extUrl);
|
||||
cacheKey = extUrl;
|
||||
}
|
||||
|
||||
return {val, fromCache: false};
|
||||
}
|
||||
|
||||
async getCachedUrlResult(extUrl: string): Promise<{ val: string, fromCache: boolean, response?: Response, hash?: string }> {
|
||||
const cacheKey = extUrl;
|
||||
if (cacheKey === undefined) {
|
||||
return {val, fromCache: false, hash: cacheKey};
|
||||
}
|
||||
|
||||
// try to get cached value first
|
||||
if (this.wikiTTL !== false) {
|
||||
@@ -1897,60 +1715,46 @@ export class SubredditResources {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const [wikiContentVal, responseVal] = await fetchExternalResult(extUrl as string, this.logger);
|
||||
return {val: wikiContentVal, fromCache: false, response: responseVal, hash: cacheKey};
|
||||
} catch (err: any) {
|
||||
throw new CMError(`Error occurred while trying to fetch the url ${extUrl}`, {cause: err});
|
||||
}
|
||||
}
|
||||
let wikiContent: string;
|
||||
let response: Response | undefined;
|
||||
|
||||
async getWikiPage(data: WikiContext, subredditArg?: string): Promise<{ val: string, fromCache: boolean, response?: Response, hash?: string }> {
|
||||
const {
|
||||
subreddit = subredditArg ?? this.subreddit.display_name,
|
||||
wiki
|
||||
} = data;
|
||||
|
||||
const cacheKey = `${subreddit}-content-${wiki}${data.subreddit !== undefined ? `|${data.subreddit}` : ''}`;
|
||||
|
||||
if (this.wikiTTL !== false) {
|
||||
await this.stats.cache.content.identifierRequestCount.set(cacheKey, (await this.stats.cache.content.identifierRequestCount.wrap(cacheKey, () => 0) as number) + 1);
|
||||
this.stats.cache.content.requestTimestamps.push(Date.now());
|
||||
this.stats.cache.content.requests++;
|
||||
const cachedContent = await this.cache.get(cacheKey);
|
||||
if (cachedContent !== undefined && cachedContent !== null) {
|
||||
this.logger.debug(`Content Cache Hit: ${cacheKey}`);
|
||||
return {val: cachedContent as string, fromCache: true, hash: cacheKey};
|
||||
// no cache hit, get from source
|
||||
if (wikiContext !== undefined) {
|
||||
let sub;
|
||||
if (wikiContext.subreddit === undefined || wikiContext.subreddit.toLowerCase() === subreddit.display_name) {
|
||||
sub = subreddit;
|
||||
} else {
|
||||
this.stats.cache.content.miss++;
|
||||
sub = this.client.getSubreddit(wikiContext.subreddit);
|
||||
}
|
||||
}
|
||||
|
||||
let sub = this.client.getSubreddit(subreddit);
|
||||
|
||||
try {
|
||||
// @ts-ignore
|
||||
const wikiPage = sub.getWikiPage(wiki);
|
||||
const wikiContent = await wikiPage.content_md;
|
||||
return {val: wikiContent, fromCache: false, hash: cacheKey};
|
||||
} catch (err: any) {
|
||||
if (isStatusError(err)) {
|
||||
const error = err.statusCode === 404 ? 'does not exist' : 'is not accessible';
|
||||
let reasons = [];
|
||||
if (!this.client.scope.includes('wikiread')) {
|
||||
reasons.push(`Bot does not have 'wikiread' oauth permission`);
|
||||
} else {
|
||||
const modPermissions = await this.getSubredditModeratorPermissions(this.botName, subreddit);
|
||||
if (!modPermissions.includes('all') && !modPermissions.includes('wiki')) {
|
||||
reasons.push(`Bot does not have required mod permissions ('all' or 'wiki') to read restricted wiki pages`);
|
||||
try {
|
||||
// @ts-ignore
|
||||
const wikiPage = sub.getWikiPage(wikiContext.wiki);
|
||||
wikiContent = await wikiPage.content_md;
|
||||
} catch (err: any) {
|
||||
let msg = `Could not read wiki page for an unknown reason. Please ensure the page 'https://reddit.com${sub.display_name_prefixed}/wiki/${wikiContext.wiki}' exists and is readable`;
|
||||
if(err.statusCode !== undefined) {
|
||||
if(err.statusCode === 404) {
|
||||
msg = `Could not find a wiki page at https://reddit.com${sub.display_name_prefixed}/wiki/${wikiContext.wiki} -- Reddit returned a 404`;
|
||||
} else if(err.statusCode === 403 || err.statusCode === 401) {
|
||||
msg = `Bot either does not have permission visibility permissions for the wiki page at https://reddit.com${sub.display_name_prefixed}wiki/${wikiContext.wiki} (due to subreddit restrictions) or the bot does have have oauth permissions to read wiki pages (operator error). Reddit returned a ${err.statusCode}`;
|
||||
}
|
||||
}
|
||||
|
||||
throw new CMError(`Wiki page ${generateFullWikiUrl(subreddit, wiki)} ${error} (${err.statusCode})${reasons.length > 0 ? `because: ${reasons.join(' | ')}` : '.'}`, {cause: err});
|
||||
} else {
|
||||
throw new CMError(`Wiki page ${generateFullWikiUrl(subreddit, wiki)} could not be read`, {cause: err});
|
||||
this.logger.error(msg, err);
|
||||
throw new LoggedError(msg);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const [wikiContentVal, responseVal] = await fetchExternalResult(extUrl as string, this.logger);
|
||||
wikiContent = wikiContentVal;
|
||||
response = responseVal;
|
||||
} catch (err: any) {
|
||||
const msg = `Error occurred while trying to fetch the url ${extUrl}`;
|
||||
this.logger.error(msg, err);
|
||||
throw new LoggedError(msg);
|
||||
}
|
||||
}
|
||||
|
||||
return {val: wikiContent, fromCache: false, response, hash: cacheKey};
|
||||
}
|
||||
|
||||
async getContent(val: string, subredditArg?: Subreddit): Promise<string> {
|
||||
@@ -2105,11 +1909,6 @@ export class SubredditResources {
|
||||
includeIdentifier = false,
|
||||
} = options || {};
|
||||
|
||||
// return early if there are no states to filter by!
|
||||
if(states.length === 0) {
|
||||
return items;
|
||||
}
|
||||
|
||||
let passedItems: (Comment | Submission)[] = [];
|
||||
let unpassedItems: (Comment | Submission)[] = [];
|
||||
|
||||
@@ -2250,7 +2049,7 @@ export class SubredditResources {
|
||||
return res;
|
||||
}
|
||||
|
||||
async testItemCriteria(i: (Comment | Submission), activityStateObj: NamedCriteria<TypedActivityState>, logger: Logger, include = true, source?: ActivitySourceValue): Promise<FilterCriteriaResult<TypedActivityState>> {
|
||||
async testItemCriteria(i: (Comment | Submission), activityStateObj: NamedCriteria<TypedActivityState>, logger: Logger, include = true, source?: ActivitySource): Promise<FilterCriteriaResult<TypedActivityState>> {
|
||||
const {criteria: activityState} = activityStateObj;
|
||||
if(Object.keys(activityState).length === 0) {
|
||||
return {
|
||||
@@ -2414,7 +2213,7 @@ export class SubredditResources {
|
||||
})() as boolean;
|
||||
}
|
||||
|
||||
async isItem (item: Submission | Comment, stateCriteria: TypedActivityState, logger: Logger, include: boolean, source?: ActivitySourceValue): Promise<FilterCriteriaResult<(SubmissionState & CommentState)>> {
|
||||
async isItem (item: Submission | Comment, stateCriteria: TypedActivityState, logger: Logger, include: boolean, source?: ActivitySource): Promise<FilterCriteriaResult<(SubmissionState & CommentState)>> {
|
||||
|
||||
//const definedStateCriteria = (removeUndefinedKeys(stateCriteria) as RequiredItemCrit);
|
||||
|
||||
@@ -2505,12 +2304,10 @@ export class SubredditResources {
|
||||
} else {
|
||||
propResultsMap.source!.found = source;
|
||||
|
||||
const itemSource = new ActivitySource(source);
|
||||
|
||||
const requestedSourcesVal: string[] = !Array.isArray(itemOptVal) ? [itemOptVal] as string[] : itemOptVal as string[];
|
||||
const requestedSources = requestedSourcesVal.map(x => new ActivitySource(x));
|
||||
const requestedSources = requestedSourcesVal.map(x => strToActivitySource(x).toLowerCase());
|
||||
|
||||
propResultsMap.source!.passed = criteriaPassWithIncludeBehavior(requestedSources.some(x => x.matches(itemSource)), include);
|
||||
propResultsMap.source!.passed = criteriaPassWithIncludeBehavior(requestedSources.some(x => source.toLowerCase().trim() === x.toLowerCase().trim()), include);
|
||||
break;
|
||||
}
|
||||
case 'score':
|
||||
@@ -2646,23 +2443,6 @@ export class SubredditResources {
|
||||
propResultsMap.age!.passed = criteriaPassWithIncludeBehavior(ageTest, include);
|
||||
propResultsMap.age!.found = created.format('MMMM D, YYYY h:mm A Z');
|
||||
break;
|
||||
case 'createdOn':
|
||||
const createdAt = dayjs.unix(await item.created);
|
||||
propResultsMap.createdOn!.found = createdAt.format('MMMM D, YYYY h:mm A Z');
|
||||
propResultsMap.createdOn!.passed = false;
|
||||
|
||||
const expressions = Array.isArray(itemOptVal) ? itemOptVal as RelativeDateTimeMatch[] : [itemOptVal] as RelativeDateTimeMatch[];
|
||||
try {
|
||||
for (const expr of expressions) {
|
||||
if (matchesRelativeDateTime(expr, createdAt)) {
|
||||
propResultsMap.createdOn!.passed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(err: any) {
|
||||
propResultsMap.createdOn!.reason = err.message;
|
||||
}
|
||||
break;
|
||||
case 'title':
|
||||
if(asComment(item)) {
|
||||
const titleWarn ='`title` is not allowed in `itemIs` criteria when the main Activity is a Comment';
|
||||
@@ -2814,22 +2594,13 @@ export class SubredditResources {
|
||||
case 'flairTemplate':
|
||||
case 'link_flair_text':
|
||||
case 'link_flair_css_class':
|
||||
case 'link_flair_background_color':
|
||||
case 'authorFlairText':
|
||||
case 'authorFlairCssClass':
|
||||
case 'authorFlairTemplateId':
|
||||
case 'authorFlairBackgroundColor':
|
||||
|
||||
let actualPropName = cmToSnoowrapActivityMap[k] ?? k;
|
||||
|
||||
if(!asSubmission(item) && (actualPropName as string).includes('link_flair')) {
|
||||
propResultsMap[k]!.passed = true;
|
||||
propResultsMap[k]!.reason = `Cannot test for ${k} on Comment`;
|
||||
log.warn(`Cannot test for ${k} on Comment`);
|
||||
break;
|
||||
} else {
|
||||
// @ts-ignore
|
||||
let propertyValue: string | null = await item[actualPropName];
|
||||
if(asSubmission(item)) {
|
||||
let propertyValue: string | null;
|
||||
if(k === 'flairTemplate') {
|
||||
propertyValue = await item.link_flair_template_id;
|
||||
} else {
|
||||
propertyValue = await item[k];
|
||||
}
|
||||
|
||||
propResultsMap[k]!.found = propertyValue;
|
||||
|
||||
@@ -2843,38 +2614,15 @@ export class SubredditResources {
|
||||
// if crit is not a boolean but property is "empty" then it'll never pass anyway
|
||||
propResultsMap[k]!.passed = !include;
|
||||
} else {
|
||||
// remove # if comparing hex values
|
||||
const isHex = k.toLowerCase().includes('background');
|
||||
|
||||
const expectedValues = (typeof itemOptVal === 'string' ? [itemOptVal] : (itemOptVal as string[])).map(x => isHex ? x.replace('#','').trim() : x.trim());
|
||||
const cleanProp = isHex ? propertyValue.replace('#','').trim() : propertyValue.trim();
|
||||
let anyPassed = false;
|
||||
const errorReasons = [];
|
||||
for(const expectedVal of expectedValues) {
|
||||
try {
|
||||
const [regPassed] = testMaybeStringRegex(expectedVal,cleanProp);
|
||||
if(regPassed) {
|
||||
anyPassed = true;
|
||||
}
|
||||
} catch (err: any) {
|
||||
if(err.message.includes('Could not convert test value')) {
|
||||
errorReasons.push(`Could not convert ${expectedVal} to Regex, fallback to simple case-insenstive comparison`);
|
||||
// fallback to simple comparison
|
||||
anyPassed = expectedVal.toLowerCase() === cleanProp.toLowerCase();
|
||||
} else {
|
||||
errorReasons.push(err.message);
|
||||
}
|
||||
}
|
||||
if(anyPassed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(errorReasons.length > 0) {
|
||||
propResultsMap[k]!.reason = `Some errors occurred while testing: ${errorReasons.join(' | ')}`;
|
||||
}
|
||||
propResultsMap[k]!.passed = criteriaPassWithIncludeBehavior(anyPassed, include);
|
||||
const expectedValues = typeof itemOptVal === 'string' ? [itemOptVal] : (itemOptVal as string[]);
|
||||
propResultsMap[k]!.passed = criteriaPassWithIncludeBehavior(expectedValues.some(x => x.trim().toLowerCase() === propertyValue?.trim().toLowerCase()), include);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
propResultsMap[k]!.passed = true;
|
||||
propResultsMap[k]!.reason = `Cannot test for ${k} on Comment`;
|
||||
log.warn(`Cannot test for ${k} on Comment`);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -3324,6 +3072,7 @@ export class SubredditResources {
|
||||
|
||||
const {search = 'current', count = '>= 1'} = actionCriteria;
|
||||
|
||||
|
||||
const {
|
||||
value,
|
||||
operator,
|
||||
@@ -3331,10 +3080,146 @@ export class SubredditResources {
|
||||
duration,
|
||||
extra = ''
|
||||
} = parseGenericValueOrPercentComparison(count);
|
||||
const cutoffDate = duration === undefined ? undefined : dayjs().subtract(duration);
|
||||
|
||||
const [validActions, actionsToUse] = this.filterAuthorModActions(modActions, actionCriteria, item);
|
||||
let actionsToUse: ModNote[] = [];
|
||||
if(asModNoteCriteria(actionCriteria)) {
|
||||
actionsToUse = actionsToUse.filter(x => x.type === 'NOTE');
|
||||
} else {
|
||||
actionsToUse = modActions;
|
||||
}
|
||||
|
||||
if(search === 'current' && actionsToUse.length > 0) {
|
||||
actionsToUse = [actionsToUse[0]];
|
||||
}
|
||||
|
||||
let validActions: ModNote[] = [];
|
||||
if (asModLogCriteria(actionCriteria)) {
|
||||
const fullCrit = toFullModLogCriteria(actionCriteria);
|
||||
const fullCritEntries = Object.entries(fullCrit);
|
||||
validActions = actionsToUse.filter(x => {
|
||||
|
||||
// filter out any notes that occur before time range
|
||||
if(cutoffDate !== undefined && x.createdAt.isBefore(cutoffDate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const [k, v] of fullCritEntries) {
|
||||
const key = k.toLocaleLowerCase();
|
||||
if (['count', 'search'].includes(key)) {
|
||||
continue;
|
||||
}
|
||||
switch (key) {
|
||||
case 'type':
|
||||
if (!v.includes((x.type as ModActionType))) {
|
||||
return false
|
||||
}
|
||||
break;
|
||||
case 'activitytype':
|
||||
const anyMatch = v.some((a: ActivityType) => {
|
||||
switch (a) {
|
||||
case 'submission':
|
||||
if (x.action.actedOn instanceof Submission) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 'comment':
|
||||
if (x.action.actedOn instanceof Comment) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!anyMatch) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'description':
|
||||
case 'action':
|
||||
case 'details':
|
||||
const actionPropVal = x.action[key] as string;
|
||||
if (actionPropVal === undefined) {
|
||||
return false;
|
||||
}
|
||||
const anyPropMatch = v.some((y: RegExp) => y.test(actionPropVal));
|
||||
if (!anyPropMatch) {
|
||||
return false;
|
||||
}
|
||||
} // case end
|
||||
|
||||
} // for each end
|
||||
|
||||
return true;
|
||||
}); // filter end
|
||||
} else if(asModNoteCriteria(actionCriteria)) {
|
||||
const fullCrit = toFullModNoteCriteria(actionCriteria as ModNoteCriteria);
|
||||
const fullCritEntries = Object.entries(fullCrit);
|
||||
validActions = actionsToUse.filter(x => {
|
||||
|
||||
// filter out any notes that occur before time range
|
||||
if(cutoffDate !== undefined && x.createdAt.isBefore(cutoffDate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const [k, v] of fullCritEntries) {
|
||||
const key = k.toLocaleLowerCase();
|
||||
if (['count', 'search'].includes(key)) {
|
||||
continue;
|
||||
}
|
||||
switch (key) {
|
||||
case 'notetype':
|
||||
if (!v.map((x: ModUserNoteLabel) => x.toUpperCase()).includes((x.note.label as ModUserNoteLabel))) {
|
||||
return false
|
||||
}
|
||||
break;
|
||||
case 'note':
|
||||
const actionPropVal = x.note.note;
|
||||
if (actionPropVal === undefined) {
|
||||
return false;
|
||||
}
|
||||
const anyPropMatch = v.some((y: RegExp) => y.test(actionPropVal));
|
||||
if (!anyPropMatch) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'activitytype':
|
||||
const anyMatch = v.some((a: ActivityType) => {
|
||||
switch (a) {
|
||||
case 'submission':
|
||||
if (x.action.actedOn instanceof Submission) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 'comment':
|
||||
if (x.action.actedOn instanceof Comment) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!anyMatch) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
} // case end
|
||||
|
||||
} // for each end
|
||||
|
||||
return true;
|
||||
}); // filter end
|
||||
} else {
|
||||
throw new SimpleError(`Could not determine if a modActions criteria was for Mod Log or Mod Note. Given: ${JSON.stringify(actionCriteria)}`);
|
||||
}
|
||||
|
||||
switch (search) {
|
||||
case 'current':
|
||||
if (validActions.length === 0) {
|
||||
actionResult.push('No Mod Actions present');
|
||||
} else {
|
||||
actionResult.push('Current Action matches criteria');
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 'consecutive':
|
||||
if (isPercent) {
|
||||
throw new SimpleError(`When comparing Mod Actions with 'search: consecutive' the 'count' value cannot be a percentage. Given: ${count}`);
|
||||
@@ -3361,11 +3246,10 @@ export class SubredditResources {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 'current':
|
||||
case 'total':
|
||||
if (isPercent) {
|
||||
// avoid divide by zero
|
||||
const percent = actionsToUse.length === 0 ? 0 : validActions.length / actionsToUse.length;
|
||||
const percent = notes.length === 0 ? 0 : validActions.length / actionsToUse.length;
|
||||
actionResult.push(`${formatNumber(percent)}% of ${actionsToUse.length} matched criteria`);
|
||||
if (comparisonTextOp(percent, operator, value / 100)) {
|
||||
return true;
|
||||
@@ -3544,7 +3428,7 @@ export class BotResourcesManager {
|
||||
authorTTL: number = 10000;
|
||||
enabled: boolean = true;
|
||||
modStreams: Map<string, SPoll<Snoowrap.Submission | Snoowrap.Comment>> = new Map();
|
||||
defaultCache: Promise<Cache>;
|
||||
defaultCache: Cache;
|
||||
defaultCacheConfig: StrongCache
|
||||
defaultCacheMigrated: boolean = false;
|
||||
cacheType: string = 'none';
|
||||
@@ -3648,7 +3532,7 @@ export class BotResourcesManager {
|
||||
// });
|
||||
|
||||
let opts: SubredditResourceOptions = {
|
||||
cache: await this.defaultCache,
|
||||
cache: this.defaultCache,
|
||||
cacheType: this.cacheType,
|
||||
cacheSettingsHash: hash,
|
||||
ttl: this.ttlDefaults,
|
||||
@@ -3679,7 +3563,7 @@ export class BotResourcesManager {
|
||||
trueProvider.prefix = subPrefix;
|
||||
const eventsMax = this.actionedEventsMaxDefault !== undefined ? Math.min(actionedEventsMax, this.actionedEventsMaxDefault) : actionedEventsMax;
|
||||
opts = {
|
||||
cache: await createCacheManager(trueProvider),
|
||||
cache: createCacheManager(trueProvider),
|
||||
actionedEventsMax: eventsMax,
|
||||
cacheType: trueProvider.store,
|
||||
cacheSettingsHash: hash,
|
||||
@@ -3694,7 +3578,7 @@ export class BotResourcesManager {
|
||||
await runMigrations(opts.cache, opts.logger, trueProvider.prefix);
|
||||
}
|
||||
} else if(!this.defaultCacheMigrated) {
|
||||
await runMigrations(await this.defaultCache, this.logger, opts.prefix);
|
||||
await runMigrations(this.defaultCache, this.logger, opts.prefix);
|
||||
this.defaultCacheMigrated = true;
|
||||
}
|
||||
|
||||
@@ -3729,7 +3613,7 @@ export class BotResourcesManager {
|
||||
}
|
||||
|
||||
async getPendingSubredditInvites(): Promise<(string[])> {
|
||||
const subredditNames = await (await this.defaultCache).get(`modInvites`);
|
||||
const subredditNames = await this.defaultCache.get(`modInvites`);
|
||||
if (subredditNames !== undefined && subredditNames !== null) {
|
||||
return subredditNames as string[];
|
||||
}
|
||||
@@ -3740,7 +3624,7 @@ export class BotResourcesManager {
|
||||
if(subreddit === null || subreddit === undefined || subreddit == '') {
|
||||
throw new CMError('Subreddit name cannot be empty');
|
||||
}
|
||||
let subredditNames = await (await this.defaultCache).get(`modInvites`) as (string[] | undefined | null);
|
||||
let subredditNames = await this.defaultCache.get(`modInvites`) as (string[] | undefined | null);
|
||||
if (subredditNames === undefined || subredditNames === null) {
|
||||
subredditNames = [];
|
||||
}
|
||||
@@ -3750,22 +3634,22 @@ export class BotResourcesManager {
|
||||
throw new CMError(`An invite for the Subreddit '${subreddit}' already exists`);
|
||||
}
|
||||
subredditNames.push(cleanName);
|
||||
await (await this.defaultCache).set(`modInvites`, subredditNames, {ttl: 0});
|
||||
await this.defaultCache.set(`modInvites`, subredditNames, {ttl: 0});
|
||||
return;
|
||||
}
|
||||
|
||||
async deletePendingSubredditInvite(subreddit: string): Promise<void> {
|
||||
let subredditNames = await (await this.defaultCache).get(`modInvites`) as (string[] | undefined | null);
|
||||
let subredditNames = await this.defaultCache.get(`modInvites`) as (string[] | undefined | null);
|
||||
if (subredditNames === undefined || subredditNames === null) {
|
||||
subredditNames = [];
|
||||
}
|
||||
subredditNames = subredditNames.filter(x => x.toLowerCase() !== subreddit.trim().toLowerCase());
|
||||
await (await this.defaultCache).set(`modInvites`, subredditNames, {ttl: 0});
|
||||
await this.defaultCache.set(`modInvites`, subredditNames, {ttl: 0});
|
||||
return;
|
||||
}
|
||||
|
||||
async clearPendingSubredditInvites(): Promise<void> {
|
||||
await (await this.defaultCache).del(`modInvites`);
|
||||
await this.defaultCache.del(`modInvites`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -3844,7 +3728,7 @@ export const checkAuthorFilter = async (item: (Submission | Comment), filter: Au
|
||||
return [true, undefined, {criteriaResults: allCritResults, join: 'OR', passed: true}];
|
||||
}
|
||||
|
||||
export const checkItemFilter = async (item: (Submission | Comment), filter: ItemOptions, resources: SubredditResources, options?: {logger?: Logger, source?: ActivitySourceValue, includeIdentifier?: boolean}): Promise<[boolean, ('inclusive' | 'exclusive' | undefined), FilterResult<TypedActivityState>]> => {
|
||||
export const checkItemFilter = async (item: (Submission | Comment), filter: ItemOptions, resources: SubredditResources, options?: {logger?: Logger, source?: ActivitySource, includeIdentifier?: boolean}): Promise<[boolean, ('inclusive' | 'exclusive' | undefined), FilterResult<TypedActivityState>]> => {
|
||||
|
||||
const {
|
||||
logger: parentLogger = NoopLogger,
|
||||
@@ -4002,7 +3886,7 @@ export const checkItemFilter = async (item: (Submission | Comment), filter: Item
|
||||
return [true, undefined, {criteriaResults: allCritResults, join: 'OR', passed: true}];
|
||||
}
|
||||
|
||||
export const checkCommentSubmissionStates = async (item: Comment, submissionStates: SubmissionState[], resources: SubredditResources, logger: Logger, source?: ActivitySourceValue, excludeCondition?: JoinOperands): Promise<[boolean, FilterCriteriaPropertyResult<CommentState>]> => {
|
||||
export const checkCommentSubmissionStates = async (item: Comment, submissionStates: SubmissionState[], resources: SubredditResources, logger: Logger, source?: ActivitySource, excludeCondition?: JoinOperands): Promise<[boolean, FilterCriteriaPropertyResult<CommentState>]> => {
|
||||
// test submission state first since it's more likely(??) we have crit results or cache data for this submission than for the comment
|
||||
|
||||
// get submission
|
||||
|
||||
@@ -3,7 +3,7 @@ import {Submission, Subreddit, Comment} from "snoowrap/dist/objects";
|
||||
import {parseSubredditName} from "../util";
|
||||
import {ModUserNoteLabel} from "../Common/Infrastructure/Atomic";
|
||||
import {CreateModNoteData, ModNote, ModNoteRaw, ModNoteSnoowrapPopulated} from "../Subreddit/ModNotes/ModNote";
|
||||
import {CMError, isStatusError, SimpleError} from "./Errors";
|
||||
import {CMError, SimpleError} from "./Errors";
|
||||
import {RawSubredditRemovalReasonData, SnoowrapActivity} from "../Common/Infrastructure/Reddit";
|
||||
|
||||
// const proxyFactory = (endpoint: string) => {
|
||||
@@ -66,28 +66,6 @@ export class ExtendedSnoowrap extends Snoowrap {
|
||||
return await this.oauthRequest({uri: '/api/info', method: 'get', qs: { sr_name: names.join(',')}}) as Listing<Subreddit>;
|
||||
}
|
||||
|
||||
async subredditExists(name: string): Promise<[boolean, Subreddit?]> {
|
||||
try {
|
||||
// @ts-ignore
|
||||
const sub = await this.getSubreddit(name).fetch();
|
||||
return [true, sub];
|
||||
} catch (e: any) {
|
||||
if (isStatusError(e)) {
|
||||
switch (e.statusCode) {
|
||||
case 403:
|
||||
// we know that the sub exists but it is private
|
||||
return [true, undefined];
|
||||
case 404:
|
||||
return [false, undefined];
|
||||
default:
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async assignUserFlairByTemplateId(options: { flairTemplateId: string, username: string, subredditName: string }): Promise<any> {
|
||||
return await this.oauthRequest({
|
||||
uri: `/r/${options.subredditName}/api/selectflair`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
BotInstance,
|
||||
BotInstanceResponse, BotSubredditInviteResponse,
|
||||
BotInstanceResponse,
|
||||
CMInstanceInterface,
|
||||
ManagerResponse,
|
||||
NormalizedManagerResponse
|
||||
@@ -15,7 +15,6 @@ export class ClientBotInstance implements BotInstance {
|
||||
managers: NormalizedManagerResponse[];
|
||||
nanny?: string | undefined;
|
||||
running: boolean;
|
||||
invites: BotSubredditInviteResponse[]
|
||||
|
||||
constructor(data: BotInstanceResponse, instance: CMInstanceInterface) {
|
||||
this.instance = instance;
|
||||
@@ -25,7 +24,6 @@ export class ClientBotInstance implements BotInstance {
|
||||
this.managers = data.managers.map(x => ({...x, subredditNormal: parseRedditEntity(x.subreddit).name}));
|
||||
this.nanny = data.nanny;
|
||||
this.running = data.running;
|
||||
this.invites = data.invites === undefined || data.invites === null ? [] : data.invites;
|
||||
}
|
||||
|
||||
getManagerNames(): string[] {
|
||||
@@ -58,14 +56,6 @@ export class ClientBotInstance implements BotInstance {
|
||||
return this.getAccessibleSubreddits(user, subreddits).includes(parseRedditEntity(subreddit).name);
|
||||
}
|
||||
|
||||
getInvites() {
|
||||
return this.invites;
|
||||
}
|
||||
|
||||
getInvite(val: string) {
|
||||
return this.invites.find(x => x.id === val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ClientBotInstance;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {SessionOptions, Store} from "express-session";
|
||||
import {TypeormStore} from "connect-typeorm";
|
||||
import {InviteData} from "../Common/interfaces";
|
||||
import {buildCachePrefix, mergeArr} from "../../util";
|
||||
import {buildCachePrefix, createCacheManager, mergeArr} from "../../util";
|
||||
import {Cache} from "cache-manager";
|
||||
// @ts-ignore
|
||||
import CacheManagerStore from 'express-session-cache-manager'
|
||||
@@ -11,7 +11,6 @@ import {ClientSession} from "../../Common/WebEntities/ClientSession";
|
||||
import {Logger} from "winston";
|
||||
import {WebSetting} from "../../Common/WebEntities/WebSetting";
|
||||
import {ErrorWithCause} from "pony-cause";
|
||||
import {createCacheManager} from "../../Common/Cache";
|
||||
|
||||
export interface CacheManagerStoreOptions {
|
||||
prefix?: string
|
||||
@@ -25,7 +24,7 @@ export type TypeormStoreOptions = Partial<SessionOptions & {
|
||||
}>;
|
||||
|
||||
interface IWebStorageProvider {
|
||||
createSessionStore(options?: CacheManagerStoreOptions | TypeormStoreOptions): Promise<Store>
|
||||
createSessionStore(options?: CacheManagerStoreOptions | TypeormStoreOptions): Store
|
||||
|
||||
getSessionSecret(): Promise<string | undefined>
|
||||
|
||||
@@ -49,7 +48,7 @@ abstract class StorageProvider implements IWebStorageProvider {
|
||||
this.logger = logger.child({labels: ['Web', 'Storage', ...loggerLabels]}, mergeArr);
|
||||
}
|
||||
|
||||
abstract createSessionStore(options?: CacheManagerStoreOptions | TypeormStoreOptions): Promise<Store>;
|
||||
abstract createSessionStore(options?: CacheManagerStoreOptions | TypeormStoreOptions): Store;
|
||||
|
||||
abstract getSessionSecret(): Promise<string | undefined>;
|
||||
|
||||
@@ -58,24 +57,24 @@ abstract class StorageProvider implements IWebStorageProvider {
|
||||
|
||||
export class CacheStorageProvider extends StorageProvider {
|
||||
|
||||
protected cache: Promise<Cache>;
|
||||
protected cache: Cache;
|
||||
|
||||
constructor(caching: CacheOptions & StorageProviderOptions) {
|
||||
super(caching);
|
||||
const {logger, invitesMaxAge, loggerLabels, ...restCache } = caching;
|
||||
this.cache = createCacheManager({...restCache, prefix: buildCachePrefix(['web'])}) as Promise<Cache>;
|
||||
this.cache = createCacheManager({...restCache, prefix: buildCachePrefix(['web'])}) as Cache;
|
||||
this.logger.debug('Using CACHE');
|
||||
if (caching.store === 'none') {
|
||||
this.logger.warn(`Using 'none' as cache provider means no one will be able to access the interface since sessions will never be persisted!`);
|
||||
}
|
||||
}
|
||||
|
||||
async createSessionStore(options?: CacheManagerStoreOptions): Promise<Store> {
|
||||
return new CacheManagerStore((await this.cache), {prefix: 'sess:'});
|
||||
createSessionStore(options?: CacheManagerStoreOptions): Store {
|
||||
return new CacheManagerStore(this.cache, {prefix: 'sess:'});
|
||||
}
|
||||
|
||||
async getSessionSecret() {
|
||||
const val = await (await this.cache).get(`sessionSecret`);
|
||||
const val = await this.cache.get(`sessionSecret`);
|
||||
if (val === null || val === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -83,7 +82,7 @@ export class CacheStorageProvider extends StorageProvider {
|
||||
}
|
||||
|
||||
async setSessionSecret(secret: string) {
|
||||
await (await this.cache).set('sessionSecret', secret, {ttl: 0});
|
||||
await this.cache.set('sessionSecret', secret, {ttl: 0});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,7 +101,7 @@ export class DatabaseStorageProvider extends StorageProvider {
|
||||
this.logger.debug('Using DATABASE');
|
||||
}
|
||||
|
||||
async createSessionStore(options?: TypeormStoreOptions): Promise<Store> {
|
||||
createSessionStore(options?: TypeormStoreOptions): Store {
|
||||
return new TypeormStore(options).connect(this.clientSessionRepo)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "../../Common/interfaces";
|
||||
import {
|
||||
buildCachePrefix,
|
||||
defaultFormat, filterLogBySubreddit, filterCriteriaSummary, formatFilterData,
|
||||
createCacheManager, defaultFormat, filterLogBySubreddit, filterCriteriaSummary, formatFilterData,
|
||||
formatLogLineToHtml, filterLogs, getUserAgent,
|
||||
intersect, isLogLineMinLevel,
|
||||
LogEntry, parseInstanceLogInfoName, parseInstanceLogName, parseRedditEntity,
|
||||
@@ -33,7 +33,7 @@ import tcpUsed from "tcp-port-used";
|
||||
import http from "http";
|
||||
import jwt from 'jsonwebtoken';
|
||||
import {Server as SocketServer} from "socket.io";
|
||||
import got, {HTTPError} from 'got';
|
||||
import got from 'got';
|
||||
import sharedSession from "express-socket.io-session";
|
||||
import dayjs from "dayjs";
|
||||
import httpProxy from 'http-proxy';
|
||||
@@ -56,15 +56,8 @@ import {MigrationService} from "../../Common/MigrationService";
|
||||
import {RuleResultEntity} from "../../Common/Entities/RuleResultEntity";
|
||||
import {RuleSetResultEntity} from "../../Common/Entities/RuleSetResultEntity";
|
||||
import { PaginationAwareObject } from "../Common/util";
|
||||
import {
|
||||
BotInstance,
|
||||
BotStatusResponse,
|
||||
BotSubredditInviteResponse,
|
||||
CMInstanceInterface, HeartbeatResponse,
|
||||
InviteData, SubredditInviteDataPersisted
|
||||
} from "../Common/interfaces";
|
||||
import {BotInstance, BotStatusResponse, CMInstanceInterface, InviteData} from "../Common/interfaces";
|
||||
import {open} from "fs/promises";
|
||||
import {createCacheManager} from "../../Common/Cache";
|
||||
|
||||
const emitter = new EventEmitter();
|
||||
|
||||
@@ -324,7 +317,7 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
cookie: {
|
||||
maxAge: sessionMaxAge * 1000,
|
||||
},
|
||||
store: await sessionStoreProvider.createSessionStore(sessionStorage === 'database' ? {
|
||||
store: sessionStoreProvider.createSessionStore(sessionStorage === 'database' ? {
|
||||
cleanupLimit: 2,
|
||||
ttl: sessionMaxAge
|
||||
} : {}),
|
||||
@@ -600,18 +593,7 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
next();
|
||||
}
|
||||
|
||||
const initHeartbeat = async (req: express.Request, res: express.Response, next: Function) => {
|
||||
if(!init) {
|
||||
for(const c of clients) {
|
||||
await refreshClient(c);
|
||||
}
|
||||
init = true;
|
||||
loopHeartbeat();
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
app.getAsync('/auth/helper', initHeartbeat, helperAuthed, instanceWithPermissions, instancesViewData, (req, res) => {
|
||||
app.getAsync('/auth/helper', helperAuthed, instanceWithPermissions, instancesViewData, (req, res) => {
|
||||
return res.render('helper', {
|
||||
redirectUri: clientCredentials.redirectUri,
|
||||
clientId: clientCredentials.clientId,
|
||||
@@ -622,7 +604,7 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.getAsync('/auth/invite/:inviteId', initHeartbeat, async (req, res) => {
|
||||
app.getAsync('/auth/invite/:inviteId', async (req, res) => {
|
||||
const {inviteId} = req.params;
|
||||
|
||||
if (inviteId === undefined) {
|
||||
@@ -717,7 +699,7 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.getAsync('/auth/init/:inviteId', initHeartbeat, async (req: express.Request, res: express.Response) => {
|
||||
app.getAsync('/auth/init/:inviteId', async (req: express.Request, res: express.Response) => {
|
||||
const { inviteId } = req.params;
|
||||
if(inviteId === undefined) {
|
||||
return res.render('error', {error: '`invite` param is missing from URL'});
|
||||
@@ -840,8 +822,6 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
next();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// const authenticatedRouter = Router();
|
||||
// authenticatedRouter.use([ensureAuthenticated, defaultSession]);
|
||||
// app.use(authenticatedRouter);
|
||||
@@ -857,7 +837,7 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
// logger.debug(`Got proxy response: ${res.statusCode} for ${req.url}`);
|
||||
// });
|
||||
|
||||
app.useAsync('/api/', [ensureAuthenticatedApi, initHeartbeat, defaultSession, instanceWithPermissions, botWithPermissions(false), createUserToken], (req: express.Request, res: express.Response) => {
|
||||
app.useAsync('/api/', [ensureAuthenticatedApi, defaultSession, instanceWithPermissions, botWithPermissions(false), createUserToken], (req: express.Request, res: express.Response) => {
|
||||
req.headers.Authorization = `Bearer ${req.token}`
|
||||
|
||||
const instance = req.instance as CMInstanceInterface;
|
||||
@@ -909,6 +889,17 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
next();
|
||||
}*/
|
||||
|
||||
const initHeartbeat = async (req: express.Request, res: express.Response, next: Function) => {
|
||||
if(!init) {
|
||||
for(const c of clients) {
|
||||
await refreshClient(c);
|
||||
}
|
||||
init = true;
|
||||
loopHeartbeat();
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
const redirectBotsNotAuthed = async (req: express.Request, res: express.Response, next: Function) => {
|
||||
if(cmInstances.length === 1 && cmInstances[0].error === 'Missing credentials: refreshToken, accessToken') {
|
||||
// assuming user is doing first-time setup and this is the default localhost bot
|
||||
@@ -1055,139 +1046,8 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.getAsync('/bot/invites/subreddit/:inviteId', initHeartbeat, ensureAuthenticated, defaultSession, async (req: express.Request, res: express.Response) => {
|
||||
|
||||
const {inviteId} = req.params;
|
||||
|
||||
if (inviteId === undefined) {
|
||||
return res.render('error', {error: '`invite` param is missing from URL'});
|
||||
}
|
||||
|
||||
let validInstance: CMInstance | undefined = undefined;
|
||||
let validInvite: BotSubredditInviteResponse | undefined = undefined;
|
||||
let validBot: BotInstance | undefined = undefined;
|
||||
for(const instance of cmInstances) {
|
||||
for(const bot of instance.bots) {
|
||||
validInvite = bot.getInvite(inviteId);
|
||||
if(validInvite !== undefined) {
|
||||
validInstance = instance;
|
||||
validBot = bot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(validInvite === undefined) {
|
||||
// try refreshing clients first
|
||||
await refreshClients(true);
|
||||
}
|
||||
|
||||
for(const instance of cmInstances) {
|
||||
for(const bot of instance.bots) {
|
||||
validInvite = bot.getInvite(inviteId);
|
||||
if(validInvite !== undefined) {
|
||||
validInstance = instance;
|
||||
validBot = bot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(validInvite === undefined || validInstance === undefined || validBot === undefined) {
|
||||
return res.render('error', {error: 'Either no invite exists with the given ID or you are not a moderator of the subreddit this invite is for.'});
|
||||
}
|
||||
|
||||
const user = req.user as Express.User;
|
||||
|
||||
// @ts-ignore
|
||||
if(!user.subreddits.some(x => x.toLowerCase() === validInvite.subreddit.toLowerCase())) {
|
||||
return res.render('error', {error: 'Either no invite exists with the given ID or you are not a moderator of the subreddit this invite is for.'});
|
||||
}
|
||||
|
||||
try {
|
||||
const invite = await got.get(`${validInstance.normalUrl}/bot/invite/${validInvite.id}?bot=${validBot.botName}`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${validInstance.getToken()}`,
|
||||
}
|
||||
}).json() as SubredditInviteDataPersisted;
|
||||
|
||||
const {guests, ...rest} = invite;
|
||||
const guestStr = guests !== undefined && guests !== null && guests.length > 0 ? guests.join(',') : '';
|
||||
|
||||
return res.render('subredditOnboard/onboard', {
|
||||
invite: {...rest, guests: guestStr},
|
||||
bot: validBot.botName,
|
||||
title: `Subreddit Onboarding`,
|
||||
});
|
||||
|
||||
} catch (err: any) {
|
||||
logger.error(err);
|
||||
return res.render('error', {error: `Error occurred while retriving invite data: ${err.message}`});
|
||||
}
|
||||
});
|
||||
|
||||
app.postAsync('/bot/invites/subreddit/:inviteId', ensureAuthenticated, defaultSession, async (req: express.Request, res: express.Response) => {
|
||||
|
||||
const {inviteId} = req.params;
|
||||
|
||||
if (inviteId === undefined) {
|
||||
return res.status(400).send('`invite` param is missing from URL')
|
||||
}
|
||||
|
||||
let validInstance: CMInstance | undefined = undefined;
|
||||
let validInvite: BotSubredditInviteResponse | undefined = undefined;
|
||||
let validBot: BotInstance | undefined = undefined;
|
||||
for(const instance of cmInstances) {
|
||||
for(const bot of instance.bots) {
|
||||
validInvite = bot.getInvite(inviteId);
|
||||
if(validInvite !== undefined) {
|
||||
validInstance = instance;
|
||||
validBot = bot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(validInvite === undefined || validInstance === undefined || validBot === undefined) {
|
||||
return res.status(400).send('Either no invite exists with the given ID or you are not a moderator of the subreddit this invite is for.')
|
||||
}
|
||||
|
||||
const user = req.user as Express.User;
|
||||
|
||||
// @ts-ignore
|
||||
if(!user.subreddits.some(x => x.toLowerCase() === validInvite.subreddit.toLowerCase())) {
|
||||
return res.status(400).send('Either no invite exists with the given ID or you are not a moderator of the subreddit this invite is for.')
|
||||
}
|
||||
|
||||
try {
|
||||
await got.post(`${validInstance.normalUrl}/bot/invite/${validInvite.id}?bot=${validBot.botName}`, {
|
||||
json: req.body,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${validInstance.getToken()}`,
|
||||
}
|
||||
})
|
||||
|
||||
return res.status(200);
|
||||
|
||||
} catch (err: any) {
|
||||
logger.error(err);
|
||||
res.status(500)
|
||||
let msg = err.message;
|
||||
if(err instanceof HTTPError && typeof err.response.body === 'string') {
|
||||
msg = err.response.body
|
||||
}
|
||||
return res.send(msg);
|
||||
}
|
||||
});
|
||||
|
||||
app.getAsync('/bot/invites/subreddit', initHeartbeat, ensureAuthenticated, defaultSession, instanceWithPermissions, botWithPermissions(true), async (req: express.Request, res: express.Response) => {
|
||||
res.render('subredditOnboard/helper', {
|
||||
title: `Create Subreddit Invite`,
|
||||
});
|
||||
});
|
||||
|
||||
app.getAsync('/bot/invites', initHeartbeat, ensureAuthenticated, defaultSession, async (req: express.Request, res: express.Response) => {
|
||||
res.render('subredditOnboard/manager', {
|
||||
app.getAsync('/bot/invites', defaultSession, async (req: express.Request, res: express.Response) => {
|
||||
res.render('modInvites', {
|
||||
title: `Pending Moderation Invites`,
|
||||
});
|
||||
});
|
||||
@@ -1201,7 +1061,7 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.getAsync('/guest', [ensureAuthenticatedApi, initHeartbeat, defaultSession, instanceWithPermissions, botWithPermissions(true)], async (req: express.Request, res: express.Response) => {
|
||||
app.getAsync('/guest', [ensureAuthenticatedApi, defaultSession, instanceWithPermissions, botWithPermissions(true)], async (req: express.Request, res: express.Response) => {
|
||||
const {subreddit} = req.query as any;
|
||||
return res.status(req.user?.isSubredditGuest(req.bot, subreddit) ? 200 : 403).send();
|
||||
});
|
||||
@@ -1247,7 +1107,7 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
return res.send();
|
||||
});
|
||||
|
||||
app.getAsync('/events', [ensureAuthenticatedApi, initHeartbeat, defaultSession, instanceWithPermissions, botWithPermissions(true), createUserToken], async (req: express.Request, res: express.Response) => {
|
||||
app.getAsync('/events', [ensureAuthenticatedApi, defaultSession, instanceWithPermissions, botWithPermissions(true), createUserToken], async (req: express.Request, res: express.Response) => {
|
||||
const {subreddit, page = 1, permalink, related, author} = req.query as any;
|
||||
const resp = await got.get(`${(req.instance as CMInstanceInterface).normalUrl}/events`, {
|
||||
headers: {
|
||||
@@ -1615,18 +1475,14 @@ const webClient = async (options: OperatorConfigWithFileContext) => {
|
||||
|
||||
const loopHeartbeat = async () => {
|
||||
while(true) {
|
||||
await refreshClients();
|
||||
for(const c of clients) {
|
||||
await refreshClient(c);
|
||||
}
|
||||
// sleep for 10 seconds then do heartbeat check again
|
||||
await sleep(10000);
|
||||
}
|
||||
}
|
||||
|
||||
const refreshClients = async (force = false) => {
|
||||
for(const c of clients) {
|
||||
await refreshClient(c, force);
|
||||
}
|
||||
}
|
||||
|
||||
const addBot = async (inviteId: string, botPayload: any) => {
|
||||
|
||||
const cmInstance = cmInstances.find(x => x.invites.includes(inviteId));
|
||||
|
||||
@@ -16,24 +16,24 @@ class ServerUser extends CMUser<App, Bot, Manager> {
|
||||
}
|
||||
|
||||
canAccessInstance(val: App): boolean {
|
||||
return this.isOperator || this.machine || val.bots.filter(x => x.canUserAccessBot(this.name, this.subreddits)).length > 0;
|
||||
return this.isOperator || val.bots.filter(x => x.canUserAccessBot(this.name, this.subreddits)).length > 0;
|
||||
}
|
||||
|
||||
canAccessBot(val: Bot): boolean {
|
||||
return this.isOperator || this.machine || val.canUserAccessBot(this.name, this.subreddits);
|
||||
return this.isOperator || val.canUserAccessBot(this.name, this.subreddits);
|
||||
}
|
||||
|
||||
accessibleBots(bots: Bot[]): Bot[] {
|
||||
return (this.isOperator || this.machine) ? bots : bots.filter(x => x.canUserAccessBot(this.name, this.subreddits));
|
||||
return this.isOperator ? bots : bots.filter(x => x.canUserAccessBot(this.name, this.subreddits));
|
||||
}
|
||||
|
||||
canAccessSubreddit(val: Bot, name: string): boolean {
|
||||
const normalName = parseRedditEntity(name).name;
|
||||
return this.isOperator || this.machine || this.accessibleSubreddits(val).some(x => x.toNormalizedManager().subredditNormal === normalName);
|
||||
return this.isOperator || this.accessibleSubreddits(val).some(x => x.toNormalizedManager().subredditNormal === normalName);
|
||||
}
|
||||
|
||||
accessibleSubreddits(bot: Bot): Manager[] {
|
||||
if(this.isOperator || this.machine) {
|
||||
if(this.isOperator) {
|
||||
return bot.subManagers;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import {BotConnection, LogInfo, ManagerStats} from "../../Common/interfaces";
|
||||
import {Guest, GuestAll} from "../../Common/Entities/Guest/GuestInterfaces";
|
||||
import {URL} from "url";
|
||||
import {Dayjs} from "dayjs";
|
||||
import {Subreddit} from "snoowrap/dist/objects";
|
||||
|
||||
export interface BotStats {
|
||||
startedAtHuman: string,
|
||||
@@ -91,10 +90,6 @@ export interface NormalizedManagerResponse extends ManagerResponse {
|
||||
subredditNormal: string
|
||||
}
|
||||
|
||||
export interface BotSubredditInviteResponse {
|
||||
subreddit: string
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface BotInstanceResponse {
|
||||
botName: string
|
||||
@@ -103,12 +98,6 @@ export interface BotInstanceResponse {
|
||||
managers: ManagerResponse[]
|
||||
nanny?: string
|
||||
running: boolean
|
||||
invites: BotSubredditInviteResponse[]
|
||||
}
|
||||
|
||||
export interface SubredditOnboardingReadiness {
|
||||
hasManager: boolean
|
||||
isMod: boolean
|
||||
}
|
||||
|
||||
export interface BotInstanceFunctions {
|
||||
@@ -119,7 +108,6 @@ export interface BotInstanceFunctions {
|
||||
getGuestSubreddits: (user: string) => string[]
|
||||
canUserAccessBot: (user: string, subreddits: string[]) => boolean
|
||||
canUserAccessSubreddit: (subreddit: string, user: string, subreddits: string[]) => boolean
|
||||
getInvite(val: string): BotSubredditInviteResponse | undefined
|
||||
}
|
||||
|
||||
export interface BotInstance extends BotInstanceResponse, BotInstanceFunctions {
|
||||
@@ -174,11 +162,3 @@ export interface SubredditInviteData {
|
||||
initialConfig?: string
|
||||
expiresAt?: number | Dayjs
|
||||
}
|
||||
|
||||
export interface HydratedSubredditInviteData extends Omit<SubredditInviteData, 'subreddit'>{
|
||||
subreddit: string | Subreddit
|
||||
}
|
||||
|
||||
export interface SubredditInviteDataPersisted extends SubredditInviteData {
|
||||
id: string
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ export const heartbeat = (opData: OperatorData) => {
|
||||
guests: y.managerEntity.getGuests().map(x => guestEntityToApiGuest(x)),
|
||||
})),
|
||||
running: x.running,
|
||||
invites: x.getSubredditInvites().map(y => ({subreddit: y.subreddit, id: y.id}))
|
||||
})),
|
||||
operators: opData.name,
|
||||
operatorDisplay: opData.display,
|
||||
|
||||
@@ -237,7 +237,12 @@ const saveGuestWikiEdit = async (req: Request, res: Response) => {
|
||||
const {location, data, reason = 'Updated through CM Web', create = false} = req.body as any;
|
||||
|
||||
try {
|
||||
await req.manager?.writeConfig(data, `${reason} by Guest Mod ${req.user?.name}`)
|
||||
// @ts-ignore
|
||||
const wiki = await req.manager?.subreddit.getWikiPage(location) as WikiPage;
|
||||
await wiki.edit({
|
||||
text: data,
|
||||
reason: `${reason} by Guest Mod ${req.user?.name}`,
|
||||
});
|
||||
} catch (err: any) {
|
||||
res.status(500);
|
||||
return res.send(err.message);
|
||||
|
||||
@@ -4,61 +4,17 @@ import {CMError} from "../../../../../Utils/Errors";
|
||||
|
||||
const getSubredditInvites = async (req: Request, res: Response) => {
|
||||
|
||||
return res.json(await req.serverBot.getSubredditInvites());
|
||||
return res.json(await req.serverBot.cacheManager.getPendingSubredditInvites());
|
||||
};
|
||||
export const getSubredditInvitesRoute = [authUserCheck(), botRoute(), getSubredditInvites];
|
||||
|
||||
const getSubredditInvite = async (req: Request, res: Response) => {
|
||||
|
||||
const {id} = req.params;
|
||||
const invite = await req.serverBot.getInvite(id);
|
||||
if(invite !== undefined) {
|
||||
const {bot, ...inviteRest} = invite;
|
||||
const readiness = req.serverBot.getOnboardingReadiness(invite);
|
||||
return res.json({...inviteRest, ...readiness});
|
||||
}
|
||||
return res.status(404);
|
||||
};
|
||||
export const getSubredditInviteRoute = [authUserCheck(['operator', 'machine']), botRoute(), getSubredditInvite];
|
||||
|
||||
const acceptSubredditInvite = async (req: Request, res: Response) => {
|
||||
|
||||
const {id} = req.params;
|
||||
const invite = await req.serverBot.getInvite(id);
|
||||
if(invite !== undefined) {
|
||||
const {initialConfig, guests} = req.body as any;
|
||||
invite.initialConfig = initialConfig;
|
||||
invite.guests = guests;
|
||||
|
||||
try {
|
||||
await req.serverBot.finishOnboarding(invite);
|
||||
return res.status(200);
|
||||
} catch(e: any) {
|
||||
const errorParts = [e.message];
|
||||
if(e instanceof CMError && e.cause !== undefined) {
|
||||
errorParts.push(e.cause?.message);
|
||||
}
|
||||
res.status(500)
|
||||
return res.send(e.message);
|
||||
}
|
||||
}
|
||||
return res.status(404);
|
||||
};
|
||||
export const acceptSubredditInviteRoute = [authUserCheck(['operator', 'machine']), botRoute(), acceptSubredditInvite];
|
||||
|
||||
const addSubredditInvite = async (req: Request, res: Response) => {
|
||||
|
||||
const {subreddit, initialConfig, guests} = req.body as any;
|
||||
const {subreddit} = req.body as any;
|
||||
if (subreddit === undefined || subreddit === null || subreddit === '') {
|
||||
return res.status(400).send('subreddit must be defined');
|
||||
}
|
||||
try {
|
||||
const invite = await req.serverBot.addSubredditInvite({
|
||||
subreddit,
|
||||
initialConfig,
|
||||
guests,
|
||||
});
|
||||
return res.status(200).send(invite.id);
|
||||
await req.serverBot.cacheManager.addPendingSubredditInvite(subreddit);
|
||||
} catch (e: any) {
|
||||
if (e instanceof CMError) {
|
||||
req.logger.warn(e);
|
||||
@@ -68,15 +24,16 @@ const addSubredditInvite = async (req: Request, res: Response) => {
|
||||
return res.status(500).send(e.message);
|
||||
}
|
||||
}
|
||||
return res.status(200).send();
|
||||
};
|
||||
export const addSubredditInviteRoute = [authUserCheck(), botRoute(), addSubredditInvite];
|
||||
const deleteSubredditInvite = async (req: Request, res: Response) => {
|
||||
|
||||
const {subreddit, id} = req.query as any;
|
||||
const {subreddit} = req.query as any;
|
||||
if (subreddit === undefined || subreddit === null || subreddit === '') {
|
||||
return res.status(400).send('subreddit must be defined');
|
||||
}
|
||||
await req.serverBot.deleteSubredditInvite(subreddit);
|
||||
await req.serverBot.cacheManager.deletePendingSubredditInvite(subreddit);
|
||||
return res.status(200).send();
|
||||
};
|
||||
export const deleteSubredditInviteRoute = [authUserCheck(), botRoute(), deleteSubredditInvite];
|
||||
|
||||
@@ -73,10 +73,8 @@ const logs = () => {
|
||||
const requestedBots = bots.map(x => x.botName);
|
||||
|
||||
const origin = req.header('X-Forwarded-For') ?? req.header('host');
|
||||
const stream = logger.stream();
|
||||
try {
|
||||
|
||||
stream.on('log', (log: LogInfo) => {
|
||||
logger.stream().on('log', (log: LogInfo) => {
|
||||
if (isLogLineMinLevel(log, level as string)) {
|
||||
const {subreddit: subName, bot, user} = log;
|
||||
let canAccess = false;
|
||||
@@ -107,13 +105,13 @@ const logs = () => {
|
||||
logger.info(`${userName} from ${origin} => CONNECTED`);
|
||||
await pEvent(req, 'close');
|
||||
//logger.debug('Request closed detected with "close" listener');
|
||||
res.destroy();
|
||||
return;
|
||||
} catch (e: any) {
|
||||
if (e.code !== 'ECONNRESET') {
|
||||
logger.error(e);
|
||||
}
|
||||
} finally {
|
||||
stream.removeAllListeners();
|
||||
logger.info(`${userName} from ${origin} => DISCONNECTED`);
|
||||
res.destroy();
|
||||
}
|
||||
|
||||
@@ -36,12 +36,10 @@ import { sleep } from '../../util';
|
||||
import {Invokee} from "../../Common/Infrastructure/Atomic";
|
||||
import {Point} from "@influxdata/influxdb-client";
|
||||
import {
|
||||
acceptSubredditInviteRoute,
|
||||
addBotInviteRoute,
|
||||
addSubredditInviteRoute,
|
||||
deleteSubredditInviteRoute,
|
||||
getBotInviteRoute,
|
||||
getSubredditInviteRoute,
|
||||
getSubredditInvitesRoute
|
||||
} from "./routes/authenticated/user/invites";
|
||||
|
||||
@@ -192,10 +190,6 @@ const rcbServer = async function (options: OperatorConfigWithFileContext) {
|
||||
|
||||
server.getAsync('/bot/invite', ...getSubredditInvitesRoute);
|
||||
|
||||
server.getAsync('/bot/invite/:id', ...getSubredditInviteRoute);
|
||||
|
||||
server.postAsync('/bot/invite/:id', ...acceptSubredditInviteRoute);
|
||||
|
||||
server.postAsync('/bot/invite', ...addSubredditInviteRoute);
|
||||
|
||||
server.deleteAsync('/bot/invite', ...deleteSubredditInviteRoute);
|
||||
|
||||
|
Before Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 23 KiB |
@@ -169,14 +169,6 @@ a {
|
||||
display: inherit;
|
||||
}
|
||||
|
||||
.show {
|
||||
display: inherit;
|
||||
}
|
||||
|
||||
.invisible {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.triggeredStateToggle {
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -191,7 +183,7 @@ li > ul {
|
||||
}
|
||||
|
||||
.smallLi:before {
|
||||
margin-left: -5px;
|
||||
margin-left: -10px;
|
||||
content: ""
|
||||
}
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 620 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 15 KiB |
@@ -1 +0,0 @@
|
||||
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
|
||||
@@ -1,17 +1,19 @@
|
||||
<html lang="en">
|
||||
<%- include('../partials/head', {title: 'CM Manage Subreddit Onboarding'}) %>
|
||||
<%- include('partials/head', {title: 'CM Accept Moderator Invitations From'}) %>
|
||||
<body class="bg-gray-900 text-white">
|
||||
<div class="min-w-screen min-h-screen font-sans">
|
||||
<%- include('../partials/title', {title: 'Manage Subreddit Onboarding'}) %>
|
||||
<%- include('partials/title', {title: 'Accept Moderator Invitations From'}) %>
|
||||
<div class="container mx-auto">
|
||||
<div class="grid">
|
||||
<div class="bg-gray-600">
|
||||
<div class="p-6 md:px-10 md:py-6">
|
||||
<div id="error" class="font-semibold"></div>
|
||||
<ul id="sublist" class="list-inside list-disc mb-5">
|
||||
<ul id="sublist" class="list-inside list-disc">
|
||||
<li id="noSubs">Not accepting any invitations...</li>
|
||||
</ul>
|
||||
<a id="subredditInviteHelper" href="/bot/invites/subreddit">Create Subreddit Onboarding Invites</a>
|
||||
<input id="subName" style="min-width:500px;"
|
||||
class="text-black placeholder-gray-500 rounded ml-3 mt-2 mb-3 mt-3 p-2"
|
||||
placeholder="Subreddit to accept invite from..."> <a id="addSub" class="ml-3" href="">Add</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -48,39 +50,44 @@
|
||||
}
|
||||
});
|
||||
|
||||
let helperLink = document.querySelector('#subredditInviteHelper');
|
||||
const url = new URL(helperLink.href)
|
||||
for (let [k,v] of new URLSearchParams(window.location.search).entries()){
|
||||
url.searchParams.set(k,v)
|
||||
}
|
||||
helperLink.href = url.toString();
|
||||
document.querySelector('#addSub').addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
function addSubredditElement(data) {
|
||||
const {
|
||||
subreddit: sub,
|
||||
guests,
|
||||
initialConfig,
|
||||
expiresAt,
|
||||
id,
|
||||
} = data;
|
||||
const subNameElm = document.querySelector('#subName');
|
||||
subName = subNameElm.value;
|
||||
|
||||
fetch(`/api/bot/invite${document.location.search}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
subreddit: document.querySelector('#subName').value,
|
||||
})
|
||||
}).then((resp) => {
|
||||
if (!resp.ok) {
|
||||
document.querySelector("#errorWrapper").classList.remove('hidden');
|
||||
resp.text().then(t => {
|
||||
document.querySelector("#error").innerHTML = t;
|
||||
});
|
||||
} else {
|
||||
const ns = document.querySelector('#noSubs');
|
||||
if(ns !== null) {
|
||||
document.querySelector('#noSubs').style = 'display: none;';
|
||||
}
|
||||
addSubredditElement(subName);
|
||||
subNameElm.value = '';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function addSubredditElement(sub) {
|
||||
var node = document.createElement("LI");
|
||||
node.id = `subInvite-${sub}`;
|
||||
var textNode = document.createTextNode(sub);
|
||||
node.appendChild(textNode);
|
||||
node.insertAdjacentHTML('beforeend', `<a href="" class="removeSub" id="removeSub-${sub}" data-subreddit="${sub}"><span style="display:inline; margin-left: 10px" class="iconify-inline" data-icon="icons8:cancel"></span></a>`);
|
||||
|
||||
const parts = [
|
||||
`<li><a href="${document.location.origin}/bot/invites/subreddit/${id}">${document.location.origin}/bot/invites/subreddit/${id}</a></li>`
|
||||
];
|
||||
if(guests !== null && guests !== undefined) {
|
||||
parts.push(`<li>Guests: ${guests.join(', ')}`);
|
||||
}
|
||||
if(initialConfig !== null && initialConfig !== undefined) {
|
||||
parts.push(`<li>Initial Config: <a href="${initialConfig}">${initialConfig}</a>`);
|
||||
}
|
||||
|
||||
node.insertAdjacentHTML('beforeend',`<ul class="list-inside list-disc mb-5">${parts.join('\n')}</ul`)
|
||||
|
||||
sl.appendChild(node);
|
||||
document.querySelector(`#removeSub-${sub}`).addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
@@ -13,9 +13,4 @@
|
||||
<meta name="robots" content="noindex">
|
||||
<!--icons from https://heroicons.com -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/intro.js/6.0.0/introjs.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/public/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/public/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/public/favicon-16x16.png">
|
||||
<link rel="manifest" href="/public/site.webmanifest">
|
||||
<link rel="icon" type="image/x-icon" href="/public/favicon.ico">
|
||||
</head>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<svg class="loading invisible" version="1.1" id="L9" xmlns="http://www.w3.org/2000/svg"
|
||||
<svg class="loading" version="1.1" id="L9" xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 100 100" xml:space="preserve">
|
||||
<path
|
||||
|
||||
|
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 596 B |
@@ -20,7 +20,7 @@
|
||||
<li class="my-3 px-3">
|
||||
<span class="rounded-md py-2 px-3 border">
|
||||
<a class="font-normal pointer hover:font-bold" href="/bot/invites?instance=<%= instanceId %>&bot=<%= botData.system.name %>">
|
||||
Manage Subreddits Invites +
|
||||
Add Subreddit +
|
||||
</a>
|
||||
</span>
|
||||
</li>
|
||||
|
||||
@@ -689,13 +689,7 @@
|
||||
</div>
|
||||
<%- include('partials/logSettings') %>
|
||||
</div>
|
||||
<div class="liveLogIndicator">
|
||||
<%- include('partials/loadingIcon') %>
|
||||
<span class="liveLogErrorWrapper invisible">
|
||||
<span class="iconify-inline red" style="display: inline;" data-icon="ci:error-outline"></span>
|
||||
<span class="liveLogError"></span><a class="restartLogs ml-3" href="#">Restart Live Logs</a>
|
||||
</span>
|
||||
</div>
|
||||
<div data-subreddit="<%= data.name %>" class="logs font-mono text-sm">
|
||||
<% data.logs.forEach(function (logEntry){ %>
|
||||
<%- logEntry %>
|
||||
@@ -757,17 +751,6 @@
|
||||
});
|
||||
})
|
||||
|
||||
document.querySelectorAll('.restartLogs').forEach(el => {
|
||||
el.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
const subSection = e.target.closest('div.sub');
|
||||
|
||||
if (subSection !== null) {
|
||||
getStreamingLogs(subSection.dataset.subreddit, subSection.dataset.bot);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll(".checkUrl").forEach(el => {
|
||||
const toggleButtons = (e) => {
|
||||
const subFilter = `.sub[data-subreddit="${e.target.dataset.subreddit}"]`;
|
||||
@@ -979,7 +962,7 @@
|
||||
}).observe(element);
|
||||
}
|
||||
|
||||
function getStreamingLogs(sub, bot, restarts = 0) {
|
||||
function getStreamingLogs(sub, bot) {
|
||||
|
||||
console.debug(`Getting stream for ${bot} ${sub}`);
|
||||
|
||||
@@ -1035,49 +1018,38 @@
|
||||
bufferedLogs = [];
|
||||
}
|
||||
|
||||
setLiveLogIndicator(bot, sub, true);
|
||||
const fetchPromise = fetch(`/api/logs?instance=<%= instanceId %>&bot=${bot}&subreddit=${sub}&level=${level}&sort=${sort}&limit=${limitSel}&stream=true&streamObjects=true&formatted=false`, {signal})
|
||||
.then(response => {
|
||||
return response.body;
|
||||
})
|
||||
.then(rs => {
|
||||
return rs.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(new TransformStream({
|
||||
transform(chunk, controller) {
|
||||
textBuffer += chunk;
|
||||
const lines = textBuffer.split('\n');
|
||||
for (const line of lines.slice(0, -1)) {
|
||||
controller.enqueue(line);
|
||||
}
|
||||
textBuffer = lines.slice(-1)[0];
|
||||
},
|
||||
flush(controller) {
|
||||
if (textBuffer) {
|
||||
controller.enqueue(textBuffer);
|
||||
}
|
||||
.then(response => response.body)
|
||||
.then(rs =>
|
||||
rs.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(new TransformStream({
|
||||
transform(chunk, controller) {
|
||||
textBuffer += chunk;
|
||||
const lines = textBuffer.split('\n');
|
||||
for (const line of lines.slice(0, -1)) {
|
||||
controller.enqueue(line);
|
||||
}
|
||||
}))
|
||||
textBuffer = lines.slice(-1)[0];
|
||||
},
|
||||
flush(controller) {
|
||||
if (textBuffer) {
|
||||
controller.enqueue(textBuffer);
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
// Parse JSON objects
|
||||
.pipeThrough(new TransformStream({
|
||||
transform(line, controller) {
|
||||
if (line) {
|
||||
controller.enqueue(
|
||||
JSON.parse(line)
|
||||
);
|
||||
}
|
||||
// Parse JSON objects
|
||||
.pipeThrough(new TransformStream({
|
||||
transform(line, controller) {
|
||||
if (line) {
|
||||
controller.enqueue(
|
||||
JSON.parse(line)
|
||||
);
|
||||
}
|
||||
}));
|
||||
}
|
||||
)
|
||||
.catch((e) => {
|
||||
if(e.name === 'AbortError') {
|
||||
setLiveLogIndicator(bot, sub, false);
|
||||
console.debug(`Log streaming for ${bot} ${sub} aborted`);
|
||||
} else {
|
||||
setLiveLogIndicator(bot, sub, false, `Live Log encountered an error: ${e.message}`);
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
}))
|
||||
).catch((e) => {
|
||||
console.warn(e);
|
||||
});
|
||||
|
||||
fetchPromise.then(async res => {
|
||||
@@ -1092,11 +1064,6 @@
|
||||
if(done) {
|
||||
keepReading = false;
|
||||
console.debug(`${bot}.${sub} log stream reader signalled it is done`);
|
||||
if(restarts < 3) {
|
||||
getStreamingLogs(sub, bot, restarts + 1);
|
||||
} else {
|
||||
setLiveLogIndicator(bot, sub, false, `Tried to automatically restart stream too many times (${restarts +1}) which indicates something may be wrong with communication.`);
|
||||
}
|
||||
}
|
||||
if(value) {
|
||||
//console.log(`((Logged For ${bot} ${sub})) ${value.message}`);
|
||||
@@ -1131,11 +1098,9 @@
|
||||
}).catch((e) => {
|
||||
if(e.name !== 'AbortError') {
|
||||
console.debug(`Non-abort error occurred while streaming logs for ${bot} ${sub}`);
|
||||
console.warn(e);
|
||||
setLiveLogIndicator(bot, sub, false, `Live Log encountered an error: ${e.message}`);
|
||||
console.error(e);
|
||||
} else {
|
||||
console.debug(`Log streaming for ${bot} ${sub} aborted`);
|
||||
setLiveLogIndicator(bot, sub, false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1143,36 +1108,6 @@
|
||||
recentlySeen.set(`${bot}.${sub}`, {...existing, fetch: fetchPromise, controller, streamStart: Date.now()});
|
||||
}
|
||||
|
||||
function setLiveLogIndicator(bot, sub, live, error = undefined) {
|
||||
const liveIndicator = document.querySelector(`[data-bot="${bot}"][data-subreddit="${sub}"] .liveLogIndicator .loading`);
|
||||
if(null !== liveIndicator) {
|
||||
if(live) {
|
||||
if(liveIndicator.classList.contains('invisible')) {
|
||||
liveIndicator.classList.remove('invisible');
|
||||
}
|
||||
// if(!liveIndicator.classList.contains('show')) {
|
||||
// liveIndicator.classList.add('show');
|
||||
// }
|
||||
} else {
|
||||
if(!liveIndicator.classList.contains('invisible')) {
|
||||
liveIndicator.classList.add('invisible');
|
||||
}
|
||||
}
|
||||
}
|
||||
const liveErrorWrapper = document.querySelector(`[data-bot="${bot}"][data-subreddit="${sub}"] .liveLogIndicator .liveLogErrorWrapper`);
|
||||
if(null !== liveErrorWrapper) {
|
||||
if(live && !liveErrorWrapper.classList.contains('invisible')) {
|
||||
liveErrorWrapper.classList.add('invisible');
|
||||
}
|
||||
if(!live && error !== undefined) {
|
||||
if(liveErrorWrapper.classList.contains('invisible')) {
|
||||
liveErrorWrapper.classList.remove('invisible');
|
||||
}
|
||||
document.querySelector(`[data-bot="${bot}"][data-subreddit="${sub}"] .liveLogIndicator .liveLogError`).innerHTML = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const delayedItemsMap = new Map();
|
||||
let lastSeenIdentifier = null;
|
||||
const subIndicators = ['red', 'green', 'yellow'];
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
<html lang="en">
|
||||
<%- include('../partials/head', {title: 'Subreddit Onboarding Helper'}) %>
|
||||
<body class="bg-gray-900 text-white font-sans">
|
||||
<div class="min-w-screen min-h-screen">
|
||||
<%- include('../partials/header') %>
|
||||
<div class="container mx-auto mt-5">
|
||||
<div class="grid grid-cols-1 gap-5">
|
||||
<div class="bg-gray-600">
|
||||
<div class="bg-gray-700">
|
||||
<div class="text-xl px-4 p-2">Choose subreddit(s) to onboard</div>
|
||||
</div>
|
||||
<div class="p-6 md:px-10 md:py-6">
|
||||
<div class="my-2 ml-5">
|
||||
<div class="space-y-3">
|
||||
<div>Specify which subreddits this bot should recognize moderator invites from.</div>
|
||||
<div>CM will NOT recognize (or accept) moderator invites from Subreddits you have not created an Onboarding invite for.</div>
|
||||
<div>Subreddits should be seperated with a comma.</div>
|
||||
<input id="subreddits" style="max-width:800px; display: block;"
|
||||
class="text-black placeholder-gray-500 rounded mt-2 mb-3 p-2 w-full"
|
||||
placeholder="aSubreddit,aSecondSubreddit,aThirdSubreddit">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-gray-600">
|
||||
<div class="bg-gray-700">
|
||||
<div class="text-xl px-4 p-2">Settings that require Subreddit approval</div>
|
||||
</div>
|
||||
<div class="p-6 md:px-10 md:py-6">
|
||||
<div class="space-y-3 mb-6">
|
||||
<div><strong>If any of these settings are specified then a moderator will need to login to CM to complete the onboarding process even after sending the moderator invite to the bot.</strong> If none of these settings are specified CM will automatically accept the moderator invite.</div>
|
||||
<div>The moderator completing onboarding will also be able to opt-out or change any of these settings.</div>
|
||||
</div>
|
||||
<div class="text-lg text-semibold my-3">(Optional) Specify initial Guest Access</div>
|
||||
<div class="my-2 ml-5">
|
||||
<div class="space-y-3">
|
||||
<div>Specify Reddit users who should be automatically added with <b>Guest Access</b> to these subreddits once onboarding is complete.</div>
|
||||
<div>If you are already a moderator on all of the subreddits being added you can skip this step.</div>
|
||||
<div>Adding initial Guest Access is useful when you (the operator) want to setup configs for subreddits you are not a moderator of. This step reduces friction for onboarding as it eliminates the need for moderators to login to the dashboard and manually give you Guest Access.</div>
|
||||
<input id="guestMods" style="max-width:800px; display: block;"
|
||||
class="text-black placeholder-gray-500 rounded mt-2 mb-3 p-2 w-full"
|
||||
placeholder="RedditUser1,RedditUser2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-lg text-semibold my-3">(Optional) Set initial Config
|
||||
</div>
|
||||
<div class="ml-5">
|
||||
<div class="space-y-2">
|
||||
<div>If specified, this is a normal URL or <a target="_blank" href="https://github.com/FoxxMD/context-mod/tree/master/docs/subreddit/components#url-tokens"><span class="font-mono">wiki:</span> token</a> pointing to a configuration that CM should automatically write to the Subreddit's config during onboarding.</div>
|
||||
<input id="initialConfig" style="max-width:800px; display: block;"
|
||||
class="text-black placeholder-gray-500 rounded mt-2 mb-3 p-2 w-full"
|
||||
placeholder="https://...">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-gray-600">
|
||||
<div class="bg-gray-700">
|
||||
<div class="text-xl px-4 p-2">Create Onboaring Invites</div>
|
||||
</div>
|
||||
<div class="p-6 md:px-10 md:py-6">
|
||||
<div class="space-y-3">
|
||||
<div class="text-lg text-semibold my-3"><a id="doAuth" href="">Click to generate Onboarding Invites</a></div>
|
||||
<div>Unique links will be generated for each subreddit.</div>
|
||||
<ul class="list-inside list-disc" id="inviteLinks"></ul>
|
||||
<div id="errorWrapper" class="font-semibold hidden">Errors:
|
||||
<ul id="errorList" class="list-inside list-disc"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%- include('../partials/footer') %>
|
||||
<script>
|
||||
function setError(val) {
|
||||
if(val === null) {
|
||||
document.querySelector("#errorWrapper").classList.add('hidden');
|
||||
document.querySelector('#errorList').innerHTML = '';
|
||||
} else {
|
||||
document.querySelector("#errorWrapper").classList.remove('hidden');
|
||||
const node = document.createElement("LI");
|
||||
node.appendChild(document.createTextNode(val));
|
||||
document.querySelector("#errorList").appendChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
function addLink(sub, val) {
|
||||
if(val === null) {
|
||||
document.querySelector('#inviteLinks').innerHTML = '';
|
||||
} else {
|
||||
const node = document.createElement("LI");
|
||||
node.appendChild(document.createTextNode(`${sub}: `));
|
||||
node.insertAdjacentHTML('beforeend', `<a class="font-semibold" href="${document.location.origin}/bot/invites/subreddit/${val}">${document.location.origin}/bot/invites/subreddit/${val}</a>`);
|
||||
document.querySelector("#inviteLinks").appendChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector('#doAuth').addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
const subredditVal = document.querySelector('#subreddits').value.trim();
|
||||
|
||||
if(subredditVal === '') {
|
||||
setError('Subreddits cannot be empty!');
|
||||
return;
|
||||
} else {
|
||||
setError(null);
|
||||
}
|
||||
|
||||
const subreddits = subredditVal.split(',').map(x => x.trim());
|
||||
|
||||
const body = {};
|
||||
const config = document.querySelector('#initialConfig').value.trim();
|
||||
if(config !== '') {
|
||||
body.initialConfig = config;
|
||||
}
|
||||
const guests = document.querySelector('#guestMods').value.trim();
|
||||
if(guests !== '') {
|
||||
body.guests = guests.split(',').map(x => x.trim());
|
||||
}
|
||||
|
||||
for(const sub of subreddits) {
|
||||
fetch(`/api/bot/invite${document.location.search}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({...body, subreddit: sub})
|
||||
}).then((resp) => {
|
||||
if(!resp.ok) {
|
||||
|
||||
document.querySelector("#errorWrapper").classList.remove('hidden');
|
||||
resp.text().then(t => {
|
||||
setError(`${sub}: ${t}`);
|
||||
});
|
||||
} else {
|
||||
document.querySelector("#errorWrapper").classList.add('hidden');
|
||||
document.querySelector('#subreddits').value = '';
|
||||
resp.text().then(t => {
|
||||
addLink(sub, t);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,139 +0,0 @@
|
||||
<html lang="en">
|
||||
<%- include('../partials/head', {title: 'Subreddit Onboarding Helper'}) %>
|
||||
<body class="bg-gray-900 text-white font-sans">
|
||||
<div class="min-w-screen min-h-screen">
|
||||
<%- include('../partials/title', {title: 'Subreddit Onboarding'}) %>
|
||||
<div class="container mx-auto mt-5">
|
||||
<div class="grid grid-cols-1 gap-5">
|
||||
<div class="bg-gray-600">
|
||||
<div class="bg-gray-700">
|
||||
<div class="text-xl px-4 p-2">Hello 👋</div>
|
||||
</div>
|
||||
<div class="p-6 md:px-10 md:py-6">
|
||||
<div class="my-2 ml-5">
|
||||
<div class="space-y-3">
|
||||
<div>This is the onboarding invitation to setup
|
||||
<strong><a href="https://reddit.com/<%= bot %>"><%= bot %></a></strong> as a
|
||||
<a taget="_blank" href="https://github.com/FoxxMD/context-mod">Context Mod</a> (CM) bot on the subreddit
|
||||
<strong><a href="https://reddit.com/r/<%= invite.subreddit %>">r/<%= invite.subreddit %></a></strong>.
|
||||
|
||||
<% if (invite.isMod || invite.hasManager) { %>
|
||||
<div> <strong>Good news!</strong> <%= bot %> is already a moderator of this subreddit. "Finishing" onboarding below will have no effect on your bot. If you want to set Guest Access or a Config please do so from the <a href="/">Dashboard</a>.</div>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-gray-600">
|
||||
<div class="bg-gray-700">
|
||||
<div class="text-xl px-4 p-2">Initial Settings</div>
|
||||
</div>
|
||||
<div class="p-6 md:px-10 md:py-6">
|
||||
<div class="space-y-3 mb-6">
|
||||
<div>The settings below, if specified, will automatically be applied when you finish onboarding.</div>
|
||||
</div>
|
||||
<div class="text-lg text-semibold my-3">Guest Access</div>
|
||||
<div class="my-2 ml-5">
|
||||
<div class="space-y-3">
|
||||
<div><strong>Guest Access</strong> allows Reddit Users who are not moderators of this subreddit to access the bot's dashboard and edit its configuration.
|
||||
This is useful when you want help from outside your mod team with setting up CM but don't want to set the user as Moderator of your subreddit.</div>
|
||||
<div>Separate multiple users with commas. Users listed will have Guest Access for 24 hours.</div>
|
||||
<input id="guestMods" style="max-width:800px; display: block;"
|
||||
class="text-black placeholder-gray-500 rounded mt-2 mb-3 p-2 w-full"
|
||||
placeholder="RedditUser1,RedditUser2" value="<%= invite.guests %>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-lg text-semibold my-3">Initial Config
|
||||
</div>
|
||||
<div class="ml-5">
|
||||
<div class="space-y-2">
|
||||
<div>A normal URL or <a target="_blank" href="https://github.com/FoxxMD/context-mod/tree/master/docs/subreddit/components#url-tokens"><span class="font-mono">wiki:</span> token</a> pointing to a configuration that CM should automatically write to the Subreddit's config during onboarding.</div>
|
||||
<input id="initialConfig" style="max-width:800px; display: block;"
|
||||
class="text-black placeholder-gray-500 rounded mt-2 mb-3 p-2 w-full"
|
||||
placeholder="https://..."
|
||||
value="<%= invite.initialConfig %>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-gray-600">
|
||||
<div class="bg-gray-700">
|
||||
<div class="text-xl px-4 p-2">Finish Onboaring</div>
|
||||
</div>
|
||||
<div class="p-6 md:px-10 md:py-6">
|
||||
<div class="space-y-3">
|
||||
<div>Some things to know:</div>
|
||||
<ul class="list-disc list-inside">
|
||||
<li>Like Automoderator, CM will NOT RUN if it does not have a configuration set.</li>
|
||||
<li>To run correctly <%= bot %> must at least have the <strong>Manage Wiki Pages</strong> Mod permission.</li>
|
||||
<li>Click the <strong>Help</strong> link on the top-right of the Dashboard, after finishing onboarding, to get a guided tour of the bot's interface or check out the Dashboard <a href="https://github.com/FoxxMD/context-mod/blob/master/docs/webInterface.md">Tips and Tricks</a> documentation.</li>
|
||||
</ul>
|
||||
<div id="finishOnboarding" class="text-lg text-semibold my-3"><a id="doOnboarding" href="">Click to finish Onboarding</a></div>
|
||||
<div id="errorWrapper" class="font-semibold hidden">Errors:
|
||||
<ul id="errorList" class="list-inside list-disc"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%- include('../partials/footer') %>
|
||||
<script>
|
||||
function setError(val) {
|
||||
if(val === null) {
|
||||
document.querySelector("#errorWrapper").classList.add('hidden');
|
||||
document.querySelector('#errorList').innerHTML = '';
|
||||
} else {
|
||||
document.querySelector("#errorWrapper").classList.remove('hidden');
|
||||
const node = document.createElement("LI");
|
||||
node.innerHTML = val;
|
||||
document.querySelector("#errorList").appendChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector('#doOnboarding').addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
const body = {};
|
||||
const config = document.querySelector('#initialConfig').value.trim();
|
||||
if(config !== '') {
|
||||
body.initialConfig = config;
|
||||
}
|
||||
const guests = document.querySelector('#guestMods').value.trim();
|
||||
if(guests !== '') {
|
||||
body.guests = guests.split(',').map(x => x.trim());
|
||||
}
|
||||
|
||||
fetch(`/bot/invites/subreddit/<%= invite.id%>`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
}).then((resp) => {
|
||||
if(!resp.ok) {
|
||||
document.querySelector("#errorWrapper").classList.remove('hidden');
|
||||
resp.text().then(t => {
|
||||
let msg = t;
|
||||
if(t.toLowerCase().includes('accepted moderator')) {
|
||||
msg = `${t}<br/><br/>CM is now running but not all Initial Settings were applied. Please finish applying them using the dashboard. <a href="/">Click here</a> to go to the dashboard.`;
|
||||
setError(msg);
|
||||
} else {
|
||||
setError(msg);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
document.querySelector("#errorWrapper").classList.add('hidden');
|
||||
document.querySelector('#finishOnboarding').innerHTML = 'Onboarding complete! Redirecting you to the Dashboard...';
|
||||
setTimeout(() => {
|
||||
window.location.href = window.location.origin;
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
197
src/util.ts
@@ -1,24 +1,23 @@
|
||||
import winston, {Logger} from "winston";
|
||||
import dayjs, {Dayjs} from 'dayjs';
|
||||
import {Duration} from 'dayjs/plugin/duration.js';
|
||||
import * as cronjs from '@datasert/cronjs-matcher';
|
||||
import Ajv from "ajv";
|
||||
import {InvalidOptionArgumentError} from "commander";
|
||||
import {deflateSync, inflateSync} from "zlib";
|
||||
import pixelmatch from 'pixelmatch';
|
||||
import os from 'os';
|
||||
import pathUtil from 'path';
|
||||
import fetch, {Response} from 'node-fetch';
|
||||
import {Response} from 'node-fetch';
|
||||
import crypto, {createHash} from 'crypto';
|
||||
import {
|
||||
ActionResult,
|
||||
ActivityDispatch,
|
||||
ActivityDispatchConfig,
|
||||
CacheOptions,
|
||||
CheckSummary,
|
||||
ImageComparisonResult,
|
||||
ItemCritPropHelper,
|
||||
LogInfo,
|
||||
NamedGroup,
|
||||
LogInfo, NamedGroup,
|
||||
PollingOptionsStrong,
|
||||
PostBehaviorOptionConfig,
|
||||
RegExResult,
|
||||
@@ -34,12 +33,15 @@ import {
|
||||
} from "./Common/interfaces";
|
||||
import InvalidRegexError from "./Utils/InvalidRegexError";
|
||||
import {accessSync, constants, promises} from "fs";
|
||||
import {VERSION} from "./Common/defaults";
|
||||
import cacheManager from "cache-manager";
|
||||
import {cacheOptDefaults, VERSION} from "./Common/defaults";
|
||||
import cacheManager, {Cache} from "cache-manager";
|
||||
import redisStore from "cache-manager-redis-store";
|
||||
import Autolinker from 'autolinker';
|
||||
import {create as createMemoryStore} from './Utils/memoryStore';
|
||||
import {LEVEL, MESSAGE} from "triple-beam";
|
||||
import {Comment, PrivateMessage, RedditUser, Submission, Subreddit} from "snoowrap/dist/objects";
|
||||
import reRegExp from '@stdlib/regexp-regexp';
|
||||
import fetch from "node-fetch";
|
||||
import ImageData from "./Common/ImageData";
|
||||
import {Sharp, SharpOptions} from "sharp";
|
||||
import {ErrorWithCause, stackWithCauses} from "pony-cause";
|
||||
@@ -68,22 +70,18 @@ import {
|
||||
UserNoteCriteria
|
||||
} from "./Common/Infrastructure/Filters/FilterCriteria";
|
||||
import {
|
||||
ActivitySourceData,
|
||||
ActivitySource,
|
||||
ActivitySourceTypes,
|
||||
ActivitySourceValue,
|
||||
CacheProvider,
|
||||
ConfigFormat,
|
||||
DurationVal,
|
||||
ExternalUrlContext,
|
||||
ImageHashCacheData,
|
||||
DurationVal, ExternalUrlContext, ImageHashCacheData,
|
||||
ModUserNoteLabel,
|
||||
modUserNoteLabels,
|
||||
RedditEntity,
|
||||
RedditEntityType,
|
||||
RelativeDateTimeMatch,
|
||||
statFrequencies,
|
||||
StatisticFrequency,
|
||||
StatisticFrequencyOption,
|
||||
UrlContext,
|
||||
StatisticFrequencyOption, UrlContext,
|
||||
WikiContext
|
||||
} from "./Common/Infrastructure/Atomic";
|
||||
import {
|
||||
@@ -118,7 +116,7 @@ import {
|
||||
} from "./Common/Infrastructure/ActivityWindow";
|
||||
import {RunnableBaseJson} from "./Common/Infrastructure/Runnable";
|
||||
import Snoowrap from "snoowrap";
|
||||
import {adjectives, animals, colors, uniqueNamesGenerator} from 'unique-names-generator';
|
||||
import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';
|
||||
import {ActionResultEntity} from "./Common/Entities/ActionResultEntity";
|
||||
|
||||
|
||||
@@ -219,26 +217,8 @@ const errorAwareFormat = {
|
||||
}
|
||||
}
|
||||
|
||||
const isProbablyError = (val: any, explicitErrorName?: string) => {
|
||||
if(typeof val !== 'object' || val === null) {
|
||||
return false;
|
||||
}
|
||||
const {name, stack} = val;
|
||||
if(explicitErrorName !== undefined) {
|
||||
if(name !== undefined && name.toLowerCase().includes(explicitErrorName)) {
|
||||
return true;
|
||||
}
|
||||
if(stack !== undefined && stack.trim().toLowerCase().indexOf(explicitErrorName.toLowerCase()) === 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else if(stack !== undefined) {
|
||||
return true;
|
||||
} else if(name !== undefined && name.toLowerCase().includes('error')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
const isProbablyError = (val: any, errName = 'error') => {
|
||||
return typeof val === 'object' && val.name !== undefined && val.name.toLowerCase().includes(errName);
|
||||
}
|
||||
|
||||
export const PASS = '✓';
|
||||
@@ -729,7 +709,8 @@ export const deflateUserNotes = (usersObject: object) => {
|
||||
const binaryData = deflateSync(jsonString);
|
||||
|
||||
// Convert binary data to a base64 string with a Buffer
|
||||
return Buffer.from(binaryData).toString('base64');
|
||||
const blob = Buffer.from(binaryData).toString('base64');
|
||||
return blob;
|
||||
}
|
||||
|
||||
export const isActivityWindowConfig = (val: any): val is FullActivityWindowConfig => {
|
||||
@@ -785,34 +766,6 @@ export const parseDuration = (val: string, strict = true): Duration => {
|
||||
return res[0].duration;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/63729682
|
||||
const RELATIVE_DATETIME_REGEX: RegExp = /(?<cron>(?:(?:(?:(?:\d+,)+\d+|(?:\d+(?:\/|-|#)\d+)|\d+L?|\*(?:\/\d+)?|L(?:-\d+)?|\?|[A-Z]{3}(?:-[A-Z]{3})?) ?){5,7})$)|(?<dayofweek>mon|tues|wed|thurs|fri|sat|sun){1}/i;
|
||||
const RELATIVE_DATETIME_REGEX_URL = 'https://regexr.com/6u3cc';
|
||||
|
||||
// https://day.js.org/docs/en/get-set/day
|
||||
const dayOfWeekMap: Record<string, number> = {
|
||||
sun: 0,
|
||||
mon: 1,
|
||||
tues: 2,
|
||||
wed: 3,
|
||||
thurs: 4,
|
||||
fri: 5,
|
||||
sat: 6,
|
||||
};
|
||||
|
||||
export const matchesRelativeDateTime = (expr: RelativeDateTimeMatch, dt: Dayjs) => {
|
||||
const res = parseRegexSingleOrFail(RELATIVE_DATETIME_REGEX, expr);
|
||||
if (res === undefined) {
|
||||
throw new InvalidRegexError(RELATIVE_DATETIME_REGEX, expr, RELATIVE_DATETIME_REGEX_URL);
|
||||
}
|
||||
if (res.named.dayofweek !== undefined) {
|
||||
return dayOfWeekMap[res.named.dayofweek] === dt.day();
|
||||
}
|
||||
// assume 5-point cron expression
|
||||
// the matcher requires datetime second field to be 0 https://github.com/datasert/cronjs/issues/31
|
||||
return cronjs.isTimeMatches(res.named.cron, dt.set('second', 0).toISOString());
|
||||
}
|
||||
|
||||
const SUBREDDIT_NAME_REGEX: RegExp = /^\s*(?:\/r\/|r\/)*(\w+)*\s*$/;
|
||||
const SUBREDDIT_NAME_REGEX_URL = 'https://regexr.com/61a1d';
|
||||
export const parseSubredditName = (val:string): string => {
|
||||
@@ -1762,6 +1715,42 @@ export const cacheStats = (): ResourceStats => {
|
||||
};
|
||||
}
|
||||
|
||||
export const buildCacheOptionsFromProvider = (provider: CacheProvider | any): CacheOptions => {
|
||||
if(typeof provider === 'string') {
|
||||
return {
|
||||
store: provider as CacheProvider,
|
||||
...cacheOptDefaults
|
||||
}
|
||||
}
|
||||
return {
|
||||
store: 'memory',
|
||||
...cacheOptDefaults,
|
||||
...provider,
|
||||
}
|
||||
}
|
||||
|
||||
export const createCacheManager = (options: CacheOptions): Cache => {
|
||||
const {store, max, ttl = 60, host = 'localhost', port, auth_pass, db, ...rest} = options;
|
||||
switch (store) {
|
||||
case 'none':
|
||||
return cacheManager.caching({store: 'none', max, ttl});
|
||||
case 'redis':
|
||||
return cacheManager.caching({
|
||||
store: redisStore,
|
||||
host,
|
||||
port,
|
||||
auth_pass,
|
||||
db,
|
||||
ttl,
|
||||
...rest,
|
||||
});
|
||||
case 'memory':
|
||||
default:
|
||||
//return cacheManager.caching({store: 'memory', max, ttl});
|
||||
return cacheManager.caching({store: {create: createMemoryStore}, max, ttl, shouldCloneBeforeSet: false});
|
||||
}
|
||||
}
|
||||
|
||||
export const randomId = () => crypto.randomBytes(20).toString('hex');
|
||||
|
||||
export const intersect = (a: Array<any>, b: Array<any>) => {
|
||||
@@ -2450,24 +2439,20 @@ export const mergeFilters = (objectConfig: RunnableBaseJson, filterDefs: FilterC
|
||||
let derivedAuthorIs: AuthorOptions = buildFilter(authorIsDefault);
|
||||
if (authorIsBehavior === 'merge') {
|
||||
derivedAuthorIs = merge.all([authorIs, authorIsDefault], {arrayMerge: removeFromSourceIfKeysExistsInDestination});
|
||||
} else if (!filterIsEmpty(authorIs)) {
|
||||
} else if (Object.keys(authorIs).length > 0) {
|
||||
derivedAuthorIs = authorIs;
|
||||
}
|
||||
|
||||
let derivedItemIs: ItemOptions = buildFilter(itemIsDefault);
|
||||
if (itemIsBehavior === 'merge') {
|
||||
derivedItemIs = merge.all([itemIs, itemIsDefault], {arrayMerge: removeFromSourceIfKeysExistsInDestination});
|
||||
} else if (!filterIsEmpty(itemIs)) {
|
||||
} else if (Object.keys(itemIs).length > 0) {
|
||||
derivedItemIs = itemIs;
|
||||
}
|
||||
|
||||
return [derivedAuthorIs, derivedItemIs];
|
||||
}
|
||||
|
||||
export const filterIsEmpty = (obj: FilterOptions<any>): boolean => {
|
||||
return (obj.include === undefined || obj.include.length === 0) && (obj.exclude === undefined || obj.exclude.length === 0);
|
||||
}
|
||||
|
||||
export const buildFilter = (filterVal: MinimalOrFullMaybeAnonymousFilter<AuthorCriteria | TypedActivityState | ActivityState>): FilterOptions<AuthorCriteria | TypedActivityState | ActivityState> => {
|
||||
if(Array.isArray(filterVal)) {
|
||||
const named = filterVal.map(x => normalizeCriteria(x));
|
||||
@@ -2571,7 +2556,28 @@ export const normalizeCriteria = <T extends AuthorCriteria | TypedActivityState
|
||||
criteria.description = Array.isArray(criteria.description) ? criteria.description : [criteria.description];
|
||||
}
|
||||
if(criteria.modActions !== undefined) {
|
||||
criteria.modActions.map((x, index) => normalizeModActionCriteria(x));
|
||||
criteria.modActions.map((x, index) => {
|
||||
const common = {
|
||||
...x,
|
||||
type: x.type === undefined ? undefined : (Array.isArray(x.type) ? x.type : [x.type])
|
||||
}
|
||||
if(asModNoteCriteria(x)) {
|
||||
return {
|
||||
...common,
|
||||
noteType: x.noteType === undefined ? undefined : (Array.isArray(x.noteType) ? x.noteType : [x.noteType]),
|
||||
note: x.note === undefined ? undefined : (Array.isArray(x.note) ? x.note : [x.note]),
|
||||
}
|
||||
} else if(asModLogCriteria(x)) {
|
||||
return {
|
||||
...common,
|
||||
action: x.action === undefined ? undefined : (Array.isArray(x.action) ? x.action : [x.action]),
|
||||
details: x.details === undefined ? undefined : (Array.isArray(x.details) ? x.details : [x.details]),
|
||||
description: x.description === undefined ? undefined : (Array.isArray(x.description) ? x.description : [x.description]),
|
||||
activityType: x.activityType === undefined ? undefined : (Array.isArray(x.activityType) ? x.activityType : [x.activityType]),
|
||||
}
|
||||
}
|
||||
return common;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2581,29 +2587,6 @@ export const normalizeCriteria = <T extends AuthorCriteria | TypedActivityState
|
||||
};
|
||||
}
|
||||
|
||||
export const normalizeModActionCriteria = (x: (ModNoteCriteria | ModLogCriteria)): (ModNoteCriteria | ModLogCriteria) => {
|
||||
const common = {
|
||||
...x,
|
||||
type: x.type === undefined ? undefined : (Array.isArray(x.type) ? x.type : [x.type])
|
||||
}
|
||||
if(asModNoteCriteria(x)) {
|
||||
return {
|
||||
...common,
|
||||
noteType: x.noteType === undefined ? undefined : (Array.isArray(x.noteType) ? x.noteType : [x.noteType]),
|
||||
note: x.note === undefined ? undefined : (Array.isArray(x.note) ? x.note : [x.note]),
|
||||
}
|
||||
} else if(asModLogCriteria(x)) {
|
||||
return {
|
||||
...common,
|
||||
action: x.action === undefined ? undefined : (Array.isArray(x.action) ? x.action : [x.action]),
|
||||
details: x.details === undefined ? undefined : (Array.isArray(x.details) ? x.details : [x.details]),
|
||||
description: x.description === undefined ? undefined : (Array.isArray(x.description) ? x.description : [x.description]),
|
||||
activityType: x.activityType === undefined ? undefined : (Array.isArray(x.activityType) ? x.activityType : [x.activityType]),
|
||||
}
|
||||
}
|
||||
return common;
|
||||
}
|
||||
|
||||
export const asNamedCriteria = <T>(val: MaybeAnonymousCriteria<T> | undefined): val is NamedCriteria<T> => {
|
||||
if(val === undefined || typeof val === 'string') {
|
||||
return false;
|
||||
@@ -2691,30 +2674,17 @@ export const isCommentState = (state: TypedActivityState): state is CommentState
|
||||
const DISPATCH_REGEX: RegExp = /^dispatch:/i;
|
||||
const POLL_REGEX: RegExp = /^poll:/i;
|
||||
const USER_REGEX: RegExp = /^user:/i;
|
||||
const ACTIVITY_SOURCE_REGEX: RegExp = /^(?<type>dispatch|poll|user)(?:$|:(?<identifier>[^\s\r\n]+)$)/i
|
||||
const ACTIVITY_SOURCE_REGEX_URL = 'https://regexr.com/6uqn6';
|
||||
export const asActivitySourceValue = (val: string): val is ActivitySourceValue => {
|
||||
export const asActivitySource = (val: string): val is ActivitySource => {
|
||||
if(['dispatch','poll','user'].some(x => x === val)) {
|
||||
return true;
|
||||
}
|
||||
return DISPATCH_REGEX.test(val) || POLL_REGEX.test(val) || USER_REGEX.test(val);
|
||||
}
|
||||
|
||||
export const asActivitySource = (val: any): val is ActivitySourceData => {
|
||||
return null !== val && typeof val === 'object' && 'type' in val;
|
||||
}
|
||||
|
||||
export const strToActivitySourceData = (val: string): ActivitySourceData => {
|
||||
export const strToActivitySource = (val: string): ActivitySource => {
|
||||
const cleanStr = val.trim();
|
||||
if (asActivitySourceValue(cleanStr)) {
|
||||
const res = parseRegexSingleOrFail(ACTIVITY_SOURCE_REGEX, cleanStr);
|
||||
if (res === undefined) {
|
||||
throw new InvalidRegexError(ACTIVITY_SOURCE_REGEX, cleanStr, ACTIVITY_SOURCE_REGEX_URL, 'Could not parse activity source');
|
||||
}
|
||||
return {
|
||||
type: res.named.type,
|
||||
identifier: res.named.identifier
|
||||
}
|
||||
if (asActivitySource(cleanStr)) {
|
||||
return cleanStr;
|
||||
}
|
||||
throw new SimpleError(`'${cleanStr}' is not a valid ActivitySource. Must be one of: dispatch, dispatch:[identifier], poll, poll:[identifier], user, or user:[identifier]`);
|
||||
}
|
||||
@@ -2994,8 +2964,3 @@ export const generateRandomName = () => {
|
||||
export const asStrongImageHashCache = (data: ImageHashCacheData): data is Required<ImageHashCacheData> => {
|
||||
return data.original !== undefined && data.flipped !== undefined;
|
||||
}
|
||||
|
||||
export const generateFullWikiUrl = (subreddit: Subreddit | string, location: string) => {
|
||||
const subName = subreddit instanceof Subreddit ? subreddit.url : `r/${subreddit}/`;
|
||||
return `https://reddit.com${subName}wiki/${location}`
|
||||
}
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
import {describe, it} from 'mocha';
|
||||
import {assert} from 'chai';
|
||||
import dayjs from "dayjs";
|
||||
import dduration, {Duration, DurationUnitType} from 'dayjs/plugin/duration.js';
|
||||
import utc from 'dayjs/plugin/utc.js';
|
||||
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
||||
import tz from 'dayjs/plugin/timezone';
|
||||
import relTime from 'dayjs/plugin/relativeTime.js';
|
||||
import sameafter from 'dayjs/plugin/isSameOrAfter.js';
|
||||
import samebefore from 'dayjs/plugin/isSameOrBefore.js';
|
||||
import weekOfYear from 'dayjs/plugin/weekOfYear.js';
|
||||
import {SubredditResources} from "../src/Subreddit/SubredditResources";
|
||||
import {NoopLogger} from '../src/Utils/loggerFactory';
|
||||
import {Subreddit, Comment, Submission, RedditUser} from 'snoowrap/dist/objects';
|
||||
import Snoowrap from "snoowrap";
|
||||
import {getResource, getSnoowrap, getSubreddit, sampleActivity} from "./testFactory";
|
||||
import {Subreddit as SubredditEntity} from "../src/Common/Entities/Subreddit";
|
||||
import {Activity} from '../src/Common/Entities/Activity';
|
||||
import {cmToSnoowrapActivityMap} from "../src/Common/Infrastructure/Filters/FilterCriteria";
|
||||
import {SnoowrapActivity} from "../src/Common/Infrastructure/Reddit";
|
||||
|
||||
dayjs.extend(dduration);
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(relTime);
|
||||
dayjs.extend(sameafter);
|
||||
dayjs.extend(samebefore);
|
||||
dayjs.extend(tz);
|
||||
dayjs.extend(advancedFormat);
|
||||
dayjs.extend(weekOfYear);
|
||||
|
||||
|
||||
|
||||
describe('Author Criteria', function () {
|
||||
let resource: SubredditResources;
|
||||
let snoowrap: Snoowrap;
|
||||
let subreddit: Subreddit;
|
||||
let subredditEntity: SubredditEntity;
|
||||
|
||||
before(async () => {
|
||||
resource = await getResource();
|
||||
snoowrap = await getSnoowrap();
|
||||
subreddit = await getSubreddit();
|
||||
subredditEntity = await resource.database.getRepository(SubredditEntity).save(new SubredditEntity({
|
||||
id: subreddit.id,
|
||||
name: subreddit.name
|
||||
}));
|
||||
});
|
||||
|
||||
const testAuthor = (userProps: any = {}, activityType: string = 'submission', activityProps: any = {}) => {
|
||||
const author = new RedditUser({
|
||||
name: 'aTestUser',
|
||||
is_suspended: false,
|
||||
...userProps,
|
||||
}, snoowrap, true);
|
||||
|
||||
|
||||
let activity: SnoowrapActivity;
|
||||
if (activityType === 'submission') {
|
||||
activity = new Submission({
|
||||
created: 1664220502,
|
||||
...activityProps,
|
||||
}, snoowrap, false);
|
||||
} else {
|
||||
activity = new Comment({
|
||||
created: 1664220502,
|
||||
...activityProps,
|
||||
}, snoowrap, false);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
author._fetch = author;
|
||||
activity.author = author;
|
||||
return activity;
|
||||
};
|
||||
|
||||
describe('Moderator accessible criteria', function () {
|
||||
|
||||
// TODO isContributor
|
||||
});
|
||||
|
||||
describe('Publicly accessible criteria', function () {
|
||||
|
||||
it('Should match name literal', async function () {
|
||||
assert.isTrue((await resource.isAuthor(testAuthor(), {name: ['foo','test']}, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match name regex', async function () {
|
||||
assert.isTrue((await resource.isAuthor(testAuthor(), {name: ['/fo.*/i','/te.*/i']}, true)).passed);
|
||||
});
|
||||
|
||||
for(const prop of ['flairCssClass', 'flairTemplate', 'flairText']) {
|
||||
let activityPropName = cmToSnoowrapActivityMap[prop] ?? prop;
|
||||
if(activityPropName === 'link_flair_template_id') {
|
||||
activityPropName = 'author_flair_template_id';
|
||||
}
|
||||
|
||||
it(`Should detect specific ${prop} as single string`, async function () {
|
||||
assert.isTrue((await resource.isAuthor(testAuthor({}, 'submission',{
|
||||
[activityPropName]: 'test',
|
||||
}), {[prop]: 'test'}, true)).passed);
|
||||
});
|
||||
it(`Should detect specific ${prop} from array of string`, async function () {
|
||||
assert.isTrue((await resource.isAuthor(testAuthor({}, 'submission',{
|
||||
[activityPropName]: 'test',
|
||||
}), {[prop]: ['foo','test']}, true)).passed);
|
||||
});
|
||||
it(`Should detect specific ${prop} is not in criteria`, async function () {
|
||||
assert.isFalse((await resource.isAuthor(testAuthor({}, 'submission',{
|
||||
[activityPropName]: 'test',
|
||||
}), {[prop]: ['foo']}, true)).passed);
|
||||
});
|
||||
it(`Should detect any ${prop}`, async function () {
|
||||
assert.isTrue((await resource.isAuthor(testAuthor({}, 'submission',{
|
||||
[activityPropName]: 'test',
|
||||
}), {[prop]: true}, true)).passed);
|
||||
});
|
||||
it(`Should detect no ${prop}`, async function () {
|
||||
assert.isTrue((await resource.isAuthor(testAuthor({}, 'submission',{
|
||||
[activityPropName]: null,
|
||||
}), {[prop]: false}, true)).passed);
|
||||
assert.isTrue((await resource.isAuthor(testAuthor({}, 'submission',{
|
||||
[activityPropName]: '',
|
||||
}), {[prop]: false}, true)).passed);
|
||||
assert.isFalse((await resource.isAuthor(testAuthor({}, 'submission',{
|
||||
[activityPropName]: '',
|
||||
}), {[prop]: 'foo'}, true)).passed);
|
||||
});
|
||||
/*it(`Should detect ${prop} as Regular Expression`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test'
|
||||
}, snoowrap, false), {[prop]: '/te.*!/'}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test'
|
||||
}, snoowrap, false), {[prop]: ['foo', '/t.*!/']}, NoopLogger, true)).passed);
|
||||
});*/
|
||||
}
|
||||
|
||||
// TODO isMod
|
||||
// TODO shadowbanned
|
||||
|
||||
it('Should detect age', async function () {
|
||||
const time = dayjs().subtract(5, 'minutes').unix();
|
||||
const agedAuthor = testAuthor({created: time})
|
||||
assert.isTrue((await resource.isAuthor(agedAuthor, {age: '> 4 minutes'}, true)).passed);
|
||||
assert.isTrue((await resource.isAuthor(agedAuthor, {age: '< 10 minutes'}, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match link karma', async function () {
|
||||
const author = testAuthor({link_karma: 10})
|
||||
assert.isTrue((await resource.isAuthor(author, {linkKarma: '> 4'}, true)).passed);
|
||||
assert.isTrue((await resource.isAuthor(author, {linkKarma: '< 11'}, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match comment karma', async function () {
|
||||
const author = testAuthor({comment_karma: 10})
|
||||
assert.isTrue((await resource.isAuthor(author, {commentKarma: '> 4'}, true)).passed);
|
||||
assert.isTrue((await resource.isAuthor(author, {commentKarma: '< 11'}, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match total karma', async function () {
|
||||
const author = testAuthor({total_karma: 10})
|
||||
assert.isTrue((await resource.isAuthor(author, {totalKarma: '> 4'}, true)).passed);
|
||||
assert.isTrue((await resource.isAuthor(author, {totalKarma: '< 11'}, true)).passed);
|
||||
});
|
||||
|
||||
it('Should check verfied email status', async function () {
|
||||
const author = testAuthor({has_verified_mail: true})
|
||||
assert.isTrue((await resource.isAuthor(author, {verified: true}, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match profile description literal', async function () {
|
||||
const author = testAuthor({subreddit: new Subreddit({
|
||||
display_name: {
|
||||
public_description: 'this is a test'
|
||||
}
|
||||
}, snoowrap, true)});
|
||||
assert.isTrue((await resource.isAuthor(author, {description: 'this is a test'}, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match profile description regex', async function () {
|
||||
const author = testAuthor({subreddit: new Subreddit({
|
||||
display_name: {
|
||||
public_description: 'this is a test'
|
||||
}
|
||||
}, snoowrap, true)});
|
||||
assert.isTrue((await resource.isAuthor(author, {description: '/te.*/i'}, true)).passed);
|
||||
});
|
||||
|
||||
// TODO usernotes
|
||||
// TODO modactions
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,342 +0,0 @@
|
||||
import {describe, it} from 'mocha';
|
||||
import {assert} from 'chai';
|
||||
import dayjs from "dayjs";
|
||||
import dduration, {Duration, DurationUnitType} from 'dayjs/plugin/duration.js';
|
||||
import utc from 'dayjs/plugin/utc.js';
|
||||
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
||||
import tz from 'dayjs/plugin/timezone';
|
||||
import relTime from 'dayjs/plugin/relativeTime.js';
|
||||
import sameafter from 'dayjs/plugin/isSameOrAfter.js';
|
||||
import samebefore from 'dayjs/plugin/isSameOrBefore.js';
|
||||
import weekOfYear from 'dayjs/plugin/weekOfYear.js';
|
||||
import {SubredditResources} from "../src/Subreddit/SubredditResources";
|
||||
import {NoopLogger} from '../src/Utils/loggerFactory';
|
||||
import {Subreddit, Comment, Submission} from 'snoowrap/dist/objects';
|
||||
import Snoowrap from "snoowrap";
|
||||
import {getResource, getSnoowrap, getSubreddit, sampleActivity} from "./testFactory";
|
||||
import {Subreddit as SubredditEntity} from "../src/Common/Entities/Subreddit";
|
||||
import {Activity} from '../src/Common/Entities/Activity';
|
||||
import {cmToSnoowrapActivityMap} from "../src/Common/Infrastructure/Filters/FilterCriteria";
|
||||
|
||||
dayjs.extend(dduration);
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(relTime);
|
||||
dayjs.extend(sameafter);
|
||||
dayjs.extend(samebefore);
|
||||
dayjs.extend(tz);
|
||||
dayjs.extend(advancedFormat);
|
||||
dayjs.extend(weekOfYear);
|
||||
|
||||
describe('Item Criteria', function () {
|
||||
let resource: SubredditResources;
|
||||
let snoowrap: Snoowrap;
|
||||
let subreddit: Subreddit;
|
||||
let subredditEntity: SubredditEntity;
|
||||
|
||||
before(async () => {
|
||||
resource = await getResource();
|
||||
snoowrap = await getSnoowrap();
|
||||
subreddit = await getSubreddit();
|
||||
subredditEntity = await resource.database.getRepository(SubredditEntity).save(new SubredditEntity({
|
||||
id: subreddit.id,
|
||||
name: subreddit.name
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Moderator accessible criteria', function () {
|
||||
|
||||
describe('Reports criteria', function () {
|
||||
|
||||
let sub: Submission;
|
||||
let activity: Activity;
|
||||
|
||||
before(async () => {
|
||||
try {
|
||||
sub = new Submission({
|
||||
title: 'test',
|
||||
id: 't3_je93j',
|
||||
name: 't3_je93j',
|
||||
created: dayjs().subtract(10, 'minutes').unix(),
|
||||
created_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
num_reports: 7,
|
||||
user_reports: [
|
||||
['misinformation', 1, false, true],
|
||||
['personal attack', 3, false, true]
|
||||
],
|
||||
mod_reports: [
|
||||
['suspicious activity', 1, false, true],
|
||||
['hate', 2, false, true]
|
||||
],
|
||||
subreddit,
|
||||
permalink: 'test',
|
||||
author: 'aUser'
|
||||
}, snoowrap, false);
|
||||
|
||||
activity = Activity.fromSnoowrapActivity(subredditEntity, sub);
|
||||
await resource.database.getRepository(Activity).save(activity);
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('Matches number of reports', async function () {
|
||||
assert.isTrue((await resource.isItem(sub, {reports: '> 2'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Matches number of user reports', async function () {
|
||||
assert.isTrue((await resource.isItem(sub, {reports: '> 3 user'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Matches number of mod reports', async function () {
|
||||
assert.isTrue((await resource.isItem(sub, {reports: '< 4 mod'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Matches report reason literal', async function () {
|
||||
assert.isTrue((await resource.isItem(sub, {reports: '> 0 "misinformation"'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Matches report reason regex', async function () {
|
||||
assert.isTrue((await resource.isItem(sub, {reports: '> 0 /misi.*/'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Matches report time period', async function () {
|
||||
assert.isTrue((await resource.isItem(sub, {reports: '> 0 in 20 minutes'}, NoopLogger, true)).passed);
|
||||
});
|
||||
});
|
||||
|
||||
it('Should detect if activity is removed when a moderator', async function () {
|
||||
assert.isTrue((await resource.isItem(sampleActivity.moddable.commentRemoved(), {removed: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Should detect if activity is filtered when a moderator', async function () {
|
||||
assert.isTrue((await resource.isItem(sampleActivity.moddable.commentFiltered(), {filtered: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Should detect if activity is approved when a moderator', async function () {
|
||||
assert.isTrue((await resource.isItem(new Comment({
|
||||
approved: true
|
||||
}, snoowrap, false), {approved: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should detect if activity is marked as spam when a moderator', async function () {
|
||||
assert.isTrue((await resource.isItem(new Comment({
|
||||
spam: true,
|
||||
can_mod_post: true,
|
||||
}, snoowrap, false), {spam: true}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Comment({
|
||||
spam: false,
|
||||
can_mod_post: true
|
||||
}, snoowrap, false), {spam: false}, NoopLogger, true)).passed);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Publicly accessible criteria', function () {
|
||||
|
||||
// TODO dispatched
|
||||
|
||||
it('should detect broad source', async function() {
|
||||
const sub = new Submission({
|
||||
}, snoowrap, false);
|
||||
assert.isTrue((await resource.isItem(sub, {source: 'dispatch'}, NoopLogger, true, 'dispatch:test')).passed);
|
||||
assert.isFalse((await resource.isItem(sub, {source: 'poll'}, NoopLogger, true, 'dispatch:test')).passed);
|
||||
assert.isTrue((await resource.isItem(sub, {source: 'poll'}, NoopLogger, true, 'poll')).passed);
|
||||
})
|
||||
|
||||
it('should detect source with identifier', async function() {
|
||||
const sub = new Submission({
|
||||
}, snoowrap, false);
|
||||
assert.isTrue((await resource.isItem(sub, {source: 'dispatch:test'}, NoopLogger, true, 'dispatch:test')).passed);
|
||||
assert.isFalse((await resource.isItem(sub, {source: 'user:test'}, NoopLogger, true, 'user')).passed);
|
||||
})
|
||||
|
||||
it('Should detect score (upvotes)', async function () {
|
||||
const sub = new Submission({
|
||||
score: 100,
|
||||
}, snoowrap, false);
|
||||
assert.isTrue((await resource.isItem(sub, {score: '> 50'}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(sub, {score: '< 101'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should detect if activity is removed', async function () {
|
||||
assert.isTrue((await resource.isItem(sampleActivity.public.activityRemoved(), {removed: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
it('Should detect if activity is deleted', async function () {
|
||||
assert.isTrue((await resource.isItem(sampleActivity.public.submissionDeleted(), {deleted: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should fail if trying to detect approved and not a moderator', async function () {
|
||||
assert.isFalse((await resource.isItem(new Comment({
|
||||
approved_by: undefined
|
||||
}, snoowrap, false), {approved: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should detect age', async function () {
|
||||
const time = dayjs().subtract(5, 'minutes').unix();
|
||||
const sub = new Submission({
|
||||
created: time,
|
||||
}, snoowrap, false);
|
||||
assert.isTrue((await resource.isItem(sub, {age: '> 4 minutes'}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(sub, {age: '< 10 minutes'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match created day of week', async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
created: 1664220502,
|
||||
}, snoowrap, false), {createdOn: 'monday'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match created cron expression', async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
created: 1664220502,
|
||||
}, snoowrap, false), {createdOn: '* * 26 * *'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match title literal on submission', async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
title: 'foo test',
|
||||
}, snoowrap, false), {title: 'foo'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should match title regex on submission', async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
title: 'foo test',
|
||||
}, snoowrap, false), {title: '/foo .*/i'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should detect reddit media domain on submission', async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
is_reddit_media_domain: true,
|
||||
}, snoowrap, false), {isRedditMediaDomain: true}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
is_reddit_media_domain: false,
|
||||
}, snoowrap, false), {isRedditMediaDomain: false}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should detect if author is OP', async function () {
|
||||
// for comments
|
||||
assert.isTrue((await resource.isItem(new Comment({
|
||||
is_submitter: true,
|
||||
}, snoowrap, false), {op: true}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Comment({
|
||||
is_submitter: false,
|
||||
}, snoowrap, false), {op: false}, NoopLogger, true)).passed);
|
||||
|
||||
// for submission
|
||||
assert.isTrue((await resource.isItem(new Submission({}, snoowrap, false), {op: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should detect comment depth', async function () {
|
||||
assert.isTrue((await resource.isItem(new Comment({
|
||||
depth: 2,
|
||||
}, snoowrap, false), {depth: '> 1'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
it('Should detect upvote ratio on submission', async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
upvote_ratio: 0.55,
|
||||
}, snoowrap, false), {upvoteRatio: '> 33'}, NoopLogger, true)).passed);
|
||||
});
|
||||
|
||||
for(const prop of ['link_flair_text', 'link_flair_css_class', 'authorFlairCssClass', 'authorFlairTemplateId', 'authorFlairText', 'flairTemplate']) {
|
||||
const activityPropName = cmToSnoowrapActivityMap[prop] ?? prop;
|
||||
|
||||
it(`Should detect specific ${prop} as single string`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test',
|
||||
}, snoowrap, false), {[prop]: 'test'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect specific ${prop} from array of string`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test',
|
||||
}, snoowrap, false), {[prop]: ['foo','test']}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect specific ${prop} is not in criteria`, async function () {
|
||||
assert.isFalse((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test',
|
||||
}, snoowrap, false), {[prop]: ['foo']}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect any ${prop}`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test',
|
||||
}, snoowrap, false), {[prop]: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect no ${prop}`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: null
|
||||
}, snoowrap, false), {[prop]: false}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: ''
|
||||
}, snoowrap, false), {[prop]: false}, NoopLogger, true)).passed);
|
||||
assert.isFalse((await resource.isItem(new Submission({
|
||||
[activityPropName]: ''
|
||||
}, snoowrap, false), {[prop]: 'foo'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect ${prop} as Regular Expression`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test'
|
||||
}, snoowrap, false), {[prop]: '/te.*/'}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: 'test'
|
||||
}, snoowrap, false), {[prop]: ['foo', '/t.*/']}, NoopLogger, true)).passed);
|
||||
});
|
||||
}
|
||||
|
||||
for(const prop of ['authorFlairBackgroundColor', 'link_flair_background_color']) {
|
||||
const activityPropName = cmToSnoowrapActivityMap[prop] ?? prop;
|
||||
|
||||
it(`Should detect specific ${prop} as single string`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: '#400080',
|
||||
}, snoowrap, false), {[prop]: '#400080'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect specific ${prop} from array of string`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: '#400080',
|
||||
}, snoowrap, false), {[prop]: ['#903480','#400080']}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect specific ${prop} is not in criteria`, async function () {
|
||||
assert.isFalse((await resource.isItem(new Submission({
|
||||
[activityPropName]: '#400080',
|
||||
}, snoowrap, false), {[prop]: ['#903480']}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect any ${prop}`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: '#400080',
|
||||
}, snoowrap, false), {[prop]: true}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect no ${prop}`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: null
|
||||
}, snoowrap, false), {[prop]: false}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect ${prop} and remove # prefix`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: '#400080'
|
||||
}, snoowrap, false), {[prop]: '400080'}, NoopLogger, true)).passed);
|
||||
});
|
||||
it(`Should detect ${prop} as Regular Expression`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: '#400080'
|
||||
}, snoowrap, false), {[prop]: '/#400.*/'}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[activityPropName]: '#400080'
|
||||
}, snoowrap, false), {[prop]: ['#903480', '/400.*/']}, NoopLogger, true)).passed);
|
||||
});
|
||||
}
|
||||
|
||||
for(const prop of ['link_flair_text', 'link_flair_css_class', 'flairTemplate', 'link_flair_background_color']) {
|
||||
it(`Should PASS submission criteria '${prop}' with a reason when Activity is a Comment`, async function () {
|
||||
const result = await resource.isItem(new Comment({}, snoowrap, false), {[prop]: true}, NoopLogger, true);
|
||||
assert.isTrue(result.passed);
|
||||
assert.equal(result.propertyResults[0].reason, `Cannot test for ${prop} on Comment`)
|
||||
});
|
||||
}
|
||||
|
||||
for(const prop of ['pinned', 'spoiler', 'is_self', 'over_18', 'locked', 'distinguished']) {
|
||||
it(`Should detect activity with ${prop} attribute`, async function () {
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[prop]: true,
|
||||
}, snoowrap, false), {[prop]: true}, NoopLogger, true)).passed);
|
||||
assert.isTrue((await resource.isItem(new Submission({
|
||||
[prop]: false,
|
||||
}, snoowrap, false), {[prop]: false}, NoopLogger, true)).passed);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO submissionState
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,42 +4,66 @@ import {mock, spy, when, instance} from 'ts-mockito';
|
||||
import Snoowrap from "snoowrap";
|
||||
import {Submission, Comment} from "snoowrap/dist/objects";
|
||||
import {activityIsDeleted, activityIsFiltered, activityIsRemoved} from "../src/Utils/SnoowrapUtils";
|
||||
import {sampleActivity} from "./testFactory";
|
||||
|
||||
const mockSnoowrap = new Snoowrap({userAgent: 'test', accessToken: 'test'});
|
||||
|
||||
describe('Activity state recognition', function () {
|
||||
describe('activity is removed', function () {
|
||||
describe('when bot is a moderator', function () {
|
||||
it('submission not removed when filtered by automod', function () {
|
||||
|
||||
assert.isFalse(activityIsRemoved(sampleActivity.moddable.activityFilteredByAutomod()));
|
||||
assert.isFalse(activityIsRemoved(new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: 12345,
|
||||
removed_by_category: 'automod_filtered'
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
it('submission is removed when not filtered by automod', function () {
|
||||
|
||||
assert.isTrue(activityIsRemoved(sampleActivity.moddable.activityRemovedByMod()));
|
||||
assert.isTrue(activityIsRemoved(new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: 12345,
|
||||
removed_by_category: 'mod'
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
it('comment is removed', function () {
|
||||
|
||||
assert.isTrue(activityIsRemoved(sampleActivity.moddable.commentRemoved()));
|
||||
assert.isTrue(activityIsRemoved(sampleActivity.moddable.commentRemovedByMod()));
|
||||
assert.isTrue(activityIsRemoved(new Comment({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: 12345,
|
||||
removed: true,
|
||||
replies: ''
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
})
|
||||
describe('when bot is not a moderator', function () {
|
||||
it('submission is deleted by moderator', function () {
|
||||
|
||||
assert.isTrue(activityIsRemoved(sampleActivity.public.submissionRemoved()));
|
||||
assert.isTrue(activityIsRemoved(new Submission({
|
||||
can_mod_post: false,
|
||||
removed_by_category: 'moderator'
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
it('submission is deleted by user or other', function () {
|
||||
|
||||
assert.isTrue(activityIsRemoved(sampleActivity.moddable.submissionDeleted()));
|
||||
assert.isTrue(activityIsRemoved(new Submission({
|
||||
can_mod_post: false,
|
||||
removed_by_category: 'deleted'
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
|
||||
it('comment body is removed', function () {
|
||||
|
||||
assert.isTrue(activityIsRemoved(sampleActivity.public.commentRemoved()));
|
||||
assert.isTrue(activityIsRemoved(new Comment({
|
||||
can_mod_post: false,
|
||||
body: '[removed]',
|
||||
replies: ''
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
})
|
||||
@@ -47,17 +71,31 @@ describe('Activity state recognition', function () {
|
||||
|
||||
describe('activity is filtered', function() {
|
||||
it('not filtered when user is not a moderator', function() {
|
||||
assert.isFalse(activityIsFiltered(sampleActivity.public.activityRemoved()));
|
||||
assert.isFalse(activityIsFiltered(new Submission({
|
||||
can_mod_post: false,
|
||||
banned_at_utc: 12345,
|
||||
removed_by_category: 'mod'
|
||||
}, mockSnoowrap, true)));
|
||||
})
|
||||
|
||||
it('submission is filtered', function () {
|
||||
|
||||
assert.isTrue(activityIsFiltered(sampleActivity.moddable.activityFilteredByAutomod()));
|
||||
assert.isTrue(activityIsFiltered(new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: 12345,
|
||||
removed_by_category: 'automod_filtered'
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
|
||||
it('comment is filtered', function () {
|
||||
|
||||
assert.isTrue(activityIsFiltered(sampleActivity.moddable.commentFiltered()));
|
||||
assert.isTrue(activityIsFiltered(new Comment({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: 12345,
|
||||
removed: false,
|
||||
replies: ''
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
})
|
||||
@@ -66,14 +104,25 @@ describe('Activity state recognition', function () {
|
||||
|
||||
it('submission is deleted', function () {
|
||||
|
||||
assert.isTrue(activityIsDeleted(sampleActivity.moddable.submissionDeleted()));
|
||||
assert.isTrue(activityIsDeleted(sampleActivity.public.submissionDeleted()));
|
||||
assert.isTrue(activityIsDeleted(new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: 12345,
|
||||
removed_by_category: 'deleted'
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
|
||||
it('comment is deleted', function () {
|
||||
|
||||
assert.isTrue(activityIsDeleted(sampleActivity.moddable.commentDeleted()));
|
||||
assert.isTrue(activityIsDeleted(new Comment({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: 12345,
|
||||
removed: false,
|
||||
replies: '',
|
||||
author: {
|
||||
name: '[deleted]'
|
||||
}
|
||||
}, mockSnoowrap, true)));
|
||||
|
||||
})
|
||||
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
import {OperatorConfig, OperatorJsonConfig} from "../src/Common/interfaces";
|
||||
import Snoowrap from "snoowrap";
|
||||
import Bot from "../src/Bot/index"
|
||||
import {buildOperatorConfigWithDefaults} from "../src/ConfigBuilder";
|
||||
import {App} from "../src/App";
|
||||
import {YamlOperatorConfigDocument} from "../src/Common/Config/Operator";
|
||||
import {NoopLogger} from "../src/Utils/loggerFactory";
|
||||
import {ManagerEntity} from "../src/Common/Entities/ManagerEntity";
|
||||
import {Bot as BotEntity} from "../src/Common/Entities/Bot";
|
||||
import {SubredditResources} from "../src/Subreddit/SubredditResources";
|
||||
import {Subreddit, Comment, Submission} from 'snoowrap/dist/objects';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
const mockSnoowrap = new Snoowrap({userAgent: 'test', accessToken: 'test'});
|
||||
|
||||
const memoryConfig: OperatorJsonConfig = {
|
||||
databaseConfig: {
|
||||
connection: {
|
||||
type: 'sqljs',
|
||||
location: ':memory:'
|
||||
}
|
||||
},
|
||||
logging: {
|
||||
level: 'debug',
|
||||
file: {
|
||||
dirname: false
|
||||
}
|
||||
},
|
||||
bots: [
|
||||
{
|
||||
name: 'test',
|
||||
credentials: {
|
||||
reddit: {
|
||||
clientId: 'test',
|
||||
clientSecret: 'test',
|
||||
accessToken: 'test',
|
||||
refreshToken: 'test'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
let config: OperatorConfig;
|
||||
let app: App;
|
||||
let snoowrap: Snoowrap;
|
||||
let bot: Bot;
|
||||
let resource: SubredditResources;
|
||||
let subreddit: Subreddit;
|
||||
|
||||
export const getConfig = async () => {
|
||||
if (config === undefined) {
|
||||
config = await buildOperatorConfigWithDefaults(memoryConfig);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
export const getApp = async () => {
|
||||
if (app === undefined) {
|
||||
const config = await getConfig();
|
||||
app = new App({...config, fileConfig: {document: new YamlOperatorConfigDocument('')}});
|
||||
await app.initDatabase();
|
||||
}
|
||||
return app;
|
||||
}
|
||||
|
||||
export const getSnoowrap = async () => {
|
||||
if (snoowrap === undefined) {
|
||||
const bot = await getBot();
|
||||
snoowrap = bot.client;
|
||||
}
|
||||
return snoowrap;
|
||||
}
|
||||
|
||||
export const getBot = async () => {
|
||||
if (bot === undefined) {
|
||||
await getApp();
|
||||
const config = await getConfig();
|
||||
bot = new Bot(config.bots[0], NoopLogger);
|
||||
await bot.cacheManager.set('test', {
|
||||
logger: NoopLogger,
|
||||
caching: {
|
||||
authorTTL: false,
|
||||
submissionTTL: false,
|
||||
commentTTL: false,
|
||||
provider: 'memory'
|
||||
},
|
||||
subreddit: bot.client.getSubreddit('test'),
|
||||
client: bot.client,
|
||||
statFrequency: 'minute',
|
||||
managerEntity: new ManagerEntity(),
|
||||
botEntity: new BotEntity()
|
||||
});
|
||||
}
|
||||
return bot;
|
||||
}
|
||||
|
||||
export const getResource = async () => {
|
||||
if (resource === undefined) {
|
||||
const bot = await getBot();
|
||||
resource = bot.cacheManager.get('test') as SubredditResources;
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
export const getSubreddit = async () => {
|
||||
if (subreddit === undefined) {
|
||||
const snoo = await getSnoowrap();
|
||||
subreddit = new Subreddit({id: 't3_test', name: 'test'}, snoo, true);
|
||||
}
|
||||
// @ts-ignore
|
||||
return subreddit;
|
||||
}
|
||||
|
||||
export const sampleActivity = {
|
||||
moddable: {
|
||||
commentRemovedByMod: (snoowrap = mockSnoowrap) => {
|
||||
return new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed_by_category: 'mod'
|
||||
}, snoowrap, true);
|
||||
},
|
||||
activityRemovedByMod: (snoowrap = mockSnoowrap) => {
|
||||
return new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed_by_category: 'mod'
|
||||
}, snoowrap, true)
|
||||
},
|
||||
activityFilteredByAutomod: (snoowrap = mockSnoowrap) => {
|
||||
return new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed_by_category: 'automod_filtered'
|
||||
}, snoowrap, true);
|
||||
},
|
||||
commentFiltered: (snoowrap = mockSnoowrap) => {
|
||||
return new Comment({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed: false,
|
||||
replies: ''
|
||||
}, snoowrap, true)
|
||||
},
|
||||
commentRemoved: (snoowrap = mockSnoowrap) => {
|
||||
return new Comment({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed: true,
|
||||
replies: ''
|
||||
}, snoowrap, true);
|
||||
},
|
||||
submissionDeleted: (snoowrap = mockSnoowrap) => {
|
||||
return new Submission({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed_by_category: 'deleted'
|
||||
}, snoowrap, true);
|
||||
},
|
||||
commentDeleted: (snoowrap = mockSnoowrap) => {
|
||||
return new Comment({
|
||||
can_mod_post: true,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed: false,
|
||||
replies: '',
|
||||
author: {
|
||||
name: '[deleted]'
|
||||
}
|
||||
}, snoowrap, true);
|
||||
}
|
||||
},
|
||||
public: {
|
||||
submissionRemoved: (snoowrap = mockSnoowrap) => {
|
||||
return new Submission({
|
||||
can_mod_post: false,
|
||||
removed_by_category: 'moderator'
|
||||
}, snoowrap, true)
|
||||
},
|
||||
submissionDeleted: (snoowrap = mockSnoowrap) => {
|
||||
return new Submission({
|
||||
can_mod_post: false,
|
||||
removed_by_category: 'deleted'
|
||||
}, snoowrap, true);
|
||||
},
|
||||
commentRemoved: (snoowrap = mockSnoowrap) => {
|
||||
return new Comment({
|
||||
can_mod_post: false,
|
||||
body: '[removed]',
|
||||
replies: ''
|
||||
}, snoowrap, true)
|
||||
},
|
||||
activityRemoved: (snoowrap = mockSnoowrap) => {
|
||||
return new Submission({
|
||||
can_mod_post: false,
|
||||
banned_at_utc: dayjs().subtract(10, 'minutes').unix(),
|
||||
removed_by_category: 'moderator'
|
||||
}, snoowrap, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,11 @@
|
||||
import {describe, it} from 'mocha';
|
||||
import {assert} from 'chai';
|
||||
import {
|
||||
COMMENT_URL_ID,
|
||||
GH_BLOB_REGEX,
|
||||
GIST_RAW_REGEX,
|
||||
COMMENT_URL_ID, GH_BLOB_REGEX, GIST_RAW_REGEX,
|
||||
GIST_REGEX,
|
||||
parseDurationFromString,
|
||||
parseLinkIdentifier,
|
||||
parseRedditEntity,
|
||||
parseRegexSingleOrFail,
|
||||
REGEXR_REGEX,
|
||||
removeUndefinedKeys,
|
||||
strToActivitySourceData,
|
||||
SUBMISSION_URL_ID
|
||||
parseRedditEntity, parseRegexSingleOrFail, REGEXR_REGEX, removeUndefinedKeys, SUBMISSION_URL_ID
|
||||
} from "../src/util";
|
||||
import dayjs from "dayjs";
|
||||
import dduration, {Duration, DurationUnitType} from 'dayjs/plugin/duration.js';
|
||||
@@ -22,7 +15,6 @@ import {
|
||||
parseGenericValueOrPercentComparison, parseReportComparison
|
||||
} from "../src/Common/Infrastructure/Comparisons";
|
||||
import {RegExResult} from "../src/Common/interfaces";
|
||||
import {SOURCE_DISPATCH, SOURCE_POLL, SOURCE_USER} from "../src/Common/Infrastructure/Atomic";
|
||||
|
||||
dayjs.extend(dduration);
|
||||
|
||||
@@ -365,19 +357,3 @@ describe('Link Recognition', function () {
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
describe('Activity Source Parsing', function () {
|
||||
it('should parse all activity types', function () {
|
||||
for (const type of [SOURCE_DISPATCH, SOURCE_POLL, SOURCE_USER]) {
|
||||
const source = strToActivitySourceData(type);
|
||||
assert.equal(source.type, type);
|
||||
}
|
||||
});
|
||||
it('should throw if invalid activity source type', function () {
|
||||
assert.throws(() => strToActivitySourceData('jflksdf'));
|
||||
});
|
||||
it('should parse identifier from activity source', function () {
|
||||
const source = strToActivitySourceData('dispatch:test');
|
||||
assert.equal(source.identifier, 'test');
|
||||
});
|
||||
})
|
||||
|
||||