Compare commits

..

118 Commits

Author SHA1 Message Date
FoxxMD
9e364c3e28 Refactor cache instantiation to use async method 2022-10-17 11:42:58 -04:00
FoxxMD
acd4b54d8e Implement typings for cache-manager-redis-store@3^ 2022-10-17 11:42:39 -04:00
FoxxMD
19f4ff0b53 feat: Update to cache-manager-redis-store ^3.0.0
* Also bump node minor version to be in line with cache-manager-redis-store
2022-10-17 11:42:04 -04:00
FoxxMD
98a8568eb6 fix: Add missing else condition 2022-10-13 16:17:43 -04:00
FoxxMD
457f947603 fix: Further improvements for influxdb logging
* Suppress write failure warnings to reduce noise in log
  * Can be toggled using debug flag in config
2022-10-13 12:34:11 -04:00
FoxxMD
7fb69ae67a fix: Attempt to decrease frequency of influxdb timeout errors
* Use keep-alive http agent to reuse open connections
* Decrease max batch size and flush interval to payload sent is smaller
* Add debug logging for fail/success/retry events on flush
2022-10-13 11:39:45 -04:00
FoxxMD
2241d40e49 fix: Fix custom footer never loading
Custom footer needs to be loaded AFTER resources are set
2022-10-13 08:58:12 -04:00
FoxxMD
a3ca3f17ec refactor(recent): Log image parsing error with cause 2022-10-12 14:39:21 -04:00
FoxxMD
f527a17fa2 feat(modnote): Implement existing note check before adding note to replace allowDuplicates
* Use "modActions" authorIs filtering to check note prior to adding note using "existingNoteCheck" property
  * Refactors concept of "allowDuplicates" to allow any arbitrary modActions test to be used
* Provide convenience ModLogCriteria generation for "existingNoteCheck" based on boolean (emulates allowDuplicates functionality)
2022-10-12 13:00:47 -04:00
FoxxMD
e98364eae9 feat(filter): Improve modAction filtering functionality
* Implement filtering activityType by "false" in order to return actions/notes not added to a specific activity
* Implement "referencesCurrentActivity" property to allow filtering by actions/notes that are associated with the activity being processed
* Implement using "count" for "current" search to enable criteria condition based on presence or non-presence of current action/note passing
2022-10-12 12:58:49 -04:00
FoxxMD
8b125d7433 feat(ui): Improve visibility and resilience for live log stream
* Tie loading indicator to live stream status and display error if one occurs
  * Add manual restart action to end of error
* Restart stream automatically if reader ends, up to 3 retries
2022-10-11 12:19:55 -04:00
FoxxMD
6ee060c5ce fix(logs): Remove listeners from log stream event emitter before end of response to prevent write-after-end errors 2022-10-11 12:18:00 -04:00
FoxxMD
9b12d0b2b3 feat(bot): Improve log wording for manager loading phase 2022-10-11 10:51:00 -04:00
FoxxMD
b174c7928a feat(ui): Add favicon files 2022-10-11 10:49:57 -04:00
FoxxMD
74dfe9258a fix(filter): Fix mod action note filtering assignment 2022-10-10 15:00:39 -04:00
FoxxMD
1cf8855a24 feat(testing): Implement initial author filter tests 2022-10-10 12:06:08 -04:00
FoxxMD
adc69894fc fix(filter): Fix detecting empty filter when using 'replace' filter default behavior 2022-10-10 11:03:57 -04:00
FoxxMD
3435c683c8 feat(filter): Add author flair item criteria 2022-10-05 11:24:44 -04:00
FoxxMD
f0032cd433 Bump version 2022-10-05 08:56:53 -04:00
FoxxMD
ade0b7948e Add patreon funding link 2022-10-04 09:40:03 -04:00
FoxxMD
542aa26c62 feat(history): Implement ratio comparison #112 2022-10-03 13:25:05 -04:00
FoxxMD
3faf4ca3dc fix: Fix wiki location usage when getting from subreddit resources 2022-09-28 10:34:48 -04:00
FoxxMD
2f35b82d5e feat(history): Log failure results for easier rule tuning 2022-09-28 10:25:26 -04:00
FoxxMD
c9d8bf637b chore: Add tests for item criteria 2022-09-26 16:59:46 -04:00
FoxxMD
027f4087e3 refactor: Improve activity source parse and comparison
* Implement a DTO class for activity source to make parts usage (type, identifier) and matching easier
* Implement regex to parse type and identifier from activity source string
* Refactor activity source interface/types to better distinguish as string, data, and class
2022-09-26 12:07:24 -04:00
FoxxMD
1b20122ffc docs: Fix some typos 2022-09-23 10:35:13 -04:00
FoxxMD
5d53571ec0 fix: Fix typo in default footer
Thanks u/SampleOfNone for catching that
2022-09-22 10:59:57 -04:00
FoxxMD
b3df1b4d41 Update default confidence for MHS based on feedback from Welton 2022-09-20 10:56:39 -04:00
FoxxMD
4abe8e07f3 docs: Add docs for MHS toxic content prediction rule 2022-09-20 10:44:08 -04:00
FoxxMD
9bb95106ba feat(mhs): Add default confidence threshold 2022-09-20 09:35:38 -04:00
FoxxMD
02414478bf feat: Implement rule that tests activity content against moderatehatespeech.com ML model using api #110
* Add mhs rule type and MHS credentials interface
* Implement MHS rule with similar criteria options to sentiment
* Allow testing against author history content
2022-09-19 16:20:35 -04:00
FoxxMD
8b0a582464 fix(recent): Empty viable activity list if processing activity is required to be reference but is not a valid type 2022-09-19 11:46:20 -04:00
FoxxMD
d1db5f4688 fix: Fix subreddit filtering result when no subreddit criteria are present
Should return all items instead of none. Thanks u/SampleOfNone for helping track this down with examples.
2022-09-19 10:01:39 -04:00
FoxxMD
44f9389b69 docs: Add general subreddit/moderator docs readme
* Also add Guest Access docs
2022-09-16 16:40:28 -04:00
FoxxMD
71b2d0597d docs: Update screenshots 2022-09-16 15:38:52 -04:00
FoxxMD
57cfcebe9f fix: Set default invites to empty array on heartbeat 2022-09-16 14:34:28 -04:00
FoxxMD
07ecc505ff fix: Check bot entity exists before getting invites 2022-09-16 14:29:34 -04:00
FoxxMD
81213686ce Merge branch 'subredditInviteUI' into edge
# Conflicts:
#	src/Subreddit/SubredditResources.ts
2022-09-16 13:31:37 -04:00
FoxxMD
08735d505a refactor(manager): Improve wiki CRUD and onboarding initial config
* Refactor write/read into separate functions
* Improve error hinting for wiki read/write/permissions WRT mod/oauth permissions
* Remove superfluous error wrapping to reduce logging length for wiki errors
* More debug logging for onboarding process
* Don't return error if manager fails to parse after all onboarding complete (not critical)
2022-09-16 13:27:41 -04:00
FoxxMD
1a62c752c1 feat(ui): Improve finished onboarding response
* don't redirect on error
* increase delay to redirect on success
2022-09-16 13:24:09 -04:00
FoxxMD
6aa7367297 fix(client): Improve responses dependent on server information
* run initHeartbeat on any GET route that render a page so that user doesn't get access denied on initial app load
* Force client refresh if no invite found on initial check for onboarding landing
2022-09-16 13:22:44 -04:00
FoxxMD
cf9583227c feat: Add subredditExists function to snoowrap client
Reddit returns 403 if the subreddit exists but is private. Using this function wraps the error so we can just get boolean back along with subreddit object, if successful
2022-09-16 13:20:07 -04:00
FoxxMD
aa505ba3f2 feat: Improve external resource fetching in subreddit resources
* Add "default" hint to force val to a url or wiki key if neither is detected but know it should be one of them
* Refactor wiki/url fetching into own functions for better reuseability
* Implement mod permission getter function to check for valid permissions on wiki page error
* Improve error hints on wiki page read failure
2022-09-16 13:19:23 -04:00
FoxxMD
a0182d89ca feat: util function for generating full wiki urls 2022-09-16 13:16:26 -04:00
FoxxMD
d46f0a5be8 fix: Improve error detection for log transform
Check for error name OR stack existence
2022-09-16 13:16:06 -04:00
FoxxMD
4a55d35e14 feat(filter): Rename createdAt to createdOn
Better naming
2022-09-15 13:27:41 -04:00
FoxxMD
1284051fe8 fix(filter): Fix copy-past typo for createdAt 2022-09-15 11:24:53 -04:00
FoxxMD
00680494a3 feat(filter): Add createdAt activity criteria matching
* May be a string or array of strings. Passes if any expression matches
  * Value may be a convience day-of-week value (mon, tues, wed...)
  * or a cron expression
2022-09-15 11:22:04 -04:00
FoxxMD
77856a6d97 chore: Bump version 2022-09-14 15:30:12 -04:00
FoxxMD
b216cd08e1 Merge branch 'edge' into subredditInviteUI 2022-09-14 15:27:14 -04:00
FoxxMD
052c1218c6 feat(ui): Add home logo 2022-09-14 15:26:59 -04:00
FoxxMD
c2343683bb Finish implementation accept flow 2022-09-14 15:12:33 -04:00
FoxxMD
fcf718f1d0 fix(ui): Fix typo in reddit status indicator switch 2022-09-14 13:21:48 -04:00
FoxxMD
77f848007a Implement subreddit onboarding accept process
* Refactor some manager/bot methods to be more accessible for invites/wiki
* Add routes and authentication for getting invite information and checking user is moderator of subreddit
* Add route for accept invite and completing onboarding guest/config
2022-09-14 13:20:53 -04:00
FoxxMD
95216b3950 docs: Add GHCR image location to install docs
Closes #109
2022-09-13 15:06:13 -04:00
FoxxMD
58a21e8d05 Scope required permissions for github token 2022-09-13 14:35:11 -04:00
FoxxMD
49ac8cda19 feat: Update github actions to push to multiple registries
And add documentation for GH actions local dev/testing
2022-09-13 14:23:22 -04:00
FoxxMD
bc8be3608b Use methods for bot entity subreddit invite crud 2022-09-13 10:33:55 -04:00
FoxxMD
1b69cd78bb Refactor subreddit invites to use db and add interface
* Refactor to use db instead of cache for persisting invites
* Implement subreddit invite helper page
* Add initial config and guests as optional data for invite
* Refactor bot to use db subreddit invite and auto-accept when no config/guests

TODO: subreddit accept page, mod authorization, initial config usage, and documentation
2022-09-12 16:29:41 -04:00
FoxxMD
e736379f85 feat(ui): Improve guest expiration interface
* Set default time to 24 hours
* Add label and tooltip for expiration datetime picker
2022-09-07 11:57:29 -04:00
FoxxMD
c0e1a93fb4 fix(config): Use correct filter defaults data structure for runs
Should use "json" data structure type so named filters can be used in defaults on runs
2022-09-06 11:18:24 -04:00
FoxxMD
bd35b06ebf fix(filter): Fix missed toLowerCase for named filter getter 2022-09-02 17:41:28 -04:00
FoxxMD
f852e85234 feat(author): authorIs 'name' criteria may be regular expression 2022-09-02 16:21:53 -04:00
FoxxMD
661ae11e18 refactor(ui): Replace websockets opStats with client delta polling #106
* Refactor/remove websockets functionality for relaying opstats from server with direct polling by client
* Implement delta responses initially introduced in #91 to reduce bandwidth
2022-09-01 16:01:37 -04:00
FoxxMD
18c1ac0fd7 Chore: Bump version 2022-09-01 09:03:12 -04:00
FoxxMD
2fb503f09f feat(message): Implement templating for to field so subreddit can be used generically
since 'to' be now be templated a user can configure a message to send to the subreddit the action is being processed from using `to: 'r/{{item.subreddit}}'`
2022-08-31 09:58:24 -04:00
FoxxMD
7e5eeb71da fix(submission): Fix targets data type to accept array 2022-08-31 09:31:25 -04:00
FoxxMD
84f2da8b6d feat(action): Implement Action templating data #104
* Add top-level 'actionSummary' template variable that renders a markdown list of action results
* Add individual action result/data, in the same structure as rules, under the top-level 'actions' template variable
2022-08-30 17:12:51 -04:00
FoxxMD
be51f8ae43 fix(image): Fix hash result test assertion 2022-08-30 16:13:35 -04:00
FoxxMD
f82d985eab feat(template): Refactor templating to be more extensible and add some requested data
* Implement interfaces for template parts
* Refactor Action constructor to take an object for runtime options (cleaner, more extensible)
* Refactor subreddit resource and snoowraputils content rendering and organization to use objects of optional data rather than required arguments
  * Make almost all data optional and only parse/render if included
  * Move rule results parsing/formatting into own function
  * Refactor footer render to use renderContent (DRY)
* Add some requested template data #104
  * {{item.subreddit}} #87
  * {{check}} #87
* Updated templating documentation
2022-08-26 13:42:02 -04:00
FoxxMD
aab014650a fix(template): Fix rule data spread to template 2022-08-26 11:22:59 -04:00
FoxxMD
113ac3e10e fix(template): Fix subreddit breakdown reference override 2022-08-25 17:14:28 -04:00
FoxxMD
afb6aad26d fix(template): Fix subreddit breakdown when empty activities array 2022-08-25 16:30:15 -04:00
FoxxMD
33b60825d9 fix(template): Return empty string if no subreddits in breakdown 2022-08-25 16:16:15 -04:00
FoxxMD
b5202a33ac feat(template): Add subreddit breakdown to template data for Recent and History rule 2022-08-25 10:39:03 -04:00
FoxxMD
c02a2ad622 chore: Bump version constant due to BC 2022-08-23 09:49:12 -04:00
FoxxMD
e9f08915a4 chore: Bump version constant 2022-08-23 09:47:35 -04:00
FoxxMD
4b95ccd0ba feat(docs): Simplify getting started operator instructions
Take advantage of First Time Setup page when no configuration is present to help generate a minimum configuration.
2022-08-23 09:46:54 -04:00
FoxxMD
567a2f0720 feat(action): Implement creating submissions #93
* Create self/link submissions, no reddit media (upload) yet
* Submission can use user modifiers (nsfw, spoiler) and mod modifiers (sticky, distinguish, lock)
* Can create submission in current subreddit (default) or arbitrary subreddit defined in configuration (targets)
  * Can create multiple submissions by defining multiple targets
2022-08-22 14:00:27 -04:00
FoxxMD
61ff402256 feat(config): Allow wikiConfig override at subreddit-level 2022-08-22 10:36:18 -04:00
FoxxMD
9158bda992 feat(comment): Implement arbitrary comment targets #93 2022-08-19 11:01:54 -04:00
FoxxMD
873f9d3c91 refactor(image): Normalize image hash usage a bit more to reduce complexity 2022-08-18 13:35:37 -04:00
FoxxMD
783ef5db53 fix(image): url variable name usage 2022-08-16 13:36:36 -04:00
FoxxMD
f0cb5c1315 fix(ui): Fix constant reassignment 2022-08-16 13:36:20 -04:00
FoxxMD
8e1b916ea4 fix(database): Remove table data check due to incompatibility with postgres
Not sure what the issue is but a generic message should be enough for now
2022-08-16 10:28:10 -04:00
FoxxMD
4acf87eacd feat(database): Implement automated backup for better-sqlite3 connection 2022-08-16 10:05:20 -04:00
FoxxMD
5dd5a32c51 fix(database): Fix how new columns are added to existing table on invite migration 2022-08-16 09:47:53 -04:00
FoxxMD
207907881f feat: Add initial setup wizard
* If web client does not have credentials (or operator) then redirect login to form to fill them in
  * Write to config location on form completion
2022-08-15 17:17:23 -04:00
FoxxMD
44da276d41 fix: Fix missing column type specifying for db session entity 2022-08-15 16:05:00 -04:00
FoxxMD
6c98b6f995 fix: cleanup guests and no-config scenario
* Check for no/null guest data during invite creation/usage for both client and server side
* Add instances tab on invite page
* Replace instance select on invite page with query string usage
* Redirect from status page to auth helper when instance has no bots
2022-08-15 15:59:51 -04:00
FoxxMD
cc0c3dfe61 docs: Fix incorrect url for minimum config 2022-08-15 15:57:45 -04:00
FoxxMD
b48d75fda3 fix(config): Fix setting api friendly name
addIn creates missing collections automatically
2022-08-15 15:57:26 -04:00
FoxxMD
2adf2d258d fix(database): Handle invite migration when db is sqljs
* Create table if it does not exist (sqljs has two database)
* Drop Invite table from sqljs db if it has no rows
2022-08-15 15:56:43 -04:00
FoxxMD
c55a1c6502 feat(ui): Add initial guests to bot invite and rename Guest Mod to Guest
* Rename to Guest since this is more accurate of a description -- "mod" is confusing since user doesn't have any actual mod power
* Add guests as an option to invite creation and display on invite page
2022-08-11 15:23:09 -04:00
FoxxMD
0011ff8853 chore: Re-add clean username for guest due to merge 2022-08-11 14:53:48 -04:00
FoxxMD
4bbf871051 Merge branch 'edge' into tempAccess
# Conflicts:
#	src/Web/Server/routes/authenticated/user/index.ts
#	src/Web/Server/server.ts
2022-08-11 14:50:45 -04:00
FoxxMD
54755dc480 refactor(guest)!: Migrate invites to be owned by the server
It makes more sense for the CM instance that will actually have a bot added to it to own the invite for that bot.

* (BC) Move Invite into server entity mappings and rename to BotInvite
  * Add guests and initialConfig (future use)
  * BC -- Existing invites need to have instance defined to be used
  * BC -- Cache-based invite storage has been REMOVED
  * BC -- Removed inviteMaxAge config property (for now)
* Add SubredditInvite entity for future use
* Force/implement server (api) having a defined friendly name. This is used to determine which invites in a DB belong to which server instance
  * If not defined in config it is generated at random and then written to config
* Refactor how invites are retrieved and parsed client-side -- CRUD using server api
  * BC -- Invite URL structure has changed from ?invite=id to /invite/id...
* Added better UI for migration redirect
  * Show all reachable instances in redirect page header
  * Error page also shows reachable instances in page header
2022-08-11 14:47:45 -04:00
FoxxMD
01f95a37e7 feat(ui): Add guided tour for main dashboard 2022-08-03 14:37:56 -04:00
FoxxMD
5ddad418b0 fix(manager): Fix missing valid config check before starting queue 2022-08-02 16:05:48 -04:00
FoxxMD
b5b2e88c1f fix(guest mod): Parse/clean name from user input before adding
So that we don't care if user sends FoxxMD or u/FoxxMD
2022-08-02 15:46:56 -04:00
FoxxMD
194ded7be6 fix(auth): Fix subreddit normalization on client instance 2022-08-02 15:31:00 -04:00
FoxxMD
7ba375d702 fix(auth): Fix subreddit normalization 2022-08-02 14:15:01 -04:00
FoxxMD
9a4c38151f fix(auth): Fix default instance middleware accessibility check 2022-08-02 14:06:49 -04:00
FoxxMD
f8df6fc93f docs: Remove removal reason footnote 2022-08-02 13:02:28 -04:00
FoxxMD
86a3b229cb feat(remove): Implement removal reason id and note
* Cache subreddit removal reasons and display in popup helper in authenticated config editor
* Add fields for removal reason note/reason in remove action
* Update remove action documentation to include new fields
2022-08-02 12:34:40 -04:00
FoxxMD
ca3e8d7d80 feat: Add removal reason related endpoints to snoowrap client
Using undocumented endpoints pulled from praw documentation/code. Snoowrap can now:

* add removal reason/mod note on a removed activity
* get subreddit removal reasons (used for getting ids for use with removal reason endpoint)
2022-08-02 11:09:05 -04:00
FoxxMD
5af4384871 Merge branch 'tempAccess' into edge 2022-08-01 12:08:10 -04:00
FoxxMD
47957e6ab9 fix: Remove debug statements for image processing 2022-07-29 15:05:08 -04:00
FoxxMD
7f1a404b4e feat(image): Implement image flip detection in recent rule 2022-07-29 14:42:49 -04:00
FoxxMD
1f64a56260 feat(image): Improve image normalization to make duplicate detection more powerful
* Trim image to remove arbitrary borders
* Convert image to greyscale in order to reduce effect of saturation differences
* Implement "mirrored" (y-axis flip) hash calculations
* Implement local file fetch and image processing test suite
2022-07-29 14:19:32 -04:00
FoxxMD
366cb2b629 More guest mod cleanup and fixes
* Default value on guest mod CRUD
* Validate expire time client-side
2022-07-28 14:28:43 -04:00
FoxxMD
b9b442ad1e feat(ui): Implement saving config as guest mod 2022-07-28 14:14:55 -04:00
FoxxMD
81a1bdb446 refactor: Simplify ACL for server/client users and introduce guest context
* Use BotInstance class on client side for easier state tracking and simplifying ACL functions (moved from user to instance)
* Implement and use same interface for client/server Bot representations
* Implement mod/guest context for status and live stats data
* Restrict guest mod CRUD to mods only
2022-07-28 13:39:46 -04:00
FoxxMD
1e4b369b1e Fix CRUD for guest mods 2022-07-28 09:45:30 -04:00
FoxxMD
7a34a7b531 Almost working correctly guest mod add
Need to fix something wrong with time parsing server-side
2022-07-27 17:06:55 -04:00
FoxxMD
b83bb6f998 Refactor guest relationship
* Use eager relation
* Fix orphan row usage
2022-07-27 16:18:34 -04:00
FoxxMD
3348af2780 Implement guest mod removal via UI and refactor guest rendering into live stats 2022-07-27 15:32:00 -04:00
FoxxMD
04896a7363 Implement guest mod entities and read-only ui 2022-07-27 13:07:56 -04:00
170 changed files with 11944 additions and 1990 deletions

View File

@@ -13,7 +13,7 @@ coverage
*.json5
*.yaml
*.yml
*.env
# exceptions
!heroku.yml

1
.github/FUNDING.yml vendored
View File

@@ -1,2 +1,3 @@
github: [FoxxMD]
patreon: FoxxMD
custom: ["bitcoincash:qqmpsh365r8n9jhp4p8ks7f7qdr7203cws4kmkmr8q"]

3
.github/push-hook-sample.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"ref": "refs/heads/edge"
}

View File

@@ -1,4 +1,14 @@
name: Publish Docker image to Dockerhub
name: Publish Docker image to registries
# Builds image and tags based on the type of push event:
# * branch push -> tag is branch name IE context-mod:edge
# * release (tag) -> tag is release name IE context-mod:0.13.0
#
# Then pushes tagged images to multiple registries
#
# Based on
# https://github.com/docker/build-push-action/blob/master/docs/advanced/push-multi-registries.md
# https://github.com/docker/metadata-action
on:
push:
@@ -13,8 +23,12 @@ on:
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
name: Build and Push Docker image to registries
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v2
@@ -25,12 +39,22 @@ jobs:
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: foxxmd/context-mod
images: |
foxxmd/context-mod
ghcr.io/foxxmd/context-mod
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, 'master') }}
@@ -40,7 +64,8 @@ jobs:
latest=false
- name: Build and push Docker image
uses: docker/build-push-action@v2
if: ${{ !env.ACT }}
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}

2
.gitignore vendored
View File

@@ -336,6 +336,7 @@ web_modules/
# dotenv environment variables file
.env
.env.test
*.env
# parcel-bundler cache (https://parceljs.org/)
.cache
@@ -391,6 +392,7 @@ dist
*.json5
!src/Schema/*.json
!.github/push-hook-sample.json
!docs/**/*.json5
!docs/**/*.yaml
!docs/**/*.json

2
.nvmrc
View File

@@ -1 +1 @@
16.14.2
16.18.0

View File

@@ -31,6 +31,8 @@ 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):**
@@ -134,6 +136,10 @@ Moderator view/invite and authorization:
![Invite View](docs/images/oauth-invite.jpg)
A similar helper and invitation experience is available for adding **subreddits to an existing bot.**
![Subreddit Invite View](docs/images/subredditInvite.jpg)
### Configuration Editor
A built-in editor using [monaco-editor](https://microsoft.github.io/monaco-editor/) makes editing configurations easy:

3
act.env.example Normal file
View File

@@ -0,0 +1,3 @@
GITHUB_TOKEN=
DOCKERHUB_USERNAME=
DOCKER_PASSWORD=

View File

@@ -152,6 +152,7 @@ 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

View File

@@ -1,5 +1,17 @@
TODO add more development sections...
# Developing/Testing Github Actions
Use [act](https://github.com/nektos/act) to run Github actions locally.
An example secrets file can be found in the project working directory at [act.env.example](act.env.example)
Modify [push-hook-sample.json](.github/push-hook-sample.json) to point to the local branch you want to run a `push` event trigger on, then run this command from the project working directory:
```bash
act -e .github/push-hook-sample.json --secret-file act.env
```
# Mocking Reddit API
Using [MockServer](https://www.mock-server.com/)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 133 KiB

BIN
docs/images/guests.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 226 KiB

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 479 KiB

After

Width:  |  Height:  |  Size: 225 KiB

View File

@@ -21,7 +21,7 @@ They are responsible for configuring the software at a high-level and managing a
# Overview
CM is composed of two applications that operate indepedently but are packaged together such that they act as one piece of software:
CM is composed of two applications that operate independently but are packaged together such that they act as one piece of software:
* **Server** -- Responsible for **running the bot(s)** and providing an API to retrieve information on and interact with them EX start/stop bot, reload config, retrieve operational status, etc.
* **Client** -- Responsible for serving the **web interface** and handling the bot oauth authentication flow between operators and subreddits/bots.

View File

@@ -136,6 +136,8 @@ You will need have this information available:
See the [**example minimum configuration** below.](#minimum-config)
This configuration can also be **generated** by CM if you start CM with **no configuration defined** and visit the web interface.
# Bots
Configured using the `bots` top-level property. Bot configuration can override and specify many more options than are available at the operator-level. Many of these can also set the defaults for each subreddit the bot runs:

View File

@@ -4,9 +4,7 @@ This getting started guide is for **Operators** -- that is, someone who wants to
* [Installation](#installation)
* [Create a Reddit Client](#create-a-reddit-client)
* [Create a Minimum Configuration](#create-a-minimum-configuration)
* [Local Installation](#local-installation)
* [Docker Installation](#docker-installation)
* [Start ContextMod](#start-contextmod)
* [Add a Bot to CM](#add-a-bot-to-cm)
* [Access The Dashboard](#access-the-dashboard)
* [What's Next?](#whats-next)
@@ -19,29 +17,25 @@ Follow the [installation](/docs/operator/installation.md) documentation. It is r
[Create a reddit client](/docs/operator/README.md#provisioning-a-reddit-client)
# Create a Minimum Configuration
# Start ContextMod
Using the information you received in the previous step [create a minimum file configuration](/docs/operator/configuration.md#minimum-configuration) save it as `config.yaml` somewhere.
Start CM using the example command from your [installation](#installation) and visit http://localhost:8085
# Start ContextMod With Configuration
The First Time Setup page will ask you to input:
## Local Installation
* Client ID (from [Create a Reddit Client](#create-a-reddit-client))
* Client Secret (from [Create a Reddit Client](#create-a-reddit-client))
* Operator -- this is the username of your main Reddit account.
If you [installed CM locally](/docs/installation.md#locally) move your configuration file `config.yaml` to the root of the project directory (where `package.json`) is located.
From the root directory run this command to start CM
```
node src/index.js run
```
## Docker Installation
If you [installed CM using Docker](/docs/installation.md#docker-recommended) make note of the directory you saved your minimum configuration to and substitute its full path for `host/path/folder` in the docker command show in the [docker install directions](/docs/operator/installation.md#docker-recommended)
**Write Config** and then restart CM. You have now created the [minimum configuration](/docs/operator/configuration.md#minimum-configuration) required to run CM.
# Add A Bot to CM
Once CM is up and running use the [CM OAuth Helper](/docs/operator/addingBot.md#cm-oauth-helper-recommended) to add authorize and add a Bot to your CM instance.
You should automatically be directed to the [Bot Invite Helper](/docs/operator/addingBot.md#cm-oauth-helper-recommended) used to authorize and add a Bot to your CM instance.
Follow the directions here and **create an Authorization Invite** at the bottom of the page.
Next, login to Reddit with the account you will be using as the Bot and then visit the **Authorization Invite** link you created. Follow the steps there to finish adding the Bot to your CM instance.
# Access The Dashboard
@@ -57,4 +51,4 @@ As an operator you should familiarize yourself with how the [operator configurat
If you are also the moderator of the subreddit the bot will be running you should check out the [moderator getting started guide.](/docs/subreddit/gettingStarted.md#setup-wiki-page)
You might also be interested in these [quick tips for using the web interface](/docs/webInterface.md)
You might also be interested in these [quick tips for using the web interface](/docs/webInterface.md). Additionally, on the dashboard click the **Help** button at the top of the page to get a guided tour of the dashboard.

View File

@@ -8,15 +8,19 @@ ContextMod can be run on almost any operating system but it is recommended to us
PROTIP: Using a container management tool like [Portainer.io CE](https://www.portainer.io/products/community-edition) will help with setup/configuration tremendously.
### [Dockerhub](https://hub.docker.com/r/foxxmd/context-mod)
Images available from these registeries:
An example of starting the container using the [minimum configuration](/docs/operator/operatorConfiguration.md#minimum-config) with a [configuration file](/docs/operator/operatorConfiguration.md#defining-configuration-via-file):
* [Dockerhub](https://hub.docker.com/r/foxxmd/context-mod) - `docker.io/foxxmd/context-mod`
* [GHCR](https://github.com/foxxmd/context-mod/pkgs/container/context-mod) - `ghcr.io/foxxmd/context-mod`
An example of starting the container using the [minimum configuration](/docs/operator/configuration.md#minimum-config):
* Bind the directory where your config file, logs, and database are located on your host machine into the container's default `DATA_DIR` by using `-v /host/path/folder:/config`
* Note: **You must do this** or else your configuration will be lost next time your container is updated.
* Expose the web interface using the container port `8085`
```
docker run -d -v /host/path/folder:/config -p 8085:8085 foxxmd/context-mod
docker run -d -v /host/path/folder:/config -p 8085:8085 ghcr.io/foxxmd/context-mod:latest
```
The location of `DATA_DIR` in the container can be changed by passing it as an environmental variable EX `-e "DATA_DIR=/home/abc/config`
@@ -33,7 +37,7 @@ To get the UID and GID for the current user run these commands from a terminal:
* `id -g` -- prints GID
```
docker run -d -v /host/path/folder:/config -p 8085:8085 -e PUID=1000 -e PGID=1000 foxxmd/context-mod
docker run -d -v /host/path/folder:/config -p 8085:8085 -e PUID=1000 -e PGID=1000 ghcr.io/foxxmd/context-mod:latest
```
## Locally

95
docs/subreddit/README.md Normal file
View File

@@ -0,0 +1,95 @@
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)

View File

@@ -1,12 +1,32 @@
Actions that can submit text (Report, Comment, UserNote) will have their `content` values run through a [Mustache Template](https://mustache.github.io/). This means you can insert data generated by Rules into your text before the Action is performed.
Actions that can submit text (Report, Comment, UserNote, Message, Ban, Submission) will have their `content` values run through a [Mustache Template](https://mustache.github.io/). This means you can insert data generated by Rules into your text before the Action is performed.
See here for a [cheatsheet](https://gist.github.com/FoxxMD/d365707cf99fdb526a504b8b833a5b78) and [here](https://www.tsmean.com/articles/mustache/the-ultimate-mustache-tutorial/) for a more thorough tutorial.
# Template Data
Some data can always be accessed at the top-level. Example
```
This action was run from {{manager}} in Check {{check}}.
The bot intro post is {{botLink}}
Message the moderators of this subreddit using this [compose link]({{modmailLink}})
```
| Name | Description | Example |
|---------------|---------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `manager` | The name of the subreddit the bot is running in | mealtimevideos |
| `check` | The name of the Check that was triggered | myCheck |
| `botLink` | A link to the bot introduction | https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot |
| `modmailLink` | A link that opens reddit's DM compose with the subject line as the Activity being processed | https://www.reddit.com/message/compose?to=/r/mealtimevideos&message=https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot |
## Activity Data
Activity data can be accessed using the `item` variable. Example
**Activity data can be accessed using the `item` variable.** Example
```
This activity is a {{item.kind}} with {{item.votes}} votes, created {{item.age}} ago.
@@ -19,14 +39,17 @@ Produces:
All Actions with `content` have access to this data:
| Name | Description | Example |
|-------------|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| `kind` | The Activity type (submission or comment) | submission |
| `author` | Name of the Author of the Activity being processed | FoxxMD |
| `permalink` | URL to the Activity | https://reddit.com/r/mySuibreddit/comments/ab23f/my_post |
| `votes` | Number of upvotes | 69 |
| `age` | The age of the Activity in a [human friendly format](https://day.js.org/docs/en/durations/humanize) | 5 minutes |
| `botLink` | A URL to CM's introduction thread | https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot |
| Name | Description | Example |
|--------------|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| `kind` | The Activity type (submission or comment) | submission |
| `author` | Name of the Author of the Activity being processed | FoxxMD |
| `permalink` | URL to the Activity | https://reddit.com/r/mySuibreddit/comments/ab23f/my_post |
| `votes` | Number of upvotes | 69 |
| `age` | The age of the Activity in a [human friendly format](https://day.js.org/docs/en/durations/humanize) | 5 minutes |
| `subreddit` | The name of the subreddit the Activity is from | mealtimevideos |
| `id` | The `Reddit Thing` ID for the Activity | t3_0tin1 |
| `title` | As comments => the body of the comment. As Submission => title | Test post please ignore |
| `shortTitle` | The same as `title` but truncated to 15 characters | test post pleas... |
### Submissions
@@ -89,7 +112,39 @@ Produces
> Submission was repeated 7 times
#### Quick Templating Tutorial
## Action Data
### Summary
A summary of what actions have already been run **when the template is rendered** is available using the `actionSummary` variable. It is therefore important that the Action you want to produce the summary is run **after** any other Actions you want to get a summary for.
Example:
```
A summary of actions processed for this activity, so far:
{{actionSummary}}
```
Would produce:
> A summary of actions processed for this activity, so far:
>
> * approve - ✘ - Item is already approved??
> * lock - ✓
> * modnote - ✓ - (SOLID_CONTRIBUTOR) User is good
### Individual
Individual **Actions** can be accessed using the name of the action, **lower-cased, with all spaces/dashes/underscores.** Example:
```
User was banned for {{actions.exampleban.duration}} for {{actions.exampleban.reason}}
```
Produces
> User was banned for 4 days for toxic behavior
# Quick Templating Tutorial
As a quick example for how you will most likely be using templating -- wrapping a variable in curly brackets, `{{variable}}`, will cause the variable value to be rendered instead of the brackets:

View File

@@ -22,6 +22,7 @@ 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)
@@ -29,6 +30,7 @@ This list is not exhaustive. [For complete documentation on a subreddit's config
* [List of Actions](#list-of-actions)
* [Approve](#approve)
* [Ban](#ban)
* [Submission](#submission)
* [Comment](#comment)
* [Contributor (Add/Remove)](#contributor)
* [Dispatch/Delay](#dispatch)
@@ -376,6 +378,12 @@ 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.
@@ -494,11 +502,30 @@ actions:
### Comment
Reply to the Activity being processed with a comment. [Schema Documentation](https://json-schema.app/view/%23/%23%2Fdefinitions%2FSubmissionCheckJson/%23%2Fdefinitions%2FCommentActionJson?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Freddit-context-bot%2Fmaster%2Fsrc%2FSchema%2FApp.json)
Reply to an Activity with a comment. [Schema Documentation](https://json-schema.app/view/%23/%23%2Fdefinitions%2FSubmissionCheckJson/%23%2Fdefinitions%2FCommentActionJson?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Freddit-context-bot%2Fmaster%2Fsrc%2FSchema%2FApp.json)
* If the Activity is a Submission the comment is a top-level reply
* If the Activity is a Comment the comment is a child reply
#### Templating
`content` can be [templated](#templating) and use [URL Tokens](#url-tokens)
#### Targets
Optionally, specify the Activity CM should reply to. **When not specified CM replies to the Activity being processed using `self`**
Valid values: `self`, `parent`, or a Reddit permalink.
`self` and `parent` are special targets that are relative to the Activity being processed:
* When the Activity being processed is a **Submission** => `parent` logs a warning and does nothing
* When the Activity being processed is a **Comment**
* `self` => reply to Comment
* `parent` => make a top-level Comment in the **Submission** the Comment belong to
If target is not self/parent then CM assumes the value is a **reddit permalink** and will attempt to make a Comment to that Activity
```yaml
actions:
- kind: comment
@@ -506,7 +533,71 @@ actions:
distinguish: boolean # distinguish as a mod
sticky: boolean # sticky comment
lock: boolean # lock the comment after creation
targets: string # 'self' or 'parent' or 'https://reddit.com/r/someSubreddit/21nfdi....'
```
### Submission
Create a Submission [Schema Documentation](https://json-schema.app/view/%23/%23%2Fdefinitions%2FSubmissionCheckJson/%23%2Fdefinitions%2FSubmissionActionJson?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Freddit-context-bot%2Fmaster%2Fsrc%2FSchema%2FApp.json)
The Submission type, Link or Self-Post, is determined based on the presence of `url` in the action's configuration.
```yaml
actions:
- kind: submission
title: string # required, the title of the submission. can be templated.
content: string # the body of the submission. can be templated
url: string # if specified the submission will be a Link Submission. can be templated
distinguish: boolean # distinguish as a mod
sticky: boolean # sticky comment
lock: boolean # lock the comment after creation
nsfw: boolean # mark submission as NSFW
spoiler: boolean # mark submission as a spoiler
flairId: string # flair template id for submission
flairText: string # flair text for submission
targets: string # 'self' or a subreddit name IE mealtimevideos
```
#### Templating
`content`,`url`, and `title` can be [templated](#templating) and use [URL Tokens](#url-tokens)
TIP: To create a Link Submission pointing to the Activity currently being processed use
```yaml
actions:
- kind: submission
url: {{item.permalink}}
# ...
```
#### Targets
Optionally, specify the Subreddit the Submission should be made in. **When not specified CM uses `self`**
Valid values: `self` or Subreddit Name
* `self` => (**Default**) Create Submission in the same Subreddit of the Activity being processed
* Subreddit Name => Create Submission in given subreddit IE `mealtimevideos`
* Your bot must be able to access and be able to post in the given subreddit
Example:
```yaml
actions:
- kind: comment
targets: mealtimevideos
```
To post to multiple subreddits use a list:
```yaml
actions:
- kind: comment
targets:
- self
- mealtimevideos
- anotherSubreddit
```
### Contributor
@@ -608,31 +699,35 @@ Some other things to note:
* If the `to` property is not specified then the message is sent to the Author of the Activity being processed
* `to` may be a **User** (u/aUser) or a **Subreddit** (r/aSubreddit)
* `to` **cannot** be a Subreddit when `asSubreddit: true` -- IE cannot send subreddit-to-subreddit messages
* `content` can be [templated](#templating) and use [URL Tokens](#url-tokens)
* TIP: `to` can be templated -- to send a message to the subreddit the Activity being processed is in use `'r/{{item.subreddit}}'`
* `content` and `title` can be [templated](#templating) and use [URL Tokens](#url-tokens)
```yaml
actions:
- kind: message
asSubreddit: true
content: 'A message sent as the subreddit'
title: 'Title of the message'
to: 'u/aUser' # do not specify 'to' in order default to sending to Author of Activity being processed
content: 'A message sent as the subreddit' # can be templated
title: 'Title of the message' # can be templated
to: 'u/aUser' # do not specify 'to' in order default to sending to Author of Activity being processed. Can also be templated
```
### Remove
Remove the Activity being processed. [Schema Documentation](https://json-schema.app/view/%23/%23%2Fdefinitions%2FSubmissionCheckJson/%23%2Fdefinitions%2FRemoveActionJson?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Freddit-context-bot%2Fedge%2Fsrc%2FSchema%2FApp.json)
* **note** can be [templated](#templating)
* **reasonId** IDs can be found in the [editor](/docs/webInterface.md) using the **Removal Reasons** popup
If neither note nor reasonId are included then no removal reason is added.
```yaml
actions:
- kind: remove
spam: boolean # optional, mark as spam on removal
spam: false # optional, mark as spam on removal
note: 'a moderator-readable note' # optional, a note only visible to moderators (new reddit only)
reasonId: '2n0f4674-365e-46d2-8fc7-a337d85d5340' # optional, the ID of a removal reason to add to the removal action (new reddit only)
```
#### What About Removal Reason?
Reddit does not support setting a removal reason through the API. Please complain in [r/modsupport](https://www.reddit.com/r/modsupport) or [r/redditdev](https://www.reddit.com/r/redditdev) to help get this added :)
### Report
Report the Activity being processed. [Schema Documentation](https://json-schema.app/view/%23/%23%2Fdefinitions%2FSubmissionCheckJson/%23%2Fdefinitions%2FReportActionJson?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Freddit-context-bot%2Fedge%2Fsrc%2FSchema%2FApp.json)

View File

@@ -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
// AND = any of the nested Rules will be the Rule Set trigger
// OR = 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

View File

@@ -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
# AND = any of the nested Rules will be the Rule Set trigger
# OR = 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

View File

@@ -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"],
"name": ["user1","user2"]
"names": ["user1","user2"]
},
{
// for this to pass the Author of the Submission must not have the flair "Decent Memer"

View File

@@ -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
name:
names:
- user1
- user2
# for this to pass the Author of the Submission must not have the flair "Decent Memer"

View File

@@ -5,9 +5,45 @@ 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.

View File

@@ -0,0 +1,165 @@
# 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
```

View File

@@ -43,7 +43,7 @@
// remove this after confirming behavior is acceptable
{
"kind": "report",
"content": "Remove=> {{rules.newtube.totalCount}} activities in freekarma subs"
"content": "Remove=> {{rules.freekarma.totalCount}} activities in freekarma subs"
},
//
//

View File

@@ -25,7 +25,7 @@ runs:
actions:
- kind: report
enable: true
content: 'Remove=> {{rules.newtube.totalCount}} activities in freekarma subs'
content: 'Remove=> {{rules.freekarma.totalCount}} activities in freekarma subs'
- kind: remove
enable: true
- kind: comment

View File

@@ -20,6 +20,7 @@
## Web Dashboard Tips
* Click the **Help** button at the top of the page to get a **guided tour of the dashboard**
* Use the [**Overview** section](/docs/images/botOperations.png) to control the bot at a high-level
* You can **manually run** the bot on any activity (comment/submission) by pasting its permalink into the [input field below the Overview section](/docs/images/runInput.png) and hitting one of the **run buttons**
* **Dry run** will make the bot run on the activity but it will only **pretend** to run actions, if triggered. This is super useful for testing your config without consequences

358
package-lock.json generated
View File

@@ -11,9 +11,10 @@
"license": "ISC",
"dependencies": {
"@awaitjs/express": "^0.8.0",
"@datasert/cronjs-matcher": "^1.2.0",
"@googleapis/youtube": "^2.0.0",
"@influxdata/influxdb-client": "^1.27.0",
"@influxdata/influxdb-client-apis": "^1.27.0",
"@influxdata/influxdb-client": "^1.31.0",
"@influxdata/influxdb-client-apis": "^1.31.0",
"@nlpjs/core": "^4.23.4",
"@nlpjs/lang-de": "^4.23.4",
"@nlpjs/lang-en": "^4.23.4",
@@ -28,7 +29,7 @@
"autolinker": "^3.14.3",
"body-parser": "^1.19.0",
"cache-manager": "^3.4.4",
"cache-manager-redis-store": "^2.0.0",
"cache-manager-redis-store": "^3.0.1",
"commander": "^8.0.0",
"comment-json": "^4.1.1",
"connect-typeorm": "^2.0.0",
@@ -77,6 +78,7 @@
"triple-beam": "^1.3.0",
"typeorm": "^0.3.7",
"typeorm-logger-adaptor": "^1.1.0",
"unique-names-generator": "^4.7.1",
"vader-sentiment": "^1.1.3",
"webhook-discord": "^3.7.7",
"wink-sentiment": "^5.0.2",
@@ -93,7 +95,6 @@
"@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",
@@ -136,7 +137,7 @@
"typescript-json-schema": "~0.53"
},
"engines": {
"node": ">=16"
"node": ">=16.18.0"
},
"optionalDependencies": {
"better-sqlite3": "^7.5.0",
@@ -655,6 +656,20 @@
"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",
@@ -667,14 +682,14 @@
}
},
"node_modules/@influxdata/influxdb-client": {
"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=="
"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=="
},
"node_modules/@influxdata/influxdb-client-apis": {
"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==",
"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==",
"peerDependencies": {
"@influxdata/influxdb-client": "*"
}
@@ -963,6 +978,59 @@
"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",
@@ -1147,16 +1215,6 @@
"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",
@@ -1440,15 +1498,6 @@
"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",
@@ -2334,14 +2383,14 @@
}
},
"node_modules/cache-manager-redis-store": {
"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==",
"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==",
"dependencies": {
"redis": "^3.0.2"
"redis": "^4.3.1"
},
"engines": {
"node": ">= 8.3"
"node": ">= 16.18.0"
}
},
"node_modules/cacheable-lookup": {
@@ -2625,6 +2674,14 @@
"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",
@@ -3194,14 +3251,6 @@
"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",
@@ -4150,6 +4199,14 @@
"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",
@@ -5795,6 +5852,14 @@
"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",
@@ -7774,45 +7839,16 @@
}
},
"node_modules/redis": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/redis/-/redis-4.3.1.tgz",
"integrity": "sha512-cM7yFU5CA6zyCF7N/+SSTcSJQSRMEKN0k0Whhu6J7n9mmXRoXugfWDBo5iOzGwABmsWKSwGPTU5J4Bxbl+0mrA==",
"dependencies": {
"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"
"@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"
}
},
"node_modules/reflect-metadata": {
@@ -9741,6 +9777,14 @@
"node": ">= 0.8.x"
}
},
"node_modules/unique-names-generator": {
"version": "4.7.1",
"resolved": "https://registry.npmjs.org/unique-names-generator/-/unique-names-generator-4.7.1.tgz",
"integrity": "sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow==",
"engines": {
"node": ">=8"
}
},
"node_modules/universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
@@ -10803,6 +10847,20 @@
"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",
@@ -10812,14 +10870,14 @@
}
},
"@influxdata/influxdb-client": {
"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=="
"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=="
},
"@influxdata/influxdb-client-apis": {
"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==",
"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==",
"requires": {}
},
"@istanbuljs/load-nyc-config": {
@@ -11069,6 +11127,46 @@
"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",
@@ -11168,16 +11266,6 @@
"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",
@@ -11461,15 +11549,6 @@
"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",
@@ -12207,11 +12286,11 @@
}
},
"cache-manager-redis-store": {
"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==",
"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==",
"requires": {
"redis": "^3.0.2"
"redis": "^4.3.1"
}
},
"cacheable-lookup": {
@@ -12424,6 +12503,11 @@
"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",
@@ -12887,11 +12971,6 @@
"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",
@@ -13629,6 +13708,11 @@
"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",
@@ -14877,6 +14961,11 @@
"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",
@@ -16404,32 +16493,16 @@
}
},
"redis": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/redis/-/redis-4.3.1.tgz",
"integrity": "sha512-cM7yFU5CA6zyCF7N/+SSTcSJQSRMEKN0k0Whhu6J7n9mmXRoXugfWDBo5iOzGwABmsWKSwGPTU5J4Bxbl+0mrA==",
"requires": {
"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"
"@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"
}
},
"reflect-metadata": {
@@ -17837,6 +17910,11 @@
"resolved": "https://registry.npmjs.org/unicode/-/unicode-14.0.0.tgz",
"integrity": "sha512-BjinxTXkbm9Jomp/YBTMGusr4fxIG67fNGShHIRAL16Ur2GJTq2xvLi+sxuiJmInCmwqqev2BCFKyvbfp/yAkg=="
},
"unique-names-generator": {
"version": "4.7.1",
"resolved": "https://registry.npmjs.org/unique-names-generator/-/unique-names-generator-4.7.1.tgz",
"integrity": "sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow=="
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",

View File

@@ -24,16 +24,17 @@
"initMigration": "npm run typeorm -- migration:generate -t 1642180264563 -d ormconfig.js \"src/Common/Migrations/Database/init\""
},
"engines": {
"node": ">=16"
"node": ">=16.18.0"
},
"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.27.0",
"@influxdata/influxdb-client-apis": "^1.27.0",
"@influxdata/influxdb-client": "^1.31.0",
"@influxdata/influxdb-client-apis": "^1.31.0",
"@nlpjs/core": "^4.23.4",
"@nlpjs/lang-de": "^4.23.4",
"@nlpjs/lang-en": "^4.23.4",
@@ -48,7 +49,7 @@
"autolinker": "^3.14.3",
"body-parser": "^1.19.0",
"cache-manager": "^3.4.4",
"cache-manager-redis-store": "^2.0.0",
"cache-manager-redis-store": "^3.0.1",
"commander": "^8.0.0",
"comment-json": "^4.1.1",
"connect-typeorm": "^2.0.0",
@@ -97,6 +98,7 @@
"triple-beam": "^1.3.0",
"typeorm": "^0.3.7",
"typeorm-logger-adaptor": "^1.1.0",
"unique-names-generator": "^4.7.1",
"vader-sentiment": "^1.1.3",
"webhook-discord": "^3.7.7",
"wink-sentiment": "^5.0.2",
@@ -113,7 +115,6 @@
"@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",

View File

@@ -3,7 +3,7 @@ import LockAction, {LockActionJson} from "./LockAction";
import {RemoveAction, RemoveActionJson} from "./RemoveAction";
import {ReportAction, ReportActionJson} from "./ReportAction";
import {FlairAction, FlairActionJson} from "./SubmissionAction/FlairAction";
import Action, {ActionJson, StructuredActionJson} from "./index";
import Action, {ActionJson, ActionRuntimeOptions, StructuredActionJson} from "./index";
import {Logger} from "winston";
import {UserNoteAction, UserNoteActionJson} from "./UserNoteAction";
import ApproveAction, {ApproveActionConfig} from "./ApproveAction";
@@ -18,38 +18,41 @@ import {CancelDispatchAction, CancelDispatchActionJson} from "./CancelDispatchAc
import ContributorAction, {ContributorActionJson} from "./ContributorAction";
import {StructuredFilter} from "../Common/Infrastructure/Filters/FilterShapes";
import {ModNoteAction, ModNoteActionJson} from "./ModNoteAction";
import {SubmissionAction, SubmissionActionJson} from "./SubmissionAction";
export function actionFactory
(config: StructuredActionJson, logger: Logger, subredditName: string, resources: SubredditResources, client: ExtendedSnoowrap, emitter: EventEmitter): Action {
(config: StructuredActionJson, runtimeOptions: ActionRuntimeOptions): Action {
switch (config.kind) {
case 'comment':
return new CommentAction({...config as StructuredFilter<CommentActionJson>, logger, subredditName, resources, client, emitter});
return new CommentAction({...config as StructuredFilter<CommentActionJson>, ...runtimeOptions});
case 'submission':
return new SubmissionAction({...config as StructuredFilter<SubmissionActionJson>, ...runtimeOptions});
case 'lock':
return new LockAction({...config as StructuredFilter<LockActionJson>, logger, subredditName, resources, client, emitter});
return new LockAction({...config as StructuredFilter<LockActionJson>, ...runtimeOptions});
case 'remove':
return new RemoveAction({...config as StructuredFilter<RemoveActionJson>, logger, subredditName, resources, client, emitter});
return new RemoveAction({...config as StructuredFilter<RemoveActionJson>, ...runtimeOptions});
case 'report':
return new ReportAction({...config as StructuredFilter<ReportActionJson>, logger, subredditName, resources, client, emitter});
return new ReportAction({...config as StructuredFilter<ReportActionJson>, ...runtimeOptions});
case 'flair':
return new FlairAction({...config as StructuredFilter<FlairActionJson>, logger, subredditName, resources, client, emitter});
return new FlairAction({...config as StructuredFilter<FlairActionJson>, ...runtimeOptions});
case 'userflair':
return new UserFlairAction({...config as StructuredFilter<UserFlairActionJson>, logger, subredditName, resources, client, emitter});
return new UserFlairAction({...config as StructuredFilter<UserFlairActionJson>, ...runtimeOptions});
case 'approve':
return new ApproveAction({...config as StructuredFilter<ApproveActionConfig>, logger, subredditName, resources, client, emitter});
return new ApproveAction({...config as StructuredFilter<ApproveActionConfig>, ...runtimeOptions});
case 'usernote':
return new UserNoteAction({...config as StructuredFilter<UserNoteActionJson>, logger, subredditName, resources, client, emitter});
return new UserNoteAction({...config as StructuredFilter<UserNoteActionJson>, ...runtimeOptions});
case 'ban':
return new BanAction({...config as StructuredFilter<BanActionJson>, logger, subredditName, resources, client, emitter});
return new BanAction({...config as StructuredFilter<BanActionJson>, ...runtimeOptions});
case 'message':
return new MessageAction({...config as StructuredFilter<MessageActionJson>, logger, subredditName, resources, client, emitter});
return new MessageAction({...config as StructuredFilter<MessageActionJson>, ...runtimeOptions});
case 'dispatch':
return new DispatchAction({...config as StructuredFilter<DispatchActionJson>, logger, subredditName, resources, client, emitter});
return new DispatchAction({...config as StructuredFilter<DispatchActionJson>, ...runtimeOptions});
case 'cancelDispatch':
return new CancelDispatchAction({...config as StructuredFilter<CancelDispatchActionJson>, logger, subredditName, resources, client, emitter})
return new CancelDispatchAction({...config as StructuredFilter<CancelDispatchActionJson>, ...runtimeOptions})
case 'contributor':
return new ContributorAction({...config as StructuredFilter<ContributorActionJson>, logger, subredditName, resources, client, emitter})
return new ContributorAction({...config as StructuredFilter<ContributorActionJson>, ...runtimeOptions})
case 'modnote':
return new ModNoteAction({...config as StructuredFilter<ModNoteActionJson>, logger, subredditName, resources, client, emitter})
return new ModNoteAction({...config as StructuredFilter<ModNoteActionJson>, ...runtimeOptions})
default:
throw new Error('rule "kind" was not recognized.');
}

View File

@@ -8,6 +8,7 @@ import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTarget, ActionTypes} from "../Common/Infrastructure/Atomic";
import {asComment, asSubmission} from "../util";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class ApproveAction extends Action {
@@ -26,7 +27,7 @@ export class ApproveAction extends Action {
this.targets = targets;
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const touchedEntities = [];

View File

@@ -7,10 +7,18 @@ import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {truncateStringToLength} from "../util";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
const truncate = truncateStringToLength(100);
const truncateLongMessage = truncateStringToLength(200);
const truncateIfNotUndefined = (val: string | undefined) => {
if(val === undefined) {
return undefined;
}
return truncate(val);
}
export class BanAction extends Action {
message?: string;
@@ -39,13 +47,13 @@ export class BanAction extends Action {
return 'ban';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const renderedBody = this.message === undefined ? undefined : await this.resources.renderContent(this.message, item, ruleResults);
const renderedContent = renderedBody === undefined ? undefined : `${renderedBody}${await this.resources.generateFooter(item, this.footer)}`;
const renderedBody = await this.renderContent(this.message, item, ruleResults, actionResults);
const renderedContent = renderedBody === undefined ? undefined : `${renderedBody}${await this.resources.renderFooter(item, this.footer)}`;
const renderedReason = this.reason === undefined ? undefined : truncate(await this.resources.renderContent(this.reason, item, ruleResults));
const renderedNote = this.note === undefined ? undefined : truncate(await this.resources.renderContent(this.note, item, ruleResults));
const renderedReason = truncateIfNotUndefined(await this.renderContent(this.reason, item, ruleResults, actionResults) as string);
const renderedNote = truncateIfNotUndefined(await this.renderContent(this.note, item, ruleResults, actionResults) as string);
const touchedEntities = [];
let banPieces = [];
@@ -72,7 +80,13 @@ export class BanAction extends Action {
dryRun,
success: true,
result: `Banned ${item.author.name} ${durText}${renderedReason !== undefined ? ` (${renderedReason})` : ''}`,
touchedEntities
touchedEntities,
data: {
message: renderedContent === undefined ? undefined : renderedContent,
reason: renderedReason,
note: renderedNote,
duration: durText
}
};
}

View File

@@ -12,6 +12,7 @@ import {isSubmission, parseDurationValToDuration} from "../util";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTarget, ActionTypes, InclusiveActionTarget} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class CancelDispatchAction extends Action {
identifiers?: (string | null)[];
@@ -35,7 +36,7 @@ export class CancelDispatchAction extends Action {
this.targets = !Array.isArray(target) ? [target] : target;
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
// see note in DispatchAction about missing runtimeDryrun
const dryRun = this.dryRun;

View File

@@ -1,12 +1,15 @@
import Action, {ActionJson, ActionOptions} from "./index";
import {Comment} from "snoowrap";
import {Comment, VoteableContent} from "snoowrap";
import Submission from "snoowrap/dist/objects/Submission";
import {renderContent} from "../Utils/SnoowrapUtils";
import {ActionProcessResult, Footer, RequiredRichContent, RichContent, RuleResult} from "../Common/interfaces";
import {truncateStringToLength} from "../util";
import {asComment, asSubmission, parseRedditThingsFromLink, truncateStringToLength} from "../util";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionTarget, ActionTypes, ArbitraryActionTarget} from "../Common/Infrastructure/Atomic";
import {CMError} from "../Utils/Errors";
import {SnoowrapActivity} from "../Common/Infrastructure/Reddit";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class CommentAction extends Action {
content: string;
@@ -14,6 +17,7 @@ export class CommentAction extends Action {
sticky: boolean = false;
distinguish: boolean = false;
footer?: false | string;
targets: ArbitraryActionTarget[]
constructor(options: CommentActionOptions) {
super(options);
@@ -23,71 +27,139 @@ export class CommentAction extends Action {
sticky = false,
distinguish = false,
footer,
targets = ['self']
} = options;
this.footer = footer;
this.content = content;
this.lock = lock;
this.sticky = sticky;
this.distinguish = distinguish;
if (!Array.isArray(targets)) {
this.targets = [targets];
} else {
this.targets = targets;
}
}
getKind(): ActionTypes {
return 'comment';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const content = await this.resources.getContent(this.content, item.subreddit);
const body = await renderContent(content, item, ruleResults, this.resources.userNotes);
const body = await this.renderContent(this.content, item, ruleResults, actionResults) as string;
const footer = await this.resources.generateFooter(item, this.footer);
const footer = await this.resources.renderFooter(item, this.footer);
const renderedContent = `${body}${footer}`;
this.logger.verbose(`Contents:\r\n${renderedContent.length > 100 ? `\r\n${renderedContent}` : renderedContent}`);
if(item.archived) {
this.logger.warn('Cannot comment because Item is archived');
return {
dryRun,
success: false,
result: 'Cannot comment because Item is archived'
};
}
let allErrors = true;
const targetResults: string[] = [];
const touchedEntities = [];
let modifiers = [];
let reply: Comment;
if(!dryRun) {
// @ts-ignore
reply = await item.reply(renderedContent);
// add to recent so we ignore activity when/if it is discovered by polling
await this.resources.setRecentSelf(reply);
touchedEntities.push(reply);
}
if (this.lock) {
modifiers.push('Locked');
for (const target of this.targets) {
let targetItem = item;
let targetIdentifier = target;
if (target === 'parent') {
if (asSubmission(item)) {
const noParent = `[Parent] Submission ${item.name} does not have a parent`;
this.logger.warn(noParent);
targetResults.push(noParent);
continue;
}
targetItem = await this.resources.getActivity(this.client.getSubmission(item.link_id));
} else if (target !== 'self') {
const redditThings = parseRedditThingsFromLink(target);
let id = '';
try {
if (redditThings.comment !== undefined) {
id = redditThings.comment.id;
targetIdentifier = `Permalink Comment ${id}`
// @ts-ignore
await this.resources.getActivity(this.client.getSubmission(redditThings.submission.id));
targetItem = await this.resources.getActivity(this.client.getComment(redditThings.comment.id));
} else if (redditThings.submission !== undefined) {
id = redditThings.submission.id;
targetIdentifier = `Permalink Submission ${id}`
targetItem = await this.resources.getActivity(this.client.getSubmission(redditThings.submission.id));
} else {
targetResults.push(`[Permalink] Could not parse ${target} as a reddit permalink`);
continue;
}
} catch (err: any) {
targetResults.push(`[${targetIdentifier}] error occurred while fetching activity: ${err.message}`);
this.logger.warn(new CMError(`[${targetIdentifier}] error occurred while fetching activity`, {cause: err}));
continue;
}
}
if (targetItem.archived) {
const archived = `[${targetIdentifier}] Cannot comment because Item is archived`;
this.logger.warn(archived);
targetResults.push(archived);
continue;
}
let modifiers = [];
let reply: Comment;
if (!dryRun) {
// snoopwrap typing issue, thinks comments can't be locked
// @ts-ignore
await reply.lock();
reply = await targetItem.reply(renderedContent);
// add to recent so we ignore activity when/if it is discovered by polling
await this.resources.setRecentSelf(reply);
touchedEntities.push(reply);
}
}
if (this.distinguish && !dryRun) {
modifiers.push('Distinguished');
if(this.sticky) {
modifiers.push('Stickied');
if (this.lock && targetItem.can_mod_post) {
if (!targetItem.can_mod_post) {
this.logger.warn(`[${targetIdentifier}] Cannot lock because bot is not a moderator`);
} else {
modifiers.push('Locked');
if (!dryRun) {
// snoopwrap typing issue, thinks comments can't be locked
// @ts-ignore
await reply.lock();
}
}
}
if(!dryRun) {
// @ts-ignore
await reply.distinguish({sticky: this.sticky});
if (this.distinguish) {
if (!targetItem.can_mod_post) {
this.logger.warn(`[${targetIdentifier}] Cannot lock Distinguish/Sticky because bot is not a moderator`);
} else {
modifiers.push('Distinguished');
if (this.sticky) {
modifiers.push('Stickied');
}
if (!dryRun) {
// @ts-ignore
await reply.distinguish({sticky: this.sticky});
}
}
}
const modifierStr = modifiers.length === 0 ? '' : ` == ${modifiers.join(' | ')} == =>`;
// @ts-ignore
targetResults.push(`${targetIdentifier}${modifierStr} created Comment ${dryRun ? 'DRYRUN' : (reply as SnoowrapActivity).name}`)
allErrors = false;
}
const modifierStr = modifiers.length === 0 ? '' : `[${modifiers.join(' | ')}]`;
return {
dryRun,
success: true,
result: `${modifierStr}${truncateStringToLength(100)(body)}`,
success: !allErrors,
result: `${targetResults.join('\n')}${truncateStringToLength(100)(body)}`,
touchedEntities,
data: {
body,
bodyShort: truncateStringToLength(100)(body),
comments: targetResults,
commentsFormatted: targetResults.map(x => `* ${x}`).join('\n')
}
};
}
@@ -97,7 +169,8 @@ export class CommentAction extends Action {
lock: this.lock,
sticky: this.sticky,
distinguish: this.distinguish,
footer: this.footer
footer: this.footer,
targets: this.targets,
}
}
}
@@ -115,6 +188,21 @@ export interface CommentActionConfig extends RequiredRichContent, Footer {
* Distinguish the comment after creation?
* */
distinguish?: boolean,
/**
* Specify where this comment should be made
*
* Valid values: 'self' | 'parent' | [reddit permalink]
*
* 'self' and 'parent' are special targets that are relative to the Activity being processed:
* * When Activity is Submission => 'parent' does nothing
* * When Activity is Comment
* * 'self' => reply to Activity
* * 'parent' => make a top-level comment in the Submission the Comment is in
*
* If target is not self/parent then CM assumes the value is a reddit permalink and will attempt to make a comment to that Activity
* */
targets?: ArbitraryActionTarget | ArbitraryActionTarget[]
}
export interface CommentActionOptions extends CommentActionConfig, ActionOptions {
@@ -124,5 +212,5 @@ export interface CommentActionOptions extends CommentActionConfig, ActionOptions
* Reply to the Activity. For a submission the reply will be a top-level comment.
* */
export interface CommentActionJson extends CommentActionConfig, ActionJson {
kind: 'comment'
kind: 'comment'
}

View File

@@ -7,6 +7,7 @@ import Comment from "snoowrap/dist/objects/Comment";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTarget, ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class ContributorAction extends Action {
@@ -25,7 +26,7 @@ export class ContributorAction extends Action {
this.actionType = action;
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const contributors = await this.resources.getSubredditContributors();

View File

@@ -8,6 +8,7 @@ import {activityDispatchConfigToDispatch, isSubmission, parseDurationValToDurati
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTarget, ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class DispatchAction extends Action {
dispatchData: ActivityDispatchConfig;
@@ -39,7 +40,7 @@ export class DispatchAction extends Action {
this.targets = !Array.isArray(target) ? [target] : target;
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
// ignore runtimeDryrun here because "real run" isn't causing any reddit api calls to happen
// -- basically if bot is in dryrun this should still run since we want the "full effect" of the bot
// BUT if the action explicitly sets 'dryRun: true' then do not dispatch as they probably don't want to it actually going (intention?)

View File

@@ -5,13 +5,14 @@ import {ActionProcessResult, RuleResult} from "../Common/interfaces";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class LockAction extends Action {
getKind(): ActionTypes {
return 'lock';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const touchedEntities = [];
//snoowrap typing issue, thinks comments can't be locked

View File

@@ -16,6 +16,7 @@ import {ErrorWithCause} from "pony-cause";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class MessageAction extends Action {
content: string;
@@ -48,28 +49,30 @@ export class MessageAction extends Action {
return 'message';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const body = await this.resources.renderContent(this.content, item, ruleResults);
const subject = this.title === undefined ? `Concerning your ${isSubmission(item) ? 'Submission' : 'Comment'}` : await this.resources.renderContent(this.title, item, ruleResults);
const body = await this.renderContent(this.content, item, ruleResults, actionResults);
const titleTemplate = this.title ?? `Concerning your ${isSubmission(item) ? 'Submission' : 'Comment'}`;
const subject = await this.renderContent(titleTemplate, item, ruleResults, actionResults) as string;
const footer = await this.resources.generateFooter(item, this.footer);
const footer = await this.resources.renderFooter(item, this.footer);
const renderedContent = `${body}${footer}`;
let recipient = item.author.name;
if(this.to !== undefined) {
const renderedTo = await this.renderContent(this.to, item, ruleResults, actionResults) as string;
// parse to value
try {
const entityData = parseRedditEntity(this.to, 'user');
const entityData = parseRedditEntity(renderedTo, 'user');
if(entityData.type === 'user') {
recipient = entityData.name;
} else {
recipient = `/r/${entityData.name}`;
}
} catch (err: any) {
throw new ErrorWithCause(`'to' field for message was not in a valid format. See ${REDDIT_ENTITY_REGEX_URL} for valid examples`, {cause: err});
throw new ErrorWithCause(`'to' field for message was not in a valid format, given value after templating: ${renderedTo} -- See ${REDDIT_ENTITY_REGEX_URL} for valid examples`, {cause: err});
}
if(recipient.includes('/r/') && this.asSubreddit) {
throw new SimpleError(`Cannot send a message as a subreddit to another subreddit. Requested recipient: ${recipient}`);
@@ -123,7 +126,7 @@ export interface MessageActionConfig extends RequiredRichContent, Footer {
asSubreddit: boolean
/**
* Entity to send message to.
* Entity to send message to. It can be templated.
*
* If not present Message be will sent to the Author of the Activity being checked.
*
@@ -135,8 +138,9 @@ export interface MessageActionConfig extends RequiredRichContent, Footer {
*
* **Note:** Reddit does not support sending a message AS a subreddit TO another subreddit
*
* @pattern ^\s*(\/[ru]\/|[ru]\/)*(\w+)*\s*$
* @examples ["aUserName","u/aUserName","r/aSubreddit"]
* **Tip:** To send a message to the subreddit of the Activity us `to: 'r/{{item.subreddit}}'`
*
* @examples ["aUserName","u/aUserName","r/aSubreddit", "r/{{item.subreddit}}"]
* */
to?: string

View File

@@ -1,29 +1,32 @@
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 {toModNoteLabel} from "../util";
import {buildFilterCriteriaSummary, normalizeModActionCriteria, toModNoteLabel} from "../util";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes, ModUserNoteLabel} from "../Common/Infrastructure/Atomic";
import {ModNote} from "../Subreddit/ModNotes/ModNote";
import {
ActionTypes,
ModUserNoteLabel,
} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
import {ModNoteCriteria} from "../Common/Infrastructure/Filters/FilterCriteria";
export class ModNoteAction extends Action {
content: string;
type?: string;
allowDuplicate: boolean;
existingNoteCheck?: ModNoteCriteria
referenceActivity: boolean
constructor(options: ModNoteActionOptions) {
super(options);
const {type, content = '', allowDuplicate = false, referenceActivity = true} = options;
const {type, content = '', existingNoteCheck = true, 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 {
@@ -34,41 +37,43 @@ export class ModNoteAction extends Action {
return {
content: this.content,
type: this.type,
allowDuplicate: this.allowDuplicate,
existingNoteCheck: this.existingNoteCheck,
referenceActivity: this.referenceActivity,
}
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const modLabel = this.type !== undefined ? toModNoteLabel(this.type) : undefined;
const content = await this.resources.getContent(this.content, item.subreddit);
const renderedContent = await renderContent(content, item, ruleResults, this.resources.userNotes);
const renderedContent = await this.renderContent(this.content, item, ruleResults, actionResults);
this.logger.verbose(`Note:\r\n(${this.type}) ${renderedContent}`);
// 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`
// };
// }
// }
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
};
}
if (!dryRun) {
await this.resources.addModNote({
label: modLabel,
@@ -84,15 +89,36 @@ 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 {
/**
* Add Note even if a Note already exists for this Activity
* @examples [false]
* @default false
* 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
* */
allowDuplicate?: boolean,
existingNoteCheck?: boolean | ModNoteCriteria,
type?: ModUserNoteLabel
referenceActivity?: boolean
}

View File

@@ -4,13 +4,17 @@ import Snoowrap, {Comment, Submission} from "snoowrap";
import {activityIsRemoved} from "../Utils/SnoowrapUtils";
import {ActionProcessResult, RuleResult} from "../Common/interfaces";
import dayjs from "dayjs";
import {isSubmission} from "../util";
import {isSubmission, truncateStringToLength} from "../util";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
const truncate = truncateStringToLength(100);
export class RemoveAction extends Action {
spam: boolean;
note?: string;
reasonId?: string;
getKind(): ActionTypes {
return 'remove';
@@ -20,21 +24,54 @@ export class RemoveAction extends Action {
super(options);
const {
spam = false,
note,
reasonId,
} = options;
this.spam = spam;
this.note = note;
this.reasonId = reasonId;
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const touchedEntities = [];
let removeSummary = [];
// issue with snoowrap typings, doesn't think prop exists on Submission
// @ts-ignore
if (activityIsRemoved(item)) {
this.logger.warn('It looks like this Item is already removed!');
}
if (this.spam) {
removeSummary.push('Marked as SPAM');
this.logger.verbose('Marking as spam on removal');
}
const renderedNote = await this.renderContent(this.note, item, ruleResults, actionResults);
let foundReasonId: string | undefined;
let foundReason: string | undefined;
if(this.reasonId !== undefined) {
const reason = await this.resources.getSubredditRemovalReasonById(this.reasonId);
if(reason === undefined) {
const reasonWarn = [`Could not find any Removal Reason with the ID ${this.reasonId}!`];
if(renderedNote === undefined) {
reasonWarn.push('Cannot add any Removal Reason because note is also empty!');
} else {
reasonWarn.push('Will add Removal Reason but only with note.');
}
this.logger.warn(reasonWarn.join(''));
} else {
foundReason = truncate(reason.title);
foundReasonId = reason.id;
removeSummary.push(`Reason: ${truncate(foundReason)} (${foundReasonId})`);
}
}
if(renderedNote !== undefined) {
removeSummary.push(`Note: ${truncate(renderedNote)}`);
}
this.logger.verbose(removeSummary.join(' | '));
if (!dryRun) {
// @ts-ignore
await item.remove({spam: this.spam});
@@ -44,6 +81,18 @@ export class RemoveAction extends Action {
// @ts-ignore
item.removed = true;
}
if(foundReasonId !== undefined || renderedNote !== undefined) {
await this.client.addRemovalReason(item, renderedNote, foundReasonId);
item.mod_reason_by = this.resources.botAccount as string;
if(renderedNote !== undefined) {
item.removal_reason = renderedNote;
}
if(foundReason !== undefined) {
item.mod_reason_title = foundReason;
}
}
await this.resources.resetCacheForItem(item);
touchedEntities.push(item);
}
@@ -51,7 +100,8 @@ export class RemoveAction extends Action {
return {
dryRun,
success: true,
touchedEntities
touchedEntities,
result: removeSummary.join(' | ')
}
}
@@ -66,7 +116,22 @@ export interface RemoveOptions extends Omit<RemoveActionConfig, 'authorIs' | 'it
}
export interface RemoveActionConfig extends ActionConfig {
/** (Optional) Mark Activity as spam */
spam?: boolean
/** (Optional) A mod-readable note added to the removal reason for this Activity. Can use Templating.
*
* This note (and removal reasons) are only visible on New Reddit
* */
note?: string
/** (Optional) The ID of the Removal Reason to use
*
* Removal reasons are only visible on New Reddit
*
* To find IDs for removal reasons check the "Removal Reasons" popup located in the CM dashboard config editor for your subreddit
*
* More info on Removal Reasons: https://mods.reddithelp.com/hc/en-us/articles/360010094892-Removal-Reasons
* */
reasonId?: string
}
/**

View File

@@ -7,6 +7,7 @@ import {ActionProcessResult, RichContent, RuleResult} from "../Common/interfaces
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
// https://www.reddit.com/dev/api/oauth#POST_api_report
// denotes 100 characters maximum
@@ -25,10 +26,9 @@ export class ReportAction extends Action {
return 'report';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const content = await this.resources.getContent(this.content, item.subreddit);
const renderedContent = await renderContent(content, item, ruleResults, this.resources.userNotes);
const renderedContent = (await this.renderContent(this.content, item, ruleResults, actionResults) as string);
this.logger.verbose(`Contents:\r\n${renderedContent}`);
const truncatedContent = reportTrunc(renderedContent);
const touchedEntities = [];

View File

@@ -0,0 +1,329 @@
import Action, {ActionJson, ActionOptions} from "./index";
import {Comment, SubmitLinkOptions, SubmitSelfPostOptions, VoteableContent} from "snoowrap";
import Submission from "snoowrap/dist/objects/Submission";
import {renderContent} from "../Utils/SnoowrapUtils";
import {ActionProcessResult, Footer, RequiredRichContent, RichContent, RuleResult} from "../Common/interfaces";
import {asComment, asSubmission, parseRedditEntity, parseRedditThingsFromLink, sleep, truncateStringToLength} from "../util";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTarget, ActionTypes, ArbitraryActionTarget} from "../Common/Infrastructure/Atomic";
import {CMError} from "../Utils/Errors";
import {SnoowrapActivity} from "../Common/Infrastructure/Reddit";
import Subreddit from "snoowrap/dist/objects/Subreddit";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class SubmissionAction extends Action {
content?: string;
lock: boolean = false;
sticky: boolean = false;
distinguish: boolean = false;
spoiler: boolean = false;
nsfw: boolean = false;
flairId?: string
flairText?: string
url?: string
title: string
footer?: false | string;
targets: ('self' | string)[]
constructor(options: SubmissionActionOptions) {
super(options);
const {
content,
lock = false,
sticky = false,
spoiler = false,
distinguish = false,
nsfw = false,
flairText,
flairId,
footer,
url,
title,
targets = ['self']
} = options;
this.footer = footer;
this.content = content;
this.lock = lock;
this.sticky = sticky;
if(this.sticky) {
this.distinguish = sticky;
} else {
this.distinguish = distinguish;
}
this.spoiler = spoiler;
this.nsfw = nsfw;
this.flairText = flairText;
this.flairId = flairId;
this.url = url;
this.title = title;
if (!Array.isArray(targets)) {
this.targets = [targets];
} else {
this.targets = targets;
}
}
getKind(): ActionTypes {
return 'submission';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const title = await this.renderContent(this.title, item, ruleResults, actionResults) as string;
this.logger.verbose(`Title: ${title}`);
const url = await this.renderContent(this.url, item, ruleResults, actionResults);
this.logger.verbose(`URL: ${url !== undefined ? url : '[No URL]'}`);
const body = await this.renderContent(this.content, item, ruleResults, actionResults);
let renderedContent: string | undefined = undefined;
if(body !== undefined) {
const footer = await this.resources.renderFooter(item, this.footer);
renderedContent = `${body}${footer}`;
this.logger.verbose(`Contents:\r\n${renderedContent.length > 100 ? `\r\n${renderedContent}` : renderedContent}`);
} else {
this.logger.verbose(`Contents: [No Body]`);
}
let allErrors = true;
const targetResults: string[] = [];
const touchedEntities = [];
let submittedOnce = false;
for (const targetVal of this.targets) {
//
if(submittedOnce) {
// delay submissions by 3 seconds (on previous successful call)
// to try to spread out load
await sleep(3000);
}
let target: Subreddit = item.subreddit;
let targetIdentifier = targetVal;
if (targetVal !== 'self') {
const subredditVal = parseRedditEntity(targetVal);
try {
target = await this.resources.getSubreddit(subredditVal.name);
targetIdentifier = `[Subreddit ${target.display_name}]`;
} catch (err: any) {
targetResults.push(`[${targetIdentifier}] error occurred while fetching subreddit: ${err.message}`);
if(!err.logged) {
this.logger.warn(new CMError(`[${targetIdentifier}] error occurred while fetching subreddit`, {cause: err}));
}
continue;
}
}
// TODO check if we can post in subreddit
let modifiers = [];
let post: Submission | undefined;
if (!dryRun) {
let opts: SubmitLinkOptions | SubmitSelfPostOptions;
let type: 'self' | 'link';
const genericOpts = {
title,
subredditName: target.display_name,
nsfw: this.nsfw,
spoiler: this.spoiler,
flairId: this.flairId,
flairText: this.flairText,
};
if(url !== undefined) {
type = 'link';
opts = {
...genericOpts,
url,
};
if(renderedContent !== undefined) {
// @ts-ignore
linkOpts.text = renderedContent;
}
} else {
type = 'self';
opts = {
...genericOpts,
text: renderedContent,
}
}
// @ts-ignore
post = await this.tryPost(type, target, opts);
await this.resources.setRecentSelf(post as Submission);
if(post !== undefined) {
touchedEntities.push(post);
}
}
if (this.lock) {
if (post !== undefined && !post.can_mod_post) {
this.logger.warn(`[${targetIdentifier}] Cannot lock because bot is not a moderator`);
} else {
modifiers.push('Locked');
if (!dryRun && post !== undefined) {
// snoopwrap typing issue, thinks comments can't be locked
// @ts-ignore
await post.lock();
}
}
}
if (this.distinguish) {
if (post !== undefined && !post.can_mod_post) {
this.logger.warn(`[${targetIdentifier}] Cannot Distinguish/Sticky because bot is not a moderator`);
} else {
modifiers.push('Distinguished');
if (this.sticky) {
modifiers.push('Stickied');
}
if (!dryRun && post !== undefined) {
// @ts-ignore
await post.distinguish({sticky: this.sticky});
}
}
}
const modifierStr = modifiers.length === 0 ? '' : ` == ${modifiers.join(' | ')} == =>`;
const targetSummary = `${targetIdentifier} ${modifierStr} created Submission ${dryRun ? 'DRYRUN' : (post as SnoowrapActivity).name}`;
// @ts-ignore
targetResults.push(targetSummary)
this.logger.verbose(targetSummary);
allErrors = false;
}
return {
dryRun,
success: !allErrors,
result: `${targetResults.join('\n')}${this.url !== undefined ? `\nURL: ${this.url}` : ''}${body !== undefined ? truncateStringToLength(100)(body) : ''}`,
touchedEntities,
data: {
body,
bodyShort: body !== undefined ? truncateStringToLength(100)(body) : '',
submissions: targetResults.map(x => `* ${x}`).join('\n')
}
};
}
// @ts-ignore
protected async tryPost(type: 'self' | 'link', target: Subreddit, data: SubmitLinkOptions | SubmitSelfPostOptions, maxAttempts = 2): Promise<Submission> {
let post: Submission | undefined;
let error: any;
for (let i = 0; i <= maxAttempts; i++) {
try {
if (type === 'self') {
// @ts-ignore
post = await target.submitSelfpost(data as SubmitSelfPostOptions);
} else {
// @ts-ignore
post = await target.submitLink(data as SubmitLinkOptions);
}
break;
} catch (e: any) {
if (e.message.includes('RATELIMIT')) {
// Looks like you've been doing that a lot. Take a break for 5 seconds before trying again
await sleep(5000);
error = e;
} else {
throw e;
}
}
}
if (error !== undefined) {
throw error;
}
// @ts-ignore
return post;
}
protected getSpecificPremise(): object {
return {
content: this.content,
lock: this.lock,
sticky: this.sticky,
spoiler: this.spoiler,
distinguish: this.distinguish,
nsfw: this.nsfw,
flairId: this.flairId,
flairText: this.flairText,
url: this.url,
text: this.content !== undefined ? truncateStringToLength(50)(this.content) : undefined,
footer: this.footer,
targets: this.targets,
}
}
}
export interface SubmissionActionConfig extends RichContent, Footer {
/**
* Lock the Submission after creation?
* */
lock?: boolean,
/**
* Sticky the Submission after creation?
* */
sticky?: boolean,
nsfw?: boolean
spoiler?: boolean
/**
* The title of this Submission.
*
* Templated the same as **content**
* */
title: string
/**
* If Submission should be a Link, the URL to use
*
* Templated the same as **content**
*
* PROTIP: To make a Link Submission pointing to the Activity being processed use `{{item.permalink}}` as the URL value
* */
url?: string
/**
* Flair template to apply to this Submission
* */
flairId?: string
/**
* Flair text to apply to this Submission
* */
flairText?: string
/**
* Distinguish as Mod after creation?
* */
distinguish?: boolean
/**
* Specify where this Submission should be made
*
* Valid values: 'self' | [subreddit]
*
* * 'self' -- DEFAULT. Post Submission to same subreddit of Activity being processed
* * [subreddit] -- The name of a subreddit to post Submission to. EX mealtimevideos
* */
targets?: ('self' | string) | ('self' | string)[]
}
export interface SubmissionActionOptions extends SubmissionActionConfig, ActionOptions {
}
/**
* Reply to the Activity. For a submission the reply will be a top-level comment.
* */
export interface SubmissionActionJson extends SubmissionActionConfig, ActionJson {
kind: 'submission'
}

View File

@@ -6,6 +6,7 @@ import Comment from 'snoowrap/dist/objects/Comment';
import {RuleResultEntity} from "../../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../../Subreddit/Manager";
import {ActionTypes} from "../../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../../Common/Entities/ActionResultEntity";
export class FlairAction extends Action {
text: string;
@@ -26,7 +27,7 @@ export class FlairAction extends Action {
return 'flair';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
let flairParts = [];
if(this.text !== '') {

View File

@@ -4,6 +4,7 @@ import {ActionProcessResult, RuleResult} from '../Common/interfaces';
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class UserFlairAction extends Action {
text?: string;
@@ -22,7 +23,7 @@ export class UserFlairAction extends Action {
return 'userflair';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
let flairParts = [];

View File

@@ -8,6 +8,7 @@ import {ActionProcessResult, RuleResult} from "../Common/interfaces";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {runCheckOptions} from "../Subreddit/Manager";
import {ActionTypes, UserNoteType} from "../Common/Infrastructure/Atomic";
import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
export class UserNoteAction extends Action {
@@ -27,10 +28,9 @@ export class UserNoteAction extends Action {
return 'usernote';
}
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
async process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult> {
const dryRun = this.getRuntimeAwareDryrun(options);
const content = await this.resources.getContent(this.content, item.subreddit);
const renderedContent = await renderContent(content, item, ruleResults, this.resources.userNotes);
const renderedContent = (await this.renderContent(this.content, item, ruleResults, actionResults) as string);
this.logger.verbose(`Note:\r\n(${this.type}) ${renderedContent}`);
if (!this.allowDuplicate) {

View File

@@ -19,6 +19,8 @@ import {ActionResultEntity} from "../Common/Entities/ActionResultEntity";
import {FindOptionsWhere} from "typeorm/find-options/FindOptionsWhere";
import {ActionTypes} from "../Common/Infrastructure/Atomic";
import {RunnableBaseJson, RunnableBaseOptions, StructuredRunnableBase} from "../Common/Infrastructure/Runnable";
import { SubredditResources } from "../Subreddit/SubredditResources";
import {SnoowrapActivity} from "../Common/Infrastructure/Reddit";
export abstract class Action extends RunnableBase {
name?: string;
@@ -29,6 +31,8 @@ export abstract class Action extends RunnableBase {
managerEmitter: EventEmitter;
// actionEntity: ActionEntity | null = null;
actionPremiseEntity: ActionPremise | null = null;
checkName: string;
subredditName: string;
constructor(options: ActionOptions) {
super(options);
@@ -40,6 +44,7 @@ export abstract class Action extends RunnableBase {
subredditName,
dryRun = false,
emitter,
checkName,
} = options;
this.name = name;
@@ -48,6 +53,8 @@ export abstract class Action extends RunnableBase {
this.client = client;
this.logger = logger.child({labels: [`Action ${this.getActionUniqueName()}`]}, mergeArr);
this.managerEmitter = emitter;
this.checkName = checkName;
this.subredditName = subredditName;
}
abstract getKind(): ActionTypes;
@@ -112,7 +119,7 @@ export abstract class Action extends RunnableBase {
}
}
async handle(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionResultEntity> {
async handle(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionResultEntity> {
const {dryRun: runtimeDryrun} = options;
const dryRun = runtimeDryrun || this.dryRun;
@@ -148,10 +155,11 @@ export abstract class Action extends RunnableBase {
actRes.runReason = runReason;
return actRes;
}
const results = await this.process(item, ruleResults, options);
const results = await this.process(item, ruleResults, actionResults, options);
actRes.success = results.success;
actRes.dryRun = results.dryRun;
actRes.result = results.result;
actRes.data = results.data;
actRes.touchedEntities = results.touchedEntities ?? [];
return actRes;
@@ -166,20 +174,31 @@ export abstract class Action extends RunnableBase {
}
}
abstract process(item: Comment | Submission, ruleResults: RuleResultEntity[], options: runCheckOptions): Promise<ActionProcessResult>;
abstract process(item: Comment | Submission, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[], options: runCheckOptions): Promise<ActionProcessResult>;
getRuntimeAwareDryrun(options: runCheckOptions): boolean {
const {dryRun: runtimeDryrun} = options;
return runtimeDryrun || this.dryRun;
}
async renderContent(template: string | undefined, item: SnoowrapActivity, ruleResults: RuleResultEntity[], actionResults: ActionResultEntity[]): Promise<string | undefined> {
if(template === undefined) {
return undefined;
}
return await this.resources.renderContent(template, item, ruleResults, actionResults, {manager: this.subredditName, check: this.checkName});
}
}
export interface ActionOptions extends Omit<ActionConfig, 'authorIs' | 'itemIs'>, RunnableBaseOptions {
//logger: Logger;
subredditName: string;
//resources: SubredditResources;
export interface ActionRuntimeOptions {
checkName: string
subredditName: string
client: ExtendedSnoowrap;
emitter: EventEmitter
emitter: EventEmitter;
resources: SubredditResources;
logger: Logger;
}
export interface ActionOptions extends Omit<ActionConfig, 'authorIs' | 'itemIs'>, RunnableBaseOptions, ActionRuntimeOptions {
}
export interface ActionConfig extends RunnableBaseJson {

View File

@@ -4,24 +4,27 @@ import {getLogger} from "./Utils/loggerFactory";
import {DatabaseMigrationOptions, OperatorConfig, OperatorConfigWithFileContext, OperatorFileConfig} from "./Common/interfaces";
import Bot from "./Bot";
import LoggedError from "./Utils/LoggedError";
import {mergeArr, sleep} from "./util";
import {copyFile} from "fs/promises";
import {generateRandomName, mergeArr, sleep} from "./util";
import {copyFile, open} from "fs/promises";
import {constants} from "fs";
import {Connection} from "typeorm";
import {Connection, DataSource, Repository} from "typeorm";
import {ErrorWithCause} from "pony-cause";
import {MigrationService} from "./Common/MigrationService";
import {Invokee} from "./Common/Infrastructure/Atomic";
import {DatabaseConfig} from "./Common/Infrastructure/Database";
import {InviteData} from "./Web/Common/interfaces";
import {BotInvite} from "./Common/Entities/BotInvite";
export class App {
bots: Bot[] = [];
logger: Logger;
dbLogger: Logger;
database: Connection
database: DataSource
startedAt: Dayjs = dayjs();
ranMigrations: boolean = false;
migrationBlocker?: string;
friendly?: string;
config: OperatorConfig;
@@ -30,6 +33,7 @@ export class App {
fileConfig: OperatorFileConfig;
migrationService: MigrationService;
inviteRepo: Repository<BotInvite>;
constructor(config: OperatorConfigWithFileContext) {
const {
@@ -49,6 +53,8 @@ export class App {
this.logger = getLogger(config.logging);
this.dbLogger = this.logger.child({labels: ['Database']}, mergeArr);
this.database = database;
this.inviteRepo = this.database.getRepository(BotInvite);
this.friendly = this.config.api.friendly;
this.logger.info(`Operators: ${name.length === 0 ? 'None Specified' : name.join(', ')}`)
@@ -114,6 +120,8 @@ export class App {
return;
}
await this.checkFriendlyName();
if(this.bots.length > 0) {
this.logger.info('Bots already exist, will stop and destroy these before building new ones.');
await this.destroy(causedBy);
@@ -161,4 +169,54 @@ export class App {
await b.destroy(causedBy);
}
}
async checkFriendlyName() {
if(this.friendly === undefined) {
let randFriendly: string = generateRandomName();
this.logger.verbose(`No friendly name set for Server. Generated: ${randFriendly}`);
const exists = async (name: string) => {
const existing = await this.inviteRepo.findBy({instance: name});
return existing.length > 0;
}
while (await exists(randFriendly)) {
let oldFriendly = randFriendly;
randFriendly = generateRandomName();
this.logger.verbose(`${oldFriendly} already exists! Generated: ${randFriendly}`);
}
this.friendly = randFriendly;
this.fileConfig.document.setFriendlyName(this.friendly);
const handle = await open(this.fileConfig.document.location as string, 'w');
await handle.writeFile(this.fileConfig.document.toString());
await handle.close();
this.logger.verbose(`Wrote ${randFriendly} as friendly server name to config.`);
}
}
async getInviteById(id: string): Promise<BotInvite | undefined> {
const invite = await this.inviteRepo.findOne({where: {id, instance: this.friendly}});
if(invite === null) {
return undefined;
}
return invite;
}
async getInviteIds(): Promise<string[]> {
if(!this.ranMigrations) {
// not ready!
return [];
}
const invites = await this.inviteRepo.findBy({instance: this.friendly});
return invites.map(x => x.id);
}
async addInvite(data: InviteData): Promise<InviteData> {
return await this.inviteRepo.save(new BotInvite(data));
}
async deleteInvite(id: string): Promise<void> {
await this.inviteRepo.delete({ id });
}
}

View File

@@ -1,4 +1,5 @@
import Snoowrap, {Comment, ConfigOptions, RedditUser, Submission, Subreddit} from "snoowrap";
import Snoowrap, {Comment, ConfigOptions, RedditUser, Submission} from "snoowrap";
import {Subreddit} from "snoowrap/dist/objects"
import {Logger} from "winston";
import dayjs, {Dayjs} from "dayjs";
import {Duration} from "dayjs/plugin/duration";
@@ -19,7 +20,7 @@ import {
parseBool,
parseDuration, parseMatchMessage, parseRedditEntity,
parseSubredditName, partition, RetryOptions,
sleep
sleep, intersect
} from "../util";
import {Manager} from "../Subreddit/Manager";
import {ExtendedSnoowrap, ProxiedSnoowrap} from "../Utils/SnoowrapClients";
@@ -27,7 +28,15 @@ 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} from "../Utils/Errors";
import {
SimpleError,
isRateLimitError,
isRequestError,
isScopeError,
isStatusError,
CMError,
ISeriousError, definesSeriousError
} from "../Utils/Errors";
import {ErrorWithCause} from "pony-cause";
import {DataSource, Repository} from "typeorm";
import {Bot as BotEntity} from '../Common/Entities/Bot';
@@ -43,8 +52,19 @@ 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 {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 {
class Bot implements BotInstanceFunctions {
client!: ExtendedSnoowrap;
logger!: Logger;
@@ -57,6 +77,7 @@ class Bot {
excludeSubreddits: string[];
filterCriteriaDefaults?: FilterCriteriaDefaults
subManagers: Manager[] = [];
moderatedSubreddits: Subreddit[] = []
heartbeatInterval: number;
nextHeartbeat: Dayjs = dayjs();
heartBeating: boolean = false;
@@ -99,6 +120,10 @@ class Bot {
database: DataSource
invokeeRepo: Repository<InvokeeType>;
runTypeRepo: Repository<RunStateType>;
managerRepo: Repository<ManagerEntity>;
authorRepo: Repository<AuthorEntity>;
subredditInviteRepo: Repository<SubredditInvite>
botRepo: Repository<BotEntity>
botEntity!: BotEntity
getBotName = () => {
@@ -160,6 +185,10 @@ class Bot {
this.database = database;
this.invokeeRepo = this.database.getRepository(InvokeeType);
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;
@@ -378,7 +407,7 @@ class Bot {
async testClient(initial = true) {
try {
// @ts-ignore
const user = this.client.getMe().fetch();
const user = await this.client.getMe().fetch();
this.logger.info('Test API call successful');
return user;
} catch (err: any) {
@@ -398,18 +427,27 @@ class Bot {
}
}
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...');
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}`);
const availSubs = await this.getModeratedSubreddits(true);
this.logger.verbose(`${this.botAccount} is a moderator of these subreddits: ${availSubs.map(x => x.display_name_prefixed).join(', ')}`);
@@ -491,7 +529,7 @@ class Bot {
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 existing managers. Creating now...`);
this.logger.info(`Manager for ${sub.display_name_prefixed} not found in loaded managers. Loading now...`);
subsToInit.push(sub.display_name);
try {
this.subManagers.push(await this.createManager(sub));
@@ -627,7 +665,7 @@ class Bot {
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 because config was not valid`, {cause: err});
const normalizedError = new ErrorWithCause(`Bot could not initialize manager`, {cause: err});
// @ts-ignore
this.logger.error(normalizedError, {subreddit: manager.subreddit.display_name_prefixed});
} else {
@@ -672,15 +710,15 @@ class Bot {
databaseConfig: {
retention = undefined
} = {},
wikiConfig = this.wikiLocation,
} = override || {};
const managerRepo = this.database.getRepository(ManagerEntity);
const subRepo = this.database.getRepository(SubredditEntity)
let subreddit = await subRepo.findOne({where: {id: sub.name}});
if(subreddit === null) {
subreddit = await subRepo.save(new SubredditEntity({id: sub.name, name: sub.display_name}))
}
let managerEntity = await managerRepo.findOne({
let managerEntity = await this.managerRepo.findOne({
where: {
bot: {
id: this.botEntity.id
@@ -689,12 +727,15 @@ class Bot {
id: subreddit.id
}
},
relations: {
guests: true
}
});
if(managerEntity === undefined || managerEntity === null) {
const invokee = await this.invokeeRepo.findOneBy({name: SYSTEM}) as InvokeeType;
const runType = await this.runTypeRepo.findOneBy({name: STOPPED}) as RunStateType;
managerEntity = await managerRepo.save(new ManagerEntity({
managerEntity = await this.managerRepo.save(new ManagerEntity({
name: sub.display_name,
bot: this.botEntity,
subreddit: subreddit as SubredditEntity,
@@ -702,12 +743,15 @@ class Bot {
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, {
dryRun: this.dryRun,
sharedStreams: this.sharedStreams,
wikiLocation: this.wikiLocation,
wikiLocation: wikiConfig,
botName: this.botName as string,
maxWorkers: this.maxWorkers,
filterCriteriaDefaults: this.filterCriteriaDefaults,
@@ -749,21 +793,50 @@ class Bot {
}
async checkModInvites() {
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 {
this.logger.error(`Error occurred while checking r/${name} for a pending moderation invite. Error: ${err.message}`);
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.`;
} else {
msg = `${msg} If this subreddit is private it is likely no moderation invite exists.`;
}
throw new CMError(msg, {cause: err})
} else {
throw new CMError(`Error occurred while checking r/${name} for a pending moderation invite.`, {cause: err});
}
}
}
@@ -816,6 +889,7 @@ class Bot {
await sleep(5000);
const time = dayjs().valueOf()
await this.apiHealthCheck(time);
await this.guestModCleanup();
if (!this.running) {
break;
}
@@ -910,6 +984,19 @@ class Bot {
}
async guestModCleanup() {
const now = dayjs();
for(const m of this.subManagers) {
const expiredGuests = m.managerEntity.getGuests().filter(x => x.expiresAt.isBefore(now));
if(expiredGuests.length > 0) {
m.managerEntity.removeGuestById(expiredGuests.map(x => x.id));
m.logger.info(`Removed expired Guest Mods: ${expiredGuests.map(x => x.author.name).join(', ')}`);
await this.managerRepo.save(m.managerEntity);
}
}
}
async retentionCleanup() {
const now = dayjs();
if(now.isSameOrAfter(this.nextRetentionCheck)) {
@@ -1100,6 +1187,251 @@ class Bot {
throw err;
}
}
getManagerNames(): string[] {
return this.subManagers.map(x => x.displayLabel);
}
getSubreddits(normalized = true): string[] {
return normalized ? this.subManagers.map(x => parseRedditEntity(x.subreddit.display_name).name) : this.subManagers.map(x => x.subreddit.display_name);
}
getGuestManagers(user: string): NormalizedManagerResponse[] {
return this.subManagers.filter(x => x.managerEntity.getGuests().map(y => y.author.name).includes(user)).map(x => x.toNormalizedManager());
}
getGuestSubreddits(user: string): string[] {
return this.getGuestManagers(user).map(x => x.subredditNormal);
}
getAccessibleSubreddits(user: string, subreddits: string[] = []): string[] {
const normalSubs = subreddits.map(x => parseRedditEntity(x).name);
const moderatedSubs = intersect(normalSubs, this.getSubreddits());
const guestSubs = this.getGuestSubreddits(user);
return Array.from(new Set([...guestSubs, ...moderatedSubs]));
}
canUserAccessBot(user: string, subreddits: string[] = []) {
return this.getAccessibleSubreddits(user, subreddits).length > 0;
}
canUserAccessSubreddit(subreddit: string, user: string, subreddits: string[] = []): boolean {
return this.getAccessibleSubreddits(user, subreddits).includes(parseRedditEntity(subreddit).name);
}
async addGuest(userVal: string | string[], expiresAt: Dayjs, managerVal?: string | string[]) {
let managerNames: string[];
if(typeof managerVal === 'string') {
managerNames = [managerVal];
} else if(Array.isArray(managerVal)) {
managerNames = managerVal;
} else {
managerNames = this.subManagers.map(x => x.subreddit.display_name);
}
const cleanSubredditNames = managerNames.map(x => parseRedditEntity(x).name);
const userNames = typeof userVal === 'string' ? [userVal] : userVal;
const cleanUsers = userNames.map(x => parseRedditEntity(x.trim(), 'user').name);
const users: AuthorEntity[] = [];
for(const uName of cleanUsers) {
let user = await this.authorRepo.findOne({
where: {
name: uName,
}
});
if(user === null) {
users.push(await this.authorRepo.save(new AuthorEntity({name: uName})));
} else {
users.push(user);
}
}
const newGuestData = users.map(x => ({author: x, expiresAt})) as GuestEntityData[];
let newGuests = new Map<string, Guest[]>();
const updatedManagerEntities: ManagerEntity[] = [];
for(const m of this.subManagers) {
if(!cleanSubredditNames.includes(m.subreddit.display_name)) {
continue;
}
const filteredGuests = m.managerEntity.addGuest(newGuestData);
updatedManagerEntities.push(m.managerEntity);
newGuests.set(m.displayLabel, filteredGuests.map(x => guestEntityToApiGuest(x)));
m.logger.info(`Added ${cleanUsers.join(', ')} as Guest`);
}
await this.managerRepo.save(updatedManagerEntities);
return newGuests;
}
async removeGuest(userVal: string | string[], managerVal?: string | string[]) {
let managerNames: string[];
if(typeof managerVal === 'string') {
managerNames = [managerVal];
} else if(Array.isArray(managerVal)) {
managerNames = managerVal;
} else {
managerNames = this.subManagers.map(x => x.subreddit.display_name);
}
const cleanSubredditNames = managerNames.map(x => parseRedditEntity(x).name);
const userNames = typeof userVal === 'string' ? [userVal] : userVal;
const cleanUsers = userNames.map(x => parseRedditEntity(x.trim(), 'user').name);
let newGuests = new Map<string, Guest[]>();
const updatedManagerEntities: ManagerEntity[] = [];
for(const m of this.subManagers) {
if(!cleanSubredditNames.includes(m.subreddit.display_name)) {
continue;
}
const filteredGuests = m.managerEntity.removeGuestByUser(cleanUsers);
updatedManagerEntities.push(m.managerEntity);
newGuests.set(m.displayLabel, filteredGuests.map(x => guestEntityToApiGuest(x)));
m.logger.info(`Removed ${cleanUsers.join(', ')} from Guests`);
}
await this.managerRepo.save(updatedManagerEntities);
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;

View File

@@ -222,7 +222,14 @@ export abstract class Check extends RunnableBase implements Omit<ICheck, 'postTr
this.actions.push(actionFactory({
...aj,
dryRun: this.dryRun || aj.dryRun
}, this.logger, subredditName, this.resources, this.client, this.emitter));
}, {
logger: this.logger,
subredditName,
resources: this.resources,
client: this.client,
emitter: this.emitter,
checkName: this.name
}));
// @ts-ignore
a.logger = this.logger;
} else {
@@ -564,7 +571,7 @@ export abstract class Check extends RunnableBase implements Omit<ICheck, 'postTr
const dr = dryRun || this.dryRun;
this.logger.debug(`${dr ? 'DRYRUN - ' : ''}Running Actions`);
for (const a of this.actions) {
const res = await a.handle(item, ruleResults, options);
const res = await a.handle(item, ruleResults, runActions, options);
runActions.push(res);
}
this.logger.info(`${dr ? 'DRYRUN - ' : ''}Ran Actions: ${runActions.map(x => x.premise.getFriendlyIdentifier()).join(' | ')}`);

View File

@@ -0,0 +1,34 @@
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();
}
}

47
src/Common/Cache/index.ts Normal file
View File

@@ -0,0 +1,47 @@
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});
}
}

View File

@@ -1,11 +1,14 @@
import YamlConfigDocument from "../YamlConfigDocument";
import JsonConfigDocument from "../JsonConfigDocument";
import {YAMLMap, YAMLSeq, Pair, Scalar} from "yaml";
import {BotInstanceJsonConfig, OperatorJsonConfig} from "../../interfaces";
import {BotInstanceJsonConfig, OperatorJsonConfig, WebCredentials} from "../../interfaces";
import {assign} from 'comment-json';
export interface OperatorConfigDocumentInterface {
addBot(botData: BotInstanceJsonConfig): void;
setFriendlyName(name: string): void;
setWebCredentials(data: Required<WebCredentials>): void;
setOperator(name: string): void;
toJS(): OperatorJsonConfig;
}
@@ -29,6 +32,18 @@ export class YamlOperatorConfigDocument extends YamlConfigDocument implements Op
}
}
setFriendlyName(name: string) {
this.parsed.addIn(['api', 'friendly'], name);
}
setWebCredentials(data: Required<WebCredentials>) {
this.parsed.addIn(['web', 'credentials'], data);
}
setOperator(name: string) {
this.parsed.addIn(['operator', 'name'], name);
}
toJS(): OperatorJsonConfig {
return super.toJS();
}
@@ -68,6 +83,23 @@ export class JsonOperatorConfigDocument extends JsonConfigDocument implements Op
}
}
setFriendlyName(name: string) {
const api = this.parsed.api || {};
this.parsed.api = {...api, friendly: name};
}
setWebCredentials(data: Required<WebCredentials>) {
const {
web = {},
} = this.parsed;
this.parsed.web = {...web, credentials: data};
}
setOperator(name: string) {
this.parsed.operator = { name };
}
toJS(): OperatorJsonConfig {
return super.toJS();
}

View File

@@ -56,6 +56,11 @@ export class ActionResultEntity extends TimeAwareRandomBaseEntity {
@JoinColumn({name: 'premiseId'})
premise!: ActionPremise;
/**
* Ephemeral -- only added during actual run time and used for action templating. Is not available after loading from DB.
* */
data?: any;
touchedEntities: (Submission | Comment | RedditUser | string)[] = []
set itemIs(data: ActivityStateFilterResult | IFilterResult<TypedActivityState> | undefined) {

View File

@@ -12,4 +12,10 @@ export class AuthorEntity {
@OneToMany(type => Activity, act => act.author)
activities!: Activity[]
constructor(data?: any) {
if(data !== undefined) {
this.name = data.name;
}
}
}

View File

@@ -1,13 +1,90 @@
import {Entity, Column, PrimaryColumn, OneToMany, PrimaryGeneratedColumn} from "typeorm";
import {ManagerEntity} from "./ManagerEntity";
import {RandomIdBaseEntity} from "./Base/RandomIdBaseEntity";
import {BotGuestEntity, ManagerGuestEntity} from "./Guest/GuestEntity";
import {Guest, GuestEntityData, HasGuests} from "./Guest/GuestInterfaces";
import {SubredditInvite} from "./SubredditInvite";
@Entity()
export class Bot extends RandomIdBaseEntity {
export class Bot extends RandomIdBaseEntity implements HasGuests {
@Column("varchar", {length: 200})
name!: string;
@OneToMany(type => ManagerEntity, obj => obj.bot)
managers!: Promise<ManagerEntity[]>
@OneToMany(type => BotGuestEntity, obj => obj.guestOf, {eager: true, cascade: ['insert', 'remove', 'update']})
guests!: BotGuestEntity[]
@OneToMany(type => SubredditInvite, obj => obj.bot, {eager: true, cascade: ['insert', 'remove', 'update']})
subredditInvites!: SubredditInvite[]
getGuests() {
const g = this.guests;
if (g === undefined) {
return [];
}
//return g.map(x => ({id: x.id, name: x.author.name, expiresAt: x.expiresAt})) as Guest[];
return g;
}
addGuest(val: GuestEntityData | GuestEntityData[]) {
const reqGuests = Array.isArray(val) ? val : [val];
const guests = this.guests;
for (const g of reqGuests) {
const existing = guests.find(x => x.author.name.toLowerCase() === g.author.name.toLowerCase());
if (existing !== undefined) {
// update existing guest expiresAt
existing.expiresAt = g.expiresAt;
} else {
guests.push(new BotGuestEntity({...g, guestOf: this}));
}
}
this.guests = guests
return guests;
}
removeGuestById(val: string | string[]) {
const reqGuests = Array.isArray(val) ? val : [val];
const guests = this.guests;
const filteredGuests = guests.filter(x => reqGuests.includes(x.id));
this.guests = filteredGuests;
return filteredGuests;
}
removeGuestByUser(val: string | string[]) {
const reqGuests = (Array.isArray(val) ? val : [val]).map(x => x.trim().toLowerCase());
const guests = this.guests;
const filteredGuests = guests.filter(x => reqGuests.includes(x.author.name.toLowerCase()));
this.guests =filteredGuests;
return filteredGuests;
}
removeGuests() {
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);
}
}

View File

@@ -1,13 +1,12 @@
import {Column, Entity, PrimaryColumn} from "typeorm";
import {TimeAwareBaseEntity} from "../Entities/Base/TimeAwareBaseEntity";
import {TimeAwareBaseEntity} from "./Base/TimeAwareBaseEntity";
import {InviteData} from "../../Web/Common/interfaces";
import dayjs, {Dayjs} from "dayjs";
import {TimeAwareRandomBaseEntity} from "./Base/TimeAwareRandomBaseEntity";
import {parseRedditEntity} from "../../util";
@Entity()
export class Invite extends TimeAwareBaseEntity implements InviteData {
@PrimaryColumn('varchar', {length: 255})
id!: string
@Entity({name: 'BotInvite'})
export class BotInvite extends TimeAwareRandomBaseEntity implements InviteData {
@Column("varchar", {length: 50})
clientId!: string;
@@ -30,6 +29,12 @@ export class Invite extends TimeAwareBaseEntity implements InviteData {
@Column()
overwrite?: boolean;
@Column("simple-json")
guests?: string[]
@Column("text")
initialConfig?: string
@Column("simple-json", {nullable: true})
subreddits?: string[];
@@ -51,10 +56,9 @@ export class Invite extends TimeAwareBaseEntity implements InviteData {
}
}
constructor(data?: InviteData & { id: string, expiresIn?: number }) {
constructor(data?: InviteData) {
super();
if (data !== undefined) {
this.id = data.id;
this.permissions = data.permissions;
this.subreddits = data.subreddits;
this.instance = data.instance;
@@ -63,9 +67,16 @@ export class Invite extends TimeAwareBaseEntity implements InviteData {
this.redirectUri = data.redirectUri;
this.creator = data.creator;
this.overwrite = data.overwrite;
this.initialConfig = data.initialConfig;
if(data.guests !== undefined && data.guests !== null && data.guests.length > 0) {
const cleanGuests = data.guests.filter(x => x !== '').map(x => parseRedditEntity(x, 'user').name);
if(cleanGuests.length > 0) {
this.guests = cleanGuests;
}
}
if (data.expiresIn !== undefined && data.expiresIn !== 0) {
this.expiresAt = dayjs().add(data.expiresIn, 'seconds');
if (data.expiresAt !== undefined && data.expiresAt !== 0) {
this.expiresAt = dayjs(data.expiresAt);
}
}
}

View File

@@ -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, NonDispatchActivitySource, onExistingFoundBehavior} from "../Infrastructure/Atomic";
import {ActivitySourceTypes, DurationVal, NonDispatchActivitySourceValue, 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 | NonDispatchActivitySource | NonDispatchActivitySource[]
cancelIfQueued?: boolean | NonDispatchActivitySourceValue | NonDispatchActivitySourceValue[]
@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 NonDispatchActivitySource[];
this.cancelIfQueued = JSON.parse(cVal) as NonDispatchActivitySourceValue[];
}
}
if(this.goto === null) {

View File

@@ -0,0 +1,119 @@
import {ChildEntity, Column, Entity, JoinColumn, ManyToOne, TableInheritance} from "typeorm";
import {AuthorEntity} from "../AuthorEntity";
import { ManagerEntity } from "../ManagerEntity";
import { Bot } from "../Bot";
import {TimeAwareRandomBaseEntity} from "../Base/TimeAwareRandomBaseEntity";
import dayjs, {Dayjs} from "dayjs";
import {Guest, GuestAll, GuestEntityData} from "./GuestInterfaces";
export interface GuestOptions<T extends ManagerEntity | Bot> extends GuestEntityData {
guestOf: T
}
@Entity({name: 'Guests'})
@TableInheritance({ column: { type: "varchar", name: "type" } })
export abstract class GuestEntity<T extends ManagerEntity | Bot> extends TimeAwareRandomBaseEntity {
@ManyToOne(type => AuthorEntity, undefined, {cascade: ['insert'], eager: true})
@JoinColumn({name: 'authorName'})
author!: AuthorEntity;
@Column({ name: 'expiresAt', nullable: true })
_expiresAt?: Date = new Date();
public get expiresAt(): Dayjs {
return dayjs(this._expiresAt);
}
public set expiresAt(d: Dayjs | undefined) {
if(d === undefined) {
this._expiresAt = d;
} else {
this._expiresAt = d.utc().toDate();
}
}
expiresAtTimestamp(): number | undefined {
if(this._expiresAt !== undefined) {
return this.expiresAt.valueOf();
}
return undefined;
}
protected constructor(data?: GuestOptions<T>) {
super();
if(data !== undefined) {
this.author = data.author;
this.expiresAt = data.expiresAt;
}
}
}
@ChildEntity('manager')
export class ManagerGuestEntity extends GuestEntity<ManagerEntity> {
type: string = 'manager';
@ManyToOne(type => ManagerEntity, act => act.guests, {nullable: false, orphanedRowAction: 'delete'})
@JoinColumn({name: 'guestOfId', referencedColumnName: 'id'})
guestOf!: ManagerEntity
constructor(data?: GuestOptions<ManagerEntity>) {
super(data);
if(data !== undefined) {
this.guestOf = data.guestOf;
}
}
}
@ChildEntity('bot')
export class BotGuestEntity extends GuestEntity<Bot> {
type: string = 'bot';
@ManyToOne(type => Bot, act => act.guests, {nullable: false, orphanedRowAction: 'delete'})
@JoinColumn({name: 'guestOfId', referencedColumnName: 'id'})
guestOf!: Bot
constructor(data?: GuestOptions<Bot>) {
super(data);
if(data !== undefined) {
this.guestOf = data.guestOf;
this.author = data.author;
}
}
}
export const guestEntityToApiGuest = (val: GuestEntity<any>): Guest => {
return {
id: val.id,
name: val.author.name,
expiresAt: val.expiresAtTimestamp(),
}
}
interface ContextualGuest extends Guest {
subreddit: string
}
export const guestEntitiesToAll = (val: Map<string, Guest[]>): GuestAll[] => {
const contextualGuests: ContextualGuest[] = Array.from(val.entries()).map(([sub, guests]) => guests.map(y => ({...y, subreddit: sub} as ContextualGuest))).flat(3);
const userMap = contextualGuests.reduce((acc, curr) => {
let u: GuestAll | undefined = acc.get(curr.name);
if (u === undefined) {
u = {name: curr.name, expiresAt: curr.expiresAt, subreddits: [curr.subreddit]};
} else {
if (!u.subreddits.includes(curr.subreddit)) {
u.subreddits.push(curr.subreddit);
}
if ((u.expiresAt === undefined && curr.expiresAt !== undefined) || (u.expiresAt !== undefined && curr.expiresAt !== undefined && curr.expiresAt < u.expiresAt)) {
u.expiresAt = curr.expiresAt;
}
}
acc.set(curr.name, u);
return acc;
}, new Map<string, GuestAll>());
return Array.from(userMap.values());
}

View File

@@ -0,0 +1,28 @@
import { Dayjs } from "dayjs"
import {AuthorEntity} from "../AuthorEntity";
export interface Guest {
id: string
name: string
expiresAt?: number
}
export interface GuestAll {
name: string
expiresAt?: number
subreddits: string[]
}
export interface GuestEntityData {
expiresAt?: Dayjs
author: AuthorEntity
}
export interface HasGuests {
getGuests: () => GuestEntityData[]
addGuest: (val: GuestEntityData | GuestEntityData[]) => GuestEntityData[]
removeGuestById: (val: string | string[]) => GuestEntityData[]
removeGuestByUser: (val: string | string[]) => GuestEntityData[]
removeGuests: () => GuestEntityData[]
}

View File

@@ -15,12 +15,14 @@ import {RunEntity} from "./RunEntity";
import {Bot} from "./Bot";
import {RandomIdBaseEntity} from "./Base/RandomIdBaseEntity";
import {ManagerRunState} from "./EntityRunState/ManagerRunState";
import { QueueRunState } from "./EntityRunState/QueueRunState";
import {QueueRunState} from "./EntityRunState/QueueRunState";
import {EventsRunState} from "./EntityRunState/EventsRunState";
import {RulePremise} from "./RulePremise";
import {ActionPremise} from "./ActionPremise";
import { RunningStateTypes } from "../../Subreddit/Manager";
import {RunningStateTypes} from "../../Subreddit/Manager";
import {EntityRunState} from "./EntityRunState/EntityRunState";
import {GuestEntity, ManagerGuestEntity} from "./Guest/GuestEntity";
import {Guest, GuestEntityData, HasGuests} from "./Guest/GuestInterfaces";
export interface ManagerEntityOptions {
name: string
@@ -36,12 +38,12 @@ export type RunningStateEntities = {
};
@Entity({name: 'Manager'})
export class ManagerEntity extends RandomIdBaseEntity implements RunningStateEntities {
export class ManagerEntity extends RandomIdBaseEntity implements RunningStateEntities, HasGuests {
@Column("varchar", {length: 200})
name!: string;
@ManyToOne(type => Bot, sub => sub.managers, {cascade: ['insert'], eager: true})
@ManyToOne(type => Bot, sub => sub.managers, {eager: true})
bot!: Bot;
@ManyToOne(type => Subreddit, sub => sub.activities, {cascade: ['insert'], eager: true})
@@ -56,12 +58,15 @@ export class ManagerEntity extends RandomIdBaseEntity implements RunningStateEnt
@OneToMany(type => ActionPremise, obj => obj.manager)
actions!: Promise<ActionPremise[]>
@OneToMany(type => CheckEntity, obj => obj.manager) // note: we will create author property in the Photo class below
@OneToMany(type => CheckEntity, obj => obj.manager)
checks!: Promise<CheckEntity[]>
@OneToMany(type => RunEntity, obj => obj.manager) // note: we will create author property in the Photo class below
@OneToMany(type => RunEntity, obj => obj.manager)
runs!: Promise<RunEntity[]>
@OneToMany(type => ManagerGuestEntity, obj => obj.guestOf, {eager: true, cascade: ['insert', 'remove', 'update']})
guests!: ManagerGuestEntity[]
@OneToOne(() => EventsRunState, {cascade: ['insert', 'update'], eager: true})
@JoinColumn()
eventsState!: EventsRunState
@@ -85,4 +90,50 @@ export class ManagerEntity extends RandomIdBaseEntity implements RunningStateEnt
this.managerState = data.managerState;
}
}
getGuests(): ManagerGuestEntity[] {
const g = this.guests;
if (g === undefined) {
return [];
}
//return g.map(x => ({id: x.id, name: x.author.name, expiresAt: x.expiresAt})) as Guest[];
return g;
}
addGuest(val: GuestEntityData | GuestEntityData[]) {
const reqGuests = Array.isArray(val) ? val : [val];
const guests = this.getGuests();
for (const g of reqGuests) {
const existing = guests.find(x => x.author.name.toLowerCase() === g.author.name.toLowerCase());
if (existing !== undefined) {
// update existing guest expiresAt
existing.expiresAt = g.expiresAt;
} else {
guests.push(new ManagerGuestEntity({...g, guestOf: this}));
}
}
this.guests = guests;
return guests;
}
removeGuestById(val: string | string[]) {
const reqGuests = Array.isArray(val) ? val : [val];
const guests = this.getGuests();
const filteredGuests = guests.filter(x => !reqGuests.includes(x.id));
this.guests = filteredGuests
return filteredGuests;
}
removeGuestByUser(val: string | string[]) {
const reqGuests = (Array.isArray(val) ? val : [val]).map(x => x.trim().toLowerCase());
const guests = this.getGuests();
const filteredGuests = guests.filter(x => !reqGuests.includes(x.author.name.toLowerCase()));
this.guests = filteredGuests;
return filteredGuests;
}
removeGuests() {
this.guests = [];
return [];
}
}

View File

@@ -0,0 +1,99 @@
import {AfterLoad, Column, Entity, JoinColumn, ManyToOne, PrimaryColumn} from "typeorm";
import {InviteData, SubredditInviteData, SubredditInviteDataPersisted} from "../../Web/Common/interfaces";
import dayjs, {Dayjs} from "dayjs";
import {TimeAwareRandomBaseEntity} from "./Base/TimeAwareRandomBaseEntity";
import {AuthorEntity} from "./AuthorEntity";
import {Bot} from "./Bot";
@Entity()
export class SubredditInvite extends TimeAwareRandomBaseEntity implements SubredditInviteData {
@PrimaryColumn("varchar", {length: 255})
subreddit!: string;
@Column("simple-json", {nullable: true})
guests?: string[]
@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;
@Column({name: 'expiresAt', nullable: true})
_expiresAt?: Date;
public get expiresAt(): Dayjs | undefined {
if (this._expiresAt === undefined) {
return undefined;
}
return dayjs(this._expiresAt);
}
public set expiresAt(d: Dayjs | undefined) {
if (d === undefined) {
this._expiresAt = d;
} else {
this._expiresAt = d.utc().toDate();
}
}
constructor(data?: SubredditInviteData & { expiresIn?: number, bot: Bot }) {
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;
if (data.expiresIn !== undefined && data.expiresIn !== 0) {
this.expiresAt = dayjs().add(data.expiresIn, 'seconds');
}
}
}
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;
}
}
}

View File

@@ -1,15 +1,17 @@
import fetch from "node-fetch";
import {Submission} from "snoowrap/dist/objects";
import {URL} from "url";
import {absPercentDifference, getSharpAsync, isValidImageURL} from "../util";
import {absPercentDifference, getExtension, getSharpAsync, isValidImageURL} from "../util";
import {Sharp} from "sharp";
import {blockhash} from "./blockhash/blockhash";
import {SimpleError} from "../Utils/Errors";
import {blockhashAndFlipped} from "./blockhash/blockhash";
import {CMError, SimpleError} from "../Utils/Errors";
import {FileHandle, open} from "fs/promises";
import {ImageHashCacheData} from "./Infrastructure/Atomic";
export interface ImageDataOptions {
width?: number,
height?: number,
url: string,
path: URL,
variants?: ImageData[]
}
@@ -17,19 +19,20 @@ class ImageData {
width?: number
height?: number
url: URL
path: URL
variants: ImageData[] = []
preferredResolution?: [number, number]
sharpImg!: Sharp
hashResult!: string
hashResult?: string
hashResultFlipped?: string
actualResolution?: [number, number]
constructor(data: ImageDataOptions, aggressive = false) {
this.width = data.width;
this.height = data.height;
this.url = new URL(data.url);
if (!aggressive && !isValidImageURL(`${this.url.origin}${this.url.pathname}`)) {
throw new Error('URL did not end with a valid image extension');
this.path = data.path;
if (!aggressive && !isValidImageURL(`${this.path.origin}${this.path.pathname}`)) {
throw new Error('Path did not end with a valid image extension');
}
this.variants = data.variants || [];
}
@@ -39,55 +42,90 @@ class ImageData {
return await (await this.sharp()).clone().toFormat(format).toBuffer();
}
async hash(bits: number, useVariantIfPossible = true): Promise<string> {
if(this.hashResult === undefined) {
async hash(bits: number = 16, useVariantIfPossible = true): Promise<Required<ImageHashCacheData>> {
if (this.hashResult === undefined || this.hashResultFlipped === undefined) {
let ref: ImageData | undefined;
if(useVariantIfPossible && this.preferredResolution !== undefined) {
if (useVariantIfPossible && this.preferredResolution !== undefined) {
ref = this.getSimilarResolutionVariant(this.preferredResolution[0], this.preferredResolution[1]);
}
if(ref === undefined) {
if (ref === undefined) {
ref = this;
}
this.hashResult = await blockhash((await ref.sharp()).clone(), bits);
const [hash, hashFlipped] = await blockhashAndFlipped((await ref.sharp()).clone(), bits);
this.hashResult = hash;
this.hashResultFlipped = hashFlipped;
}
return this.hashResult;
return {original: this.hashResult, flipped: this.hashResultFlipped};
}
async sharp(): Promise<Sharp> {
if (this.sharpImg === undefined) {
let animated = false;
let getBuffer: () => Promise<Buffer>;
let fileHandle: FileHandle | undefined;
try {
const response = await fetch(this.url.toString())
if (response.ok) {
const ct = response.headers.get('Content-Type');
if (ct !== null && ct.includes('image')) {
const sFunc = await getSharpAsync();
// if image is animated then we want to extract the first frame and convert it to a regular image
// so we can compare two static images later (also because sharp can't use resize() on animated images)
if(['gif','webp'].some(x => ct.includes(x))) {
this.sharpImg = await sFunc(await (await sFunc(await response.buffer(), {pages: 1, animated: false})).png().toBuffer());
} else {
this.sharpImg = await sFunc(await response.buffer());
}
const meta = await this.sharpImg.metadata();
if (this.width === undefined || this.height === undefined) {
this.width = meta.width;
this.height = meta.height;
}
this.actualResolution = [meta.width as number, meta.height as number];
} else {
throw new SimpleError(`Content-Type for fetched URL ${this.url} did not contain "image"`);
if (this.path.protocol === 'file:') {
try {
animated = ['gif', 'webp'].includes(getExtension(this.path.pathname));
fileHandle = await open(this.path, 'r');
getBuffer = async () => await (fileHandle as FileHandle).readFile();
} catch (err: any) {
throw new CMError(`Unable to retrieve local file ${this.path.toString()}`, {cause: err});
}
} else {
throw new SimpleError(`URL response was not OK: (${response.status})${response.statusText}`);
try {
const response = await fetch(this.path.toString())
if (response.ok) {
const ct = response.headers.get('Content-Type');
if (ct !== null && ct.includes('image')) {
animated = ['gif', 'webp'].some(x => ct.includes(x));
getBuffer = async () => await response.buffer();
} else {
throw new SimpleError(`Content-Type for fetched URL ${this.path.toString()} did not contain "image"`);
}
} else {
throw new SimpleError(`Fetching ${this.path.toString()} => URL response was not OK: (${response.status})${response.statusText}`);
}
} catch (err: any) {
if (!(err instanceof SimpleError)) {
throw new CMError(`Error occurred while fetching response from URL ${this.path.toString()}`, {cause: err});
} else {
throw err;
}
}
}
} catch (err: any) {
throw new CMError('Unable to fetch image resource', {cause: err, isSerious: false});
}
try {
const sFunc = await getSharpAsync();
// if image is animated then we want to extract the first frame and convert it to a regular image
// so we can compare two static images later (also because sharp can't use resize() on animated images)
if (animated) {
this.sharpImg = await sFunc(await (await sFunc(await getBuffer(), {
pages: 1,
animated: false
}).trim().greyscale()).png().withMetadata().toBuffer());
} else {
this.sharpImg = await sFunc(await sFunc(await getBuffer()).trim().greyscale().withMetadata().toBuffer());
}
if(fileHandle !== undefined) {
await fileHandle.close();
}
const meta = await this.sharpImg.metadata();
if (this.width === undefined || this.height === undefined) {
this.width = meta.width;
this.height = meta.height;
}
this.actualResolution = [meta.width as number, meta.height as number];
} catch (err: any) {
if(!(err instanceof SimpleError)) {
throw new Error(`Error occurred while fetching response from URL: ${err.message}`);
} else {
throw err;
}
throw new CMError('Error occurred while converting image buffer to Sharp object', {cause: err});
}
}
return this.sharpImg;
@@ -107,8 +145,8 @@ class ImageData {
return this.width !== undefined && this.height !== undefined;
}
get baseUrl() {
return `${this.url.origin}${this.url.pathname}`;
get basePath() {
return `${this.path.origin}${this.path.pathname}`;
}
setPreferredResolutionByWidth(prefWidth: number) {
@@ -225,10 +263,23 @@ class ImageData {
return [refSharp, compareSharp, width, height];
}
toHashCache(): ImageHashCacheData {
return {
original: this.hashResult,
flipped: this.hashResultFlipped
}
}
setFromHashCache(data: ImageHashCacheData) {
const {original, flipped} = data;
this.hashResult = original;
this.hashResultFlipped = flipped;
}
static fromSubmission(sub: Submission, aggressive = false): ImageData {
const url = new URL(sub.url);
const data: any = {
url,
path: url,
};
let variants = [];
if (sub.preview !== undefined && sub.preview.enabled && sub.preview.images.length > 0) {
@@ -237,7 +288,7 @@ class ImageData {
data.width = ref.width;
data.height = ref.height;
variants = firstImg.resolutions.map(x => new ImageData(x));
variants = firstImg.resolutions.map(x => new ImageData({...x, path: new URL(x.url)}));
data.variants = variants;
}
return new ImageData(data, aggressive);

View File

@@ -1,16 +1,40 @@
import {InfluxConfig} from "./interfaces";
import {InfluxDB, Point, WriteApi, setLogger} from "@influxdata/influxdb-client";
import {InfluxDB, Point, WriteApi, setLogger, DEFAULT_WriteOptions, ClientOptions, DEFAULT_RetryDelayStrategyOptions, Logger as InfluxLogger} 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;
@@ -34,13 +58,14 @@ 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(this.logger);
this.client = InfluxClient.createClient(this.config);
setLogger(extendLogger(this.logger, !(rest.debug ?? false)));
}
this.write = this.client.getWriteApi(config.credentials.org, config.credentials.bucket, 'ms');
this.write = this.client.getWriteApi(config.credentials.org, config.credentials.bucket, 'ms', InfluxClient.createWriteOptions(this.config, this.logger));
this.tags = tags;
this.write.useDefaultTags(tags);
this.health = new HealthAPI(this.client);
@@ -96,13 +121,62 @@ export class InfluxClient {
}
static createClient(config: InfluxConfig): InfluxDB {
return new InfluxDB({
url: config.credentials.url,
token: config.credentials.token,
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 {
writeOptions: {
defaultTags: config.defaultTags
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`);
}
});
}
return writeOptions;
}
childClient(logger: Logger, tags: Record<string, string> = {}) {

View File

@@ -1,8 +1,11 @@
import {InfluxDB, WriteApi} from "@influxdata/influxdb-client/dist";
import {InfluxDB, WriteApi, WriteOptions} from "@influxdata/influxdb-client/dist";
export interface InfluxConfig {
credentials: InfluxCredentials
defaultTags?: Record<string, string>
writeOptions?: WriteOptions
useKeepAliveAgent?: boolean
debug?: boolean
}
export interface InfluxCredentials {

View File

@@ -1,3 +1,5 @@
import {ActivityType} from "./Reddit";
/**
* A duration and how to compare it against a value
*
@@ -15,6 +17,22 @@
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
*
@@ -23,7 +41,7 @@ export type DurationComparor = string;
* * EX `> 100` => greater than 100
* * EX `<= 75%` => less than or equal to 75%
*
* @pattern ^\s*(>|>=|<|<=)\s*(\d+)\s*(%?)(.*)$
* @pattern ^\s*(>|>=|<|<=)\s*((?:\d+)(?:(?:(?:.|,)\d+)+)?)\s*(%?)(.*)$
* */
export type CompareValueOrPercent = string;
export type StringOperator = '>' | '>=' | '<' | '<=';
@@ -148,10 +166,18 @@ export type RecordOutputOption = boolean | RecordOutputType | RecordOutputType[]
export type PostBehaviorType = 'next' | 'stop' | 'nextRun' | string;
export type onExistingFoundBehavior = 'replace' | 'skip' | 'ignore';
export type ActionTarget = 'self' | 'parent';
export type ArbitraryActionTarget = ActionTarget | string;
export type InclusiveActionTarget = ActionTarget | 'any';
export type DispatchSource = 'dispatch' | `dispatch:${string}`;
export type NonDispatchActivitySource = 'poll' | `poll:${PollOn}` | 'user' | `user:${string}`;
export type ActivitySourceTypes = 'poll' | 'dispatch' | 'user'; // TODO
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
// https://github.com/YousefED/typescript-json-schema/issues/426
// https://github.com/YousefED/typescript-json-schema/issues/425
// @pattern ^(((poll|dispatch)(:\w+)?)|user)$
@@ -169,11 +195,17 @@ export type ActivitySourceTypes = 'poll' | 'dispatch' | 'user'; // TODO
*
*
* */
export type ActivitySource = NonDispatchActivitySource | DispatchSource;
export type ActivitySourceValue = NonDispatchActivitySourceValue | DispatchSourceValue;
export interface ActivitySourceData {
type: ActivitySourceTypes
identifier?: string
}
export type ConfigFormat = 'json' | 'yaml';
export type ActionTypes =
'comment'
| 'submission'
| 'lock'
| 'remove'
| 'report'
@@ -277,3 +309,89 @@ export interface UrlContext {
value: string
context: WikiContext | ExternalUrlContext
}
export interface ImageHashCacheData {
original?: string
flipped?: string
}
// https://www.reddit.com/message/compose?to=/r/mealtimevideos&message=https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot
export interface BaseTemplateData {
botLink: string
modmailLink?: string
manager?: string
check?: string
//[key: string]: any
}
export interface ActivityTemplateData {
kind: ActivityType
author: string
votes: number
age: string
permalink: string
id: string
subreddit: string
title: string
shortTitle: string
}
export interface ModdedActivityTemplateData {
reports: number
modReports: number
userReports: number
}
export interface SubmissionTemplateData extends ActivityTemplateData, Partial<ModdedActivityTemplateData> {
nsfw: boolean
spoiler: boolean
op: boolean
upvoteRatio: string
url: string
}
export interface CommentTemplateData extends ActivityTemplateData, Partial<ModdedActivityTemplateData> {
op: boolean
}
export interface SubredditTemplateData {
subredditBreakdownFormatted: string
subredditBreakdown?: {
totalFormatted: string
submissionFormatted: string
commentFormatted: string
}
}
export interface RuleResultTemplateData {
kind: string
triggered: boolean
result: string
[key: string]: any
}
export interface ActionResultTemplateData {
kind: string
success: boolean
result: string
[key: string]: any
}
export interface ActionResultsTemplateData {
actionSummary: string
actions: {
[key: string]: ActionResultTemplateData
}
}
export interface RuleResultsTemplateData {
ruleSummary: string
rules: {
[key: string]: RuleResultTemplateData
}
}
export interface GenericContentTemplateData extends BaseTemplateData, Partial<RuleResultsTemplateData>, Partial<ActionResultsTemplateData> {
item?: (SubmissionTemplateData | CommentTemplateData)
}

View File

@@ -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/60dq4';
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 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+)\s*(?<percent>%)?(?<extra>.*)$/
const GENERIC_VALUE_PERCENT_COMPARISON_URL = 'https://regexr.com/60a16';
const GENERIC_VALUE_PERCENT_COMPARISON = /^\s*(?<opStr>>|>=|<|<=)\s*(?<value>(?:\d+)(?:(?:(?:.|,)\d+)+)?)\s*(?<percent>%)?(?<extra>.*)$/
const GENERIC_VALUE_PERCENT_COMPARISON_URL = 'https://regexr.com/6valr';
export const parseGenericValueOrPercentComparison = (val: string, options?: {requireDuration: boolean}): GenericComparison => {
return parseGenericValueComparison(val, {...(options ?? {}), reg: GENERIC_VALUE_PERCENT_COMPARISON});
}

View File

@@ -4,11 +4,12 @@ import {
DurationComparor,
ModeratorNameCriteria,
ModeratorNames, ModActionType,
ModUserNoteLabel
ModUserNoteLabel, RelativeDateTimeMatch
} from "../Atomic";
import {ActivityType} from "../Reddit";
import {ActivityType, MaybeActivityType} 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.
@@ -122,13 +123,14 @@ export interface UserNoteCriteria extends UserSubredditHistoryCriteria {
export interface ModActionCriteria extends UserSubredditHistoryCriteria {
type?: ModActionType | ModActionType[]
activityType?: ActivityType | ActivityType[]
activityType?: MaybeActivityType | MaybeActivityType[]
referencesCurrentActivity?: boolean
}
export interface FullModActionCriteria extends Omit<ModActionCriteria, 'count'> {
type?: ModActionType[]
count?: GenericComparison
activityType?: ActivityType[]
activityType?: MaybeActivityType[]
}
export interface ModNoteCriteria extends ModActionCriteria {
@@ -167,6 +169,7 @@ export const toFullModNoteCriteria = (val: ModNoteCriteria): FullModNoteCriteria
break;
case 'activityType':
case 'noteType':
case 'referencesCurrentActivity':
acc[k] = rawVal;
break;
case 'note':
@@ -219,6 +222,7 @@ export const toFullModLogCriteria = (val: ModLogCriteria): FullModLogCriteria =>
break;
case 'activityType':
case 'type':
case 'referencesCurrentActivity':
acc[k as keyof FullModLogCriteria] = rawVal;
break;
case 'action':
@@ -245,10 +249,11 @@ export const authorCriteriaProperties = ['name', 'flairCssClass', 'flairText', '
* */
export interface AuthorCriteria {
/**
* A list of reddit usernames (case-insensitive) to match against. Do not include the "u/" prefix
* A list of reddit usernames (case-insensitive) or regular expressions to match against. Do not include the "u/" prefix
*
*
* EX to match against /u/FoxxMD and /u/AnotherUser use ["FoxxMD","AnotherUser"]
* @examples ["FoxxMD","AnotherUser"]
* @examples ["FoxxMD","AnotherUser", "/.*Foxx.\/*i"]
* */
name?: string[],
/**
@@ -440,6 +445,21 @@ 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
*
@@ -454,7 +474,7 @@ export interface ActivityState {
dispatched?: boolean | string | string[]
// can use ActivitySource | ActivitySource[] here because of issues with generating json schema, see ActivitySource comments
// cant use ActivitySource | ActivitySource[] here because of issues with generating json schema, see ActivitySource comments
/**
* Test where the current activity was sourced from.
*
@@ -469,6 +489,33 @@ 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[]
}
/**
@@ -491,13 +538,22 @@ 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
@@ -521,6 +577,16 @@ 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'];
/**

View File

@@ -1,6 +1,7 @@
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 {
@@ -75,3 +76,31 @@ export const activityReports = (activity: SnoowrapActivity): Report[] => {
}
return reports;
}
export interface RawSubredditRemovalReasonData {
data: {
[key: string]: SubredditRemovalReason
},
order: [string]
}
export interface SubredditRemovalReason {
message: string
id: string,
title: string
}
export interface SubredditActivityAbsoluteBreakdown {
count: number
name: string
}
export interface SubredditActivityBreakdown extends SubredditActivityAbsoluteBreakdown {
percent: number
}
export interface SubredditActivityBreakdownByType {
total: SubredditActivityBreakdown[]
submission: SubredditActivityBreakdown[]
comment: SubredditActivityBreakdown[]
}

View File

@@ -5,6 +5,7 @@ import {DatabaseMigrationOptions} from "./interfaces";
import {copyFile} from "fs/promises";
import {constants} from "fs";
import {ErrorWithCause} from "pony-cause";
import {CMError} from "../Utils/Errors";
export interface ExistingTable {
table: Table
@@ -118,9 +119,10 @@ export class MigrationService {
try {
await this.backupDatabase();
continueBCBackedup = true;
} catch (err) {
// @ts-ignore
this.dbLogger.error(err, {leaf: 'Backup'});
} catch (err: any) {
if(!(err instanceof CMError) || !err.logged) {
this.dbLogger.error(err, {leaf: 'Backup'});
}
}
} else {
this.dbLogger.info('Configuration DID NOT specify migrations may be executed if automated backup is successful. Will not try to create a backup.');
@@ -154,25 +156,34 @@ YOU SHOULD BACKUP YOUR EXISTING DATABASE BEFORE CONTINUING WITH MIGRATIONS.`);
async backupDatabase() {
try {
if (this.database.options.type === 'sqljs' && this.database.options.location !== undefined) {
let location: string | undefined;
const canBackup = ['sqljs','better-sqlite3'].includes(this.database.options.type);
if(canBackup) {
if(this.database.options.type === 'sqljs') {
location = this.database.options.location === ':memory:' ? undefined : this.database.options.location;
} else {
location = this.database.options.database === ':memory:' || (typeof this.database.options.database !== 'string') ? undefined : this.database.options.database;
}
}
if (canBackup && location !== undefined) {
try {
const ts = Date.now();
const backupLocation = `${this.database.options.location}.${ts}.bak`
const backupLocation = `${location}.${ts}.bak`
this.dbLogger.info(`Detected sqljs (sqlite) database. Will try to make a backup at ${backupLocation}`, {leaf: 'Backup'});
await copyFile(this.database.options.location, backupLocation, constants.COPYFILE_EXCL);
await copyFile(location, backupLocation, constants.COPYFILE_EXCL);
this.dbLogger.info('Successfully created backup!', {leaf: 'Backup'});
} catch (err: any) {
throw new ErrorWithCause('Cannot make an automated backup of your configured database.', {cause: err});
}
} else {
let msg = 'Cannot make an automated backup of your configured database.';
if (this.database.options.type !== 'sqljs') {
msg += ' Only SQlite (sqljs database type) is implemented for automated backups right now, sorry :( You will need to manually backup your database.';
if (!canBackup) {
msg += ' Only SQlite (sqljs or better-sqlite3 database type) is implemented for automated backups right now, sorry :( You will need to manually backup your database.';
} else {
// TODO don't throw for this??
msg += ' Database location is not defined (probably in-memory).';
}
throw new Error(msg);
throw new CMError(msg, {logged: true});
}
} catch (e: any) {
this.dbLogger.error(e, {leaf: 'Backup'});

View File

@@ -1,4 +1,4 @@
import {TableIndex} from "typeorm";
import {QueryRunner, TableIndex} from "typeorm";
/**
* Boilerplate for creating generic index
@@ -78,3 +78,15 @@ export const filterIndices = (prefix: string) => {
itemIsIndex(prefix)
]
}
export const tableHasData = async (runner: QueryRunner, name: string): Promise<boolean | null> => {
const countRes = await runner.query(`select count(*) from ${name}`);
let hasRows = null;
if (Array.isArray(countRes) && countRes[0] !== null) {
const {
'count(*)': count
} = countRes[0] || {};
hasRows = count !== 0;
}
return hasRows;
}

View File

@@ -0,0 +1,50 @@
import {MigrationInterface, QueryRunner, Table} from "typeorm"
import {createdAtColumn, createdAtIndex, idIndex, index, randomIdColumn, timeAtColumn} from "../MigrationUtil";
export class Guests1658930394548 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const dbType = queryRunner.connection.driver.options.type;
await queryRunner.createTable(
new Table({
name: 'Guests',
columns: [
randomIdColumn(),
{
name: 'authorName',
type: 'varchar',
length: '200',
isNullable: false,
},
{
name: 'type',
type: 'varchar',
isNullable: false,
length: '50'
},
{
name: 'guestOfId',
type: 'varchar',
length: '20',
isNullable: true
},
timeAtColumn('expiresAt', dbType, true),
createdAtColumn(dbType),
],
indices: [
idIndex('Guests', true),
createdAtIndex('guests'),
index('guest', ['expiresAt'], false)
]
}),
true,
true,
true
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}

View File

@@ -0,0 +1,145 @@
import {MigrationInterface, QueryRunner, Table, TableColumn} from "typeorm"
import {createdAtColumn, createdAtIndex, idIndex, index, randomIdColumn, tableHasData, timeAtColumn} from "../MigrationUtil";
export class invites1660228987769 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const dbType = queryRunner.connection.driver.options.type;
await queryRunner.createTable(
new Table({
name: 'SubredditInvite',
columns: [
{
name: 'id',
type: 'varchar',
length: '255',
isPrimary: true,
},
{
name: 'botId',
type: 'varchar',
length: '20',
isNullable: false
},
{
name: 'subreddit',
type: 'varchar',
length: '255',
isNullable: false
},
{
name: 'guests',
type: 'text',
isNullable: true
},
{
name: 'initialConfig',
type: 'text',
isNullable: true
},
createdAtColumn(dbType),
timeAtColumn('expiresAt', dbType, true)
],
}),
true,
true,
true
);
if (await queryRunner.hasTable('Invite')) {
await queryRunner.renameTable('Invite', 'BotInvite');
const table = await queryRunner.getTable('BotInvite') as Table;
await queryRunner.addColumns(table, [
new TableColumn({
name: 'initialConfig',
type: 'text',
isNullable: true
}),
new TableColumn({
name: 'guests',
type: 'text',
isNullable: true
})
]);
queryRunner.connection.logger.logSchemaBuild(`Table 'Invite' has been renamed 'BotInvite'. If there are existing rows on this table they will need to be recreated.`);
} else {
await queryRunner.createTable(
new Table({
name: 'BotInvite',
columns: [
{
name: 'id',
type: 'varchar',
length: '255',
isPrimary: true,
},
{
name: 'clientId',
type: 'varchar',
length: '255',
},
{
name: 'clientSecret',
type: 'varchar',
length: '255',
},
{
name: 'redirectUri',
type: 'text',
},
{
name: 'creator',
type: 'varchar',
length: '255',
},
{
name: 'permissions',
type: 'text'
},
{
name: 'instance',
type: 'varchar',
length: '255',
isNullable: true
},
{
name: 'overwrite',
type: 'boolean',
isNullable: true,
},
{
name: 'subreddits',
type: 'text',
isNullable: true
},
{
name: 'guests',
type: 'text',
isNullable: true
},
{
name: 'initialConfig',
type: 'text',
isNullable: true
},
createdAtColumn(dbType),
timeAtColumn('expiresAt', dbType, true)
],
}),
true,
true,
true
);
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}

View File

@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import {ActionType} from "../../../Entities/ActionType";
export class submission1661183583080 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.getRepository(ActionType).save([
new ActionType('submission')
]);
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}

View File

@@ -0,0 +1,22 @@
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> {
}
}

View File

@@ -0,0 +1,15 @@
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> {
}
}

View File

@@ -0,0 +1,33 @@
import {MigrationInterface, QueryRunner} from "typeorm"
import {tableHasData} from "../MigrationUtil";
export class removeInvites1660588028346 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const dbType = queryRunner.connection.driver.options.type;
if (dbType === 'sqljs' && await queryRunner.hasTable('Invite')) {
// const countRes = await queryRunner.query('select count(*) from Invite');
// let hasNoRows = null;
// if (Array.isArray(countRes) && countRes[0] !== null) {
// const {
// 'count(*)': count
// } = countRes[0] || {};
// hasNoRows = count === 0;
// }
const hasRows = await tableHasData(queryRunner, 'Invite');
if (hasRows === false) {
await queryRunner.dropTable('Invite');
} else {
let prefix = hasRows === null ? `Could not determine if SQL.js 'web' database had the table 'Invite' --` : `SQL.js 'web' database had the table 'Invite' and it is not empty --`
queryRunner.connection.logger.logSchemaBuild(`${prefix} This table is being replaced by 'BotInvite' table in 'app' database. If you have existing invites you will need to recreate them.`);
}
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
}
}

View File

@@ -163,3 +163,9 @@ 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;
}

View File

@@ -1,5 +1,5 @@
import { ISession } from "connect-typeorm";
import { Column, Entity, Index, PrimaryColumn } from "typeorm";
import { Column, Entity, Index, PrimaryColumn, DeleteDateColumn } from "typeorm";
@Entity()
export class ClientSession implements ISession {
@Index()
@@ -12,6 +12,6 @@ export class ClientSession implements ISession {
@Column("text")
public json = "";
@Column({ name: 'destroyedAt', nullable: true })
@DeleteDateColumn({ name: 'destroyedAt', nullable: true })
destroyedAt?: Date;
}

View File

@@ -107,8 +107,7 @@ var bmvbhash_even = function(data: BlockImageData, bits: number) {
return bits_to_hexhash(result);
};
var bmvbhash = function(data: BlockImageData, bits: number) {
var result = [];
var bmvbhash = function(data: BlockImageData, bits: number, calculateFlipped: boolean = false): string | [string, string] {
var i, j, x, y;
var block_width, block_height;
@@ -198,30 +197,51 @@ var bmvbhash = function(data: BlockImageData, bits: number) {
}
}
for (i = 0; i < bits; i++) {
for (j = 0; j < bits; j++) {
result.push(blocks[i][j]);
const blocksFlipped: number[][] | undefined = calculateFlipped ? [] : undefined;
if(blocksFlipped !== undefined) {
for(const row of blocks) {
const flippedRow = [...row];
flippedRow.reverse();
blocksFlipped.push(flippedRow);
}
}
translate_blocks_to_bits(result, block_width * block_height);
return bits_to_hexhash(result);
if(blocksFlipped !== undefined) {
const result = [];
const resultFlip = [];
for (i = 0; i < bits; i++) {
for (j = 0; j < bits; j++) {
result.push(blocks[i][j]);
resultFlip.push(blocksFlipped[i][j])
}
}
translate_blocks_to_bits(result, block_width * block_height);
translate_blocks_to_bits(resultFlip, block_width * block_height);
return [bits_to_hexhash(result), bits_to_hexhash(resultFlip)];
} else {
const result = [];
for (i = 0; i < bits; i++) {
for (j = 0; j < bits; j++) {
result.push(blocks[i][j]);
}
}
translate_blocks_to_bits(result, block_width * block_height);
return bits_to_hexhash(result);
}
};
var blockhashData = function(imgData: BlockImageData, bits: number, method: number) {
var hash;
var blockhashData = function(imgData: BlockImageData, bits: number, method: number, calculateFlipped: boolean): string | [string, string] {
if (method === 1) {
hash = bmvbhash_even(imgData, bits);
return bmvbhash_even(imgData, bits);
}
else if (method === 2) {
hash = bmvbhash(imgData, bits);
}
else {
throw new Error("Bad hashing method");
return bmvbhash(imgData, bits, calculateFlipped);
}
return hash;
throw new Error("Bad hashing method");
};
export const blockhash = async function(src: Sharp, bits: number, method: number = 2): Promise<string> {
@@ -230,5 +250,14 @@ export const blockhash = async function(src: Sharp, bits: number, method: number
width: info.width,
height: info.height,
data: buff,
}, bits, method);
}, bits, method, false) as string;
};
export const blockhashAndFlipped = async function(src: Sharp, bits: number, method: number = 2): Promise<[string, string]> {
const {data: buff, info} = await src.ensureAlpha().raw().toBuffer({resolveWithObject: true});
return blockhashData({
width: info.width,
height: info.height,
data: buff,
}, bits, method, true) as [string, string];
};

View File

@@ -2,6 +2,9 @@ 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,
@@ -42,4 +45,4 @@ export const filterCriteriaDefault: FilterCriteriaDefaults = {
export const defaultDataDir = path.resolve(__dirname, '../..');
export const defaultConfigFilenames = ['config.json', 'config.yaml'];
export const VERSION = '0.11.4';
export const VERSION = '0.13.1';

View File

@@ -21,7 +21,7 @@ import {
DurationVal,
EventRetentionPolicyRange,
JoinOperands,
NonDispatchActivitySource,
NonDispatchActivitySourceValue,
NotificationEventType,
NotificationProvider,
onExistingFoundBehavior,
@@ -1060,6 +1060,16 @@ export interface SubredditOverrides {
* */
retention?: EventRetentionPolicyRange
}
/**
* The relative URL to the ContextMod wiki page EX `https://reddit.com/r/subreddit/wiki/<path>`
*
* This will override the default relative URL as well as any URL set at the bot-level
*
* @default "botconfig/contextbot"
* @examples ["botconfig/contextbot"]
* */
wikiConfig?: string
}
/**
@@ -1479,20 +1489,6 @@ export interface OperatorJsonConfig {
storage?: 'database' | 'cache'
}
/**
* Settings related to oauth flow invites
* */
invites?: {
/**
* Number of seconds an invite should be valid for
*
* If `0` or not specified (default) invites do not expire
*
* @default 0
* @examples [0]
* */
maxAge?: number
}
/**
* The default log level to filter to in the web interface
*
@@ -1548,6 +1544,8 @@ export interface OperatorJsonConfig {
secret?: string,
/**
* A friendly name for this server. This will override `friendly` in `BotConnection` if specified.
*
* If none is set one is randomly generated.
* */
friendly?: string,
}
@@ -1587,6 +1585,9 @@ export interface ThirdPartyCredentialsJsonConfig {
youtube?: {
apiKey: string
}
mhs?: {
apiKey: string
}
[key: string]: any
}
@@ -1659,9 +1660,6 @@ export interface OperatorConfig extends OperatorJsonConfig {
secret?: string,
storage?: 'database' | 'cache'
},
invites: {
maxAge: number
},
logLevel?: LogLevel,
maxLogs: number,
clients: BotConnection[]
@@ -1735,6 +1733,7 @@ export interface ActionProcessResult {
dryRun: boolean,
result?: string
touchedEntities?: (Submission | Comment | RedditUser | string)[]
data?: any
}
export interface EventActivity {
@@ -1968,7 +1967,7 @@ export type RequiredItemCrit = Required<(CommentState & SubmissionState)>;
export interface ActivityDispatchConfig {
identifier?: string
cancelIfQueued?: boolean | NonDispatchActivitySource | NonDispatchActivitySource[]
cancelIfQueued?: boolean | NonDispatchActivitySourceValue | NonDispatchActivitySourceValue[]
goto?: string
onExistingFound?: onExistingFoundBehavior
tardyTolerant?: boolean | DurationVal

View File

@@ -19,9 +19,11 @@ 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
export type RuleObjectJsonTypes = RecentActivityRuleJSONConfig | RepeatActivityJSONConfig | AuthorRuleJSONConfig | AttributionJSONConfig | HistoryJSONConfig | RegexRuleJSONConfig | RepostRuleJSONConfig | SentimentRuleJSONConfig | MHSRuleJSONConfig
export type ActionJson = CommentActionJson | FlairActionJson | ReportActionJson | LockActionJson | RemoveActionJson | ApproveActionJson | BanActionJson | UserNoteActionJson | MessageActionJson | UserFlairActionJson | DispatchActionJson | CancelDispatchActionJson | ContributorActionJson | ModNoteActionJson | string | IncludesData;
export type ActionJson = CommentActionJson | SubmissionActionJson | FlairActionJson | ReportActionJson | LockActionJson | RemoveActionJson | ApproveActionJson | BanActionJson | UserNoteActionJson | MessageActionJson | UserFlairActionJson | DispatchActionJson | CancelDispatchActionJson | ContributorActionJson | ModNoteActionJson | string | IncludesData;

View File

@@ -2,7 +2,7 @@ import winston, {Logger} from "winston";
import {
asNamedCriteria, asWikiContext,
buildCachePrefix, buildFilter, castToBool,
createAjvFactory, fileOrDirectoryIsWriteable,
createAjvFactory, fileOrDirectoryIsWriteable, generateRandomName,
mergeArr, mergeFilters,
normalizeName,
overwriteMerge,
@@ -98,6 +98,7 @@ import {SubredditResources} from "./Subreddit/SubredditResources";
import {asIncludesData, IncludesData, IncludesString} from "./Common/Infrastructure/Includes";
import ConfigParseError from "./Utils/ConfigParseError";
import {InfluxClient} from "./Common/Influx/InfluxClient";
import {BotInvite} from "./Common/Entities/BotInvite";
export interface ConfigBuilderOptions {
logger: Logger,
@@ -417,6 +418,7 @@ export class ConfigBuilder {
}
structuredRuns.push({
...r,
filterCriteriaDefaults: configFilterDefaultsFromRun,
checks: structuredChecks,
authorIs: derivedRunAuthorIs,
itemIs: derivedRunItemIs
@@ -641,7 +643,7 @@ const getNamedOrReturn = <T>(namedFilters: Map<string, NamedCriteria<T>>, filter
if(!namedFilters.has(x.toLocaleLowerCase())) {
throw new Error(`No named ${filterName} criteria with the name "${x}"`);
}
return namedFilters.get(x) as NamedCriteria<T>;
return namedFilters.get(x.toLocaleLowerCase()) as NamedCriteria<T>;
}
if(asNamedCriteria(x)) {
return x;
@@ -1224,9 +1226,6 @@ export const buildOperatorConfigWithDefaults = async (data: OperatorJsonConfig):
maxAge: sessionMaxAge = 86400,
storage: sessionStorage = undefined,
} = {},
invites: {
maxAge: inviteMaxAge = 0,
} = {},
clients,
credentials: webCredentials,
operators,
@@ -1331,6 +1330,8 @@ export const buildOperatorConfigWithDefaults = async (data: OperatorJsonConfig):
}
const webDbConfig = createDatabaseConfig(realdbConnectionWeb);
const appDataSource = await createAppDatabaseConnection(dbConfig, appLogger);
let influx: InfluxClient | undefined = undefined;
if(influxConfig !== undefined) {
const tags = friendly !== undefined ? {server: friendly} : undefined;
@@ -1338,6 +1339,28 @@ export const buildOperatorConfigWithDefaults = async (data: OperatorJsonConfig):
await influx.isReady();
}
/* let friendlyId: string;
if (friendly === undefined) {
let randFriendly: string = generateRandomName();
// see if we can get invites to check for unique name
// if this is a new instance will not be able to get it but try anyway
try {
const inviteRepo = appDataSource.getRepository(BotInvite);
const exists = async (name: string) => {
const existing = await inviteRepo.findBy({instance: name});
return existing.length > 0;
}
while (await exists(randFriendly)) {
randFriendly = generateRandomName();
}
} catch (e: any) {
// something went wrong, just ignore this
}
friendlyId = randFriendly;
} else {
friendlyId = friendly;
}*/
const config: OperatorConfig = {
mode,
operator: {
@@ -1351,7 +1374,7 @@ export const buildOperatorConfigWithDefaults = async (data: OperatorJsonConfig):
frequency,
minFrequency
},
database: await createAppDatabaseConnection(dbConfig, appLogger),
database: appDataSource,
databaseConfig: {
connection: dbConfig,
migrations,
@@ -1371,9 +1394,6 @@ export const buildOperatorConfigWithDefaults = async (data: OperatorJsonConfig):
},
port,
storage: webStorage,
invites: {
maxAge: inviteMaxAge,
},
session: {
secret: sessionSecretFromConfig,
maxAge: sessionMaxAge,
@@ -1387,7 +1407,7 @@ export const buildOperatorConfigWithDefaults = async (data: OperatorJsonConfig):
api: {
port: apiPort,
secret: apiSecret,
friendly
friendly,
},
bots: [],
credentials,

View File

@@ -7,9 +7,10 @@ import {Rule, RuleJSONConfig, RuleOptions} from "./index";
import Submission from "snoowrap/dist/objects/Submission";
import dayjs from "dayjs";
import {
asComment,
asSubmission,
FAIL,
formatNumber, getActivitySubredditName, historyFilterConfigToOptions, isSubmission,
formatNumber, getActivitySubredditName, historyFilterConfigToOptions, isComment, isSubmission,
parseSubredditName,
PASS,
percentFromString, removeUndefinedKeys, toStrongSubredditState, windowConfigToWindowCriteria
@@ -20,6 +21,7 @@ import {CompareValueOrPercent} from "../Common/Infrastructure/Atomic";
import {ActivityWindowConfig, ActivityWindowCriteria} from "../Common/Infrastructure/ActivityWindow";
import {ErrorWithCause} from "pony-cause";
import {comparisonTextOp, parseGenericValueOrPercentComparison} from "../Common/Infrastructure/Comparisons";
import {getSubredditBreakdownByActivityType} from "../Utils/SnoowrapUtils";
export interface CommentThresholdCriteria extends ThresholdCriteria {
/**
@@ -79,6 +81,23 @@ 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
@@ -168,7 +187,7 @@ export class HistoryRule extends Rule {
for (const criteria of this.criteria) {
const {comment, window, submission, total, minActivityCount = 5} = criteria;
const {comment, window, submission, total, ratio, minActivityCount = 5} = criteria;
const {pre: activities, post: filteredActivities} = await this.resources.getAuthorActivitiesWithFilter(item.author, window);
@@ -206,10 +225,11 @@ export class HistoryRule extends Rule {
fOpTotal = filteredCounts.opTotal;
}
let asOp = false;
let commentTrigger = undefined;
if(comment !== undefined) {
const {operator, value, isPercent, extra = ''} = parseGenericValueOrPercentComparison(comment);
const asOp = extra.toLowerCase().includes('op');
asOp = extra.toLowerCase().includes('op');
if(isPercent) {
const per = value / 100;
if(asOp) {
@@ -248,6 +268,24 @@ 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];
@@ -260,11 +298,14 @@ export class HistoryRule extends Rule {
submissionTotal: fSubmissionTotal,
commentTotal: fCommentTotal,
opTotal: fOpTotal,
foundRatio,
filteredTotal: filteredActivities.length,
submissionTrigger,
commentTrigger,
totalTrigger,
triggered: (submissionTrigger === undefined || submissionTrigger === true) && (commentTrigger === undefined || commentTrigger === true) && (totalTrigger === undefined || totalTrigger === true)
ratioTrigger,
triggered: (submissionTrigger === undefined || submissionTrigger === true) && (commentTrigger === undefined || commentTrigger === true) && (totalTrigger === undefined || totalTrigger === true) && (ratioTrigger === undefined || ratioTrigger === true),
subredditBreakdown: getSubredditBreakdownByActivityType(!asOp ? filteredActivities : filteredActivities.filter(x => asSubmission(x) || x.is_submitter))
});
}
@@ -296,6 +337,12 @@ 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})]);
@@ -308,11 +355,13 @@ export class HistoryRule extends Rule {
submissionTotal,
commentTotal,
filteredTotal,
foundRatio,
opTotal,
criteria: {
comment,
submission,
total,
ratio,
window,
},
criteria,
@@ -320,6 +369,8 @@ export class HistoryRule extends Rule {
submissionTrigger,
commentTrigger,
totalTrigger,
ratioTrigger,
subredditBreakdown,
} = results;
const data: any = {
@@ -327,6 +378,7 @@ export class HistoryRule extends Rule {
submissionTotal,
commentTotal,
filteredTotal,
foundRatio,
opTotal,
commentPercent: formatNumber((commentTotal/activityTotal)*100),
submissionPercent: formatNumber((submissionTotal/activityTotal)*100),
@@ -338,12 +390,15 @@ export class HistoryRule extends Rule {
submissionTrigger,
commentTrigger,
totalTrigger,
ratioTrigger,
subredditBreakdown
};
let thresholdSummary = [];
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`;
@@ -368,6 +423,13 @@ 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 ');

420
src/Rule/MHSRule.ts Normal file
View File

@@ -0,0 +1,420 @@
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;

View File

@@ -42,6 +42,9 @@ import {
} from "../Common/Infrastructure/Filters/FilterCriteria";
import {ActivityWindow, ActivityWindowConfig} from "../Common/Infrastructure/ActivityWindow";
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();
@@ -186,8 +189,10 @@ 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;
@@ -195,21 +200,21 @@ export class RecentActivityRule extends Rule {
let filteredActivity: (Submission|Comment)[] = [];
let analysisTimes: number[] = [];
let referenceImage: ImageData | undefined;
let refHash: Required<ImageHashCacheData> | undefined;
if (this.imageDetection.enable) {
try {
referenceImage = ImageData.fromSubmission(item);
referenceImage.setPreferredResolutionByWidth(800);
if(this.imageDetection.hash.enable) {
let refHash: string | undefined;
if(this.imageDetection.hash.ttl !== undefined) {
refHash = await this.resources.getImageHash(referenceImage);
if(refHash === undefined) {
refHash = await referenceImage.hash(this.imageDetection.hash.bits);
await this.resources.setImageHash(referenceImage, refHash, this.imageDetection.hash.ttl);
} else if(refHash.length !== bitsToHexLength(this.imageDetection.hash.bits)) {
await this.resources.setImageHash(referenceImage, this.imageDetection.hash.ttl);
} else if(refHash.original.length !== bitsToHexLength(this.imageDetection.hash.bits)) {
this.logger.warn('Reference image hash length did not correspond to bits specified in config. Recomputing...');
refHash = await referenceImage.hash(this.imageDetection.hash.bits);
await this.resources.setImageHash(referenceImage, refHash, this.imageDetection.hash.ttl);
await referenceImage.hash(this.imageDetection.hash.bits);
await this.resources.setImageHash(referenceImage, this.imageDetection.hash.ttl);
}
} else {
refHash = await referenceImage.hash(this.imageDetection.hash.bits);
@@ -244,29 +249,38 @@ export class RecentActivityRule extends Rule {
}
// only do image detection if regular URL comparison and other conditions fail first
// to reduce CPU/bandwidth usage
if (referenceImage !== undefined) {
if (referenceImage !== undefined && refHash !== undefined) {
try {
let imgData = ImageData.fromSubmission(x);
imgData.setPreferredResolutionByWidth(800);
if(this.imageDetection.hash.enable) {
let compareHash: string | undefined;
let compareHash: Required<ImageHashCacheData> | undefined;
if(this.imageDetection.hash.ttl !== undefined) {
compareHash = await this.resources.getImageHash(imgData);
}
if(compareHash === undefined)
if(compareHash === undefined || compareHash.original.length !== refHash.original.length)
{
if(compareHash !== undefined) {
this.logger.debug(`Hash lengths were not the same! Will need to recompute compare hash to match reference.\n\nReference: ${referenceImage.basePath} has is ${refHash.original.length} char long | Comparing: ${imgData.basePath} has is ${compareHash} ${compareHash.original.length} long`);
}
compareHash = await imgData.hash(this.imageDetection.hash.bits);
if(this.imageDetection.hash.ttl !== undefined) {
await this.resources.setImageHash(imgData, compareHash, this.imageDetection.hash.ttl);
await this.resources.setImageHash(imgData, this.imageDetection.hash.ttl);
}
}
const refHash = await referenceImage.hash(this.imageDetection.hash.bits);
if(refHash.length !== compareHash.length) {
this.logger.debug(`Hash lengths were not the same! Will need to recompute compare hash to match reference.\n\nReference: ${referenceImage.baseUrl} has is ${refHash.length} char long | Comparing: ${imgData.baseUrl} has is ${compareHash} ${compareHash.length} long`);
compareHash = await imgData.hash(this.imageDetection.hash.bits)
let diff: number;
const odistance = leven(refHash.original, compareHash.original);
diff = (odistance/refHash.original.length)*100;
// compare flipped hash if it exists
// if it has less difference than normal comparison then the image is probably flipped (or so different it doesn't matter)
if(compareHash.flipped !== undefined) {
const fdistance = leven(refHash.original, compareHash.flipped);
const fdiff = (fdistance/refHash.original.length)*100;
if(fdiff < diff) {
diff = fdiff;
}
}
const distance = leven(refHash, compareHash);
const diff = (distance/refHash.length)*100;
// return image if hard is defined and diff is less
@@ -302,7 +316,7 @@ export class RecentActivityRule extends Rule {
}
} catch (err: any) {
if(!err.message.includes('did not end with a valid image extension')) {
this.logger.warn(`Will not compare image from Submission ${x.id} due to error while parsing image URL => ${err.message}`);
this.logger.warn(new CMError(`Will not compare image from Submission ${x.id} due to error while parsing image URL`, {cause: err}));
}
}
}
@@ -498,6 +512,7 @@ export class RecentActivityRule extends Rule {
testValue,
karmaThreshold,
combinedKarma,
subredditBreakdown: getSubredditBreakdownByActivityType(activities)
}
};
}

View File

@@ -12,6 +12,7 @@ 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 {
@@ -42,6 +43,9 @@ 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.`);
}

View File

@@ -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'
kind: 'recentActivity' | 'repeatActivity' | 'author' | 'attribution' | 'history' | 'regex' | 'repost' | 'sentiment' | 'mhs'
}

View File

@@ -24,7 +24,7 @@ import {RunResultEntity} from "../Common/Entities/RunResultEntity";
import {RuleResultEntity} from "../Common/Entities/RuleResultEntity";
import {RunnableBase} from "../Common/RunnableBase";
import {RunnableBaseJson, RunnableBaseOptions, StructuredRunnableBase} from "../Common/Infrastructure/Runnable";
import {FilterCriteriaDefaults} from "../Common/Infrastructure/Filters/FilterShapes";
import {FilterCriteriaDefaults, FilterCriteriaDefaultsJson} from "../Common/Infrastructure/Filters/FilterShapes";
import {IncludesData} from "../Common/Infrastructure/Includes";
export class Run extends RunnableBase {
@@ -284,7 +284,7 @@ export interface IRun extends PostBehavior, RunnableBaseJson {
*
* Default behavior is to exclude all mods and automoderator from checks
* */
filterCriteriaDefaults?: FilterCriteriaDefaults
filterCriteriaDefaults?: FilterCriteriaDefaultsJson
/**
* Use this option to override the `dryRun` setting for all Actions of all Checks in this Run
@@ -326,4 +326,5 @@ export interface RunConfigHydratedData extends IRun {
export interface RunConfigObject extends Omit<RunConfigHydratedData, 'authorIs' | 'itemIs'>, StructuredRunnableBase {
checks: ActivityCheckObject[]
filterCriteriaDefaults?: FilterCriteriaDefaults
}

View File

@@ -46,6 +46,9 @@
{
"$ref": "#/definitions/ModNoteActionJson"
},
{
"$ref": "#/definitions/SubmissionActionJson"
},
{
"type": "string"
}
@@ -286,10 +289,11 @@
"type": "array"
},
"name": {
"description": "A list of reddit usernames (case-insensitive) to match against. Do not include the \"u/\" prefix\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"description": "A list of reddit usernames (case-insensitive) or regular expressions to match against. Do not include the \"u/\" prefix\n\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"examples": [
"FoxxMD",
"AnotherUser"
"AnotherUser",
"/.*Foxx./*i"
],
"items": {
"type": "string"
@@ -704,6 +708,20 @@
"sticky": {
"description": "Stick the comment after creation?",
"type": "boolean"
},
"targets": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "Specify where this comment should be made\n\nValid values: 'self' | 'parent' | [reddit permalink]\n\n'self' and 'parent' are special targets that are relative to the Activity being processed:\n* When Activity is Submission => 'parent' does nothing\n* When Activity is Comment\n * 'self' => reply to Activity\n * 'parent' => make a top-level comment in the Submission the Comment is in\n\nIf target is not self/parent then CM assumes the value is a reddit permalink and will attempt to make a comment to that Activity"
}
},
"required": [
@@ -746,6 +764,88 @@
],
"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"
},
@@ -1647,13 +1747,13 @@
"type": "string"
},
"to": {
"description": "Entity to send message to.\n\nIf not present Message be will sent to the Author of the Activity being checked.\n\nValid formats:\n\n* `aUserName` -- send to /u/aUserName\n* `u/aUserName` -- send to /u/aUserName\n* `r/aSubreddit` -- sent to modmail of /r/aSubreddit\n\n**Note:** Reddit does not support sending a message AS a subreddit TO another subreddit",
"description": "Entity to send message to. It can be templated.\n\nIf not present Message be will sent to the Author of the Activity being checked.\n\nValid formats:\n\n* `aUserName` -- send to /u/aUserName\n* `u/aUserName` -- send to /u/aUserName\n* `r/aSubreddit` -- sent to modmail of /r/aSubreddit\n\n**Note:** Reddit does not support sending a message AS a subreddit TO another subreddit\n\n**Tip:** To send a message to the subreddit of the Activity us `to: 'r/{{item.subreddit}}'`",
"examples": [
"aUserName",
"u/aUserName",
"r/aSubreddit"
"r/aSubreddit",
"r/{{item.subreddit}}"
],
"pattern": "^\\s*(\\/[ru]\\/|[ru]\\/)*(\\w+)*\\s*$",
"type": "string"
}
},
@@ -1685,18 +1785,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1735,6 +1835,9 @@
}
]
},
"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",
@@ -1781,14 +1884,6 @@
"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": [
{
@@ -1839,6 +1934,21 @@
],
"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": [
{
@@ -1911,18 +2021,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1981,6 +2091,9 @@
}
]
},
"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",
@@ -2173,7 +2286,16 @@
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
"type": "string"
},
"note": {
"description": "(Optional) A mod-readable note added to the removal reason for this Activity. Can use Templating.\n\nThis note (and removal reasons) are only visible on New Reddit",
"type": "string"
},
"reasonId": {
"description": "(Optional) The ID of the Removal Reason to use\n\nRemoval reasons are only visible on New Reddit\n\nTo find IDs for removal reasons check the \"Removal Reasons\" popup located in the CM dashboard config editor for your subreddit\n\nMore info on Removal Reasons: https://mods.reddithelp.com/hc/en-us/articles/360010094892-Removal-Reasons",
"type": "string"
},
"spam": {
"description": "(Optional) Mark Activity as spam",
"type": "boolean"
}
},
@@ -2283,6 +2405,170 @@
],
"type": "object"
},
"SubmissionActionJson": {
"description": "Reply to the Activity. For a submission the reply will be a top-level comment.",
"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."
},
"content": {
"description": "The Content to submit for this Action. Content is interpreted as reddit-flavored Markdown.\n\nIf value starts with `wiki:` then the proceeding value will be used to get a wiki page from the current subreddit\n\n * EX `wiki:botconfig/mybot` tries to get `https://reddit.com/r/currentSubreddit/wiki/botconfig/mybot`\n\nIf the value starts with `wiki:` and ends with `|someValue` then `someValue` will be used as the base subreddit for the wiki page\n\n* EX `wiki:replytemplates/test|ContextModBot` tries to get `https://reddit.com/r/ContextModBot/wiki/replytemplates/test`\n\nIf the value starts with `url:` then the value is fetched as an external url and expects raw text returned\n\n* EX `url:https://pastebin.com/raw/38qfL7mL` tries to get the text response of `https://pastebin.com/raw/38qfL7mL`\n\nIf none of the above is used the value is treated as the raw context\n\n * EX `this is **bold** markdown text` => \"this is **bold** markdown text\"\n\nAll Content is rendered using [mustache](https://github.com/janl/mustache.js/#templates) to enable [Action Templating](https://github.com/FoxxMD/context-mod#action-templating).\n\nThe following properties are always available in the template (view individual Rules to see rule-specific template data):\n```\nitem.kind => The type of Activity that was checked (comment/submission)\nitem.author => The name of the Author of the Activity EX FoxxMD\nitem.permalink => A permalink URL to the Activity EX https://reddit.com/r/yourSub/comments/o1h0i0/title_name/1v3b7x\nitem.url => If the Activity is Link Sumbission then the external URL\nitem.title => If the Activity is a Submission then the title of that Submission\nrules => An object containing RuleResults of all the rules run for this check. See Action Templating for more details on naming\n```",
"examples": [
"This is the content of a comment/report/usernote",
"this is **bold** markdown text",
"wiki:botconfig/acomment"
],
"type": "string"
},
"distinguish": {
"description": "Distinguish as Mod after creation?",
"type": "boolean"
},
"dryRun": {
"default": false,
"description": "If `true` the Action will not make the API request to Reddit to perform its action.",
"examples": [
false,
true
],
"type": "boolean"
},
"enable": {
"default": true,
"description": "If set to `false` the Action will not be run",
"examples": [
true
],
"type": "boolean"
},
"flairId": {
"description": "Flair template to apply to this Submission",
"type": "string"
},
"flairText": {
"description": "Flair text to apply to this Submission",
"type": "string"
},
"footer": {
"anyOf": [
{
"enum": [
false
],
"type": "boolean"
},
{
"type": "string"
}
],
"description": "Customize the footer for Actions that send replies (Comment/Ban)\n\nIf `false` no footer is appended\n\nIf `string` the value is rendered as markdown or will use `wiki:` parser the same way `content` properties on Actions are rendered with [templating](https://github.com/FoxxMD/context-mod#action-templating).\n\nIf footer is `undefined` (not set) the default footer will be used:\n\n> *****\n> This action was performed by [a bot.] Mention a moderator or [send a modmail] if you any ideas, questions, or concerns about this action.\n\n*****\n\nThe following properties are available for [templating](https://github.com/FoxxMD/context-mod#action-templating):\n```\nsubName => name of subreddit Action was performed in (EX 'mealtimevideos')\npermaLink => The permalink for the Activity the Action was performed on EX https://reddit.com/r/yourSub/comments/o1h0i0/title_name/1v3b7x\nmodmaiLink => An encoded URL that will open a new message to your subreddit with the Action permalink appended to the body\nbotLink => A permalink to the FAQ for this bot.\n```\nIf you use your own footer or no footer **please link back to the bot FAQ** using the `{{botLink}}` property in your content :)"
},
"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": {
"description": "The type of action that will be performed",
"enum": [
"submission"
],
"type": "string"
},
"lock": {
"description": "Lock the Submission after creation?",
"type": "boolean"
},
"name": {
"description": "An optional, but highly recommended, friendly name for this Action. If not present will default to `kind`.\n\nCan only contain letters, numbers, underscore, spaces, and dashes",
"examples": [
"myDescriptiveAction"
],
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
"type": "string"
},
"nsfw": {
"type": "boolean"
},
"spoiler": {
"type": "boolean"
},
"sticky": {
"description": "Sticky the Submission after creation?",
"type": "boolean"
},
"targets": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "Specify where this Submission should be made\n\nValid values: 'self' | [subreddit]\n\n* 'self' -- DEFAULT. Post Submission to same subreddit of Activity being processed\n* [subreddit] -- The name of a subreddit to post Submission to. EX mealtimevideos"
},
"title": {
"description": "The title of this Submission.\n\nTemplated the same as **content**",
"type": "string"
},
"url": {
"description": "If Submission should be a Link, the URL to use\n\nTemplated the same as **content**\n\nPROTIP: To make a Link Submission pointing to the Activity being processed use `{{item.permalink}}` as the URL value",
"type": "string"
}
},
"required": [
"kind",
"title"
],
"type": "object"
},
"SubmissionState": {
"description": "Different attributes a `Submission` can be in. Only include a property if you want to check it.",
"examples": [
@@ -2317,6 +2603,88 @@
],
"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"
},
@@ -2367,6 +2735,23 @@
"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": [
{
@@ -2382,7 +2767,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
"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."
},
"link_flair_text": {
"anyOf": [
@@ -2399,7 +2784,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
"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."
},
"locked": {
"type": "boolean"

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,88 @@
],
"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"
},
@@ -679,10 +761,11 @@
"type": "array"
},
"name": {
"description": "A list of reddit usernames (case-insensitive) to match against. Do not include the \"u/\" prefix\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"description": "A list of reddit usernames (case-insensitive) or regular expressions to match against. Do not include the \"u/\" prefix\n\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"examples": [
"FoxxMD",
"AnotherUser"
"AnotherUser",
"/.*Foxx./*i"
],
"items": {
"type": "string"
@@ -1199,6 +1282,20 @@
"sticky": {
"description": "Stick the comment after creation?",
"type": "boolean"
},
"targets": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "Specify where this comment should be made\n\nValid values: 'self' | 'parent' | [reddit permalink]\n\n'self' and 'parent' are special targets that are relative to the Activity being processed:\n* When Activity is Submission => 'parent' does nothing\n* When Activity is Comment\n * 'self' => reply to Activity\n * 'parent' => make a top-level comment in the Submission the Comment is in\n\nIf target is not self/parent then CM assumes the value is a reddit permalink and will attempt to make a comment to that Activity"
}
},
"required": [
@@ -1270,6 +1367,9 @@
{
"$ref": "#/definitions/ModNoteActionJson"
},
{
"$ref": "#/definitions/SubmissionActionJson"
},
{
"type": "string"
}
@@ -1441,6 +1541,9 @@
{
"$ref": "#/definitions/SentimentRuleJSONConfig"
},
{
"$ref": "#/definitions/MHSRuleJSONConfig"
},
{
"$ref": "#/definitions/RuleSetConfigData"
},
@@ -1492,6 +1595,88 @@
],
"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"
},
@@ -2450,6 +2635,55 @@
},
"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": {
@@ -2520,6 +2754,40 @@
"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*(%?)(.*)$",
@@ -2919,6 +3187,126 @@
],
"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": {
@@ -3032,13 +3420,13 @@
"type": "string"
},
"to": {
"description": "Entity to send message to.\n\nIf not present Message be will sent to the Author of the Activity being checked.\n\nValid formats:\n\n* `aUserName` -- send to /u/aUserName\n* `u/aUserName` -- send to /u/aUserName\n* `r/aSubreddit` -- sent to modmail of /r/aSubreddit\n\n**Note:** Reddit does not support sending a message AS a subreddit TO another subreddit",
"description": "Entity to send message to. It can be templated.\n\nIf not present Message be will sent to the Author of the Activity being checked.\n\nValid formats:\n\n* `aUserName` -- send to /u/aUserName\n* `u/aUserName` -- send to /u/aUserName\n* `r/aSubreddit` -- sent to modmail of /r/aSubreddit\n\n**Note:** Reddit does not support sending a message AS a subreddit TO another subreddit\n\n**Tip:** To send a message to the subreddit of the Activity us `to: 'r/{{item.subreddit}}'`",
"examples": [
"aUserName",
"u/aUserName",
"r/aSubreddit"
"r/aSubreddit",
"r/{{item.subreddit}}"
],
"pattern": "^\\s*(\\/[ru]\\/|[ru]\\/)*(\\w+)*\\s*$",
"type": "string"
}
},
@@ -3070,18 +3458,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -3120,6 +3508,9 @@
}
]
},
"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",
@@ -3166,14 +3557,6 @@
"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": [
{
@@ -3224,6 +3607,21 @@
],
"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": [
{
@@ -3296,18 +3694,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -3366,6 +3764,9 @@
}
]
},
"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",
@@ -4133,7 +4534,16 @@
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
"type": "string"
},
"note": {
"description": "(Optional) A mod-readable note added to the removal reason for this Activity. Can use Templating.\n\nThis note (and removal reasons) are only visible on New Reddit",
"type": "string"
},
"reasonId": {
"description": "(Optional) The ID of the Removal Reason to use\n\nRemoval reasons are only visible on New Reddit\n\nTo find IDs for removal reasons check the \"Removal Reasons\" popup located in the CM dashboard config editor for your subreddit\n\nMore info on Removal Reasons: https://mods.reddithelp.com/hc/en-us/articles/360010094892-Removal-Reasons",
"type": "string"
},
"spam": {
"description": "(Optional) Mark Activity as spam",
"type": "boolean"
}
},
@@ -4715,6 +5125,9 @@
{
"$ref": "#/definitions/SentimentRuleJSONConfig"
},
{
"$ref": "#/definitions/MHSRuleJSONConfig"
},
{
"type": "string"
}
@@ -4977,6 +5390,170 @@
],
"type": "object"
},
"SubmissionActionJson": {
"description": "Reply to the Activity. For a submission the reply will be a top-level comment.",
"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."
},
"content": {
"description": "The Content to submit for this Action. Content is interpreted as reddit-flavored Markdown.\n\nIf value starts with `wiki:` then the proceeding value will be used to get a wiki page from the current subreddit\n\n * EX `wiki:botconfig/mybot` tries to get `https://reddit.com/r/currentSubreddit/wiki/botconfig/mybot`\n\nIf the value starts with `wiki:` and ends with `|someValue` then `someValue` will be used as the base subreddit for the wiki page\n\n* EX `wiki:replytemplates/test|ContextModBot` tries to get `https://reddit.com/r/ContextModBot/wiki/replytemplates/test`\n\nIf the value starts with `url:` then the value is fetched as an external url and expects raw text returned\n\n* EX `url:https://pastebin.com/raw/38qfL7mL` tries to get the text response of `https://pastebin.com/raw/38qfL7mL`\n\nIf none of the above is used the value is treated as the raw context\n\n * EX `this is **bold** markdown text` => \"this is **bold** markdown text\"\n\nAll Content is rendered using [mustache](https://github.com/janl/mustache.js/#templates) to enable [Action Templating](https://github.com/FoxxMD/context-mod#action-templating).\n\nThe following properties are always available in the template (view individual Rules to see rule-specific template data):\n```\nitem.kind => The type of Activity that was checked (comment/submission)\nitem.author => The name of the Author of the Activity EX FoxxMD\nitem.permalink => A permalink URL to the Activity EX https://reddit.com/r/yourSub/comments/o1h0i0/title_name/1v3b7x\nitem.url => If the Activity is Link Sumbission then the external URL\nitem.title => If the Activity is a Submission then the title of that Submission\nrules => An object containing RuleResults of all the rules run for this check. See Action Templating for more details on naming\n```",
"examples": [
"This is the content of a comment/report/usernote",
"this is **bold** markdown text",
"wiki:botconfig/acomment"
],
"type": "string"
},
"distinguish": {
"description": "Distinguish as Mod after creation?",
"type": "boolean"
},
"dryRun": {
"default": false,
"description": "If `true` the Action will not make the API request to Reddit to perform its action.",
"examples": [
false,
true
],
"type": "boolean"
},
"enable": {
"default": true,
"description": "If set to `false` the Action will not be run",
"examples": [
true
],
"type": "boolean"
},
"flairId": {
"description": "Flair template to apply to this Submission",
"type": "string"
},
"flairText": {
"description": "Flair text to apply to this Submission",
"type": "string"
},
"footer": {
"anyOf": [
{
"enum": [
false
],
"type": "boolean"
},
{
"type": "string"
}
],
"description": "Customize the footer for Actions that send replies (Comment/Ban)\n\nIf `false` no footer is appended\n\nIf `string` the value is rendered as markdown or will use `wiki:` parser the same way `content` properties on Actions are rendered with [templating](https://github.com/FoxxMD/context-mod#action-templating).\n\nIf footer is `undefined` (not set) the default footer will be used:\n\n> *****\n> This action was performed by [a bot.] Mention a moderator or [send a modmail] if you any ideas, questions, or concerns about this action.\n\n*****\n\nThe following properties are available for [templating](https://github.com/FoxxMD/context-mod#action-templating):\n```\nsubName => name of subreddit Action was performed in (EX 'mealtimevideos')\npermaLink => The permalink for the Activity the Action was performed on EX https://reddit.com/r/yourSub/comments/o1h0i0/title_name/1v3b7x\nmodmaiLink => An encoded URL that will open a new message to your subreddit with the Action permalink appended to the body\nbotLink => A permalink to the FAQ for this bot.\n```\nIf you use your own footer or no footer **please link back to the bot FAQ** using the `{{botLink}}` property in your content :)"
},
"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": {
"description": "The type of action that will be performed",
"enum": [
"submission"
],
"type": "string"
},
"lock": {
"description": "Lock the Submission after creation?",
"type": "boolean"
},
"name": {
"description": "An optional, but highly recommended, friendly name for this Action. If not present will default to `kind`.\n\nCan only contain letters, numbers, underscore, spaces, and dashes",
"examples": [
"myDescriptiveAction"
],
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
"type": "string"
},
"nsfw": {
"type": "boolean"
},
"spoiler": {
"type": "boolean"
},
"sticky": {
"description": "Sticky the Submission after creation?",
"type": "boolean"
},
"targets": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "Specify where this Submission should be made\n\nValid values: 'self' | [subreddit]\n\n* 'self' -- DEFAULT. Post Submission to same subreddit of Activity being processed\n* [subreddit] -- The name of a subreddit to post Submission to. EX mealtimevideos"
},
"title": {
"description": "The title of this Submission.\n\nTemplated the same as **content**",
"type": "string"
},
"url": {
"description": "If Submission should be a Link, the URL to use\n\nTemplated the same as **content**\n\nPROTIP: To make a Link Submission pointing to the Activity being processed use `{{item.permalink}}` as the URL value",
"type": "string"
}
},
"required": [
"kind",
"title"
],
"type": "object"
},
"SubmissionCheckConfigData": {
"properties": {
"actions": {
@@ -5040,6 +5617,9 @@
{
"$ref": "#/definitions/ModNoteActionJson"
},
{
"$ref": "#/definitions/SubmissionActionJson"
},
{
"type": "string"
}
@@ -5211,6 +5791,9 @@
{
"$ref": "#/definitions/SentimentRuleJSONConfig"
},
{
"$ref": "#/definitions/MHSRuleJSONConfig"
},
{
"$ref": "#/definitions/RuleSetConfigData"
},
@@ -5262,6 +5845,88 @@
],
"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"
},
@@ -5312,6 +5977,23 @@
"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": [
{
@@ -5327,7 +6009,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
"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."
},
"link_flair_text": {
"anyOf": [
@@ -5344,7 +6026,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
"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."
},
"locked": {
"type": "boolean"

View File

@@ -133,10 +133,11 @@
"type": "array"
},
"name": {
"description": "A list of reddit usernames (case-insensitive) to match against. Do not include the \"u/\" prefix\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"description": "A list of reddit usernames (case-insensitive) or regular expressions to match against. Do not include the \"u/\" prefix\n\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"examples": [
"FoxxMD",
"AnotherUser"
"AnotherUser",
"/.*Foxx./*i"
],
"items": {
"type": "string"
@@ -186,6 +187,17 @@
},
"BotCredentialsJsonConfig": {
"properties": {
"mhs": {
"properties": {
"apiKey": {
"type": "string"
}
},
"required": [
"apiKey"
],
"type": "object"
},
"reddit": {
"$ref": "#/definitions/RedditCredentials"
},
@@ -522,6 +534,88 @@
],
"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"
},
@@ -934,7 +1028,7 @@
"file": {
"allOf": [
{
"$ref": "#/definitions/Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"dirname\"|\"options\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">"
"$ref": "#/definitions/Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"options\"|\"dirname\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">"
},
{
"properties": {
@@ -1039,18 +1133,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1089,6 +1183,9 @@
}
]
},
"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",
@@ -1140,18 +1237,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1210,6 +1307,9 @@
}
]
},
"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",
@@ -1381,7 +1481,7 @@
],
"type": "object"
},
"Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"dirname\"|\"options\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">": {
"Omit<DailyRotateFileTransportOptions,\"stream\"|\"log\"|\"options\"|\"dirname\"|\"handleRejections\"|\"format\"|\"handleExceptions\"|\"logv\"|\"close\">": {
"properties": {
"auditFile": {
"description": "A string representing the name of the name of the audit file. (default: './hash-audit.json')",
@@ -1834,6 +1934,88 @@
],
"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"
},
@@ -1884,6 +2066,23 @@
"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": [
{
@@ -1899,7 +2098,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
"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."
},
"link_flair_text": {
"anyOf": [
@@ -1916,7 +2115,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
"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."
},
"locked": {
"type": "boolean"
@@ -2030,6 +2229,14 @@
},
"name": {
"type": "string"
},
"wikiConfig": {
"default": "botconfig/contextbot",
"description": "The relative URL to the ContextMod wiki page EX `https://reddit.com/r/subreddit/wiki/<path>`\n\nThis will override the default relative URL as well as any URL set at the bot-level",
"examples": [
"botconfig/contextbot"
],
"type": "string"
}
},
"required": [
@@ -2040,6 +2247,17 @@
"ThirdPartyCredentialsJsonConfig": {
"additionalProperties": {},
"properties": {
"mhs": {
"properties": {
"apiKey": {
"type": "string"
}
},
"required": [
"apiKey"
],
"type": "object"
},
"youtube": {
"properties": {
"apiKey": {
@@ -2132,7 +2350,7 @@
"description": "Configuration for the **Server** application. See [Architecture Documentation](https://github.com/FoxxMD/context-mod/blob/master/docs/serverClientArchitecture.md) for more info",
"properties": {
"friendly": {
"description": "A friendly name for this server. This will override `friendly` in `BotConnection` if specified.",
"description": "A friendly name for this server. This will override `friendly` in `BotConnection` if specified.\n\nIf none is set one is randomly generated.",
"type": "string"
},
"port": {
@@ -2425,20 +2643,6 @@
},
"type": "object"
},
"invites": {
"description": "Settings related to oauth flow invites",
"properties": {
"maxAge": {
"default": 0,
"description": "Number of seconds an invite should be valid for\n\n If `0` or not specified (default) invites do not expire",
"examples": [
0
],
"type": "number"
}
},
"type": "object"
},
"logLevel": {
"description": "The default log level to filter to in the web interface\n\nIf not specified or `null` will be same as global `logLevel`",
"enum": [

View File

@@ -28,6 +28,9 @@
{
"$ref": "#/definitions/SentimentRuleJSONConfig"
},
{
"$ref": "#/definitions/MHSRuleJSONConfig"
},
{
"type": "string"
}
@@ -60,6 +63,88 @@
],
"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"
},
@@ -594,10 +679,11 @@
"type": "array"
},
"name": {
"description": "A list of reddit usernames (case-insensitive) to match against. Do not include the \"u/\" prefix\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"description": "A list of reddit usernames (case-insensitive) or regular expressions to match against. Do not include the \"u/\" prefix\n\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"examples": [
"FoxxMD",
"AnotherUser"
"AnotherUser",
"/.*Foxx./*i"
],
"items": {
"type": "string"
@@ -763,6 +849,88 @@
],
"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"
},
@@ -1316,6 +1484,55 @@
},
"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": {
@@ -1386,6 +1603,40 @@
"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*(%?)(.*)$",
@@ -1693,6 +1944,126 @@
],
"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": {
@@ -1714,18 +2085,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1764,6 +2135,9 @@
}
]
},
"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",
@@ -1815,18 +2189,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1885,6 +2259,9 @@
}
]
},
"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",
@@ -3241,6 +3618,88 @@
],
"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"
},
@@ -3291,6 +3750,23 @@
"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": [
{
@@ -3306,7 +3782,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
"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."
},
"link_flair_text": {
"anyOf": [
@@ -3323,7 +3799,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
"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."
},
"locked": {
"type": "boolean"

View File

@@ -28,6 +28,88 @@
],
"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"
},
@@ -562,10 +644,11 @@
"type": "array"
},
"name": {
"description": "A list of reddit usernames (case-insensitive) to match against. Do not include the \"u/\" prefix\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"description": "A list of reddit usernames (case-insensitive) or regular expressions to match against. Do not include the \"u/\" prefix\n\n\n EX to match against /u/FoxxMD and /u/AnotherUser use [\"FoxxMD\",\"AnotherUser\"]",
"examples": [
"FoxxMD",
"AnotherUser"
"AnotherUser",
"/.*Foxx./*i"
],
"items": {
"type": "string"
@@ -731,6 +814,88 @@
],
"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"
},
@@ -1284,6 +1449,55 @@
},
"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": {
@@ -1354,6 +1568,40 @@
"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*(%?)(.*)$",
@@ -1661,6 +1909,126 @@
],
"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": {
@@ -1682,18 +2050,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1732,6 +2100,9 @@
}
]
},
"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",
@@ -1783,18 +2154,18 @@
"items": {
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
},
"type": "array"
},
{
"enum": [
"comment",
false,
"submission"
],
"type": "string"
]
}
]
},
@@ -1853,6 +2224,9 @@
}
]
},
"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",
@@ -3209,6 +3583,88 @@
],
"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"
},
@@ -3259,6 +3715,23 @@
"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": [
{
@@ -3274,7 +3747,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY css\n* If `false` then passes if flair has NO css"
"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."
},
"link_flair_text": {
"anyOf": [
@@ -3291,7 +3764,7 @@
]
}
],
"description": "* If `true` then passes if flair has ANY text\n* If `false` then passes if flair has NO text"
"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."
},
"locked": {
"type": "boolean"
@@ -3509,6 +3982,9 @@
{
"$ref": "#/definitions/SentimentRuleJSONConfig"
},
{
"$ref": "#/definitions/MHSRuleJSONConfig"
},
{
"type": "string"
}

Some files were not shown because too many files have changed in this diff Show More