Compare commits

...

98 Commits

Author SHA1 Message Date
FoxxMD
2a282a0d6f Merge branch 'edge' 2021-12-21 09:35:21 -05:00
FoxxMD
0d087521a7 feat(docs): Specify yaml can be validated in editor 2021-12-21 09:35:06 -05:00
FoxxMD
fb5fc961cc feat(docs): Add youtube credentials requirements for repost rule 2021-12-21 09:33:24 -05:00
FoxxMD
c04b305881 feat(docs): Add link-spamming regex config 2021-12-21 09:22:35 -05:00
FoxxMD
5c5e9a26aa refactor(ui): Unify editor look-and-feel
* Use named entry files for webpack so we can access them from config.ejs
* Move some of the validation logic to config.ejs so it can be used by json editor as well
* Use same controls for loading files/schemas/urls for both editors
* Add validation errors box for both editors
2021-12-20 23:30:41 -05:00
Matt Foxx
477d1a10ae Merge pull request #60 from rysie/edge
Support setting user flair by flair_template_id
2021-12-20 18:37:36 -05:00
Marcin Macinski
bbee92699c Support setting user flair by flair_template_id 2021-12-21 00:10:40 +01:00
FoxxMD
7f09043cdf fix(ui): Add missing yaml asset files
Need to unignore them...
2021-12-20 15:56:36 -05:00
FoxxMD
768a199c40 feat(ui): Add quick-n-dirty YAML editor
Using one-off project cm-yaml http://github.com/foxxmd/cm-yaml to run a static version of monaco-yaml inside CM
2021-12-20 15:42:37 -05:00
FoxxMD
6e4b0c7719 feat(regex): Add match sample to rule results so it can be used in content template 2021-12-20 12:33:40 -05:00
FoxxMD
89b21e6073 fix(repost): Use average of all algos to get high score
Ensures no anomalous scores dominate
2021-12-18 18:44:52 -05:00
FoxxMD
da611c5894 fix(repost): Fix max weighted score and formatting 2021-12-18 18:22:38 -05:00
FoxxMD
2c90a260c0 fix(stream): Remove processing clear behavior for polling to try to fix weird polling behavior 2021-12-18 18:08:00 -05:00
FoxxMD
f081598da6 feat(repost): Improve text matching and default values
* Use 3 different matching algorithms using the highest score out of the three
* Weight score based on length of the sentence
* Increase minimum number of words to 3
* Enforce min word count on external (youtube) comments
2021-12-18 17:42:43 -05:00
FoxxMD
55f45163a4 feat(repost): Fix some bugs and improve result data
* Wrong hash check
* Add closest match summary and percent for use in content
2021-12-18 14:54:01 -05:00
FoxxMD
e4dfa9dde3 refactor(docker): reduce image size with best practices
* use --no-cache so repository index isn't included in image
* use FROM instructions to build project with dev dependencies, then copy built project to new stage and install production-only libraries
* properly ignore docs and node_modules with dockerignore
2021-12-17 15:10:22 -05:00
FoxxMD
0e395792db refactor: Remove unusused ts-auto-guard package
Has @ts-morph as a dependency which is a huge package
2021-12-17 14:36:03 -05:00
FoxxMD
dcbeb784e8 refactor: Remove set-random-interval
* depended on and always downloaded an entire, older typescript version (even with production install) -- was not necessary for one function
* refactor project to use newer TS version (specify any type for catch blocks to fix compiler errors)
2021-12-17 14:25:48 -05:00
FoxxMD
aeaeb6ce27 refactor(docker): Remove monaco editor local dependency to reduce image size
Wasn't necessary to have it installed locally (can use CDN) and is not a part of the core experience
2021-12-17 14:00:54 -05:00
FoxxMD
d6a29c5914 fix(bot): Actually get all moderated subreddits
Previously was only getting first page of moderated subreddits (listing). Make sure to get all pages.
2021-12-17 13:24:09 -05:00
FoxxMD
c1224121d4 feat(subreddit): Implement user profile filtering for SubredditState
* Add convenience property for filtering subreddits by user profile prefix (u_)
* Do some smart property comparison to check if SubredditState name is regex or not -- use additional user prof check if it is so we don't clobber existing name regex

Closes #56
2021-12-17 13:01:47 -05:00
FoxxMD
9790e681ea docs(regex): Add subreddit-ready example for removing discord link spam 2021-12-16 16:27:06 -05:00
FoxxMD
a48a850c98 Update winston repository package format/information 2021-12-16 14:58:43 -05:00
FoxxMD
b8369a9e9f Package bump for security
https://github.com/advisories/GHSA-93q8-gq69-wqmw
2021-12-14 12:06:48 -05:00
FoxxMD
0c31bdf25e refactor(repost): Improve repost criteria configuration and add documentation
* Simplify usage b/w comment-submission by removing "criteria" in main criteria property -- comment checks can just use additional properties
* Consolidated occurrence count/time into one property to allow and/or operands on both conditions (more powerful!)
* Added documentation describing repost configuration
* Added repost configuration examples
2021-12-07 16:30:05 -05:00
FoxxMD
4b14e581dd fix: Add more staggering on heartbeat check
Always stagger subreddit checks
2021-12-06 17:31:00 -05:00
FoxxMD
b2846efd2b fix: Improve falloff behavior when reddit api error are encountered
* Turn off snoowrap request queuing
* Aggregate errors from all managers at bot-level and force all to stop (and clear queue/polling) if a small threshold is met
* Add activity refresh on check into try-catch so delayed activities in queue don't cause a loop if they fail due to api issues
2021-12-06 17:16:04 -05:00
FoxxMD
a787e4515b feat(repost): Implement occurrence count and time comparisons
* User-defined set of comparisons for testing how many reposts were found
* User-defined set of comparisons for testing when a slice/all of reposts were created
2021-12-06 13:28:02 -05:00
FoxxMD
f63e2a0ec4 Merge branch 'topComments' into edge 2021-12-01 17:34:51 -05:00
FoxxMD
9d0e098db1 feat(rule): Implement repost rule
* checks for both submission/comment
* search by submission title, url, dups/crossposts, and external (just youtube for now)
* user-defined string sameness for all search facets
* user-defined case-sensitivity and regex-based transformations for activity/repost item values
* cache comment checks
* implemented youtube client for retrieving video comments
2021-12-01 17:34:25 -05:00
FoxxMD
181390f0eb fix: Correct error description for reading a config file
Was using copy-pasted statement from wiki error which was confusing
2021-12-01 09:33:03 -05:00
FoxxMD
a8c7b1dac9 Interim implementation of repost rule 2021-11-30 20:42:40 -05:00
FoxxMD
fd5a92758d Merge branch 'edge' 2021-11-28 19:43:20 -05:00
FoxxMD
027199d788 docs(heroku): Add information on dyno usage 2021-11-15 17:27:42 -05:00
FoxxMD
2a9f01b928 fix(heroku): Add OPERATOR to heroku deploy template 2021-11-15 17:26:34 -05:00
FoxxMD
cf54502f0d fix(heroku): Add redirect uri env to heroku deploy template 2021-11-15 17:26:34 -05:00
FoxxMD
2a3663ccc9 refactor(heroku): heroku-specific docker change
* Add image for web and worker
* Refactor port usage to conform to heroku's usage
2021-11-15 17:26:34 -05:00
FoxxMD
dc2eeffcb5 fix(bot): Remove own profile "sub" from default moderated subreddits to run on
The user profile for the bot account is returning as a moderated "subreddit" EX (/u/ContextMotBot) but its not useable by CM because it does not have a wiki and users don't use this as a sub. Filter it out of moderated subreddits when using the default behavior.
2021-11-15 13:19:21 -05:00
FoxxMD
39daa11f2d Merge branch 'edge' 2021-11-15 12:53:28 -05:00
FoxxMD
93de38a845 fix(filter): Missing 'op' property test on itemIs for comment 2021-11-15 12:47:34 -05:00
FoxxMD
43caaca1f2 fix(config): Fix wrong provider data used when bot has no caching config
Use previously built defaultProvider, instead of hardcoded memory config, so any cache config from operator waterfalls to bot/subreddit

Closes #46
2021-11-02 15:55:03 -04:00
FoxxMD
7bcc0195fe fix(author): change include/exclude on RULE to be optional
One of these properties must be present for the rule to be valid. This is enforced at runtime. Change the schema so that both are optional from the config-side though.
2021-11-02 09:41:55 -04:00
FoxxMD
dac6541e28 Merge branch 'edge' 2021-11-01 16:12:43 -04:00
FoxxMD
2504a34a34 refactor(docker): Remove old steps from node-canvas dep
Not using node-canvas anymore so dockerfile can be simplified #48
2021-11-01 15:55:12 -04:00
FoxxMD
e19639ad0d fix(ui): Forgot to add tailwin css to git
Oops!
2021-11-01 15:06:50 -04:00
FoxxMD
b8084e02b5 Merge branch 'colorImprovements' into edge 2021-11-01 14:58:01 -04:00
FoxxMD
97906281e6 Merge branch 'edge' 2021-11-01 14:55:10 -04:00
FoxxMD
2cea119657 feat(ui): Add tooltip descriptions for depleted/limit reset stats
Closes #36
2021-11-01 14:52:35 -04:00
FoxxMD
6f16d289dd feat(ui): Add lang attribute for html
Closes #35
2021-11-01 14:22:20 -04:00
FoxxMD
a96575c6b3 refactor(ui): Use local tailwind css asset
Closes #34
2021-11-01 14:19:47 -04:00
FoxxMD
0a82e83352 refactor(ui)!: Implement colorbind color changes for rest of UI and remove dark/light mode
* Apply changes made in ac409dce to the rest of the application
* Remove dark/light mode -- now always dark mode (easier to maintain this way)
* Remove dependency on tailwind dark css
2021-11-01 14:14:49 -04:00
FoxxMD
d5e1cdec61 fix(criteria): Improve criteria filtering for removed/deleted activities and logging
* Use different logging messages when criteria is not available due to mod permissions (property not available to non-mods)
* Change logging level for missing/unavailable criteria to reduce logging noise. On unavailable use debug, on missing use warn
* Improve activity removed/deleted detection based on whether activity is moddable by current user
2021-11-01 13:25:54 -04:00
FoxxMD
ef40c25b09 feat(attribution): Add additional subreddit and activity filtering functionality to criteria
* Refactor subreddit filtering with include/exclude to use subreddit state
* Add submissionState and commentState filters
2021-11-01 11:26:55 -04:00
FoxxMD
6370a2976a Merge branch 'edge' into colorImprovements 2021-11-01 10:23:40 -04:00
FoxxMD
d8180299ea fix(author): Fix missing true return statement for author flair check 2021-11-01 10:23:22 -04:00
FoxxMD
ac409dce3d POC color improvements for color blindness
Needs another pass and consolidate/clean up for pages other than status
2021-10-20 21:12:31 -04:00
FoxxMD
56c007c20d feat(author): Implement author profile description regex/string testing
May test "description" in authorIs as a regular express of string literal -- or as an array of the aforementioned values
2021-10-20 19:52:46 -04:00
FoxxMD
487f13f704 Merge branch 'edge' 2021-10-12 11:56:51 -04:00
FoxxMD
00b9d87cdc Remove unused types package 2021-10-12 11:56:29 -04:00
FoxxMD
2c797e0b9b docs(image): Add documentation for image comparison
#26
2021-10-12 11:10:14 -04:00
FoxxMD
4a2b27bfbf fix(recent): Revert debug change for concurrency on activity comparisons 2021-10-12 11:08:53 -04:00
FoxxMD
463a4dc0eb feat(image): Implement perceptual hashing image comparison
* Generate perceptual hashes using blockhash-js of images that can be cache/stored
* Take advantage of reddit thumbnail code ImageData to hash lower-res to begin with (but represent full url)
* Refactor imageDetection config so hash and pixel approaches have different configs
* Cache phash results to reduce reddit traffic and speed up performance

Addresses cpu/memory issues with pixel comparison. Allow pixel for finer comparisons if needed using tiered thresholds. Closes #26
2021-10-11 15:28:48 -04:00
FoxxMD
4b3bea661d Merge branch 'imageComparisonOptimization' into edge
# Conflicts:
#	src/Rule/RecentActivityRule.ts
2021-10-08 13:50:49 -04:00
FoxxMD
976f310f51 refactor(image): Remove resemblejs dependency
* Refactor image comparison to use pixelmatch only so resemblejs can be removed (too much memory usage)
* Heavier usage of sharp to get images into same dimensions prior to pixelmatch
* Refactor image conversion into ImageData to clean up utils/recent activity rule
2021-10-08 13:49:46 -04:00
FoxxMD
4d8d3dc266 fix(docker): Add libvips dependency 2021-10-08 13:47:35 -04:00
FoxxMD
ce9e678c4c fix(image): clone sharp instance so converting between outputs doesn't cause issues 2021-10-07 18:06:05 -04:00
FoxxMD
8cf30b6b7d refactor: Introduce staggered startup for bots/polling to decrease load on host/reddit and improve image comparison performance
* Implement staggered startup for bots (reddit accounts, top-level)
* Implement staggered startup for managers (subreddits) and subreddit polling
* Introduce random -1/+1 second to polling interval for every stream to ensure none are synced so there is no instantaneous spike in cpu/traffic/memory on host/reddit
* Add user-configurable stagger interval for shared mod polling
* Implement second image comparison approach with pixelmatch for reduced memory usage when image dimensions are exactly the same
* Use sharp to resize images to 400 width max when using resemblejs to reduce memory usage
2021-10-07 17:13:27 -04:00
FoxxMD
2b6d08f8a5 Dummy commit
To get github actions to run
2021-10-06 18:03:26 -04:00
FoxxMD
f8fc63991f feat(image): Leverage reddit image previews for download/comparison
* Refactor image acquisition/parsing to use on-demand fetching and track different resolutions
* Try to use smaller previews (under 1000px), when possible, for comparing images and downloading
* Do image comparisons in parallel
2021-10-06 17:33:56 -04:00
FoxxMD
d96a1f677c refactor(image): Profile image comparison analysis time to debug statement 2021-10-06 14:14:36 -04:00
FoxxMD
b14689791c refactor(image): Document resemble compare options for performance
* Disable color comparison is slower than nothing
* Restrict comparison to a max of 800x800 pixels is slower than nothing
2021-10-06 14:13:50 -04:00
FoxxMD
b70c877e44 refactor(polling): Improve processed list configuration/usage
* Change 'after' type to string duration for friendlier configuration
* Decrease list size trigger === limit instead of 2x (not necessary to have a list that big for polling new)
* Increase initial shared mod polling to max limit (100)
2021-10-06 12:54:23 -04:00
FoxxMD
041655376a feat(filter): Implement age test for comment/submission
Closes #27
2021-10-06 12:54:23 -04:00
FoxxMD
e1eab7696b feat(polling): Implement memory bloat mitigation for long-running SnooStorm polling
The list of processed activities SnooStorm uses to ensure only new activities are emitted when polling is never cleared. MayorMonty/Snoostorm#35

To mitigate the memory bloat this creates when RCB runs for a long time on high-volume subreddits implement user-configurable (with defaults) behavior for clearing the processed activity list. Default values ensure clearing the list does not interfere with checking for new activities.
2021-10-05 14:45:10 -04:00
FoxxMD
65d1d36d53 feat(cache): Implement batching for subreddit info
When using full criteria for subreddit state we can save a ton of api calls by get info for all uncached subreddits at the same time rather than individually
2021-09-29 16:20:02 -04:00
FoxxMD
120d776fc2 feat(ui): Display subreddit and subreddit crit statistics in cache call breakdown popup 2021-09-29 10:47:33 -04:00
FoxxMD
425e16295b refactor(cache): Better cache usage for some known state conditions
* Don't store subreddit state cache results for now since nothing computationally expensive or requires api requests
* Return early on item state check if there is nothing to check so we don't store an empty result in cache
2021-09-29 10:47:05 -04:00
FoxxMD
dd7e9d72cc fix(subreddit): Fix subreddit state testing edge case and undefined criteria
* allow both over_18 and over18 criteria in case user accidentally used name from sub/comm state
* correctly determine if subreddit property exists when testing
* fix cache hit subreddit name logging
2021-09-29 10:21:16 -04:00
FoxxMD
55535ddd62 fix(regex): Fix regex generation for simple subreddit strings
* Trim value before parsing
* If not a valid regex string then when generating regex from simple string add qualifiers for beginning/end of string so any matches must be exact
2021-09-29 09:22:40 -04:00
FoxxMD
631e21452c Merge branch 'edge' 2021-09-28 16:36:13 -04:00
FoxxMD
be6fa4dd50 fix(cache): Fix accidental re-use of maps 2021-09-24 16:13:58 -04:00
FoxxMD
0d7a82836f refactor(cache): Move bot usage stats into cache
* Moving into cache means stats will persist after restart (yay!)
* Refactored stats structure to be simpler
2021-09-24 15:24:19 -04:00
FoxxMD
d9a59b6824 feat(recent): Print log statement when image processing is causing rule to take a long time 2021-09-23 13:23:58 -04:00
FoxxMD
ddbf8c3189 fix(recent): Actually use filtered activities when using submission as reference 2021-09-23 12:58:43 -04:00
FoxxMD
8393c471b2 fix(image): Dynamically import resemblejs for better compatibility on systems not supporting node-canvas
* By dynamically importing the module any user not using image comparison will not be affected by a lack of node-canvas dependency
* try-catch on import and provide a helpful error message about node-canvas dep
2021-09-23 10:38:34 -04:00
FoxxMD
fe66a2e8f7 fix(docker): Update build to build node-canvas from source 2021-09-23 10:08:26 -04:00
FoxxMD
4b0284102d fix: Improve image comparison threshold and results for typescript 2021-09-22 22:15:00 -04:00
FoxxMD
95529f14a8 feat(recent): Implement pixel-level image comparison when using a reference (image) submission 2021-09-22 16:52:56 -04:00
FoxxMD
26af2c4e4d fix(recent): don't include submission being checked when filtering by reference 2021-09-22 10:29:06 -04:00
FoxxMD
044c293f34 fix(attribution): Update aggregateOn defaults to align with expected behavior
Majority of mods that have used this rule assume it does not aggregate on reddit domains by default (only external links), which is reasonable.
So update the default to follow this assumption.
2021-09-22 10:11:25 -04:00
FoxxMD
a082c9e593 doc(attribution): Remove unused useSubmissionAsReference property 2021-09-22 09:36:44 -04:00
FoxxMD
4f3685a1f5 Merge branch 'edge' 2021-09-21 15:18:38 -04:00
FoxxMD
e242c36c09 fix(tooling): Fix tag pattern for git cliff 2021-09-21 15:18:26 -04:00
FoxxMD
d2d945db2c Merge branch 'edge' 2021-09-21 15:08:28 -04:00
FoxxMD
c5018183e0 fix(attribution): Improve parsing of domain type to fix bug with galleries
* Add `redditMedia` as distinct domain type from `self` for more granular aggregation
* Use `redditMedia` to fix bug where video and galleries were being counted as `media`
2021-09-20 16:34:29 -04:00
FoxxMD
c5358f196d feat(author): Handle shadowbanned users
* Allow checking if user is shadowbanned via authorIs (AuthorCriteria)
* try-catch on history get or author criteria to try to detect shadowbanned user for a more descriptive error
2021-09-20 13:49:35 -04:00
FoxxMD
1d9f8245f9 feat(tooling): scope-based sorting with BC note for git cliff generation 2021-09-20 11:51:25 -04:00
FoxxMD
20b37f3a40 Initial git cliff config 2021-09-20 11:03:37 -04:00
174 changed files with 10235 additions and 2848 deletions

View File

@@ -1,8 +1,8 @@
node_modules
Dockerfile
.dockerignore
.gitignore
.git
src/logs
/docs
.github
/docs/
/node_modules/

1
.gitignore vendored
View File

@@ -381,4 +381,5 @@ dist
.pnp.*
**/src/**/*.js
!src/Web/assets/public/yaml/*
**/src/**/*.map

View File

@@ -1,13 +1,17 @@
FROM node:16-alpine3.12
FROM node:16-alpine3.14 as base
ENV TZ=Etc/GMT
RUN apk update
# vips required to run sharp library for image comparison
RUN echo "http://dl-4.alpinelinux.org/alpine/v3.14/community" >> /etc/apk/repositories \
&& apk --no-cache add vips
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /usr/app
FROM base as build
COPY package*.json ./
COPY tsconfig.json .
@@ -15,7 +19,13 @@ RUN npm install
ADD . /usr/app
RUN npm run build
RUN npm run build && rm -rf node_modules
FROM base as app
COPY --from=build /usr/app /usr/app
RUN npm install --production
ENV NPM_CONFIG_LOGLEVEL debug

View File

@@ -26,6 +26,8 @@ Some feature highlights:
* Author criteria (name, css flair/text, age, karma, moderator status, and [Toolbox User Notes](https://www.reddit.com/r/toolbox/wiki/docs/usernotes))
* Activity state (removed, locked, distinguished, etc.)
* Rules and Actions support named references (write once, reference anywhere)
* [**Image Comparisons**](/docs/imageComparison.md) via fingerprinting and/or pixel differences
* [**Repost detection**](/docs/examples/repost) with support for external services (youtube, etc...)
* Global/subreddit-level **API caching**
* Support for [Toolbox User Notes](https://www.reddit.com/r/toolbox/wiki/docs/usernotes) as criteria or Actions (writing notes)
* Docker container support
@@ -124,7 +126,7 @@ Moderator view/invite and authorization:
A built-in editor using [monaco-editor](https://microsoft.github.io/monaco-editor/) makes editing configurations easy:
* Automatic JSON syntax validation and formatting
* Automatic JSON or YAML syntax validation and formatting
* Automatic Schema (subreddit or operator) validation
* All properties are annotated via hover popups
* Unauthenticated view via `yourdomain.com/config`

View File

@@ -17,12 +17,22 @@
"REFRESH_TOKEN": {
"description": "Refresh token retrieved from authenticating an account with your Reddit Application",
"value": "",
"required": true
"required": false
},
"ACCESS_TOKEN": {
"description": "Access token retrieved from authenticating an account with your Reddit Application",
"value": "",
"required": true
"required": false
},
"REDIRECT_URI": {
"description": "Redirect URI you specified when creating your Reddit Application. Required if you want to use the web interface. In the provided example replace 'your-heroku-app-name' with the name of your HEROKU app.",
"value": "https://your-heroku-6app-name.herokuapp.com/callback",
"required": false
},
"OPERATOR": {
"description": "Your reddit username WITHOUT any prefixes EXAMPLE /u/FoxxMD => FoxxMD. Specified user will be recognized as an admin.",
"value": "",
"required": false
},
"WIKI_CONFIG": {
"description": "Relative url to contextbot wiki page EX https://reddit.com/r/subreddit/wiki/<path>",

67
cliff.toml Normal file
View File

@@ -0,0 +1,67 @@
# configuration file for git-cliff (0.1.0)
[changelog]
# changelog header
header = """
# Changelog
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://tera.netlify.app/docs/#introduction
body = """
{% if version %}\
## [{{ version | replace(from="v", to="") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits
| filter(attribute="scope")
| sort(attribute="scope") %}
- *({{commit.scope}})* {{ commit.message | upper_first }}
{%- if commit.breaking %}
{% raw %} {% endraw %}- **BREAKING**: {{commit.breaking_description}}
{%- endif -%}
{%- endfor -%}
{%- for commit in commits %}
{%- if commit.scope -%}
{% else -%}
- *(No Category)* {{ commit.message | upper_first }}
{% if commit.breaking -%}
{% raw %} {% endraw %}- **BREAKING**: {{commit.breaking_description}}
{% endif -%}
{% endif -%}
{% endfor -%}
{% endfor %}
"""
# remove the leading and trailing whitespaces from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""
[git]
# allow only conventional commits
# https://www.conventionalcommits.org
conventional_commits = true
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "Features"},
{ message = "^fix", group = "Bug Fixes"},
{ message = "^doc", group = "Documentation"},
{ message = "^perf", group = "Performance"},
{ message = "^refactor", group = "Refactor"},
{ message = "^style", group = "Styling"},
{ message = "^test", group = "Testing"},
{ message = "^chore\\(release\\): prepare for", skip = true},
{ message = "^chore", group = "Miscellaneous Tasks"},
{ body = ".*security", group = "Security"},
]
# filter out the commits that are not matched by commit parsers
filter_commits = false
# glob pattern for matching git tags
tag_pattern = "[0-9]*"
# regex for skipping tags
skip_tags = "v0.1.0-beta.1"

View File

@@ -18,6 +18,7 @@
* [Activities `window`](#activities-window)
* [Comparisons](#thresholds-and-comparisons)
* [Activity Templating](/docs/actionTemplating.md)
* [Image Comparisons](#image-comparisons)
* [Best Practices](#best-practices)
* [Named Rules](#named-rules)
* [Rule Order](#rule-order)
@@ -101,6 +102,7 @@ Find detailed descriptions of all the Rules, with examples, below:
* [History](/docs/examples/history)
* [Author](/docs/examples/author)
* [Regex](/docs/examples/regex)
* [Repost](/docs/examples/repost)
### Rule Set
@@ -268,6 +270,12 @@ The duration value compares a time range from **now** to `duration value` time i
Refer to [duration values in activity window documentation](/docs/activitiesWindow.md#duration-values) as well as the individual rule/criteria schema to see what this duration is comparing against.
### Image Comparisons
ContextMod implements two methods for comparing **image content**, perceptual hashing and pixel-to-pixel comparisons. Comparisons can be used to filter activities in some activities.
See [image comparison documentation](/docs/imageComparison.md) for a full reference.
## Best Practices
### Named Rules

View File

@@ -17,6 +17,7 @@ This directory contains example of valid, ready-to-go configurations for Context
* [History](/docs/examples/history)
* [Author](/docs/examples/author)
* [Regex](/docs/examples/regex)
* [Repost](/docs/examples/repost)
* [Toolbox User Notes](/docs/examples/userNotes)
* [Advanced Concepts](/docs/examples/advancedConcepts)
* [Rule Sets](/docs/examples/advancedConcepts/ruleSets.json5)

View File

@@ -18,3 +18,5 @@ Which can then be used in conjunction with a [`window`](https://github.com/FoxxM
* [Trigger if regex matches at least 3 of Author's last 10 activities](/docs/examples/regex/matchActivityThresholdHistory.json5)
* [Trigger if there are 5 regex matches in the Author's last 10 activities](/docs/examples/regex/matchTotalHistoryActivity.json5)
* [Trigger if there are 5 regex matches in the Author's last 10 comments](/docs/examples/regex/matchSubsetHistoryActivity.json5)
* [Remove comments that are spamming discord links](/docs/examples/regex/removeDiscordSpam.json5)
* Differs from just using automod because this config can allow one-off/organic links from users who DO NOT spam discord links but will still remove the comment if the user is spamming them

View File

@@ -0,0 +1,73 @@
{
"checks": [
{
"name": "remove discord spam",
"notifyOnTrigger": true,
"description": "remove comments from users who are spamming discord links",
"kind": "comment",
"authorIs": {
"exclude": [
{
"isMod": true
}
]
},
"itemIs": [
{
"removed": false,
"approved": false,
}
],
"condition": "OR",
"rules": [
{
// set to false if you want to allow comments with a discord link ONLY IF
// the author doesn't have a history of spamming discord links
// -- basically allows one-off/organic discord links
"enable": true,
"name": "linkOnlySpam",
"kind": "regex",
"criteria": [
{
"name": "only link",
"regex": "/^.*(discord\\.gg\\/[\\w\\d]+)$/i",
}
]
},
{
"condition": "AND",
"rules": [
{
"name": "linkAnywhereSpam",
"kind": "regex",
"criteria": [
{
"name": "contains link anywhere",
"regex": "/^.*(discord\\.gg\\/[\\w\\d]+).*$/i",
}
]
},
{
"name": "linkAnywhereHistoricalSpam",
"kind": "regex",
"criteria": [
{
"name": "contains links anywhere historically",
"regex": "/^.*(discord\\.gg\\/[\\w\\d]+).*$/i",
"totalMatchThreshold": ">= 3",
"lookAt": "comments",
"window": 10
}
]
}
]
}
],
"actions": [
{
"kind": "remove"
}
]
}
]
}

View File

@@ -0,0 +1,703 @@
The **Repost** rule is used to find reposts for both **Submissions** and **Comments**, depending on what type of **Check** it is used on.
Note: This rule is for searching **all of Reddit** for reposts, as opposed to just the Author of the Activity being checked. If you only want to check for reposts by the Author of the Activity being checked you should use the [Repeat Activity](/docs/examples/repeatActivity) rule.
# TLDR
Out of the box CM generates a repost rule with sensible default behavior without any configuration. You do not need to configure any of below options (facets, modifiers, criteria) yourself in order to have a working repost rule. Default behavior is as follows...
* When looking for Submission reposts CM will find any Submissions with
* a very similar title
* or independent of title...
* any crossposts/duplicates
* any submissions with the exact URL
* When looking for Comment reposts CM will do the above AND THEN
* compare the top 50 most-upvoted comments from the top 10 most-upvoted Submissions against the comment being checked
* compare any items found from external source (Youtube comments, etc...) against the comment being checked
# Configuration
## Search Facets
ContextMod has several ways to search for reposts -- all of which look at different elements of a Submission in order to find repost candidates. You can define any/all of these **Search Facets** you want to use to search Reddit inside the configuration for the Repost Rule in the `searchOn` property.
### Usage
Facets are specified in the `searchOn` array property within the rule's configuration.
**String**
Specify one or more types of facets as a string to use their default configurations
<details>
```json5
{
"kind": "repost",
"criteria": [
{
// ...
"searchOn": ["title", "url", "crossposts"],
// ....
}
]
}
```
</details>
**Object**
**string** and object configurations can be mixed
<details>
```json5
{
"kind": "repost",
"criteria": [
{
// ...
"searchOn": [
"title",
{
"kind": "url",
// could also specify multiple types to use the same config for all
//"kind": ["url", "duplicates"]
"matchScore": 90,
//...
},
"external"
],
// ....
}
]
}
```
</details>
### Facet Types
* **title** -- search reddit for Submissions with a similar title
* **url** -- search reddit for Submissions with the same URL
* **duplicates** -- get all Submissions **reddit has identified** as duplicates that are **NOT** crossposts
* these are found under *View discussions in other communities* (new reddit) or *other discussions* (old reddit) on the Submission
* **crossposts** -- get all Submissions where the current Submission is the source of an **official** crosspost
* this differs from duplicates in that crossposts use reddit's built-in crosspost functionality, respect subreddit crosspost rules, and link back to the original Submission
* **external** -- get items from the Submission's link source that may be reposted (currently implemented for **Comment Checks** only)
* When the Submission link is for...
* **Youtube** -- get top comments on video by replies/like count
* **NOTE:** An **API Key** for the [Youtube Data API](https://developers.google.com/youtube/v3) must be provided for this facet to work. This can be provided by the operator alongside [bot credentials](/docs/operatorConfiguration.md) or in the top-level `credentials` property for a [subreddit configuration.](https://json-schema.app/view/%23?url=https%3A%2F%2Fraw.githubusercontent.com%2FFoxxMD%2Freddit-context-bot%2Fmaster%2Fsrc%2FSchema%2FApp.json)
### Facet Modifiers
For all **Facets**, except for **external**, there are options that be configured to determine if the found Submissions is a "valid" repost IE filtering. These options can be configured **per facet**.
* **matchScore** -- The percentage, as a whole number, of a repost title that must match the title being checked in order to consider both a match
* **minWordCount** -- The minimum number of words a title must have
* **caseSensitive** -- If the match comparison should be case-sensitive (defaults to `false`)
Additionally, the current Activity's title and/or each repost's title can be transformed before matching:
* **transformations** -- An array of SearchAndReplace objects used to transform the repost's title
* **transformationsActivity** -- An array of SearchAndReplace objects used to transform the current Activity's title
#### Modifier Defaults
To make facets easier to use without configuration sensible defaults are applied to each when no other configuration is defined...
* **title**
* `matchScore: 85` -- The candidate repost's title must be at least 85% similar to the current Activity's title
* `minWordCount: 2` -- The candidate repost's title must have at least 2 words
For `url`,`duplicates`, and `crossposts` the only default is `matchScore: 0` because the assumption is you want to treat any actual dups/x-posts or exact URLs as reposts, regardless of their title.
## Additional Criteria Properties
A **criteria** object may also specify some additional tests to run against the reposts found from searching.
### For Submissions and Comments
#### Occurrences
Define a set of criteria to test against the **number of reposts**, **time reposts were created**, or both.
##### Count
<details>
```json5
{
"kind": "repost",
"criteria": [
{
// ...
"searchOn": ["title", "url", "crossposts"],
"occurrences": {
"criteria": [
{
// passes if BOTH tests are true
"count": {
"condition": "AND", // default is AND
"test": [
"> 3", // TRUE if there are GREATER THAN 3 reposts found
"<= 5" // TRUE if there are LESS THAN OR EQUAL TO 5 reposts found
]
}
}
],
}
}
]
}
```
</details>
##### Time
Define a test or array of tests to run against **when reposts were created**
<details>
```json5
{
"kind": "repost",
"criteria": [
{
// ...
"searchOn": [
"title",
"url",
"crossposts"
],
"occurrences": {
"criteria": [
{
time: {
// how to test array of comparisons. AND => all must pass, OR => any must pass
"condition": "AND",
"test": [
{
// which of the found reposts to test the time comparison on
//
// "all" => ALL reposts must pass time comparison
// "any" => ANY repost must pass time comparison
// "newest" => The newest (closest in time to now) repost must pass time comparison
// "oldest" => The oldest (furthest in time from now) repost must pass time comparison
//
"testOn": "all",
// Tested items must be OLDER THAN 3 months
"condition": "> 3 months"
}
]
}
}
]
},
}
]
}
```
</details>
### For Comments
When the rule is run in a **Comment Check** you may specify text comparisons (like those found in Search Facets) to run on the contents of the repost comments *against* the contents of the comment being checked.
* **matchScore** -- The percentage, as a whole number, of a repost comment that must match the comment being checked in order to consider both a match (defaults to 85% IE `85`)
* **minWordCount** -- The minimum number of words a comment must have
* **caseSensitive** -- If the match comparison should be case-sensitive (defaults to `false`)
# Examples
Examples of a *full* CM configuration, including the Repost Rule, in various scenarios. In each scenario the parts of the configuration that affect the rule are indicated.
## Submissions
When the Repost Rule is run on a **Submission Check** IE the activity being checked is a Submission.
### Default Behavior (No configuration)
This is the same behavior described in the [TLDR](#TLDR) section above -- find any submissions with:
* a very similar title (85% or more the same)
* or ignoring title...
* any crossposts/duplicates
* any submissions with the exact URL
<details>
```json5
{
"polling": [
"unmoderated"
],
"checks": [
{
"name": "subRepost",
"description": "Check if submission has been reposted",
// kind specifies this check is for SUBMISSIONS
"kind": "submission",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost"
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This submission was reposted"
}
]
}
]
}
```
</details>
### Search by Title Only
Find any submissions with:
* a very similar title (85% or more the same)
<details>
```json5
{
"polling": [
"unmoderated"
],
"checks": [
{
"name": "subRepost",
"description": "Check if submission has been reposted",
// kind specifies this check is for SUBMISSIONS
"kind": "submission",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost",
"criteria": [
{
// specify only title to search on
"searchOn": [
"title" // uses default configuration since only string is specified
]
}
]
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This submission was reposted"
}
]
}
]
}
```
</details>
### Search by Title only and specify similarity percentage
* a very similar title (95% or more the same)
<details>
```json5
{
"polling": [
"unmoderated"
],
"checks": [
{
"name": "subRepost",
"description": "Check if submission has been reposted",
// kind specifies this check is for SUBMISSIONS
"kind": "submission",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost",
"criteria": [
{
// specify only title to search on
"searchOn": [
{
"kind": "title",
// titles must be 95% or more similar
"matchScore": "95"
}
]
}
]
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This submission was reposted"
}
]
}
]
}
```
</details>
### Search by Title, specify similarity percentage, AND any duplicates
<details>
```json5
{
"polling": [
"unmoderated"
],
"checks": [
{
"name": "subRepost",
"description": "Check if submission has been reposted",
// kind specifies this check is for SUBMISSIONS
"kind": "submission",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost",
"criteria": [
{
"searchOn": [
// look for duplicates (NON crossposts) using default configuration
"duplicates",
// search by title
{
"kind": "title",
// titles must be 95% or more similar
"matchScore": "95"
}
]
}
]
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This submission was reposted"
}
]
}
]
}
```
</details>
### Approve Submission if not reposted in the last month, by title
<details>
```json5
{
"polling": [
"unmoderated"
],
"checks": [
{
"name": "subRepost",
"description": "Check there are no reposts with same title in the last month",
// kind specifies this check is for SUBMISSIONS
"kind": "submission",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost",
"criteria": [
{
"searchOn": [
"title"
],
"occurrences": {
// if EITHER criteria is TRUE then it "passes"
"condition": "OR",
"criteria": [
// first criteria:
// TRUE if there are LESS THAN 1 reposts (no reposts found)
{
"count": {
"test": ["< 1"]
}
},
// second criteria:
// TRUE if the newest repost is older than one month
{
"time": {
"test": [
{
"testOn": "newest",
"condition": "> 1 month"
}
]
}
}
]
},
}
]
},
//
// repost rule configuration is above
],
"actions": [
{
// approve this post since we know it is not a repost of anything within the last month
"kind": "approve",
}
]
}
]
}
```
</details>
## Comments
### Default Behavior (No configuration)
This is the same behavior described in the [TLDR](#TLDR) section above -- find any submissions with:
* a very similar title (85% or more the same)
* or ignoring title...
* any crossposts/duplicates
* any submissions with the exact URL
* If comment being checked is on a Submission for Youtube then get top 50 comments on youtube video as well...
AND THEN
* sort submissions by votes
* take top 20 (upvoted) comments from top 10 (upvoted) submissions
* sort comments by votes, take top 50 + top 50 external items
FINALLY
* filter all gathered comments by default `matchScore: 85` to find very similar matches
* rules is triggered if any are found
<details>
```json5
{
"polling": [
"newComm"
],
"checks": [
{
"name": "commRepost",
"description": "Check if comment has been reposted",
// kind specifies this check is for COMMENTS
"kind": "common",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost"
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This comment was reposted"
}
]
}
]
}
```
</details>
### Search by external (youtube) comments only
<details>
```json5
{
"polling": [
"newComm"
],
"checks": [
{
"name": "commRepost",
"description": "Check if comment has been reposted from youtube",
// kind specifies this check is for SUBMISSIONS
"kind": "comment",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost",
"criteria": [
{
// specify only external (youtube) to search on
"searchOn": [
"external"
]
}
]
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This comment was reposted from youtube"
}
]
}
]
}
```
</details>
### Search by external (youtube) comments only, with higher comment match percentage
<details>
```json5
{
"polling": [
"newComm"
],
"checks": [
{
"name": "commRepost",
"description": "Check if comment has been reposted from youtube",
// kind specifies this check is for SUBMISSIONS
"kind": "comment",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost",
"criteria": [
{
// specify only external (youtube) to search on
"searchOn": [
"external"
],
"matchScore": 95 // matchScore for comments is on criteria instead of searchOn config...
},
]
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This comment was reposted from youtube"
}
]
}
]
}
```
</details>
### Search by external (youtube) comments and submission URL, with higher comment match percentage
<details>
```json5
{
"polling": [
"newComm"
],
"checks": [
{
"name": "commRepost",
"description": "Check if comment has been reposted",
// kind specifies this check is for SUBMISSIONS
"kind": "comment",
"condition": "AND",
"rules": [
// repost rule configuration is below
//
{
"kind": "repost",
"criteria": [
{
// specify only external (youtube) to search on
"searchOn": [
"external",
// can specify any/all submission search facets to acquire comments from
"url"
],
"matchScore": 95 // matchScore for comments is on criteria instead of searchOn config...
},
]
},
//
// repost rule configuration is above
],
"actions": [
{
"kind": "report",
"content": "This comment was reposted from youtube or from submission with the same URL"
}
]
}
]
}
```
</details>

View File

@@ -39,3 +39,26 @@ then remove the submission
### [Remove comment if the user has posted the same comment 4 or more times in a row](/docs/examples/subredditReady/commentSpam.json5)
If the user made the same comment (with some fuzzy matching) 4 or more times in a row in the past (50 activities or 6 months) then remove the comment.
### [Remove comment if it is discord invite link spam](/docs/examples/subredditReady/discordSpam.json5)
This rule goes a step further than automod can by being more discretionary about how it handles this type of spam.
* Remove the comment and **ban a user** if:
* Comment being checked contains **only** a discord link (no other text) AND
* Discord links appear **anywhere** in three or more of the last 10 comments the Author has made
otherwise...
* Remove the comment if:
* Comment being checked contains **only** a discord link (no other text) OR
* Comment contains a discord link **anywhere** AND
* Discord links appear **anywhere** in three or more of the last 10 comments the Author has made
Using these checks ContextMod can more easily distinguish between these use cases for a user commenting with a discord link:
* actual spammers who only spam a discord link
* users who may comment with a link but have context for it either in the current comment or in their history
* users who many comment with a link but it's a one-off event (no other links historically)
Additionally, you could modify both/either of these checks to not remove one-off discord link comments but still remove if the user has a historical trend for spamming links

View File

@@ -0,0 +1,75 @@
{
"polling": ["newComm"],
"checks": [
{
"name": "ban discord only spammer",
"description": "ban a user who spams only a discord link many times historically",
"kind": "comment",
"condition": "AND",
"rules": [
"linkOnlySpam",
"linkAnywhereHistoricalSpam",
],
"actions": [
{
"kind": "remove"
},
{
"kind": "ban",
"content": "spamming discord links"
}
]
},
{
"name": "remove discord spam",
"description": "remove comments from users who only link to discord or mention discord link many times historically",
"kind": "comment",
"condition": "OR",
"rules": [
{
"name": "linkOnlySpam",
"kind": "regex",
"criteria": [
{
"name": "only link",
"regex": "/^.*(discord\\.gg\\/[\\w\\d]+)$/i",
}
]
},
{
"condition": "AND",
"rules": [
{
"name": "linkAnywhereSpam",
"kind": "regex",
"criteria": [
{
"name": "contains link anywhere",
"regex": "/^.*(discord\\.gg\\/[\\w\\d]+).*$/i",
}
]
},
{
"name": "linkAnywhereHistoricalSpam",
"kind": "regex",
"criteria": [
{
"name": "contains links anywhere historically",
"regex": "/^.*(discord\\.gg\\/[\\w\\d]+).*$/i",
"totalMatchThreshold": ">= 3",
"lookAt": "comments",
"window": 10
}
]
}
]
}
],
"actions": [
{
"kind": "remove"
}
]
}
]
}

View File

@@ -50,6 +50,18 @@ tsc -p .
### [Heroku Quick Deploy](https://heroku.com/about)
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://dashboard.heroku.com/new?template=https://github.com/FoxxMD/context-mod)
This template provides a **web** and **worker** dyno for heroku.
* **Web** -- Will run the bot **and** the web interface for ContextMod.
* **Worker** -- Will run **just** the bot.
Be aware that Heroku's [free dyno plan](https://devcenter.heroku.com/articles/free-dyno-hours#dyno-sleeping) enacts some limits:
* A **Web** dyno will go to sleep (pause) after 30 minutes without web activity -- so your bot will ALSO go to sleep at this time
* The **Worker** dyno **will not** go to sleep but you will NOT be able to access the web interface. You can, however, still see how Cm is running by reading the logs for the dyno.
If you want to use a free dyno it is recommended you perform first-time setup (bot authentication and configuration, testing, etc...) with the **Web** dyno, then SWITCH to a **Worker** dyno so it can run 24/7.
# Bot Authentication
Next you need to create a bot and authenticate it with Reddit. Follow the [bot authentication guide](/docs/botAuthentication.md) to complete this step.

201
docs/imageComparison.md Normal file
View File

@@ -0,0 +1,201 @@
# Overview
ContextMod supports comparing image content, for the purpose of detecting duplicates, with two different but complimentary systems. Image comparison behavior is available for the following rules:
* [Recent Activity](/docs/examples/recentActivity)
* Repeat Activity (In-progress)
To enable comparisons reference the example below (at the top-level of your rule) and configure as needed:
```json5
{
"name": "ruleWithImageDetection",
"kind": "recentActivity",
// Add block below...
//
"imageDetection": {
// enables image comparison
"enable": true,
// The difference, in percentage, between the reference submission and the submissions being checked
// must be less than this number to consider the images "the same"
"threshold": 5,
// optional
// set the behavior for determining if image comparison should occur on a URL:
//
// "extension" => try image detection if URL ends in a known image extension (jpeg, gif, png, bmp, etc.)
// "unknown" => try image detection if URL ends in known image extension OR there is no extension OR the extension is unknown (not video, html, doc, etc...)
// "all" => ALWAYS try image detection, regardless of URL extension
//
// if fetchBehavior is not defined then "extension" is the default
"fetchBehavior": "extension",
},
//
// And above ^^^
...
}
```
**Perceptual Hashing** (`hash`) and **Pixel Comparisons** (`pixel`) may be used at the same time. Refer to the documentation below to see how they interact.
**Note:** Regardless of `fetchBehavior`, if the response from the URL does not indicate it is an image then image detection will not occur. IE Response `Content-Type` must contain `image`
## Prerequisites
Both image comparison systems require [Sharp](https://sharp.pixelplumbing.com/) as a dependency. Most modern operating systems running Node.js >= 12.13.0 do not require installing additional dependencies in order to use Sharp.
If you are using the docker image for ContextMod (`foxxmd/context-mod`) Sharp is built-in.
If you are installing ContextMod using npm then **Sharp should be installed automatically as an optional dependency.**
**If you do not want to install it automatically** install ContextMod with the following command:
```
npm install --no-optional
```
If you are using ContextMod as part of a larger project you may want to require Sharp in your own package:
```
npm install sharp@0.29.1 --save
```
# Comparison Systems
## Perceptual Hashing
[Perceptual Hashing](https://en.wikipedia.org/wiki/Perceptual_hashing) creates a text fingerprint of an image by:
* Dividing up the image into a grid
* Using an algorithm to derive a value from the pixels in each grid
* Adding up all the values to create a unique string (the "fingerprint")
An example of how a perceptual hash can work [can be found here.](https://www.hackerfactor.com/blog/?/archives/432-Looks-Like-It.html)
ContextMod uses [blockhash-js](https://github.com/commonsmachinery/blockhash-js) which is a javascript implementation of the algorithm described in the paper [Block Mean Value Based Image Perceptual Hashing by Bian Yang, Fan Gu and Xiamu Niu.](https://ieeexplore.ieee.org/document/4041692)
**Advantages**
* Low memory requirements and not CPU intensive
* Does not require any image transformations
* Hash results can be stored to make future comparisons even faster and skip downloading images (cached by url)
* Resolution-independent
**Disadvantages**
* Hash is weak when image differences are based only on color
* Hash is weak when image contains lots of text
* Higher accuracy requires larger calculation (more bits required)
**When should I use it?**
* General duplicate detection
* Comparing many images
* Comparing the same images often
### How To Use
If `imageDetection.enable` is `true` then hashing is enabled by default and no further configuration is required.
To further configure hashing refer to this code block:
```json5
{
"name": "ruleWithImageDetectionAndConfiguredHashing",
"kind": "recentActivity",
"imageDetection": {
"enable": true,
// Add block below...
//
"hash": {
// enable or disable hash comparisons (enabled by default)
"enable": true,
// determines accuracy of hash and granularity of hash comparison (comparison to other hashes)
// the higher the bits the more accurate the comparison
//
// NOTE: Hashes of different sizes (bits) cannot be compared. If you are caching hashes make sure all rules where results may be shared use the same bit count to ensure hashes can be compared. Otherwise hashes will be recomputed.
"bits": 32, // default is 32 if not defined
//
// number of seconds to cache an image hash
"ttl": 60, // default is 60 if not defined
//
// "High Confidence" Threshold
// If the difference in comparison is equal to or less than this number the images are considered the same and pixel comparison WILL NOT occur
//
// Defaults to the parent-level `threshold` value if not present
//
// Use null if you want pixel comparison to ALWAYS occur (softThreshold must be present)
"hardThreshold": 5,
//
// "Low Confidence" Threshold -- only used if `pixel` is enabled
// If the difference in comparison is:
//
// 1) equal to or less than this value and
// 2) the value is greater than `hardThreshold`
//
// the images will be compared using the `pixel` method
"softThreshold": 0,
},
//
// And above ^^^
//"pixel": {...}
},
//...
```
## Pixel Comparison
This approach is as straight forward as it sounds. Both images are compared, pixel by pixel, to determine the difference between the two. ContextMod uses [pixelmatch](https://github.com/mapbox/pixelmatch) to do the comparison.
**Advantages**
* Extremely accurate, high-confidence on difference percentage
* Strong when comparing text-based images or color-only differences
**Disadvantages**
* High memory requirements (10-30MB per comparison) and CPU intensive
* Weak against similar images with different aspect ratios
* Requires image transformations (resize, crop) before comparison
* Can only store image-to-image results (no single image fingerprints)
**When should I use it?**
* Require very high accuracy in comparison results
* Comparing mostly text-based images or subtle color/detail differences
* As a secondary, high-confidence confirmation of comparison result after hashing
### How To Use
By default pixel comparisons **are not enabled.** They must be explicitly enabled in configuration.
Pixel comparisons will be performed in either of these scenarios:
* pixel is enabled, hashing is enabled and `hash.softThreshold` is defined
* When a comparison occurs that is less different than `softThreshold` but more different then `hardThreshold` (or `"hardThreshold": null`), then pixel comparison will occur as a high-confidence check
* Example
* hash comparison => 7% difference
* `"softThreshold": 10`
* `"hardThreshold": 4`
* `hash.enable` is `false` and `pixel.enable` is true
* hashing is skipped entirely and only pixel comparisons are performed
To configure pixel comparisons refer to this code block:
```json5
{
"name": "ruleWithImageDetectionAndPixelEnabled",
"kind": "recentActivity",
"imageDetection": {
//"hash": {...}
"pixel": {
// enable or disable pixel comparisons (disabled by default)
"enable": true,
// if the comparison difference percentage is equal to or less than this value the images are considered the same
//
// if not defined the value from imageDetection.threshold will be used
"threshold": 5
}
},
//...
```

29
heroku.Dockerfile Normal file
View File

@@ -0,0 +1,29 @@
FROM node:16-alpine3.14
ENV TZ=Etc/GMT
# vips required to run sharp library for image comparison
RUN echo "http://dl-4.alpinelinux.org/alpine/v3.14/community" >> /etc/apk/repositories \
&& apk --update add vips
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /usr/app
COPY package*.json ./
COPY tsconfig.json .
RUN npm install
ADD . /usr/app
RUN npm run build
ENV NPM_CONFIG_LOGLEVEL debug
ARG log_dir=/home/node/logs
RUN mkdir -p $log_dir
VOLUME $log_dir
ENV LOG_DIR=$log_dir
CMD [ "node", "src/index.js", "run", "all", "--port $PORT"]

View File

@@ -1,3 +1,4 @@
build:
docker:
worker: Dockerfile
web: heroku.Dockerfile
worker: heroku.Dockerfile

4312
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,6 @@
"test": "echo \"Error: no tests installed\" && exit 1",
"build": "tsc",
"start": "node src/index.js run",
"guard": "ts-auto-guard src/JsonConfig.ts",
"schema": "npm run -s schema-app & npm run -s schema-ruleset & npm run -s schema-rule & npm run -s schema-action & npm run -s schema-config",
"schema-app": "typescript-json-schema tsconfig.json JSONConfig --out src/Schema/App.json --required --tsNodeRegister --refs",
"schema-ruleset": "typescript-json-schema tsconfig.json RuleSetJson --out src/Schema/RuleSet.json --required --tsNodeRegister --refs",
@@ -26,8 +25,10 @@
"license": "ISC",
"dependencies": {
"@awaitjs/express": "^0.8.0",
"@googleapis/youtube": "^2.0.0",
"@stdlib/regexp-regexp": "^0.0.6",
"ajv": "^7.2.4",
"ansi-regex": ">=5.0.1",
"async": "^3.2.0",
"autolinker": "^3.14.3",
"body-parser": "^1.19.0",
@@ -50,30 +51,34 @@
"got": "^11.8.2",
"he": "^1.2.0",
"http-proxy": "^1.18.1",
"image-size": "^1.0.0",
"js-yaml": "^4.1.0",
"json5": "^2.2.0",
"jsonwebtoken": "^8.5.1",
"leven": "^3.1.0",
"lodash": "^4.17.21",
"lru-cache": "^6.0.0",
"monaco-editor": "^0.27.0",
"mustache": "^4.2.0",
"node-fetch": "^2.6.1",
"normalize-url": "^6.1.0",
"object-hash": "^2.2.0",
"p-event": "^4.2.0",
"p-map": "^4.0.0",
"passport": "^0.4.1",
"passport-custom": "^1.1.1",
"passport-jwt": "^4.0.0",
"pixelmatch": "^5.2.1",
"pretty-print-json": "^1.0.3",
"safe-stable-stringify": "^1.1.1",
"snoostorm": "^1.5.2",
"snoowrap": "^1.23.0",
"socket.io": "^4.1.3",
"string-similarity": "^4.0.4",
"tcp-port-used": "^1.0.2",
"triple-beam": "^1.3.0",
"typescript": "^4.3.4",
"webhook-discord": "^3.7.7",
"winston": "FoxxMD/winston#fbab8de969ecee578981c77846156c7f43b5f01e",
"winston": "github:FoxxMD/winston#fbab8de969ecee578981c77846156c7f43b5f01e",
"winston-daily-rotate-file": "^4.5.5",
"winston-duplex": "^0.1.1",
"winston-transport": "^4.4.0",
@@ -101,10 +106,15 @@
"@types/object-hash": "^2.1.0",
"@types/passport": "^1.0.7",
"@types/passport-jwt": "^3.0.6",
"@types/pixelmatch": "^5.2.4",
"@types/sharp": "^0.29.2",
"@types/string-similarity": "^4.0.0",
"@types/tcp-port-used": "^1.0.0",
"@types/triple-beam": "^1.3.2",
"ts-auto-guard": "*",
"ts-json-schema-generator": "^0.93.0",
"typescript-json-schema": "^0.50.1"
},
"optionalDependencies": {
"sharp": "^0.29.1"
}
}

View File

@@ -58,13 +58,13 @@ export class MessageAction extends Action {
if(this.to !== undefined) {
// parse to value
try {
const entityData = parseRedditEntity(this.to);
const entityData = parseRedditEntity(this.to, 'user');
if(entityData.type === 'user') {
recipient = entityData.name;
} else {
recipient = `/r/${entityData.name}`;
}
} catch (err) {
} catch (err: any) {
this.logger.error(`'to' field for message was not in a valid format. See ${REDDIT_ENTITY_REGEX_URL} for valid examples`);
this.logger.error(err);
err.logged = true;

View File

@@ -98,7 +98,7 @@ export abstract class Action {
actRes.run = true;
const results = await this.process(item, ruleResults, runtimeDryrun);
return {...actRes, ...results};
} catch (err) {
} catch (err: any) {
if(!(err instanceof LoggedError)) {
this.logger.error(`Encountered error while running`, err);
}

View File

@@ -4,6 +4,7 @@ import {getLogger} from "./Utils/loggerFactory";
import {Invokee, OperatorConfig} from "./Common/interfaces";
import Bot from "./Bot";
import LoggedError from "./Utils/LoggedError";
import {sleep} from "./util";
export class App {
@@ -66,13 +67,14 @@ export class App {
try {
await b.testClient();
await b.buildManagers();
await sleep(2000);
b.runManagers(causedBy).catch((err) => {
this.logger.error(`Unexpected error occurred while running Bot ${b.botName}. Bot must be re-built to restart`);
if (!err.logged || !(err instanceof LoggedError)) {
this.logger.error(err);
}
});
} catch (err) {
} catch (err: any) {
if (b.error === undefined) {
b.error = err.message;
}

View File

@@ -1,5 +1,6 @@
import {DurationComparor, UserNoteCriteria} from "../Rule";
import {CompareValue, CompareValueOrPercent} from "../Common/interfaces";
import {UserNoteCriteria} from "../Rule";
import {CompareValue, CompareValueOrPercent, DurationComparor} from "../Common/interfaces";
import {parseStringToRegex} from "../util";
/**
* If present then these Author criteria are checked before running the rule. If criteria fails then the rule is skipped.
@@ -99,6 +100,24 @@ export interface AuthorCriteria {
* Does Author's account have a verified email?
* */
verified?: boolean
/**
* Is the author shadowbanned?
*
* This is determined by trying to retrieve the author's profile. If a 404 is returned it is likely they are shadowbanned
* */
shadowBanned?: boolean
/**
* An (array of) string/regular expression to test contents of an Author's profile description against
*
* If no flags are specified then the **insensitive** flag is used by default
*
* If using an array then if **any** value in the array passes the description test passes
*
* @examples [["/test$/i", "look for this string literal"]]
* */
description?: string | string[]
}
export class Author implements AuthorCriteria {
@@ -112,6 +131,8 @@ export class Author implements AuthorCriteria {
linkKarma?: string;
totalKarma?: string;
verified?: boolean;
shadowBanned?: boolean;
description?: string[];
constructor(options: AuthorCriteria) {
this.name = options.name;
@@ -123,6 +144,8 @@ export class Author implements AuthorCriteria {
this.commentKarma = options.commentKarma;
this.linkKarma = options.linkKarma;
this.totalKarma = options.totalKarma;
this.shadowBanned = options.shadowBanned;
this.description = options.description === undefined ? undefined : Array.isArray(options.description) ? options.description : [options.description];
}
}

View File

@@ -1,4 +1,4 @@
import Snoowrap, {Subreddit} from "snoowrap";
import Snoowrap, {Comment, Submission, Subreddit} from "snoowrap";
import {Logger} from "winston";
import dayjs, {Dayjs} from "dayjs";
import {Duration} from "dayjs/plugin/duration";
@@ -15,16 +15,18 @@ import {
snooLogWrapper
} from "../util";
import {Manager} from "../Subreddit/Manager";
import {ProxiedSnoowrap} from "../Utils/SnoowrapClients";
import {ExtendedSnoowrap, ProxiedSnoowrap} from "../Utils/SnoowrapClients";
import {ModQueueStream, UnmoderatedStream} from "../Subreddit/Streams";
import {BotResourcesManager} from "../Subreddit/SubredditResources";
import LoggedError from "../Utils/LoggedError";
import pEvent from "p-event";
import SimpleError from "../Utils/SimpleError";
import {isRateLimitError} from "../Utils/Errors";
class Bot {
client!: Snoowrap;
client!: ExtendedSnoowrap;
logger!: Logger;
wikiLocation: string;
dryRun?: true | undefined;
@@ -42,6 +44,7 @@ class Bot {
nannyRunning: boolean = false;
nextNannyCheck: Dayjs = dayjs().add(10, 'second');
nannyRetryHandler: Function;
managerRetryHandler: Function;
nextExpiration: Dayjs = dayjs();
botName?: string;
botLink?: string;
@@ -49,6 +52,9 @@ class Bot {
maxWorkers: number;
startedAt: Dayjs = dayjs();
sharedModqueue: boolean = false;
streamListedOnce: string[] = [];
stagger: number;
apiSample: number[] = [];
apiRollingAvg: number = 0;
@@ -80,10 +86,12 @@ class Bot {
heartbeatInterval,
},
credentials: {
clientId,
clientSecret,
refreshToken,
accessToken,
reddit: {
clientId,
clientSecret,
refreshToken,
accessToken,
},
},
snoowrap: {
proxy,
@@ -91,6 +99,7 @@ class Bot {
},
polling: {
sharedMod,
stagger = 2000,
},
queue: {
maxWorkers,
@@ -166,15 +175,15 @@ class Bot {
}
try {
this.client = proxy === undefined ? new Snoowrap(creds) : new ProxiedSnoowrap({...creds, proxy});
this.client = proxy === undefined ? new ExtendedSnoowrap(creds) : new ProxiedSnoowrap({...creds, proxy});
this.client.config({
warnings: true,
maxRetryAttempts: 5,
debug,
logger: snooLogWrapper(this.logger.child({labels: ['Snoowrap']}, mergeArr)),
continueAfterRatelimitError: true,
continueAfterRatelimitError: false,
});
} catch (err) {
} catch (err: any) {
if(this.error === undefined) {
this.error = err.message;
this.logger.error(err);
@@ -183,6 +192,9 @@ class Bot {
const retryHandler = createRetryHandler({maxRequestRetry: 8, maxOtherRetry: 1}, this.logger);
this.nannyRetryHandler = createRetryHandler({maxRequestRetry: 5, maxOtherRetry: 1}, this.logger);
this.managerRetryHandler = createRetryHandler({maxRequestRetry: 5, maxOtherRetry: 10, waitOnRetry: false, clearRetryCountAfter: 2}, this.logger);
this.stagger = stagger ?? 2000;
const modStreamErrorListener = (name: string) => async (err: any) => {
this.logger.error('Polling error occurred', err);
@@ -199,12 +211,32 @@ class Bot {
}
}
const defaultUnmoderatedStream = new UnmoderatedStream(this.client, {subreddit: 'mod'});
const modStreamListingListener = (name: string) => async (listing: (Comment|Submission)[]) => {
// dole out in order they were received
if(!this.streamListedOnce.includes(name)) {
this.streamListedOnce.push(name);
return;
}
for(const i of listing) {
const foundManager = this.subManagers.find(x => x.subreddit.display_name === i.subreddit.display_name && x.modStreamCallbacks.get(name) !== undefined);
if(foundManager !== undefined) {
foundManager.modStreamCallbacks.get(name)(i);
if(stagger !== undefined) {
await sleep(stagger);
}
}
}
}
const defaultUnmoderatedStream = new UnmoderatedStream(this.client, {subreddit: 'mod', limit: 100, clearProcessed: { size: 100, retain: 100 }});
// @ts-ignore
defaultUnmoderatedStream.on('error', modStreamErrorListener('unmoderated'));
const defaultModqueueStream = new ModQueueStream(this.client, {subreddit: 'mod'});
defaultUnmoderatedStream.on('listing', modStreamListingListener('unmoderated'));
const defaultModqueueStream = new ModQueueStream(this.client, {subreddit: 'mod', limit: 100, clearProcessed: { size: 100, retain: 100 }});
// @ts-ignore
defaultModqueueStream.on('error', modStreamErrorListener('modqueue'));
defaultModqueueStream.on('listing', modStreamListingListener('modqueue'));
this.cacheManager.modStreams.set('unmoderated', defaultUnmoderatedStream);
this.cacheManager.modStreams.set('modqueue', defaultModqueueStream);
@@ -237,19 +269,23 @@ class Bot {
}
}
async testClient() {
async testClient(initial = true) {
try {
// @ts-ignore
await this.client.getMe();
this.logger.info('Test API call successful');
} catch (err) {
this.logger.error('An error occurred while trying to initialize the Reddit API Client which would prevent the entire application from running.');
if(err.name === 'StatusCodeError') {
} catch (err: any) {
if (initial) {
this.logger.error('An error occurred while trying to initialize the Reddit API Client which would prevent the entire application from running.');
}
if (err.name === 'StatusCodeError') {
const authHeader = err.response.headers['www-authenticate'];
if (authHeader !== undefined && authHeader.includes('insufficient_scope')) {
this.logger.error('Reddit responded with a 403 insufficient_scope. Please ensure you have chosen the correct scopes when authorizing your account.');
} else if(err.statusCode === 401) {
} else if (err.statusCode === 401) {
this.logger.error('It is likely a credential is missing or incorrect. Check clientId, clientSecret, refreshToken, and accessToken');
} else if(err.statusCode === 400) {
this.logger.error('Credentials may have been invalidated due to prior behavior. The error message may contain more information.');
}
this.logger.error(`Error Message: ${err.message}`);
} else {
@@ -276,10 +312,12 @@ class Bot {
}
this.logger.info(`Bot Name${botNameFromConfig ? ' (from config)' : ''}: ${this.botName}`);
for (const sub of await this.client.getModeratedSubreddits()) {
// TODO don't know a way to check permissions yet
availSubs.push(sub);
let subListing = await this.client.getModeratedSubreddits({count: 100});
while(!subListing.isFinished) {
subListing = await subListing.fetchMore({amount: 100});
}
availSubs = subListing;
this.logger.info(`u/${user.name} is a moderator of these subreddits: ${availSubs.map(x => x.display_name_prefixed).join(', ')}`);
let subsToRun: Subreddit[] = [];
@@ -302,8 +340,8 @@ class Bot {
const normalExcludes = this.excludeSubreddits.map(x => x.toLowerCase());
subsToRun = availSubs.filter(x => !normalExcludes.includes(x.display_name.toLowerCase()));
} else {
this.logger.info('No user-defined subreddit constraints detected, will run on all moderated subreddits');
subsToRun = availSubs;
this.logger.info(`No user-defined subreddit constraints detected, will run on all moderated subreddits EXCEPT own profile (${this.botAccount})`);
subsToRun = availSubs.filter(x => x.display_name_prefixed !== this.botAccount);
}
}
@@ -313,17 +351,28 @@ class Bot {
const manager = new Manager(sub, this.client, this.logger, this.cacheManager, {dryRun: this.dryRun, sharedModqueue: this.sharedModqueue, wikiLocation: this.wikiLocation, botName: this.botName, maxWorkers: this.maxWorkers});
try {
await manager.parseConfiguration('system', true, {suppressNotification: true});
} catch (err) {
} catch (err: any) {
if (!(err instanceof LoggedError)) {
this.logger.error(`Config was not valid:`, {subreddit: sub.display_name_prefixed});
this.logger.error(err, {subreddit: sub.display_name_prefixed});
}
}
// all errors from managers will count towards bot-level retry count
manager.on('error', async (err) => await this.panicOnRetries(err));
subSchedule.push(manager);
}
this.subManagers = subSchedule;
}
// if the cumulative errors exceeds configured threshold then stop ALL managers as there is most likely something very bad happening
async panicOnRetries(err: any) {
if(!this.managerRetryHandler(err)) {
for(const m of this.subManagers) {
await m.stop();
}
}
}
async destroy(causedBy: Invokee) {
this.logger.info('Stopping heartbeat and nanny processes, may take up to 5 seconds...');
const processWait = pEvent(this.emitter, 'healthStopped');
@@ -337,7 +386,7 @@ class Bot {
async runModStreams(notify = false) {
for(const [k,v] of this.cacheManager.modStreams) {
if(!v.running && v.listeners('item').length > 0) {
if(!v.running && this.subManagers.some(x => x.modStreamCallbacks.get(k) !== undefined)) {
v.startInterval();
this.logger.info(`Starting default ${k.toUpperCase()} mod stream`);
if(notify) {
@@ -347,6 +396,7 @@ class Bot {
}
}
}
await sleep(2000);
}
}
}
@@ -359,6 +409,7 @@ class Bot {
for (const manager of this.subManagers) {
if (manager.validConfigLoaded && manager.botState.state !== RUNNING) {
await manager.start(causedBy, {reason: 'Caused by application startup'});
await sleep(this.stagger);
}
}
@@ -380,15 +431,15 @@ class Bot {
try {
await this.runApiNanny();
this.nextNannyCheck = dayjs().add(10, 'second');
} catch (err) {
this.logger.info('Delaying next nanny check for 1 minute due to emitted error');
} catch (err: any) {
this.logger.info('Delaying next nanny check for 2 minutes due to emitted error');
this.nextNannyCheck = dayjs().add(120, 'second');
}
}
if(dayjs().isSameOrAfter(this.nextHeartbeat)) {
try {
await this.heartbeat();
} catch (err) {
} catch (err: any) {
this.logger.error(`Error occurred during heartbeat check: ${err.message}`);
}
this.nextHeartbeat = dayjs().add(this.heartbeatInterval, 'second');
@@ -400,20 +451,39 @@ class Bot {
async heartbeat() {
const heartbeat = `HEARTBEAT -- API Remaining: ${this.client.ratelimitRemaining} | Usage Rolling Avg: ~${formatNumber(this.apiRollingAvg)}/s | Est Depletion: ${this.apiEstDepletion === undefined ? 'N/A' : this.apiEstDepletion.humanize()} (${formatNumber(this.depletedInSecs, {toFixed: 0})} seconds)`
this.logger.info(heartbeat);
// run sanity check to see if there is a service issue
try {
await this.testClient(false);
} catch (err: any) {
throw new SimpleError(`Something isn't right! This could be a Reddit API issue (service is down? buggy??) or an issue with the Bot account. Will not run heartbeat operations and will wait until next heartbeat (${dayjs.duration(this.nextHeartbeat.diff(dayjs())).humanize()}) to try again`);
}
let startedAny = false;
for (const s of this.subManagers) {
if(s.botState.state === STOPPED && s.botState.causedBy === USER) {
this.logger.debug('Skipping config check/restart on heartbeat due to previously being stopped by user', {subreddit: s.displayLabel});
continue;
}
try {
// ensure calls to wiki page are also staggered so we aren't hitting api hard when bot has a ton of subreddits to check
await sleep(this.stagger);
const newConfig = await s.parseConfiguration();
if(newConfig || (s.queueState.state !== RUNNING && s.queueState.causedBy === SYSTEM))
{
await s.startQueue('system', {reason: newConfig ? 'Config updated on heartbeat triggered reload' : 'Heartbeat detected non-running queue'});
}
if(newConfig || (s.eventsState.state !== RUNNING && s.eventsState.causedBy === SYSTEM))
{
await s.startEvents('system', {reason: newConfig ? 'Config updated on heartbeat triggered reload' : 'Heartbeat detected non-running events'});
const willStart = newConfig || (s.queueState.state !== RUNNING && s.queueState.causedBy === SYSTEM) || (s.eventsState.state !== RUNNING && s.eventsState.causedBy === SYSTEM);
if(willStart) {
// stagger restart
if (startedAny) {
await sleep(this.stagger);
}
startedAny = true;
if(newConfig || (s.queueState.state !== RUNNING && s.queueState.causedBy === SYSTEM))
{
await s.startQueue('system', {reason: newConfig ? 'Config updated on heartbeat triggered reload' : 'Heartbeat detected non-running queue'});
}
if(newConfig || (s.eventsState.state !== RUNNING && s.eventsState.causedBy === SYSTEM))
{
await s.startEvents('system', {reason: newConfig ? 'Config updated on heartbeat triggered reload' : 'Heartbeat detected non-running events'});
}
}
if(s.botState.state !== RUNNING && s.eventsState.state === RUNNING && s.queueState.state === RUNNING) {
s.botState = {
@@ -421,7 +491,7 @@ class Bot {
causedBy: 'system',
}
}
} catch (err) {
} catch (err: any) {
this.logger.info('Stopping event polling to prevent activity processing queue from backing up. Will be restarted when config update succeeds.')
await s.stopEvents('system', {reason: 'Invalid config will cause events to pile up in queue. Will be restarted when config update succeeds (next heartbeat).'});
if(!(err instanceof LoggedError)) {
@@ -448,7 +518,10 @@ class Bot {
// @ts-ignore
await this.client.getMe();
shouldRetry = false;
} catch (err) {
} catch (err: any) {
if(isRateLimitError(err)) {
throw err;
}
shouldRetry = await this.nannyRetryHandler(err);
if (!shouldRetry) {
throw err;
@@ -566,7 +639,7 @@ class Bot {
this.nannyMode = undefined;
}
} catch (err) {
} catch (err: any) {
this.logger.error(`Error occurred during nanny loop: ${err.message}`);
throw err;
}

View File

@@ -268,7 +268,7 @@ export abstract class Check implements ICheck {
// otherwise AND and did not return already so all passed
this.logger.info(`${PASS} => Rules: ${resultsSummary(allResults, this.condition)}`);
return [true, allRuleResults];
} catch (e) {
} catch (e: any) {
e.logged = true;
this.logger.warn(`Running rules failed due to uncaught exception`, e);
throw e;

248
src/Common/ImageData.ts Normal file
View File

@@ -0,0 +1,248 @@
import fetch from "node-fetch";
import {Submission} from "snoowrap/dist/objects";
import {URL} from "url";
import {absPercentDifference, getSharpAsync, isValidImageURL} from "../util";
import sizeOf from "image-size";
import SimpleError from "../Utils/SimpleError";
import {Sharp} from "sharp";
import {blockhash} from "./blockhash/blockhash";
export interface ImageDataOptions {
width?: number,
height?: number,
url: string,
variants?: ImageData[]
}
class ImageData {
width?: number
height?: number
url: URL
variants: ImageData[] = []
preferredResolution?: [number, number]
sharpImg!: Sharp
hashResult!: 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.variants = data.variants || [];
}
async data(format = 'raw'): Promise<Buffer> {
// @ts-ignore
return await (await this.sharp()).clone().toFormat(format).toBuffer();
}
async hash(bits: number, useVariantIfPossible = true): Promise<string> {
if(this.hashResult === undefined) {
let ref: ImageData | undefined;
if(useVariantIfPossible && this.preferredResolution !== undefined) {
ref = this.getSimilarResolutionVariant(this.preferredResolution[0], this.preferredResolution[1]);
}
if(ref === undefined) {
ref = this;
}
this.hashResult = await blockhash((await ref.sharp()).clone(), bits);
}
return this.hashResult;
}
async sharp(): Promise<Sharp> {
if (this.sharpImg === 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"`);
}
} else {
throw new SimpleError(`URL response was not OK: (${response.status})${response.statusText}`);
}
} catch (err: any) {
if(!(err instanceof SimpleError)) {
throw new Error(`Error occurred while fetching response from URL: ${err.message}`);
} else {
throw err;
}
}
}
return this.sharpImg;
}
get pixels() {
if (this.actualResolution !== undefined) {
return this.actualResolution[0] * this.actualResolution[1];
}
if (this.width === undefined || this.height === undefined) {
return undefined;
}
return this.width * this.height;
}
get hasDimensions() {
return this.width !== undefined && this.height !== undefined;
}
get baseUrl() {
return `${this.url.origin}${this.url.pathname}`;
}
setPreferredResolutionByWidth(prefWidth: number) {
let height: number | undefined = undefined,
width: number | undefined = undefined;
if (this.variants.length === 0) {
return;
}
for (const v of this.variants) {
if (v.hasDimensions && (v.width as number) <= prefWidth) {
width = v.width as number;
height = v.height as number;
}
}
if (width !== undefined) {
this.preferredResolution = [width, (height as number)];
}
}
getSimilarResolutionVariant(width: number, height: number, allowablePercentDiff = 0): ImageData | undefined {
if (this.variants.length === 0) {
return undefined;
}
return this.variants.find(x => {
return x.hasDimensions && (absPercentDifference(width, x.width as number) <= allowablePercentDiff) && (absPercentDifference(height, x.height as number) <= allowablePercentDiff);
});
}
isSameDimensions(otherImage: ImageData) {
if (!this.hasDimensions || !otherImage.hasDimensions) {
return false;
}
return this.width === otherImage.width && this.height === otherImage.height;
}
async sameAspectRatio(otherImage: ImageData) {
let thisRes = this.actualResolution;
let otherRes = otherImage.actualResolution;
if(thisRes === undefined) {
const tMeta = await (await this.sharp()).metadata();
const thisMeta = {width: tMeta.width as number, height: tMeta.height as number };
this.actualResolution = [thisMeta.width, thisMeta.height];
thisRes = this.actualResolution;
}
if(otherRes === undefined) {
const otherMeta = await (await otherImage.sharp()).metadata();
otherRes = [otherMeta.width as number, otherMeta.height as number];
}
const thisRatio = thisRes[0] / thisRes[1];
const otherRatio = otherRes[0] / otherRes[1];
// a little leeway
return Math.abs(thisRatio - otherRatio) < 0.1;
}
static async dimensionsFromMetadata(img: Sharp) {
const {width, height, ...rest} = await img.metadata();
return {width: width as number, height: height as number};
}
async normalizeImagesForComparison(compareLibrary: ('pixel' | 'resemble'), imgToCompare: ImageData): Promise<[Sharp, Sharp, number, number]> {
const sFunc = await getSharpAsync();
let refImage = this as ImageData;
let compareImage = imgToCompare;
if (this.preferredResolution !== undefined) {
const matchingVariant = compareImage.getSimilarResolutionVariant(this.preferredResolution[0], this.preferredResolution[1]);
if (matchingVariant !== undefined) {
compareImage = matchingVariant;
refImage = this.getSimilarResolutionVariant(this.preferredResolution[0], this.preferredResolution[1]) as ImageData;
}
}
let refSharp = (await refImage.sharp()).clone();
let refMeta = await ImageData.dimensionsFromMetadata(refSharp);
let compareSharp = (await compareImage.sharp()).clone();
let compareMeta = await ImageData.dimensionsFromMetadata(compareSharp);
// if dimensions on not the same we need to crop or resize before final resize
if (refMeta.width !== compareMeta.width || refMeta.height !== compareMeta.height) {
const thisRatio = refMeta.width / (refMeta.height);
const otherRatio = compareMeta.width / compareMeta.height;
const sameRatio = Math.abs(thisRatio - otherRatio) < 0.04;
if (sameRatio) {
// then resize first since its most likely the same image
// can be fairly sure a downscale will get pixels close to the same
if (refMeta.width > compareMeta.width) {
refSharp = sFunc(await refSharp.resize(compareMeta.width, null, {fit: 'outside'}).toBuffer());
} else {
compareSharp = sFunc(await compareSharp.resize(refMeta.width, null, {fit: 'outside'}).toBuffer());
}
refMeta = await ImageData.dimensionsFromMetadata(refSharp);
compareMeta = await ImageData.dimensionsFromMetadata(compareSharp);
}
// find smallest common dimensions
const sWidth = refMeta.width <= compareMeta.width ? refMeta.width : compareMeta.width;
const sHeight = refMeta.height <= compareMeta.height ? refMeta.height : compareMeta.height;
// crop if necessary
if(sWidth !== refMeta.width || sHeight !== refMeta.height) {
refSharp = sFunc(await refSharp.extract({left: 0, top: 0, width: sWidth, height: sHeight}).toBuffer());
}
if(sWidth !== compareMeta.width || sHeight !== compareMeta.height) {
compareSharp = sFunc(await compareSharp.extract({left: 0, top: 0, width: sWidth, height: sHeight}).toBuffer());
}
}
// final resize to reduce memory/cpu usage during comparison
refSharp = sFunc(await refSharp.resize(400, null, {fit: 'outside'}).toBuffer());
compareSharp = sFunc(await compareSharp.resize(400, null, {fit: 'outside'}).toBuffer());
const {width, height} = await ImageData.dimensionsFromMetadata(refSharp);
return [refSharp, compareSharp, width, height];
}
static fromSubmission(sub: Submission, aggressive = false): ImageData {
const url = new URL(sub.url);
const data: any = {
url,
};
let variants = [];
if (sub.preview !== undefined && sub.preview.enabled && sub.preview.images.length > 0) {
const firstImg = sub.preview.images[0];
const ref = sub.preview.images[0].source;
data.width = ref.width;
data.height = ref.height;
variants = firstImg.resolutions.map(x => new ImageData(x));
data.variants = variants;
}
return new ImageData(data, aggressive);
}
}
export default ImageData;

View File

@@ -0,0 +1,234 @@
// Perceptual image hash calculation tool based on algorithm descibed in
// Block Mean Value Based Image Perceptual Hashing by Bian Yang, Fan Gu and Xiamu Niu
//
// Copyright 2014 Commons Machinery http://commonsmachinery.se/
// Distributed under an MIT license, please see LICENSE in the top dir.
// https://github.com/commonsmachinery/blockhash-js/blob/master/index.js
import {Sharp} from "sharp";
interface BlockImageData {
data: Buffer,
width: number,
height: number
}
var one_bits = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4];
/* Calculate the hamming distance for two hashes in hex format */
export const hammingDistance = (hash1: string, hash2: string) => {
var d = 0;
var i;
if (hash1.length !== hash2.length) {
throw new Error("Can't compare hashes with different length");
}
for (i = 0; i < hash1.length; i++) {
var n1 = parseInt(hash1[i], 16);
var n2 = parseInt(hash2[i], 16);
d += one_bits[n1 ^ n2];
}
return d;
};
var median = function(data: number[]) {
var mdarr = data.slice(0);
mdarr.sort(function(a, b) { return a-b; });
if (mdarr.length % 2 === 0) {
return (mdarr[mdarr.length/2 - 1] + mdarr[mdarr.length/2]) / 2.0;
}
return mdarr[Math.floor(mdarr.length/2)];
};
var translate_blocks_to_bits = function(blocks: number[], pixels_per_block: number) {
var half_block_value = pixels_per_block * 256 * 3 / 2;
var bandsize = blocks.length / 4;
// Compare medians across four horizontal bands
for (var i = 0; i < 4; i++) {
var m = median(blocks.slice(i * bandsize, (i + 1) * bandsize));
for (var j = i * bandsize; j < (i + 1) * bandsize; j++) {
var v = blocks[j];
// Output a 1 if the block is brighter than the median.
// With images dominated by black or white, the median may
// end up being 0 or the max value, and thus having a lot
// of blocks of value equal to the median. To avoid
// generating hashes of all zeros or ones, in that case output
// 0 if the median is in the lower value space, 1 otherwise
blocks[j] = Number(v > m || (Math.abs(v - m) < 1 && m > half_block_value));
}
}
};
var bits_to_hexhash = function(bitsArray: number[]) {
var hex = [];
for (var i = 0; i < bitsArray.length; i += 4) {
var nibble = bitsArray.slice(i, i + 4);
hex.push(parseInt(nibble.join(''), 2).toString(16));
}
return hex.join('');
};
var bmvbhash_even = function(data: BlockImageData, bits: number) {
var blocksize_x = Math.floor(data.width / bits);
var blocksize_y = Math.floor(data.height / bits);
var result = [];
for (var y = 0; y < bits; y++) {
for (var x = 0; x < bits; x++) {
var total = 0;
for (var iy = 0; iy < blocksize_y; iy++) {
for (var ix = 0; ix < blocksize_x; ix++) {
var cx = x * blocksize_x + ix;
var cy = y * blocksize_y + iy;
var ii = (cy * data.width + cx) * 4;
var alpha = data.data[ii+3];
if (alpha === 0) {
total += 765;
} else {
total += data.data[ii] + data.data[ii+1] + data.data[ii+2];
}
}
}
result.push(total);
}
}
translate_blocks_to_bits(result, blocksize_x * blocksize_y);
return bits_to_hexhash(result);
};
var bmvbhash = function(data: BlockImageData, bits: number) {
var result = [];
var i, j, x, y;
var block_width, block_height;
var weight_top, weight_bottom, weight_left, weight_right;
var block_top, block_bottom, block_left, block_right;
var y_mod, y_frac, y_int;
var x_mod, x_frac, x_int;
var blocks: number[][] = [];
var even_x = data.width % bits === 0;
var even_y = data.height % bits === 0;
if (even_x && even_y) {
return bmvbhash_even(data, bits);
}
// initialize blocks array with 0s
for (i = 0; i < bits; i++) {
blocks.push([]);
for (j = 0; j < bits; j++) {
blocks[i].push(0);
}
}
block_width = data.width / bits;
block_height = data.height / bits;
for (y = 0; y < data.height; y++) {
if (even_y) {
// don't bother dividing y, if the size evenly divides by bits
block_top = block_bottom = Math.floor(y / block_height);
weight_top = 1;
weight_bottom = 0;
} else {
y_mod = (y + 1) % block_height;
y_frac = y_mod - Math.floor(y_mod);
y_int = y_mod - y_frac;
weight_top = (1 - y_frac);
weight_bottom = (y_frac);
// y_int will be 0 on bottom/right borders and on block boundaries
if (y_int > 0 || (y + 1) === data.height) {
block_top = block_bottom = Math.floor(y / block_height);
} else {
block_top = Math.floor(y / block_height);
block_bottom = Math.ceil(y / block_height);
}
}
for (x = 0; x < data.width; x++) {
var ii = (y * data.width + x) * 4;
var avgvalue, alpha = data.data[ii+3];
if (alpha === 0) {
avgvalue = 765;
} else {
avgvalue = data.data[ii] + data.data[ii+1] + data.data[ii+2];
}
if (even_x) {
block_left = block_right = Math.floor(x / block_width);
weight_left = 1;
weight_right = 0;
} else {
x_mod = (x + 1) % block_width;
x_frac = x_mod - Math.floor(x_mod);
x_int = x_mod - x_frac;
weight_left = (1 - x_frac);
weight_right = x_frac;
// x_int will be 0 on bottom/right borders and on block boundaries
if (x_int > 0 || (x + 1) === data.width) {
block_left = block_right = Math.floor(x / block_width);
} else {
block_left = Math.floor(x / block_width);
block_right = Math.ceil(x / block_width);
}
}
// add weighted pixel value to relevant blocks
blocks[block_top][block_left] += avgvalue * weight_top * weight_left;
blocks[block_top][block_right] += avgvalue * weight_top * weight_right;
blocks[block_bottom][block_left] += avgvalue * weight_bottom * weight_left;
blocks[block_bottom][block_right] += avgvalue * weight_bottom * weight_right;
}
}
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;
if (method === 1) {
hash = bmvbhash_even(imgData, bits);
}
else if (method === 2) {
hash = bmvbhash(imgData, bits);
}
else {
throw new Error("Bad hashing method");
}
return hash;
};
export const blockhash = async function(src: Sharp, bits: number, method: number = 2): Promise<string> {
const {data: buff, info} = await src.ensureAlpha().raw().toBuffer({resolveWithObject: true});
return blockhashData({
width: info.width,
height: info.height,
data: buff,
}, bits, method);
};

View File

@@ -1,2 +1,31 @@
import {HistoricalStats} from "./interfaces";
export const cacheOptDefaults = {ttl: 60, max: 500, checkPeriod: 600};
export const cacheTTLDefaults = {authorTTL: 60, userNotesTTL: 300, wikiTTL: 300, submissionTTL: 60, commentTTL: 60, filterCriteriaTTL: 60, subredditTTL: 600};
export const historicalDefaults: HistoricalStats = {
eventsCheckedTotal: 0,
eventsActionedTotal: 0,
checksRun: new Map(),
checksFromCache: new Map(),
checksTriggered: new Map(),
rulesRun: new Map(),
//rulesCached: new Map(),
rulesCachedTotal: 0,
rulesTriggered: new Map(),
actionsRun: new Map(),
}
export const createHistoricalDefaults = (): HistoricalStats => {
return {
eventsCheckedTotal: 0,
eventsActionedTotal: 0,
checksRun: new Map(),
checksFromCache: new Map(),
checksTriggered: new Map(),
rulesRun: new Map(),
//rulesCached: new Map(),
rulesCachedTotal: 0,
rulesTriggered: new Map(),
actionsRun: new Map(),
};
}

View File

@@ -4,6 +4,7 @@ import {MESSAGE} from 'triple-beam';
import Poll from "snoostorm/out/util/Poll";
import Snoowrap from "snoowrap";
import {RuleResult} from "../Rule";
import {IncomingMessage} from "http";
/**
* An ISO 8601 Duration
@@ -223,6 +224,186 @@ export interface ReferenceSubmission {
useSubmissionAsReference?: boolean,
}
/**
* When comparing submissions detect if the reference submission is an image and do a pixel-comparison to other detected image submissions.
*
* **Note:** This is an **experimental feature**
* */
export interface ImageDetection {
/**
* Is image detection enabled?
* */
enable?: boolean
/**
* Determines how and when to check if a URL is an image
*
* **Note:** After fetching a URL the **Content-Type** is validated to contain `image` before detection occurs
*
* **When `extension`:** (default)
*
* * Only URLs that end in known image extensions (.png, .jpg, etc...) are fetched
*
* **When `unknown`:**
*
* * URLs that end in known image extensions (.png, .jpg, etc...) are fetched
* * URLs with no extension or unknown (IE non-video, non-doc, etc...) are fetched
*
* **When `all`:**
*
* * All submissions that have URLs (non-self) will be fetched, regardless of extension
* * **Note:** This can be bandwidth/CPU intensive if history window is large so use with care
*
* @default "extension"
* */
fetchBehavior?: 'extension' | 'unknown' | 'all',
/**
* The percentage, as a whole number, of difference between two images at which point they will not be considered the same.
*
* Will be used as `hash.hardThreshold` and `pixel.threshold` if those values are not specified
*
* Default is `5`
*
* @default 5
* */
threshold?: number
/**
* Use perceptual hashing (blockhash-js) to compare images
*
* Pros:
*
* * very fast
* * low cpu/memory usage
* * results can be cached
*
* Cons:
*
* * not as accurate as pixel comparison
* * weaker for text-heavy images
* * mostly color-blind
*
* Best uses:
*
* * Detecting (general) duplicate images
* * Comparing large number of images
* */
hash?: {
/**
* Enabled by default.
*
* If both `hash` and `pixel` are enabled then `pixel` will be used to verify image comparison when hashes matches
*
* @default true
* */
enable?: boolean
/**
* Bit count determines accuracy of hash and granularity of hash comparison (comparison to other hashes)
*
* Default is `32`
*
* **NOTE:** Hashes of different sizes (bits) cannot be compared. If you are caching results make sure all rules where results may be shared use the same bit count to ensure hashes can be compared. Otherwise hashes will be recomputed.
*
* @default 32
* */
bits?: number
/**
* Number of seconds to cache image hash
* */
ttl?: number
/**
* High Confidence Threshold
*
* If the difference in comparison is equal to or less than this number the images are considered the same and pixel comparison WILL NOT occur
*
* Defaults to the parent-level `threshold` value if not present
*
* Use `null` if you want pixel comparison to ALWAYS occur (softThreshold must be present)
* */
hardThreshold?: number | null
/**
* Low Confidence Threshold -- only used if `pixel` is enabled
*
* If the difference in comparison is
*
* 1) equal to or less than this value and
* 2) the value is greater than `hardThreshold`
*
* the images will be compared using the `pixel` method
* */
softThreshold?: number
}
/**
* Use pixel counting to compare images
*
* Pros:
*
* * most accurate
* * strong with text or color-only changes
*
* Cons:
*
* * much slower than hashing
* * memory/cpu intensive
*
* Best uses:
*
* * Comparison text-only images
* * Comparison requires high degree of accuracy or changes are subtle
* */
pixel?: {
/**
* Disabled by default.
*
* @default false
* */
enable?: boolean
/**
* The percentage, as a whole number, of pixels that are **different** between the two images at which point the images are not considered the same.
* */
threshold?: number
}
}
export interface StrongImageDetection {
enable: boolean,
fetchBehavior: 'extension' | 'unknown' | 'all'
threshold: number,
hash: {
enable: boolean
bits: number
ttl?: number
hardThreshold: number | null
softThreshold?: number
}
pixel: {
enable: boolean
threshold: number
}
}
// export interface ImageData {
// data: Promise<Buffer>,
// buf?: Buffer,
// width: number,
// height: number
// pixels?: number
// url: string
// variants?: ImageData[]
// }
export interface ImageComparisonResult {
isSameDimensions: boolean
dimensionDifference: {
width: number;
height: number;
};
misMatchPercentage: number;
analysisTime: number;
}
export interface RichContent {
/**
* The Content to submit for this Action. Content is interpreted as reddit-flavored Markdown.
@@ -305,6 +486,38 @@ export type PollOn = 'unmoderated' | 'modqueue' | 'newSub' | 'newComm';
export interface PollingOptionsStrong extends PollingOptions {
limit: number,
interval: number,
clearProcessed: ClearProcessedOptions
}
/**
* For very long-running, high-volume subreddits clearing the list of processed activities helps manage memory bloat
*
* All of these options have default values based on the limit and/or interval set for polling options on each subreddit stream. They only need to modified if the defaults are not sufficient.
*
* If both `after` and `size` are defined whichever is hit first will trigger the list to clear. `after` will be reset after ever clear.
* */
export interface ClearProcessedOptions {
/**
* An interval the processed list should be cleared after.
*
* * EX `9 days`
* * EX `3 months`
* * EX `5 minutes`
* @pattern ^\s*(?<time>\d+)\s*(?<unit>days?|weeks?|months?|years?|hours?|minutes?|seconds?|milliseconds?)\s*$
* */
after?: string,
/**
* Number of activities found in processed list after which the list should be cleared.
*
* Defaults to the `limit` value from `PollingOptions`
* */
size?: number,
/**
* The number of activities to retain in processed list after clearing.
*
* Defaults to `limit` value from `PollingOptions`
* */
retain?: number,
}
export interface PollingDefaults {
@@ -378,6 +591,8 @@ export interface PollingOptions extends PollingDefaults {
*
* */
pollOn: 'unmoderated' | 'modqueue' | 'newSub' | 'newComm'
clearProcessed?: ClearProcessedOptions
}
export interface TTLConfig {
@@ -617,6 +832,8 @@ export interface ManagerOptions {
nickname?: string
notifications?: NotificationConfig
credentials?: ThirdPartyCredentialsJsonConfig
}
/**
@@ -630,6 +847,22 @@ export interface ManagerOptions {
* */
export type CompareValue = string;
/**
* A duration and how to compare it against a value
*
* The syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`
*
* * EX `> 100 days` => Passes if the date being compared is before 100 days ago
* * EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months
*
* Unit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)
*
* [See] https://regexr.com/609n8 for example
*
* @pattern ^\s*(>|>=|<|<=)\s*(\d+)\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\s*$
* */
export type DurationComparor = string;
/**
* A string containing a comparison operator and a value to compare against
*
@@ -677,6 +910,7 @@ export interface ActivityState {
approved?: boolean
score?: CompareValue
reports?: CompareValue
age?: DurationComparor
}
/**
@@ -700,6 +934,9 @@ export interface SubmissionState extends ActivityState {
link_flair_css_class?: string
}
// properties calculated/derived by CM -- not provided as plain values by reddit
export const cmActivityProperties = ['submissionState','score','reports','removed','deleted','filtered','age','title'];
/**
* Different attributes a `Comment` can be in. Only include a property if you want to check it.
* @examples [{"op": true, "removed": false}]
@@ -713,6 +950,14 @@ export interface CommentState extends ActivityState {
* A list of SubmissionState attributes to test the Submission this comment is in
* */
submissionState?: SubmissionState[]
/**
* The (nested) level of a comment.
*
* * 0 mean the comment is at top-level (replying to submission)
* * non-zero, Nth value means the comment has N parent comments
* */
depth?: DurationComparor
}
/**
@@ -744,6 +989,8 @@ export interface SubredditState {
* A friendly description of what this State is trying to parse
* */
stateDescription?: string
isUserProfile?: boolean
}
export interface StrongSubredditState extends SubredditState {
@@ -771,6 +1018,28 @@ export const STOPPED = 'stopped';
export const RUNNING = 'running';
export const PAUSED = 'paused';
export interface SearchAndReplaceRegExp {
/**
* The search value to test for
*
* Can be a normal string (converted to a case-sensitive literal) or a valid regular expression
*
* EX `["find this string", "/some string*\/ig"]`
*
* @examples ["find this string", "/some string*\/ig"]
* */
search: string
/**
* The replacement string/value to use when search is found
*
* This can be a literal string like `'replace with this`, an empty string to remove the search value (`''`), or a special regex value
*
* See replacement here for more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
* */
replace: string
}
export interface NamedGroup {
[name: string]: string
}
@@ -1029,7 +1298,7 @@ export interface WebCredentials {
*
* */
export interface BotInstanceJsonConfig {
credentials?: RedditCredentials
credentials?: BotCredentialsJsonConfig | RedditCredentials
/*
* The name to display for the bot. If not specified will use the name of the reddit account IE `u/TheBotName`
* */
@@ -1144,6 +1413,13 @@ export interface BotInstanceJsonConfig {
* @default false
* */
sharedMod?: boolean,
/**
* If sharing a mod stream stagger pushing relevant Activities to individual subreddits.
*
* Useful when running many subreddits and rules are potentially cpu/memory/traffic heavy -- allows spreading out load
* */
stagger?: number,
},
/**
* Settings related to default configurations for queue behavior for subreddits
@@ -1402,6 +1678,8 @@ export interface OperatorJsonConfig {
* */
friendly?: string,
}
credentials?: ThirdPartyCredentialsJsonConfig
}
export interface RequiredOperatorRedditCredentials extends RedditCredentials {
@@ -1415,8 +1693,23 @@ export interface RequiredWebRedditCredentials extends RedditCredentials {
redirectUri: string
}
export interface ThirdPartyCredentialsJsonConfig {
youtube?: {
apiKey: string
}
[key: string]: any
}
export interface BotCredentialsJsonConfig extends ThirdPartyCredentialsJsonConfig {
reddit: RedditCredentials
}
export interface BotCredentialsConfig extends ThirdPartyCredentialsJsonConfig {
reddit: RequiredOperatorRedditCredentials
}
export interface BotInstanceConfig extends BotInstanceJsonConfig {
credentials: RequiredOperatorRedditCredentials
credentials: BotCredentialsJsonConfig
snoowrap: {
proxy?: string,
debug?: boolean,
@@ -1430,6 +1723,7 @@ export interface BotInstanceConfig extends BotInstanceJsonConfig {
},
polling: {
sharedMod: boolean,
stagger?: number,
limit: number,
interval: number,
},
@@ -1477,6 +1771,7 @@ export interface OperatorConfig extends OperatorJsonConfig {
friendly?: string,
}
bots: BotInstanceConfig[]
credentials: ThirdPartyCredentialsJsonConfig
}
//export type OperatorConfig = Required<OperatorJsonConfig>;
@@ -1547,3 +1842,115 @@ export interface RedditEntity {
name: string
type: RedditEntityType
}
export interface StatusCodeError extends Error {
name: 'StatusCodeError',
statusCode: number,
message: string,
response: IncomingMessage,
error: Error
}
export interface HistoricalStatsDisplay extends HistoricalStats {
checksRunTotal: number
checksFromCacheTotal: number
checksTriggeredTotal: number
rulesRunTotal: number
rulesCachedTotal: number
rulesTriggeredTotal: number
actionsRunTotal: number
}
export interface HistoricalStats {
eventsCheckedTotal: number
eventsActionedTotal: number
checksRun: Map<string, number>
checksFromCache: Map<string, number>
checksTriggered: Map<string, number>
rulesRun: Map<string, number>
//rulesCached: Map<string, number>
rulesCachedTotal: number
rulesTriggered: Map<string, number>
actionsRun: Map<string, number>
[index: string]: any
}
export interface SubredditHistoricalStats {
allTime: HistoricalStats
lastReload: HistoricalStats
}
export interface SubredditHistoricalStatsDisplay {
allTime: HistoricalStatsDisplay
lastReload: HistoricalStatsDisplay
}
export interface ManagerStats {
// eventsCheckedTotal: number
// eventsCheckedSinceStartTotal: number
eventsAvg: number
// checksRunTotal: number
// checksRunSinceStartTotal: number
// checksTriggered: number
// checksTriggeredTotal: number
// checksTriggeredSinceStart: number
// checksTriggeredSinceStartTotal: number
// rulesRunTotal: number
// rulesRunSinceStartTotal: number
// rulesCachedTotal: number
// rulesCachedSinceStartTotal: number
// rulesTriggeredTotal: number
// rulesTriggeredSinceStartTotal: number
rulesAvg: number
// actionsRun: number
// actionsRunTotal: number
// actionsRunSinceStart: number,
// actionsRunSinceStartTotal: number
historical: SubredditHistoricalStatsDisplay
cache: {
provider: string,
currentKeyCount: number,
isShared: boolean,
totalRequests: number,
totalMiss: number,
missPercent: string,
requestRate: number,
types: ResourceStats
},
}
export interface HistoricalStatUpdateData {
eventsCheckedTotal?: number
eventsActionedTotal?: number
checksRun: string[] | string
checksTriggered: string[] | string
checksFromCache: string[] | string
actionsRun: string[] | string
rulesRun: string[] | string
rulesCachedTotal: number
rulesTriggered: string[] | string
}
export type SearchFacetType = 'title' | 'url' | 'duplicates' | 'crossposts' | 'external';
export interface RepostItem {
value: string
createdOn?: number
source: string
sourceUrl?: string
score?: number
id: string
itemType: string
acquisitionType: SearchFacetType | 'comment'
sourceObj?: any
reqSameness?: number
}
export interface RepostItemResult extends RepostItem {
sameness: number
}
export interface StringComparisonOptions {
lengthWeight?: number,
transforms?: ((str: string) => string)[]
}

View File

@@ -13,9 +13,17 @@ import {ApproveActionJson} from "../Action/ApproveAction";
import {BanActionJson} from "../Action/BanAction";
import {RegexRuleJSONConfig} from "../Rule/RegexRule";
import {MessageActionJson} from "../Action/MessageAction";
import {RepostRuleJSONConfig} from "../Rule/RepostRule";
export type RuleJson = RecentActivityRuleJSONConfig | RepeatActivityJSONConfig | AuthorRuleJSONConfig | AttributionJSONConfig | HistoryJSONConfig | RegexRuleJSONConfig | string;
export type RuleJson = RecentActivityRuleJSONConfig | RepeatActivityJSONConfig | AuthorRuleJSONConfig | AttributionJSONConfig | HistoryJSONConfig | RegexRuleJSONConfig | RepostRuleJSONConfig | string;
export type RuleObjectJson = Exclude<RuleJson, string>
export type ActionJson = CommentActionJson | FlairActionJson | ReportActionJson | LockActionJson | RemoveActionJson | ApproveActionJson | BanActionJson | UserNoteActionJson | MessageActionJson | string;
export type ActionObjectJson = Exclude<ActionJson, string>;
// borrowed from https://github.com/jabacchetta/set-random-interval/blob/master/src/index.ts
export type SetRandomInterval = (
intervalFunction: () => void,
minDelay: number,
maxDelay: number,
) => { clear: () => void };

View File

@@ -31,7 +31,7 @@ import {
CacheOptions,
BotInstanceJsonConfig,
BotInstanceConfig,
RequiredWebRedditCredentials
RequiredWebRedditCredentials, RedditCredentials, BotCredentialsJsonConfig, BotCredentialsConfig
} from "./Common/interfaces";
import {isRuleSetJSON, RuleSetJson, RuleSetObjectJson} from "./Rule/RuleSet";
import deepEqual from "fast-deep-equal";
@@ -142,15 +142,30 @@ export const buildPollingOptions = (values: (string | PollingOptions)[]): Pollin
let opts: PollingOptionsStrong[] = [];
for (const v of values) {
if (typeof v === 'string') {
opts.push({pollOn: v as PollOn, interval: DEFAULT_POLLING_INTERVAL, limit: DEFAULT_POLLING_LIMIT});
opts.push({
pollOn: v as PollOn,
interval: DEFAULT_POLLING_INTERVAL,
limit: DEFAULT_POLLING_LIMIT,
clearProcessed: {
size: DEFAULT_POLLING_LIMIT,
retain: DEFAULT_POLLING_LIMIT,
}
});
} else {
const {
pollOn: p,
interval = DEFAULT_POLLING_INTERVAL,
limit = DEFAULT_POLLING_LIMIT,
delayUntil,
clearProcessed = {size: limit, retain: limit},
} = v;
opts.push({pollOn: p as PollOn, interval, limit, delayUntil});
opts.push({
pollOn: p as PollOn,
interval,
limit,
delayUntil,
clearProcessed
});
}
}
return opts;
@@ -372,10 +387,13 @@ const parseListFromEnv = (val: string | undefined) => {
export const parseDefaultBotInstanceFromEnv = (): BotInstanceJsonConfig => {
const data = {
credentials: {
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
accessToken: process.env.ACCESS_TOKEN,
refreshToken: process.env.REFRESH_TOKEN,
reddit: {
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
accessToken: process.env.ACCESS_TOKEN,
refreshToken: process.env.REFRESH_TOKEN,
},
youtube: process.env.YOUTUBE_API_KEY
},
subreddits: {
names: parseListFromEnv(process.env.SUBREDDITS),
@@ -428,6 +446,11 @@ export const parseOpConfigFromEnv = (): OperatorJsonConfig => {
clientSecret: process.env.CLIENT_SECRET,
redirectUri: process.env.REDIRECT_URI,
},
},
credentials: {
youtube: {
apiKey: process.env.YOUTUBE_API_KEY
}
}
}
@@ -461,7 +484,7 @@ export const parseOperatorConfigFromSources = async (args: any): Promise<Operato
process.env[k] = v;
}
}
} catch (err) {
} catch (err: any) {
let msg = 'No .env file found at default location (./env)';
if (envPath !== undefined) {
msg = `${msg} or OPERATOR_ENV path (${envPath})`;
@@ -477,14 +500,14 @@ export const parseOperatorConfigFromSources = async (args: any): Promise<Operato
let rawConfig;
try {
rawConfig = await readConfigFile(operatorConfig, {log: initLogger}) as object;
} catch (err) {
} catch (err: any) {
initLogger.error('Cannot continue app startup because operator config file was not parseable.');
err.logged = true;
throw err;
}
try {
configFromFile = validateJson(rawConfig, operatorSchema, initLogger) as OperatorJsonConfig;
} catch (err) {
} catch (err: any) {
initLogger.error('Cannot continue app startup because operator config file was not valid.');
throw err;
}
@@ -550,6 +573,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
secret: apiSecret = randomId(),
friendly,
} = {},
credentials = {},
bots = [],
} = data;
@@ -604,6 +628,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
name: botName,
polling: {
sharedMod = false,
stagger,
limit = 100,
interval = 30,
} = {},
@@ -616,11 +641,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
hardLimit = 50
} = {},
snoowrap = {},
credentials: {
clientId: ci,
clientSecret: cs,
...restCred
} = {},
credentials = {},
subreddits: {
names = [],
exclude = [],
@@ -630,7 +651,6 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
} = {},
} = x;
let botCache: StrongCache;
let botActionedEventsDefault: number;
@@ -640,10 +660,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
...cacheTTLDefaults,
actionedEventsDefault: opActionedEventsDefault,
actionedEventsMax: opActionedEventsMax,
provider: {
store: 'memory',
...cacheOptDefaults
}
provider: {...defaultProvider}
};
} else {
const {
@@ -654,7 +671,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
} = caching;
botActionedEventsDefault = actionedEventsDefault;
if(actionedEventsMax !== undefined) {
if (actionedEventsMax !== undefined) {
botActionedEventsDefault = Math.min(actionedEventsDefault, actionedEventsMax);
}
@@ -684,11 +701,42 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
}
}
const botCreds = {
clientId: (ci as string),
clientSecret: (cs as string),
...restCred,
};
let botCreds: BotCredentialsConfig;
if((credentials as any).clientId !== undefined) {
const creds = credentials as RedditCredentials;
const {
clientId: ci,
clientSecret: cs,
...restCred
} = creds;
botCreds = {
reddit: {
clientId: (ci as string),
clientSecret: (cs as string),
...restCred,
}
}
} else {
const creds = credentials as BotCredentialsJsonConfig;
const {
reddit: {
clientId: ci,
clientSecret: cs,
...restRedditCreds
},
...rest
} = creds;
botCreds = {
reddit: {
clientId: (ci as string),
clientSecret: (cs as string),
...restRedditCreds,
},
...rest
}
}
if (botCache.provider.prefix === undefined || botCache.provider.prefix === defaultProvider.prefix) {
// need to provide unique prefix to bot
botCache.provider.prefix = buildCachePrefix([botCache.provider.prefix, 'bot', (botName || objectHash.sha1(botCreds))]);
@@ -708,6 +756,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
caching: botCache,
polling: {
sharedMod,
stagger,
limit,
interval,
},
@@ -759,6 +808,7 @@ export const buildOperatorConfigWithDefaults = (data: OperatorJsonConfig): Opera
friendly
},
bots: hydratedBots,
credentials,
};
return config;

View File

@@ -1,12 +1,12 @@
import {SubmissionRule, SubmissionRuleJSONConfig} from "./SubmissionRule";
import {ActivityWindowType, DomainInfo, ReferenceSubmission} from "../Common/interfaces";
import {ActivityWindowType, CommentState, DomainInfo, ReferenceSubmission, SubmissionState} from "../Common/interfaces";
import {Rule, RuleOptions, RuleResult} from "./index";
import Submission from "snoowrap/dist/objects/Submission";
import {getAttributionIdentifier} from "../Utils/SnoowrapUtils";
import dayjs from "dayjs";
import {
asSubmission,
comparisonTextOp,
comparisonTextOp, convertSubredditsRawToStrong,
FAIL,
formatNumber, getActivitySubredditName, isSubmission,
parseGenericValueOrPercentComparison,
@@ -15,6 +15,7 @@ import {
} from "../util";
import { Comment } from "snoowrap/dist/objects";
import SimpleError from "../Utils/SimpleError";
import as from "async";
export interface AttributionCriteria {
@@ -76,38 +77,55 @@ export interface AttributionCriteria {
domainsCombined?: boolean,
/**
* Only include Activities from this list of Subreddits (by name, case-insensitive)
* When present, Activities WILL ONLY be counted if they are found in this list of Subreddits
*
* Each value in the list can be either:
*
* EX `["mealtimevideos","askscience"]`
* @examples ["mealtimevideos","askscience"]
* @minItems 1
* * string (name of subreddit)
* * regular expression to run on the subreddit name
* * `SubredditState`
*
* EX `["mealtimevideos","askscience", "/onlyfans*\/i", {"over18": true}]`
* @examples [["mealtimevideos","askscience", "/onlyfans*\/i", {"over18": true}]]
* */
include?: string[],
/**
* Do not include Activities from this list of Subreddits (by name, case-insensitive)
* When present, Activities WILL NOT be counted if they are found in this list of Subreddits
*
* Will be ignored if `include` is present.
* Each value in the list can be either:
*
* EX `["mealtimevideos","askscience"]`
* @examples ["mealtimevideos","askscience"]
* @minItems 1
* * string (name of subreddit)
* * regular expression to run on the subreddit name
* * `SubredditState`
*
* EX `["mealtimevideos","askscience", "/onlyfans*\/i", {"over18": true}]`
* @examples [["mealtimevideos","askscience", "/onlyfans*\/i", {"over18": true}]]
* */
exclude?: string[],
/**
* When present, Submissions from `window` will only be counted if they meet this criteria
* */
submissionState?: SubmissionState
/**
* When present, Comments from `window` will only be counted if they meet this criteria
* */
commentState?: CommentState
/**
* This list determines which categories of domains should be aggregated on. All aggregated domains will be tested against `threshold`
*
* * If `media` is included then aggregate author's submission history which reddit recognizes as media (youtube, vimeo, etc.)
* * If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or reddit image/video (i.redd.it / v.redd.it)
* * If `link` is included then aggregate author's submission history which is external links but not media
* * If `redditMedia` is included then aggregate on author's submissions history which are media hosted on reddit: galleries, videos, and images (i.redd.it / v.redd.it)
* * If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or domain is `reddit.com`
* * If `link` is included then aggregate author's submission history which is external links and not recognized as `media` by reddit
*
* If nothing is specified or list is empty (default) all domains are aggregated
* If nothing is specified or list is empty (default) rule will only aggregate on `link` and `media` (ignores reddit-hosted content and self-posts)
*
* @default undefined
* @examples [[]]
* */
aggregateOn?: ('media' | 'self' | 'link')[],
aggregateOn?: ('media' | 'redditMedia' | 'self' | 'link')[],
/**
* Should the criteria consolidate recognized media domains into the parent domain?
@@ -173,25 +191,40 @@ export class AttributionRule extends Rule {
window,
thresholdOn = 'all',
minActivityCount = 10,
aggregateOn = [],
aggregateOn = ['link','media'],
consolidateMediaDomains = false,
domains = [],
domainsCombined = false,
include: includeRaw = [],
exclude: excludeRaw = [],
include = [],
exclude = [],
commentState,
submissionState,
} = criteria;
const include = includeRaw.map(x => parseSubredditName(x).toLowerCase());
const exclude = excludeRaw.map(x => parseSubredditName(x).toLowerCase());
const {operator, value, isPercent, extra = ''} = parseGenericValueOrPercentComparison(threshold);
let activities = thresholdOn === 'submissions' ? await this.resources.getAuthorSubmissions(item.author, {window: window}) : await this.resources.getAuthorActivities(item.author, {window: window});
activities = activities.filter(act => {
if (include.length > 0) {
return include.some(x => x === getActivitySubredditName(act).toLowerCase());
} else if (exclude.length > 0) {
return !exclude.some(x => x === getActivitySubredditName(act).toLowerCase())
if(include.length > 0 || exclude.length > 0) {
const defaultOpts = {
defaultFlags: 'i',
generateDescription: true
};
if(include.length > 0) {
const subStates = include.map(x => convertSubredditsRawToStrong(x, defaultOpts));
activities = await this.resources.batchTestSubredditCriteria(activities, subStates);
} else {
const subStates = exclude.map(x => convertSubredditsRawToStrong(x, defaultOpts));
const toExclude = (await this.resources.batchTestSubredditCriteria(activities, subStates)).map(x => x.id);
activities = activities.filter(x => !toExclude.includes(x.id));
}
}
activities = await as.filter(activities, async (activity) => {
if (asSubmission(activity) && submissionState !== undefined) {
return await this.resources.testItemCriteria(activity, [submissionState]);
} else if (commentState !== undefined) {
return await this.resources.testItemCriteria(activity, [commentState]);
}
return true;
});
@@ -232,16 +265,23 @@ export class AttributionRule extends Rule {
const domainInfo = getAttributionIdentifier(sub, consolidateMediaDomains)
let domainType = 'link';
if(sub.secure_media !== undefined && sub.secure_media !== null) {
domainType = 'media';
} else if((sub.is_self || sub.is_video || sub.domain === 'i.redd.it')) {
if(sub.is_video || ['i.redd.it','v.redd.it'].includes(sub.domain)
// @ts-ignore
|| sub.gallery_data !== undefined) {
domainType = 'redditMedia';
} else if(sub.is_self || sub.domain === 'reddit.com') {
domainType = 'self';
} else if(sub.secure_media !== undefined && sub.secure_media !== null) {
domainType = 'media';
}
if(aggregateOn.length !== 0) {
if(domainType === 'media' && !aggregateOn.includes('media')) {
return acc;
}
if(domainType === 'redditMedia' && !aggregateOn.includes('redditMedia')) {
return acc;
}
if(domainType === 'self' && !aggregateOn.includes('self')) {
return acc;
}
@@ -384,7 +424,7 @@ export class AttributionRule extends Rule {
}
interface AttributionConfig extends ReferenceSubmission {
interface AttributionConfig {
/**
* A list threshold-window values to test attribution against

View File

@@ -12,11 +12,11 @@ export interface AuthorRuleConfig {
/**
* Will "pass" if any set of AuthorCriteria passes
* */
include: AuthorCriteria[];
include?: AuthorCriteria[];
/**
* Only runs if include is not present. Will "pass" if any of set of the AuthorCriteria does not pass
* */
exclude: AuthorCriteria[];
exclude?: AuthorCriteria[];
}
export interface AuthorRuleOptions extends AuthorRuleConfig, RuleOptions {
@@ -34,8 +34,13 @@ export class AuthorRule extends Rule {
constructor(options: AuthorRuleOptions) {
super(options);
this.include = options.include.map(x => new Author(x));
this.exclude = options.exclude.map(x => new Author(x));
const {
include,
exclude,
} = options;
this.include = include !== undefined ? include.map(x => new Author(x)) : [];
this.exclude = exclude !== undefined ? exclude.map(x => new Author(x)) : [];
if(this.include.length === 0 && this.exclude.length === 0) {
throw new Error('At least one of the properties [include,exclude] on Author Rule must not be empty');

View File

@@ -1,21 +1,42 @@
import {Rule, RuleJSONConfig, RuleOptions, RulePremise, RuleResult} from "./index";
import {Comment, VoteableContent} from "snoowrap";
import Submission from "snoowrap/dist/objects/Submission";
import as from 'async';
import pMap from 'p-map';
// @ts-ignore
import subImageMatch from 'matches-subimage';
import {
activityWindowText, asSubmission,
comparisonTextOp, FAIL, formatNumber, getActivitySubredditName, isSubmission, objectToStringSummary,
parseGenericValueOrPercentComparison, parseStringToRegex, parseSubredditName,
activityWindowText,
asSubmission, bitsToHexLength,
// blockHashImage,
compareImages,
comparisonTextOp, convertSubredditsRawToStrong,
FAIL,
formatNumber,
getActivitySubredditName, imageCompareMaxConcurrencyGuess,
//getImageDataFromUrl,
isSubmission,
isValidImageURL,
objectToStringSummary,
parseGenericValueOrPercentComparison,
parseStringToRegex,
parseSubredditName,
parseUsableLinkIdentifier,
PASS, toStrongSubredditState
PASS, sleep,
toStrongSubredditState
} from "../util";
import {
ActivityWindow,
ActivityWindowCriteria,
ActivityWindowType, CommentState,
ReferenceSubmission, StrongSubredditState, SubmissionState,
//ImageData,
ImageDetection,
ReferenceSubmission, StrongImageDetection, StrongSubredditState, SubmissionState,
SubredditCriteria, SubredditState
} from "../Common/interfaces";
import {SubredditResources} from "../Subreddit/SubredditResources";
import ImageData from "../Common/ImageData";
import {blockhash, hammingDistance} from "../Common/blockhash/blockhash";
import leven from "leven";
const parseLink = parseUsableLinkIdentifier();
@@ -23,6 +44,7 @@ export class RecentActivityRule extends Rule {
window: ActivityWindowType;
thresholds: ActivityThreshold[];
useSubmissionAsReference: boolean;
imageDetection: StrongImageDetection
lookAt?: 'comments' | 'submissions';
constructor(options: RecentActivityRuleOptions) {
@@ -30,8 +52,47 @@ export class RecentActivityRule extends Rule {
const {
window = 15,
useSubmissionAsReference = true,
imageDetection,
lookAt,
} = options || {};
const {
enable = false,
fetchBehavior = 'extension',
threshold = 5,
hash = {},
pixel = {},
} = imageDetection || {};
const {
enable: hEnable = true,
bits = 16,
ttl = 60,
hardThreshold = threshold,
softThreshold
} = hash || {};
const {
enable: pEnable = true,
threshold: pThreshold = threshold,
} = pixel || {};
this.imageDetection = {
enable,
fetchBehavior,
threshold,
hash: {
enable: hEnable,
hardThreshold,
softThreshold,
bits,
ttl,
},
pixel: {
enable: pEnable,
threshold: pThreshold
}
};
this.lookAt = lookAt;
this.useSubmissionAsReference = useSubmissionAsReference;
this.window = window;
@@ -73,16 +134,138 @@ export class RecentActivityRule extends Rule {
} else if (item.is_self) {
this.logger.warn('Cannot use post as reference because triggered Submission is not a link type');
} else {
const usableUrl = parseLink(await item.url);
viableActivity = viableActivity.filter((x) => {
if (!asSubmission(x)) {
return false;
const itemId = item.id;
const referenceUrl = await item.url;
const usableUrl = parseLink(referenceUrl);
let filteredActivity: (Submission|Comment)[] = [];
let analysisTimes: number[] = [];
let referenceImage: ImageData | 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)) {
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);
}
} else {
refHash = await referenceImage.hash(this.imageDetection.hash.bits);
}
}
//await referenceImage.sharp();
// await referenceImage.hash();
// if (referenceImage.preferredResolution !== undefined) {
// await (referenceImage.getSimilarResolutionVariant(...referenceImage.preferredResolution) as ImageData).sharp();
// }
} catch (err: any) {
this.logger.verbose(err.message);
}
}
let longRun;
if (referenceImage !== undefined) {
const l = this.logger;
longRun = setTimeout(() => {
l.verbose('FYI: Image processing is causing rule to take longer than normal');
}, 2500);
}
// @ts-ignore
const ci = async (x: (Submission|Comment)) => {
if (!asSubmission(x) || x.id === itemId) {
return null;
}
if (x.url === undefined) {
return false;
return null;
}
return parseLink(x.url) === usableUrl;
});
if (parseLink(x.url) === usableUrl) {
return x;
}
// only do image detection if regular URL comparison and other conditions fail first
// to reduce CPU/bandwidth usage
if (referenceImage !== undefined) {
try {
let imgData = ImageData.fromSubmission(x);
imgData.setPreferredResolutionByWidth(800);
if(this.imageDetection.hash.enable) {
let compareHash: string | undefined;
if(this.imageDetection.hash.ttl !== undefined) {
compareHash = await this.resources.getImageHash(imgData);
}
if(compareHash === undefined)
{
compareHash = await imgData.hash(this.imageDetection.hash.bits);
if(this.imageDetection.hash.ttl !== undefined) {
await this.resources.setImageHash(imgData, compareHash, 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)
}
const distance = leven(refHash, compareHash);
const diff = (distance/refHash.length)*100;
// return image if hard is defined and diff is less
if(null !== this.imageDetection.hash.hardThreshold && diff <= this.imageDetection.hash.hardThreshold) {
return x;
}
// hard is either not defined or diff was gerater than hard
// if soft is defined
if (this.imageDetection.hash.softThreshold !== undefined) {
// and diff is greater than soft allowance
if(diff > this.imageDetection.hash.softThreshold) {
// not similar enough
return null;
}
// similar enough, will continue on to pixel (if enabled!)
} else {
// only hard was defined and did not pass
return null;
}
}
// at this point either hash was not enabled or it was and we hit soft threshold but not hard
if(this.imageDetection.pixel.enable) {
try {
const [compareResult, sameImage] = await compareImages(referenceImage, imgData, this.imageDetection.pixel.threshold / 100);
analysisTimes.push(compareResult.analysisTime);
if (sameImage) {
return x;
}
} catch (err: any) {
this.logger.warn(`Unexpected error encountered while pixel-comparing images, will skip comparison => ${err.message}`);
}
}
} 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}`);
}
}
}
return null;
}
// parallel all the things
this.logger.profile('asyncCompare');
const results = await pMap(viableActivity, ci, {concurrency: imageCompareMaxConcurrencyGuess});
this.logger.profile('asyncCompare', {level: 'debug', message: 'Total time for image comparison (incl download/cache calls)'});
const totalAnalysisTime = analysisTimes.reduce((acc, x) => acc + x,0);
if(analysisTimes.length > 0) {
this.logger.debug(`Reference image pixel-compared ${analysisTimes.length} times. Timings: Avg ${formatNumber(totalAnalysisTime / analysisTimes.length, {toFixed: 0})}ms | Max: ${Math.max(...analysisTimes)}ms | Min: ${Math.min(...analysisTimes)}ms | Total: ${totalAnalysisTime}ms (${formatNumber(totalAnalysisTime/1000)}s)`);
}
filteredActivity = filteredActivity.concat(results.filter(x => x !== null));
if (longRun !== undefined) {
clearTimeout(longRun);
}
viableActivity = filteredActivity;
}
}
@@ -101,43 +284,71 @@ export class RecentActivityRule extends Rule {
} = triggerSet;
// convert subreddits array into entirely StrongSubredditState
const subStates: StrongSubredditState[] = subreddits.map((x) => {
if(typeof x === 'string') {
return toStrongSubredditState({name: x, stateDescription: x}, {defaultFlags: 'i', generateDescription: true});
const defaultOpts = {
defaultFlags: 'i',
generateDescription: true
};
const subStates: StrongSubredditState[] = subreddits.map((x) => convertSubredditsRawToStrong(x, defaultOpts));
let validActivity: (Comment | Submission)[] = await as.filter(viableActivity, async (activity) => {
if (asSubmission(activity) && submissionState !== undefined) {
return await this.resources.testItemCriteria(activity, [submissionState]);
} else if (commentState !== undefined) {
return await this.resources.testItemCriteria(activity, [commentState]);
}
return toStrongSubredditState(x, {defaultFlags: 'i', generateDescription: true});
return true;
});
for(const activity of viableActivity) {
if(asSubmission(activity) && submissionState !== undefined) {
if(!(await this.resources.testItemCriteria(activity, [submissionState]))) {
validActivity = await this.resources.batchTestSubredditCriteria(validActivity, subStates);
for (const activity of validActivity) {
currCount++;
// @ts-ignore
combinedKarma += activity.score;
const pSub = getActivitySubredditName(activity);
if (!presentSubs.includes(pSub)) {
presentSubs.push(pSub);
}
}
for (const activity of viableActivity) {
if (asSubmission(activity) && submissionState !== undefined) {
if (!(await this.resources.testItemCriteria(activity, [submissionState]))) {
continue;
}
} else if(commentState !== undefined) {
if(!(await this.resources.testItemCriteria(activity, [commentState]))) {
} else if (commentState !== undefined) {
if (!(await this.resources.testItemCriteria(activity, [commentState]))) {
continue;
}
}
let inSubreddits = false;
for(const ss of subStates) {
for (const ss of subStates) {
const res = await this.resources.testSubredditCriteria(activity, ss);
if(res) {
if (res) {
inSubreddits = true;
break;
}
}
if(inSubreddits) {
if (inSubreddits) {
currCount++;
combinedKarma += activity.score;
const pSub = getActivitySubredditName(activity);
if(!presentSubs.includes(pSub)) {
if (!presentSubs.includes(pSub)) {
presentSubs.push(pSub);
}
}
}
const {operator, value, isPercent} = parseGenericValueOrPercentComparison(threshold);
let sum = {subsWithActivity: presentSubs, combinedKarma, karmaThreshold, subreddits: subStates.map(x => x.stateDescription), count: currCount, threshold, triggered: false, testValue: currCount.toString()};
let sum = {
subsWithActivity: presentSubs,
combinedKarma,
karmaThreshold,
subreddits: subStates.map(x => x.stateDescription),
count: currCount,
threshold,
triggered: false,
testValue: currCount.toString()
};
if (isPercent) {
sum.testValue = `${formatNumber((currCount / viableActivity.length) * 100)}%`;
if (comparisonTextOp(currCount / viableActivity.length, operator, value / 100)) {
@@ -149,9 +360,9 @@ export class RecentActivityRule extends Rule {
totalTriggeredOn = sum;
}
// if we would trigger on threshold need to also test for karma
if(totalTriggeredOn !== undefined && karmaThreshold !== undefined) {
if (totalTriggeredOn !== undefined && karmaThreshold !== undefined) {
const {operator: opKarma, value: valueKarma} = parseGenericValueOrPercentComparison(karmaThreshold);
if(!comparisonTextOp(combinedKarma, opKarma, valueKarma)) {
if (!comparisonTextOp(combinedKarma, opKarma, valueKarma)) {
sum.triggered = false;
totalTriggeredOn = undefined;
}
@@ -169,7 +380,7 @@ export class RecentActivityRule extends Rule {
result = `${PASS} ${resultData.result}`;
this.logger.verbose(result);
return Promise.resolve([true, this.getResult(true, resultData)]);
} else if(summaries.length === 1) {
} else if (summaries.length === 1) {
// can display result if its only one summary otherwise need to log to debug
const res = this.generateResultData(summaries[0], viableActivity);
result = `${FAIL} ${res.result}`;
@@ -182,7 +393,7 @@ export class RecentActivityRule extends Rule {
return Promise.resolve([false, this.getResult(false, {result})]);
}
generateResultData(summary: any, activities: (Submission | Comment)[] = []) {
const {
count,
@@ -196,7 +407,7 @@ export class RecentActivityRule extends Rule {
} = summary;
const relevantSubs = subsWithActivity.length === 0 ? subreddits : subsWithActivity;
let totalSummary = `${testValue} activities over ${relevantSubs.length} subreddits${karmaThreshold !== undefined ? ` with ${combinedKarma} combined karma` : ''} ${triggered ? 'met' : 'did not meet'} threshold of ${threshold}${karmaThreshold !== undefined ? ` and ${karmaThreshold} combined karma` : ''}`;
if(triggered && subsWithActivity.length > 0) {
if (triggered && subsWithActivity.length > 0) {
totalSummary = `${totalSummary} -- subreddits: ${subsWithActivity.join(', ')}`;
}
return {
@@ -223,12 +434,12 @@ export class RecentActivityRule extends Rule {
* */
export interface ActivityThreshold {
/**
* When present, a Submission will only be counted if it meets this criteria
* */
* When present, a Submission will only be counted if it meets this criteria
* */
submissionState?: SubmissionState
/**
* When present, a Comment will only be counted if it meets this criteria
* */
* When present, a Comment will only be counted if it meets this criteria
* */
commentState?: CommentState
/**
@@ -288,6 +499,8 @@ interface RecentActivityConfig extends ActivityWindow, ReferenceSubmission {
* @minItems 1
* */
thresholds: ActivityThreshold[],
imageDetection?: ImageDetection
}
export interface RecentActivityRuleOptions extends RecentActivityConfig, RuleOptions {

View File

@@ -296,6 +296,7 @@ export class RegexRule extends Rule {
const logSummary: string[] = [];
let index = 0;
let matchSample = undefined;
for (const c of criteriaResults) {
index++;
let msg = `Criteria ${c.criteria.name || `#${index}`} ${triggeredIndicator(c.triggered)}`;
@@ -309,8 +310,8 @@ export class RegexRule extends Rule {
}
msg = `${msg} (Window: ${c.criteria.window})`;
if(c.matches.length > 0) {
let matchSample = `-- Matched Values: ${c.matches.slice(0, 3).map(x => `"${x}"`).join(', ')}${c.matches.length > 3 ? `, and ${c.matches.length - 3} more...` : ''}`;
logSummary.push(`${msg} ${matchSample}`);
matchSample = `${c.matches.slice(0, 3).map(x => `"${x}"`).join(', ')}${c.matches.length > 3 ? `, and ${c.matches.length - 3} more...` : ''}`;
logSummary.push(`${msg} -- Matched Values: ${matchSample}`);
} else {
logSummary.push(msg);
}
@@ -319,7 +320,7 @@ export class RegexRule extends Rule {
const result = `${triggeredIndicator(criteriaMet)} ${logSummary.join(' || ')}`;
this.logger.verbose(result);
return Promise.resolve([criteriaMet, this.getResult(criteriaMet, {result, data: criteriaResults})]);
return Promise.resolve([criteriaMet, this.getResult(criteriaMet, {result, data: {results: criteriaResults, matchSample }})]);
}
protected getMatchesFromActivity(a: (Submission | Comment), testOn: string[], reg: RegExp): string[] {

View File

@@ -4,7 +4,7 @@ import {
activityWindowText, asSubmission,
comparisonTextOp, FAIL, getActivitySubredditName, isExternalUrlSubmission, isRedditMedia,
parseGenericValueComparison, parseSubredditName,
parseUsableLinkIdentifier as linkParser, PASS, toStrongSubredditState
parseUsableLinkIdentifier as linkParser, PASS, subredditStateIsNameOnly, toStrongSubredditState
} from "../util";
import {
ActivityWindow,
@@ -58,6 +58,7 @@ export class RepeatActivityRule extends Rule {
lookAt: 'submissions' | 'all';
include: (string | SubredditState)[];
exclude: (string | SubredditState)[];
hasFullSubredditCrits: boolean = false;
activityFilterFunc: (x: Submission|Comment) => Promise<boolean> = async (x) => true;
keepRemoved: boolean;
minWordCount: number;
@@ -91,6 +92,7 @@ export class RepeatActivityRule extends Rule {
}
return toStrongSubredditState(x, {defaultFlags: 'i', generateDescription: true});
});
this.hasFullSubredditCrits = !subStates.every(x => subredditStateIsNameOnly(x));
this.activityFilterFunc = async (x: Submission|Comment) => {
for(const ss of subStates) {
if(await this.resources.testSubredditCriteria(x, ss)) {
@@ -106,6 +108,7 @@ export class RepeatActivityRule extends Rule {
}
return toStrongSubredditState(x, {defaultFlags: 'i', generateDescription: true});
});
this.hasFullSubredditCrits = !subStates.every(x => subredditStateIsNameOnly(x));
this.activityFilterFunc = async (x: Submission|Comment) => {
for(const ss of subStates) {
if(await this.resources.testSubredditCriteria(x, ss)) {
@@ -149,6 +152,12 @@ export class RepeatActivityRule extends Rule {
break;
}
if(this.hasFullSubredditCrits) {
// go ahead and cache subreddits now
// because we can't use batch test since testing activities in order is important for this rule
await this.resources.cacheSubreddits(activities.map(x => x.subreddit));
}
const condensedActivities = await activities.reduce(async (accProm: Promise<RepeatActivityReducer>, activity: (Submission | Comment), index: number) => {
const acc = await accProm;
const {openSets = [], allSets = []} = acc;

897
src/Rule/RepostRule.ts Normal file
View File

@@ -0,0 +1,897 @@
import {Rule, RuleJSONConfig, RuleOptions, RuleResult} from "./index";
import {Listing, SearchOptions} from "snoowrap";
import Submission from "snoowrap/dist/objects/Submission";
import Comment from "snoowrap/dist/objects/Comment";
import {
compareDurationValue,
comparisonTextOp,
FAIL, formatNumber,
isRepostItemResult, parseDurationComparison, parseGenericValueComparison,
parseUsableLinkIdentifier,
PASS, searchAndReplace, stringSameness, triggeredIndicator, windowToActivityWindowCriteria, wordCount
} from "../util";
import {
ActivityWindow,
ActivityWindowType,
CompareValue, DurationComparor,
JoinOperands,
RepostItem,
RepostItemResult,
SearchAndReplaceRegExp,
SearchFacetType,
} from "../Common/interfaces";
import objectHash from "object-hash";
import {getActivities, getAttributionIdentifier} from "../Utils/SnoowrapUtils";
import Fuse from "fuse.js";
import leven from "leven";
import {YoutubeClient, commentsAsRepostItems} from "../Utils/ThirdParty/YoutubeClient";
import dayjs from "dayjs";
import {rest} from "lodash";
const parseYtIdentifier = parseUsableLinkIdentifier();
export interface TextMatchOptions {
/**
* The percentage, as a whole number, of a repost title/comment that must match the title/comment being checked in order to consider both a match
*
* Note: Setting to 0 will make every candidate considered a match -- useful if you want to match if the URL has been reposted anywhere
*
* Defaults to `85` (85%)
*
* @default 85
* @example [85]
* */
matchScore?: number
/**
* The minimum number of words in the activity being checked for which this rule will run on
*
* If the word count is below the minimum the rule fails
*
* Defaults to 2
*
* @default 2
* @example [2]
* */
minWordCount?: number
/**
* Should text matching be case sensitive?
*
* Defaults to false
*
* @default false
* @example [false]
**/
caseSensitive?: boolean
}
export interface TextTransformOptions {
/**
* A set of search-and-replace operations to perform on text values before performing a match. Transformations are performed in the order they are defined.
*
* * If `transformationsActivity` IS NOT defined then these transformations will be performed on BOTH the activity text (submission title or comment) AND the repost candidate text
* * If `transformationsActivity` IS defined then these transformations are only performed on repost candidate text
* */
transformations?: SearchAndReplaceRegExp[]
/**
* Specify a separate set of transformations for the activity text (submission title or comment)
*
* To perform no transformations when `transformations` is defined set this to an empty array (`[]`)
* */
transformationsActivity?: SearchAndReplaceRegExp[]
}
export interface SearchFacetJSONConfig extends TextMatchOptions, TextTransformOptions, ActivityWindow {
kind: SearchFacetType | SearchFacetType[]
}
export interface SearchFacet extends SearchFacetJSONConfig {
kind: SearchFacetType
}
export type TimeBasedSelector = "newest" | "oldest" | "any" | "all";
export interface OccurredAt {
/**
* Which repost to test on
*
* * `any` -- ANY repost passing `condition` will cause this criteria to be true
* * `all` -- ALL reposts must pass `condition` for this criteria to be true
* */
"testOn": TimeBasedSelector,
"condition": DurationComparor
}
export interface OccurrenceTests {
count?: {
condition?: JoinOperands
/**
* An array of strings containing a comparison operator and the number of repost occurrences to compare against
*
* Examples:
*
* * `">= 7"` -- TRUE if 7 or more reposts were found
* * `"< 1"` -- TRUE if less than 0 reposts were found
* */
test: CompareValue[]
}
/**
* Test the time the reposts occurred at
* */
time?: {
/**
* How to test all the specified comparisons
*
* * AND -- All criteria must be true
* * OR -- Any criteria must be true
*
* Defaults to AND
*
* @default AND
* @example ["AND", "OR"]
* */
condition?: JoinOperands
/**
* An array of time-based conditions to test against found reposts (test when a repost was made)
* */
test: OccurredAt[]
}
}
/**
* A set of criteria used to find reposts
*
* Contains options and conditions used to define how candidate reposts are retrieved and if they are a match.
*
* */
export interface RepostCriteria extends ActivityWindow, TextMatchOptions, TextTransformOptions {
/**
* Define how to find candidate reposts
*
* * **title** -- search reddit for submissions with the same title
* * **url** -- search reddit for submissions with the same url
* * **external** -- WHEN ACTIVITY IS A COMMENT - tries to get comments from external source (youtube, twitter, etc...)
* */
searchOn?: (SearchFacetType | SearchFacetJSONConfig)[]
/**
* A set of comparisons to test against the number of reposts found
*
* If not specified the default is "AND [occurrences] > 0" IE any reposts makes this test pass
* */
occurrences?: {
/**
* How to test all the specified comparisons
*
* * AND -- All criteria must be true
* * OR -- Any criteria must be true
*
* Defaults to AND
*
* @default AND
* @example ["AND", "OR"]
* */
condition?: JoinOperands
criteria?: OccurrenceTests[]
}
/**
* Test the time the reposts occurred at
* */
occurredAt?: {
/**
* How to test all the specified comparisons
*
* * AND -- All criteria must be true
* * OR -- Any criteria must be true
*
* Defaults to AND
*
* @default AND
* @example ["AND", "OR"]
* */
condition?: JoinOperands
/**
* An array of time-based conditions to test against found reposts (test when a repost was made)
* */
criteria: OccurredAt[]
}
/**
* The maximum number of comments/submissions to check
*
* In both cases this list is gathered from sorting all submissions or all comments from all submission by number of votes and taking the "top" maximum specified
*
* For comment checks this is the number of comments cached
*
* @default 50
* @example [50]
* */
maxRedditItems?: number
/**
* The maximum number of external items (youtube comments) to check (and cache for comment checks)
*
* @default 50
* @example [50]
* */
maxExternalItems?: number
}
export interface CriteriaResult {
passed: boolean
conditionsSummary: string
items: RepostItemResult[]
}
const parentSubmissionSearchFacetDefaults = {
title: {
matchScore: 85,
minWordCount: 3
},
url: {
matchScore: 0, // when looking for submissions to find repost comments on automatically include any with exact same url
},
duplicates: {
matchScore: 0, // when looking for submissions to find repost comments on automatically include any that reddit thinks are duplicates
},
crossposts: {
matchScore: 0, // when looking for submissions to find repost comments on automatically include any that reddit thinks are crossposts
},
external: {}
}
const isSearchFacetType = (val: any): val is SearchFacetType => {
if (typeof val === 'string') {
return ['title', 'url', 'duplicates', 'crossposts', 'external'].includes(val);
}
return false;
}
const generateSearchFacet = (val: SearchFacetType | SearchFacetJSONConfig): SearchFacet[] => {
let facets: SearchFacet[] = [];
if (isSearchFacetType(val)) {
facets.push({
kind: val
});
} else if (Array.isArray(val.kind)) {
facets.concat(val.kind.map(x => ({...val, kind: x})));
} else {
facets.push(val as SearchFacet);
}
return facets.map(x => {
return {
...parentSubmissionSearchFacetDefaults[x.kind],
...x,
}
});
}
export class RepostRule extends Rule {
criteria: RepostCriteria[]
condition: JoinOperands;
submission?: Submission;
constructor(options: RepostRuleOptions) {
super(options);
const {
criteria = [{}],
condition = 'OR'
} = options || {};
if (criteria.length < 1) {
throw new Error('Must provide at least one RepostCriteria');
}
this.criteria = criteria;
this.condition = condition;
}
getKind(): string {
return 'Repost';
}
protected getSpecificPremise(): object {
return {
criteria: this.criteria,
condition: this.condition
}
}
// @ts-ignore
protected async getSubmission(item: Submission | Comment) {
if (item instanceof Comment) {
// @ts-ignore
return await this.client.getSubmission(item.link_id).fetch();
}
return item;
}
protected async process(item: Submission | Comment): Promise<[boolean, RuleResult]> {
let criteriaResults: CriteriaResult[] = [];
let ytClient: YoutubeClient | undefined = undefined;
let criteriaMatchedResults: RepostItemResult[] = [];
let totalSubs = 0;
let totalCommentSubs = 0;
let totalComments = 0;
let totalExternal = new Map<string,number>();
let fromCache = false;
let andFail = false;
for (const rCriteria of this.criteria) {
criteriaMatchedResults = [];
const {
searchOn = (item instanceof Submission ? ['title', 'url', 'duplicates', 'crossposts'] : ['external', 'title', 'url', 'duplicates', 'crossposts']),
//criteria = {},
maxRedditItems = 50,
maxExternalItems = 50,
window = 20,
...restCriteria
} = rCriteria;
const searchFacets = searchOn.map(x => generateSearchFacet(x)).flat(1) as SearchFacet[];
const includeCrossposts = searchFacets.some(x => x.kind === 'crossposts');
// in getDuplicate() options add "crossposts_only=1" to get only crossposts https://www.reddit.com/r/redditdev/comments/b4t5g4/get_all_the_subreddits_that_a_post_has_been/
// if a submission is a crosspost it has "crosspost_parent" attribute https://www.reddit.com/r/redditdev/comments/l46y2l/check_if_post_is_a_crosspost/
const strongWindow = windowToActivityWindowCriteria(window);
const candidateHash = `repostItems-${item instanceof Submission ? item.id : item.link_id}-${objectHash.sha1({
window,
searchOn
})}`;
let items: (RepostItem|RepostItemResult)[] = [];
let cacheRes = undefined;
if (item instanceof Comment) {
cacheRes = await this.resources.cache.get(candidateHash) as ((RepostItem|RepostItemResult)[] | undefined | null);
}
if (cacheRes === undefined || cacheRes === null) {
const sub = await this.getSubmission(item);
let dups: (Submission[] | undefined) = undefined;
for (const sf of searchFacets) {
const {
matchScore = 85,
minWordCount = 3,
transformations = [],
} = sf;
if (sf.kind === 'external') {
const attribution = getAttributionIdentifier(sub);
switch (attribution.provider) {
case 'YouTube':
const ytCreds = this.resources.getThirdPartyCredentials('youtube')
if (ytCreds === undefined) {
throw new Error('Cannot extract comments from Youtube because a Youtube Data API key was not provided in configuration');
}
if (ytClient === undefined) {
ytClient = new YoutubeClient(ytCreds.apiKey);
}
const ytComments = commentsAsRepostItems(await ytClient.getVideoTopComments(sub.url, maxExternalItems));
items = items.concat(ytComments)
totalExternal.set('Youtube comments', (totalExternal.get('Youtube comments') ?? 0) + ytComments.length);
break;
default:
if (attribution.provider === undefined) {
this.logger.debug('Unable to determine external provider');
continue;
} else {
this.logger.debug(`External parsing of ${attribution} is not supported yet.`);
continue;
}
}
} else {
let subs: Submission[];
if (['title', 'url'].includes(sf.kind)) {
let query: string;
let searchFunc: (limit: number) => Promise<Listing<Submission | Comment>>;
if (sf.kind === 'title') {
query = (await this.getSubmission(item)).title;
searchFunc = (limit: number) => {
let opts: SearchOptions = {
query,
limit,
sort: 'relevance'
};
if (strongWindow.subreddits?.include !== undefined && strongWindow.subreddits?.include.length > 0) {
opts.restrictSr = true;
opts.subreddit = strongWindow.subreddits?.include.join('+');
}
return this.client.search(opts);
}
} else {
const attr = getAttributionIdentifier(sub);
if (attr.provider === 'YouTube') {
const ytId = parseYtIdentifier(sub.url);
query = `url:https://youtu.be/${ytId}`;
} else {
query = `url:${sub.url}`;
}
searchFunc = (limit: number) => {
let opts: SearchOptions = {
query,
limit,
sort: 'top'
};
if (strongWindow.subreddits?.include !== undefined && strongWindow.subreddits?.include.length > 0) {
opts.restrictSr = true;
opts.subreddit = strongWindow.subreddits?.include.join('+');
}
return this.client.search(opts);
}
}
subs = await getActivities(searchFunc, {window: strongWindow}) as Submission[];
} else {
if (dups === undefined) {
let searchFunc: (limit: number) => Promise<Listing<Submission | Comment>> = (limit: number) => {
// this does not work correctly
// see https://github.com/not-an-aardvark/snoowrap/issues/320
// searchFunc = (limit: number) => {
// return sub.getDuplicates({crossposts_only: 0, limit});
// };
return this.client.oauthRequest({
uri: `duplicates/${sub.id}`,
qs: {
limit,
}
}).then(x => {
return Promise.resolve(x.comments) as Promise<Listing<Submission>>
});
};
subs = await getActivities(searchFunc, {window: strongWindow}) as Submission[];
dups = subs;
} else {
subs = dups;
}
if (sf.kind === 'duplicates') {
// @ts-ignore
subs = subs.filter(x => x.crosspost_parent === undefined)
} else {
// @ts-ignore
subs = subs.filter(x => x.crosspost_parent !== undefined && x.crosspost_parent === sub.id)
}
}
// filter by minimum word count
subs = subs.filter(x => wordCount(x.title) > minWordCount);
items = items.concat(subs.map(x => ({
value: searchAndReplace(x.title, transformations),
createdOn: x.created,
source: 'reddit',
sourceUrl: x.permalink,
id: x.id,
score: x.score,
itemType: 'submission',
acquisitionType: sf.kind,
sourceObj: x,
reqSameness: matchScore,
})));
}
}
if (!includeCrossposts) {
const sub = await this.getSubmission(item);
// remove submissions if they are official crossposts of the submission being checked and searchOn did not include 'crossposts'
items = items.filter(x => x.itemType !== 'submission' || !(x.sourceObj.crosspost_parent !== undefined && x.sourceObj.crosspost_parent === sub.id))
}
let sourceTitle = searchAndReplace(sub.title, restCriteria.transformationsActivity ?? []);
// do submission scoring BEFORE pruning duplicates bc...
// might end up in a situation where we get same submission for both title and url
// -- url is always a repost but title is not guaranteed and we if remove the url item but not the title we could potentially filter the title submission out and miss this repost
items = items.reduce((acc: (RepostItem|RepostItemResult)[], x) => {
if(x.itemType === 'submission') {
totalSubs++;
const sf = searchFacets.find(y => y.kind === x.acquisitionType) as SearchFacet;
let cleanTitle = x.value;
if (!(sf.caseSensitive ?? false)) {
cleanTitle = cleanTitle.toLowerCase();
}
const strMatchResults = stringSameness(sourceTitle, cleanTitle);
if(strMatchResults.highScoreWeighted >= (x.reqSameness as number)) {
return acc.concat({
...x,
sameness: Math.min(strMatchResults.highScoreWeighted, 100),
});
}
return acc;
}
return acc.concat(x);
}, []);
// now remove duplicate submissions
items = items.reduce((acc: RepostItem[], curr) => {
if(curr.itemType !== 'submission') {
return acc.concat(curr);
}
const subId = curr.sourceObj.id;
if (sub.id !== subId && !acc.some(x => x.itemType === 'submission' && x.sourceObj.id === subId)) {
return acc.concat(curr);
}
return acc;
}, []);
if (item instanceof Comment) {
// we need to gather comments from submissions
// first cut down the number of submissions to retrieve because we don't care about have ALL submissions,
// just most popular comments (which will be in the most popular submissions)
let subs = items.filter(x => x.itemType === 'submission').map(x => x.sourceObj) as Submission[];
totalCommentSubs += subs.length;
const nonSubItems = items.filter(x => x.itemType !== 'submission' && wordCount(x.value) > (restCriteria.minWordCount ?? 3));
subs.sort((a, b) => a.score - b.score).reverse();
// take top 10 submissions
subs = subs.slice(0, 10);
let comments: Comment[] = [];
for (const sub of subs) {
const commFunc = (limit: number) => {
return this.client.oauthRequest({
uri: `${sub.subreddit_name_prefixed}/comments/${sub.id}`,
// get ONLY top-level comments, sorted by Top
qs: {
sort: 'top',
depth: 0,
limit,
}
}).then(x => {
return x.comments as Promise<Listing<Comment>>
});
}
// and return the top 20 most popular
const subComments = await getActivities(commFunc, {window: {count: 20}, skipReplies: true}) as Listing<Comment>;
comments = comments.concat(subComments);
}
// sort by highest scores
comments.sort((a, b) => a.score - b.score).reverse();
// filter out all comments with fewer words than required (prevent false negatives)
comments.filter(x => wordCount(x.body) > (restCriteria.minWordCount ?? 3));
totalComments += Math.min(comments.length, maxRedditItems);
// and take the user-defined maximum number of items
items = nonSubItems.concat(comments.slice(0, maxRedditItems).map(x => ({
value: searchAndReplace(x.body, restCriteria.transformations ?? []),
createdOn: x.created,
source: 'reddit',
id: x.id,
sourceUrl: x.permalink,
score: x.score,
itemType: 'comment',
acquisitionType: 'comment'
})));
}
// cache items for 20 minutes
await this.resources.cache.set(candidateHash, items, {ttl: 1200});
} else {
items = cacheRes;
totalExternal = items.reduce((acc, curr) => {
if(curr.acquisitionType === 'external') {
acc.set(`${curr.source} comments`, (acc.get(`${curr.source} comments`) ?? 0 ) + 1);
return acc;
}
return acc;
}, new Map<string, number>());
//totalSubs = items.filter(x => x.itemType === 'submission').length;
//totalCommentSubs = totalSubs;
totalComments = items.filter(x => x.itemType === 'comment' && x.source === 'reddit').length;
fromCache = true;
}
const {
matchScore = 85,
caseSensitive = false,
transformations = [],
transformationsActivity = transformations,
occurrences = {
condition: 'AND',
criteria: [
{
count: {
test: ['> 0']
}
}
]
},
} = restCriteria;
if(item instanceof Submission) {
// we've already done difference calculations in the searchFacet phase
// and when the check is for a sub it means we are only checking if the submissions has been reposted which means either:
// * very similar title (default sameness of 85% or more)
// * duplicate/same URL -- which is a repost, duh
// so just add all items to critMatches at this point
criteriaMatchedResults = criteriaMatchedResults.concat(items.filter(x => "sameness" in x) as RepostItemResult[]);
} else {
let sourceContent = searchAndReplace(item.body, transformationsActivity);
if (!caseSensitive) {
sourceContent = sourceContent.toLowerCase();
}
for (const i of items) {
const itemContent = !caseSensitive ? i.value.toLowerCase() : i.value;
const strMatchResults = stringSameness(sourceContent, itemContent);
if(strMatchResults.highScoreWeighted >= matchScore) {
criteriaMatchedResults.push({
...i,
// @ts-ignore
reqSameness: matchScore,
sameness: Math.min(strMatchResults.highScoreWeighted, 100)
});
}
}
}
// now do occurrence and time tests
const {
condition: occCondition = 'AND',
criteria: occCriteria = [
{
count: {
test: ['> 0']
}
}
]
} = occurrences;
let orPass = false;
let occurrenceReason = null;
for(const occurrenceTest of occCriteria) {
const {
count:{
condition: oCondition = 'AND',
test: oCriteria = []
} = {},
time: {
condition: tCondition = 'AND',
test: tCriteria = [],
} = {}
} = occurrenceTest;
let conditionFailSummaries = [];
const passedConditions = [];
const failedConditions = [];
for (const oc of oCriteria) {
const ocCompare = parseGenericValueComparison(oc);
const ocMatch = comparisonTextOp(criteriaMatchedResults.length, ocCompare.operator, ocCompare.value);
if (ocMatch) {
passedConditions.push(oc);
} else {
failedConditions.push(oc);
if (oCondition === 'AND') {
conditionFailSummaries.push(`(AND) ${oc} occurrences was not true`);
break;
}
}
}
if (passedConditions.length === 0 && oCriteria.length > 0) {
conditionFailSummaries.push('(OR) No occurrence tests passed');
}
const existingPassed = passedConditions.length;
if (conditionFailSummaries.length === 0) {
const timeAwareReposts = [...criteriaMatchedResults].filter(x => x.createdOn !== undefined).sort((a, b) => (a.createdOn as number) - (b.createdOn as number));
for (const tc of tCriteria) {
let toTest: RepostItemResult[] = [];
const durationCompare = parseDurationComparison(tc.condition);
switch (tc.testOn) {
case 'newest':
case 'oldest':
if (tc.testOn === 'newest') {
toTest = timeAwareReposts.slice(-1);
} else {
toTest = timeAwareReposts.slice(0, 1);
}
break;
case 'any':
case 'all':
toTest = timeAwareReposts;
break;
}
const timePass = tc.testOn === 'any' ? toTest.some(x => compareDurationValue(durationCompare, dayjs.unix(x.createdOn as number))) : toTest.every(x => compareDurationValue(durationCompare, dayjs.unix(x.createdOn as number)));
if (timePass) {
passedConditions.push(tc.condition);
} else {
failedConditions.push(tc.condition);
if (tCondition === 'AND') {
conditionFailSummaries.push(`(AND) ${tc.condition} was not true`);
break;
}
}
}
if (tCriteria.length > 0 && passedConditions.length === existingPassed) {
conditionFailSummaries.push('(OR) No time-based tests passed');
}
}
if(conditionFailSummaries.length !== 0 && occCondition === 'AND') {
// failed occurrence tests (high-level)
occurrenceReason = conditionFailSummaries.join(' | ');
break;
}
if(passedConditions.length > 0 && occCondition === 'OR') {
occurrenceReason = passedConditions.join(' | ');
orPass = true;
break;
}
}
let passed = occCriteria.length === 0;
if(occCriteria.length > 0) {
if(occCondition === 'OR') {
passed = orPass;
occurrenceReason = occurrenceReason === null ? 'No occurrence test sets passed' : occurrenceReason;
} else if(occCondition === 'AND') {
passed = occurrenceReason === null;
occurrenceReason = occurrenceReason === null ? 'All tests passed' : occurrenceReason;
}
//passed = (occCondition === 'OR' && orPass) || (occurrenceFailureReason === null && occCondition === 'AND')
}
const results = {
passed,
conditionsSummary: occurrenceReason as string,
items: criteriaMatchedResults
};
criteriaResults.push(results)
if(!results.passed) {
if(this.condition === 'AND') {
andFail = true;
break;
}
} else if(this.condition === 'OR') {
break;
}
if (!results.passed && this.condition === 'AND') {
andFail = true;
break;
}
}
// get all repost items for stats and SCIENCE
const repostItemResults = [...criteriaResults
// only want reposts from criteria that passed
.filter(x => x.passed).map(x => x.items)
.flat()
// make sure we are only accumulating unique reposts
.reduce((acc, curr) => {
const hash = `${curr.source}-${curr.itemType}-${curr.id}`;
if (!acc.has(hash)) {
acc.set(hash, curr);
}
return acc;
}, new Map<string, RepostItemResult>()).values()];
repostItemResults.sort((a, b) => a.sameness - b.sameness).reverse();
const foundRepost = criteriaResults.length > 0;
let avgSameness = null;
let closestSummary = null;
let closestSameness = null;
let searchCandidateSummary = '';
if(item instanceof Comment) {
searchCandidateSummary = `Searched top ${totalComments} comments in top 10 ${fromCache ? '' : `of ${totalCommentSubs} `}most popular submissions`;
if(totalExternal.size > 0) {
searchCandidateSummary += ", ";
const extSumm: string[] = [];
totalExternal.forEach((v, k) => {
extSumm.push(`${v} ${k}`);
});
searchCandidateSummary += extSumm.join(', ');
}
} else {
searchCandidateSummary = `Searched ${totalSubs}`
}
let summary = `${searchCandidateSummary} and found ${repostItemResults.length} reposts.`;
if(repostItemResults.length > 0) {
avgSameness = formatNumber(repostItemResults.reduce((acc, curr) => acc + curr.sameness, 0) / criteriaResults.length);
const closest = repostItemResults[0];
summary += ` --- Closest Match => >> ${closest.value} << from ${closest.source} (${closest.sourceUrl}) with ${formatNumber(closest.sameness)}% sameness.`
closestSummary = `matched a ${closest.itemType} from ${closest.source}`;
closestSameness = closest.sameness;
if(criteriaResults.length > 1) {
summary += ` Avg ${formatNumber(avgSameness)}%`;
}
}
let passed;
if(this.condition === 'AND') {
const failedCrit = criteriaResults.find(x => !x.passed);
if(failedCrit !== undefined) {
summary += `BUT a criteria failed >> ${failedCrit.conditionsSummary} << and rule has AND condition.`;
passed = false;
} else {
passed = true;
}
} else {
const passedCrit = criteriaResults.find(x => x.passed);
if(passedCrit === undefined) {
summary += `BUT all criteria failed`;
passed = false;
} else {
passed = true;
}
}
const result = `${passed ? PASS : FAIL} ${summary}`;
this.logger.verbose(result);
return [passed, this.getResult(passed, {
result,
data: {
allResults: criteriaResults,
closestSameness: passed ? formatNumber(closestSameness as number) : undefined,
closestSummary: passed ? closestSummary : undefined,
}
})];
}
}
interface RepostConfig {
/**
* A list of Regular Expressions and conditions under which tested Activity(ies) are matched
* @minItems 1
* @examples [{"regex": "/reddit/", "matchThreshold": "> 3"}]
* */
criteria?: RepostCriteria[]
/**
* * If `OR` then any set of Criteria that pass will trigger the Rule
* * If `AND` then all Criteria sets must pass to trigger the Rule
*
* @default "OR"
* */
condition?: 'AND' | 'OR'
}
export interface RepostRuleOptions extends RepostConfig, RuleOptions {
}
/**
* Search for reposts of a Submission or Comment
*
* * For submissions the title or URL can searched and matched against
* * For comments, candidate comments are gathered from similar reddit submissions and/or external sources (youtube, twitter, etc..) and then matched against
*
* */
export interface RepostRuleJSONConfig extends RepostConfig, RuleJSONConfig {
/**
* @examples ["repost"]
* */
kind: 'repost'
}

View File

@@ -8,6 +8,7 @@ import HistoryRule, {HistoryJSONConfig} from "./HistoryRule";
import RegexRule, {RegexRuleJSONConfig} from "./RegexRule";
import {SubredditResources} from "../Subreddit/SubredditResources";
import Snoowrap from "snoowrap";
import {RepostRule, RepostRuleJSONConfig} from "./RepostRule";
export function ruleFactory
(config: RuleJSONConfig, logger: Logger, subredditName: string, resources: SubredditResources, client: Snoowrap): Rule {
@@ -31,6 +32,9 @@ export function ruleFactory
case 'regex':
cfg = config as RegexRuleJSONConfig;
return new RegexRule({...cfg, logger, subredditName, resources, client});
case 'repost':
cfg = config as RepostRuleJSONConfig;
return new RepostRule({...cfg, logger, subredditName, resources, client});
default:
throw new Error('rule "kind" was not recognized.');
}

View File

@@ -28,6 +28,7 @@ interface ResultContext {
export interface RuleResult extends ResultContext {
premise: RulePremise
kind: string
name: string
triggered: (boolean | null)
}
@@ -116,13 +117,13 @@ export abstract class Rule implements IRule, Triggerable {
this.logger.verbose('(Skipped) Exclusive author criteria not matched');
return Promise.resolve([null, this.getResult(null, {result: 'Exclusive author criteria not matched'})]);
}
} catch (err) {
} catch (err: any) {
this.logger.error('Error occurred during Rule pre-process checks');
throw err;
}
try {
return this.process(item);
} catch (err) {
} catch (err: any) {
this.logger.error('Error occurred while processing rule');
throw err;
}
@@ -153,6 +154,7 @@ export abstract class Rule implements IRule, Triggerable {
protected getResult(triggered: (boolean | null) = null, context: ResultContext = {}): RuleResult {
return {
premise: this.getPremise(),
kind: this.getKind(),
name: this.name,
triggered,
...context,
@@ -209,22 +211,6 @@ export interface UserNoteCriteria {
search?: 'current' | 'consecutive' | 'total'
}
/**
* A duration and how to compare it against a value
*
* The syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`
*
* * EX `> 100 days` => Passes if the date being compared is before 100 days ago
* * EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months
*
* Unit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)
*
* [See] https://regexr.com/609n8 for example
*
* @pattern ^\s*(>|>=|<|<=)\s*(\d+)\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\s*$
* */
export type DurationComparor = string;
export interface IRule extends ChecksActivityState {
/**
* An optional, but highly recommended, friendly name for this rule. If not present will default to `kind`.
@@ -254,6 +240,6 @@ export interface RuleJSONConfig extends IRule {
* The kind of rule to run
* @examples ["recentActivity", "repeatActivity", "author", "attribution", "history"]
*/
kind: 'recentActivity' | 'repeatActivity' | 'author' | 'attribution' | 'history' | 'regex'
kind: 'recentActivity' | 'repeatActivity' | 'author' | 'attribution' | 'history' | 'regex' | 'repost'
}

View File

@@ -29,6 +29,26 @@
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
"type": "string"
},
"description": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "An (array of) string/regular expression to test contents of an Author's profile description against\n\nIf no flags are specified then the **insensitive** flag is used by default\n\nIf using an array then if **any** value in the array passes the description test passes",
"examples": [
[
"/test$/i",
"look for this string literal"
]
]
},
"flairCssClass": {
"description": "A list of (user) flair css class values from the subreddit to match against",
"examples": [
@@ -69,6 +89,10 @@
},
"type": "array"
},
"shadowBanned": {
"description": "Is the author shadowbanned?\n\nThis is determined by trying to retrieve the author's profile. If a 404 is returned it is likely they are shadowbanned",
"type": "boolean"
},
"totalKarma": {
"description": "A string containing a comparison operator and a value to compare against\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 100` => greater than 100",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
@@ -132,12 +156,22 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},
"deleted": {
"type": "boolean"
},
"depth": {
"description": "The (nested) level of a comment.\n\n* 0 mean the comment is at top-level (replying to submission)\n* non-zero, Nth value means the comment has N parent comments",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"distinguished": {
"type": "boolean"
},
@@ -189,6 +223,11 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},

View File

@@ -233,7 +233,7 @@
"properties": {
"aggregateOn": {
"default": "undefined",
"description": "This list determines which categories of domains should be aggregated on. All aggregated domains will be tested against `threshold`\n\n* If `media` is included then aggregate author's submission history which reddit recognizes as media (youtube, vimeo, etc.)\n* If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or reddit image/video (i.redd.it / v.redd.it)\n* If `link` is included then aggregate author's submission history which is external links but not media\n\nIf nothing is specified or list is empty (default) all domains are aggregated",
"description": "This list determines which categories of domains should be aggregated on. All aggregated domains will be tested against `threshold`\n\n* If `media` is included then aggregate author's submission history which reddit recognizes as media (youtube, vimeo, etc.)\n* If `redditMedia` is included then aggregate on author's submissions history which are media hosted on reddit: galleries, videos, and images (i.redd.it / v.redd.it)\n* If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or domain is `reddit.com`\n* If `link` is included then aggregate author's submission history which is external links and not recognized as `media` by reddit\n\nIf nothing is specified or list is empty (default) rule will only aggregate on `link` and `media` (ignores reddit-hosted content and self-posts)",
"examples": [
[
]
@@ -242,12 +242,23 @@
"enum": [
"link",
"media",
"redditMedia",
"self"
],
"type": "string"
},
"type": "array"
},
"commentState": {
"$ref": "#/definitions/CommentState",
"description": "When present, Comments from `window` will only be counted if they meet this criteria",
"examples": [
{
"op": true,
"removed": false
}
]
},
"consolidateMediaDomains": {
"default": false,
"description": "Should the criteria consolidate recognized media domains into the parent domain?\n\nSubmissions to major media domains (youtube, vimeo) can be identified by individual Channel/Author...\n\n* If `false` then domains will be aggregated at the channel level IE Youtube Channel A (2 counts), Youtube Channel B (3 counts)\n* If `true` then then media domains will be consolidated at domain level and then aggregated IE youtube.com (5 counts)",
@@ -276,27 +287,37 @@
"type": "boolean"
},
"exclude": {
"description": "Do not include Activities from this list of Subreddits (by name, case-insensitive)\n\nWill be ignored if `include` is present.\n\nEX `[\"mealtimevideos\",\"askscience\"]`",
"description": "When present, Activities WILL NOT be counted if they are found in this list of Subreddits\n\nEach value in the list can be either:\n\n * string (name of subreddit)\n * regular expression to run on the subreddit name\n * `SubredditState`\n\nEX `[\"mealtimevideos\",\"askscience\", \"/onlyfans*\\/i\", {\"over18\": true}]`",
"examples": [
"mealtimevideos",
"askscience"
[
"mealtimevideos",
"askscience",
"/onlyfans*/i",
{
"over18": true
}
]
],
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"include": {
"description": "Only include Activities from this list of Subreddits (by name, case-insensitive)\n\n\nEX `[\"mealtimevideos\",\"askscience\"]`",
"description": "When present, Activities WILL ONLY be counted if they are found in this list of Subreddits\n\nEach value in the list can be either:\n\n * string (name of subreddit)\n * regular expression to run on the subreddit name\n * `SubredditState`\n\nEX `[\"mealtimevideos\",\"askscience\", \"/onlyfans*\\/i\", {\"over18\": true}]`",
"examples": [
"mealtimevideos",
"askscience"
[
"mealtimevideos",
"askscience",
"/onlyfans*/i",
{
"over18": true
}
]
],
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"minActivityCount": {
@@ -307,6 +328,16 @@
"name": {
"type": "string"
},
"submissionState": {
"$ref": "#/definitions/SubmissionState",
"description": "When present, Submissions from `window` will only be counted if they meet this criteria",
"examples": [
{
"over_18": true,
"removed": false
}
]
},
"threshold": {
"default": "> 10%",
"description": "A string containing a comparison operator and a value to compare comments against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities originate from same attribution\n* EX `<= 10%` => less than 10% of all Activities have the same attribution",
@@ -418,11 +449,6 @@
],
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
"type": "string"
},
"useSubmissionAsReference": {
"default": true,
"description": "If activity is a Submission and is a link (not self-post) then only look at Submissions that contain this link, otherwise consider all activities.",
"type": "boolean"
}
},
"required": [
@@ -458,6 +484,26 @@
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
"type": "string"
},
"description": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "An (array of) string/regular expression to test contents of an Author's profile description against\n\nIf no flags are specified then the **insensitive** flag is used by default\n\nIf using an array then if **any** value in the array passes the description test passes",
"examples": [
[
"/test$/i",
"look for this string literal"
]
]
},
"flairCssClass": {
"description": "A list of (user) flair css class values from the subreddit to match against",
"examples": [
@@ -498,6 +544,10 @@
},
"type": "array"
},
"shadowBanned": {
"description": "Is the author shadowbanned?\n\nThis is determined by trying to retrieve the author's profile. If a 404 is returned it is likely they are shadowbanned",
"type": "boolean"
},
"totalKarma": {
"description": "A string containing a comparison operator and a value to compare against\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 100` => greater than 100",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
@@ -621,8 +671,6 @@
}
},
"required": [
"exclude",
"include",
"kind"
],
"type": "object"
@@ -922,6 +970,25 @@
],
"type": "string"
},
"ClearProcessedOptions": {
"description": "For very long-running, high-volume subreddits clearing the list of processed activities helps manage memory bloat\n\nAll of these options have default values based on the limit and/or interval set for polling options on each subreddit stream. They only need to modified if the defaults are not sufficient.\n\nIf both `after` and `size` are defined whichever is hit first will trigger the list to clear. `after` will be reset after ever clear.",
"properties": {
"after": {
"description": "An interval the processed list should be cleared after.\n\n* EX `9 days`\n* EX `3 months`\n* EX `5 minutes`",
"pattern": "^\\s*(?<time>\\d+)\\s*(?<unit>days?|weeks?|months?|years?|hours?|minutes?|seconds?|milliseconds?)\\s*$",
"type": "string"
},
"retain": {
"description": "The number of activities to retain in processed list after clearing.\n\nDefaults to `limit` value from `PollingOptions`",
"type": "number"
},
"size": {
"description": "Number of activities found in processed list after which the list should be cleared.\n\nDefaults to the `limit` value from `PollingOptions`",
"type": "number"
}
},
"type": "object"
},
"CommentActionJson": {
"description": "Reply to the Activity. For a submission the reply will be a top-level comment.",
"properties": {
@@ -1189,6 +1256,9 @@
{
"$ref": "#/definitions/RegexRuleJSONConfig"
},
{
"$ref": "#/definitions/RepostRuleJSONConfig"
},
{
"$ref": "#/definitions/RuleSetJson"
},
@@ -1216,12 +1286,22 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},
"deleted": {
"type": "boolean"
},
"depth": {
"description": "The (nested) level of a comment.\n\n* 0 mean the comment is at top-level (replying to submission)\n* non-zero, Nth value means the comment has N parent comments",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"distinguished": {
"type": "boolean"
},
@@ -1604,6 +1684,77 @@
],
"type": "object"
},
"ImageDetection": {
"description": "When comparing submissions detect if the reference submission is an image and do a pixel-comparison to other detected image submissions.\n\n**Note:** This is an **experimental feature**",
"properties": {
"enable": {
"description": "Is image detection enabled?",
"type": "boolean"
},
"fetchBehavior": {
"default": "extension",
"description": "Determines how and when to check if a URL is an image\n\n**Note:** After fetching a URL the **Content-Type** is validated to contain `image` before detection occurs\n\n**When `extension`:** (default)\n\n* Only URLs that end in known image extensions (.png, .jpg, etc...) are fetched\n\n**When `unknown`:**\n\n* URLs that end in known image extensions (.png, .jpg, etc...) are fetched\n* URLs with no extension or unknown (IE non-video, non-doc, etc...) are fetched\n\n**When `all`:**\n\n* All submissions that have URLs (non-self) will be fetched, regardless of extension\n* **Note:** This can be bandwidth/CPU intensive if history window is large so use with care",
"enum": [
"all",
"extension",
"unknown"
],
"type": "string"
},
"hash": {
"description": "Use perceptual hashing (blockhash-js) to compare images\n\nPros:\n\n* very fast\n* low cpu/memory usage\n* results can be cached\n\nCons:\n\n* not as accurate as pixel comparison\n* weaker for text-heavy images\n* mostly color-blind\n\nBest uses:\n\n* Detecting (general) duplicate images\n* Comparing large number of images",
"properties": {
"bits": {
"default": 32,
"description": "Bit count determines accuracy of hash and granularity of hash comparison (comparison to other hashes)\n\nDefault is `32`\n\n**NOTE:** Hashes of different sizes (bits) cannot be compared. If you are caching results make sure all rules where results may be shared use the same bit count to ensure hashes can be compared. Otherwise hashes will be recomputed.",
"type": "number"
},
"enable": {
"default": true,
"description": "Enabled by default.\n\nIf both `hash` and `pixel` are enabled then `pixel` will be used to verify image comparison when hashes matches",
"type": "boolean"
},
"hardThreshold": {
"description": "High Confidence Threshold\n\nIf the difference in comparison is equal to or less than this number the images are considered the same and pixel comparison WILL NOT occur\n\nDefaults to the parent-level `threshold` value if not present\n\nUse `null` if you want pixel comparison to ALWAYS occur (softThreshold must be present)",
"type": [
"null",
"number"
]
},
"softThreshold": {
"description": "Low Confidence Threshold -- only used if `pixel` is enabled\n\nIf the difference in comparison is\n\n1) equal to or less than this value and\n2) the value is greater than `hardThreshold`\n\nthe images will be compared using the `pixel` method",
"type": "number"
},
"ttl": {
"description": "Number of seconds to cache image hash",
"type": "number"
}
},
"type": "object"
},
"pixel": {
"description": "Use pixel counting to compare images\n\nPros:\n\n* most accurate\n* strong with text or color-only changes\n\nCons:\n\n* much slower than hashing\n* memory/cpu intensive\n\nBest uses:\n\n* Comparison text-only images\n* Comparison requires high degree of accuracy or changes are subtle",
"properties": {
"enable": {
"default": false,
"description": "Disabled by default.",
"type": "boolean"
},
"threshold": {
"description": "The percentage, as a whole number, of pixels that are **different** between the two images at which point the images are not considered the same.",
"type": "number"
}
},
"type": "object"
},
"threshold": {
"default": 5,
"description": "The percentage, as a whole number, of difference between two images at which point they will not be considered the same.\n\nWill be used as `hash.hardThreshold` and `pixel.threshold` if those values are not specified\n\nDefault is `5`",
"type": "number"
}
},
"type": "object"
},
"LockActionJson": {
"description": "Lock the Activity",
"properties": {
@@ -1861,6 +2012,76 @@
],
"type": "object"
},
"OccurredAt": {
"properties": {
"condition": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"testOn": {
"$ref": "#/definitions/TimeBasedSelector",
"description": "Which repost to test on\n\n* `any` -- ANY repost passing `condition` will cause this criteria to be true\n* `all` -- ALL reposts must pass `condition` for this criteria to be true"
}
},
"required": [
"condition",
"testOn"
],
"type": "object"
},
"OccurrenceTests": {
"properties": {
"count": {
"properties": {
"condition": {
"enum": [
"AND",
"OR"
],
"type": "string"
},
"test": {
"description": "An array of strings containing a comparison operator and the number of repost occurrences to compare against\n\nExamples:\n\n* `\">= 7\"` -- TRUE if 7 or more reposts were found\n* `\"< 1\"` -- TRUE if less than 0 reposts were found",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"test"
],
"type": "object"
},
"time": {
"description": "Test the time the reposts occurred at",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"test": {
"description": "An array of time-based conditions to test against found reposts (test when a repost was made)",
"items": {
"$ref": "#/definitions/OccurredAt"
},
"type": "array"
}
},
"required": [
"test"
],
"type": "object"
}
},
"type": "object"
},
"PollingOptions": {
"description": "A configuration for where, how, and when to poll Reddit for Activities to process",
"examples": [
@@ -1871,6 +2092,10 @@
}
],
"properties": {
"clearProcessed": {
"$ref": "#/definitions/ClearProcessedOptions",
"description": "For very long-running, high-volume subreddits clearing the list of processed activities helps manage memory bloat\n\nAll of these options have default values based on the limit and/or interval set for polling options on each subreddit stream. They only need to modified if the defaults are not sufficient.\n\nIf both `after` and `size` are defined whichever is hit first will trigger the list to clear. `after` will be reset after ever clear."
},
"delayUntil": {
"description": "Delay processing Activity until it is `N` seconds old\n\nUseful if there are other bots that may process an Activity and you want this bot to run first/last/etc.\n\nIf the Activity is already `N` seconds old when it is initially retrieved no refresh of the Activity occurs (no API request is made) and it is immediately processed.",
"type": "number"
@@ -1929,6 +2154,10 @@
}
]
},
"imageDetection": {
"$ref": "#/definitions/ImageDetection",
"description": "When comparing submissions detect if the reference submission is an image and do a pixel-comparison to other detected image submissions.\n\n**Note:** This is an **experimental feature**"
},
"itemIs": {
"anyOf": [
{
@@ -2565,6 +2794,224 @@
],
"type": "object"
},
"RepostCriteria": {
"description": "A set of criteria used to find reposts\n\nContains options and conditions used to define how candidate reposts are retrieved and if they are a match.",
"properties": {
"caseSensitive": {
"default": false,
"description": "Should text matching be case sensitive?\n\nDefaults to false",
"type": "boolean"
},
"matchScore": {
"default": 85,
"description": "The percentage, as a whole number, of a repost title/comment that must match the title/comment being checked in order to consider both a match\n\nNote: Setting to 0 will make every candidate considered a match -- useful if you want to match if the URL has been reposted anywhere\n\nDefaults to `85` (85%)",
"type": "number"
},
"maxExternalItems": {
"default": 50,
"description": "The maximum number of external items (youtube comments) to check (and cache for comment checks)",
"type": "number"
},
"maxRedditItems": {
"default": 50,
"description": "The maximum number of comments/submissions to check\n\nIn both cases this list is gathered from sorting all submissions or all comments from all submission by number of votes and taking the \"top\" maximum specified\n\nFor comment checks this is the number of comments cached",
"type": "number"
},
"minWordCount": {
"default": 2,
"description": "The minimum number of words in the activity being checked for which this rule will run on\n\nIf the word count is below the minimum the rule fails\n\nDefaults to 2",
"type": "number"
},
"occurredAt": {
"description": "Test the time the reposts occurred at",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"description": "An array of time-based conditions to test against found reposts (test when a repost was made)",
"items": {
"$ref": "#/definitions/OccurredAt"
},
"type": "array"
}
},
"required": [
"criteria"
],
"type": "object"
},
"occurrences": {
"description": "A set of comparisons to test against the number of reposts found\n\nIf not specified the default is \"AND [occurrences] > 0\" IE any reposts makes this test pass",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"items": {
"$ref": "#/definitions/OccurrenceTests"
},
"type": "array"
}
},
"type": "object"
},
"searchOn": {
"description": "Define how to find candidate reposts\n\n* **title** -- search reddit for submissions with the same title\n* **url** -- search reddit for submissions with the same url\n* **external** -- WHEN ACTIVITY IS A COMMENT - tries to get comments from external source (youtube, twitter, etc...)",
"items": {
"anyOf": [
{
"$ref": "#/definitions/SearchFacetJSONConfig"
},
{
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
}
]
},
"type": "array"
},
"transformations": {
"description": "A set of search-and-replace operations to perform on text values before performing a match. Transformations are performed in the order they are defined.\n\n* If `transformationsActivity` IS NOT defined then these transformations will be performed on BOTH the activity text (submission title or comment) AND the repost candidate text\n* If `transformationsActivity` IS defined then these transformations are only performed on repost candidate text",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"transformationsActivity": {
"description": "Specify a separate set of transformations for the activity text (submission title or comment)\n\nTo perform no transformations when `transformations` is defined set this to an empty array (`[]`)",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/ActivityWindowCriteria"
},
{
"$ref": "#/definitions/DurationObject"
},
{
"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"
]
}
},
"type": "object"
},
"RepostRuleJSONConfig": {
"description": "Search for reposts of a Submission or Comment\n\n* For submissions the title or URL can searched and matched against\n* For comments, candidate comments are gathered from similar reddit submissions and/or external sources (youtube, twitter, etc..) and then matched against",
"properties": {
"authorIs": {
"$ref": "#/definitions/AuthorOptions",
"description": "If present then these Author criteria are checked before running the rule. If criteria fails then the rule is skipped.",
"examples": [
{
"include": [
{
"flairText": [
"Contributor",
"Veteran"
]
},
{
"isMod": true
}
]
}
]
},
"condition": {
"default": "OR",
"description": "* If `OR` then any set of Criteria that pass will trigger the Rule\n* If `AND` then all Criteria sets must pass to trigger the Rule",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"description": "A list of Regular Expressions and conditions under which tested Activity(ies) are matched",
"examples": [
{
"matchThreshold": "> 3",
"regex": "/reddit/"
}
],
"items": {
"$ref": "#/definitions/RepostCriteria"
},
"minItems": 1,
"type": "array"
},
"itemIs": {
"anyOf": [
{
"items": {
"$ref": "#/definitions/SubmissionState"
},
"type": "array"
},
{
"items": {
"$ref": "#/definitions/CommentState"
},
"type": "array"
}
],
"description": "A list of criteria to test the state of the `Activity` against before running the Rule.\n\nIf any set of criteria passes the Rule will be run. If the criteria fails then the Rule is skipped."
},
"kind": {
"description": "The kind of rule to run",
"enum": [
"repost"
],
"examples": [
"repost"
],
"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"
},
"RuleSetJson": {
"description": "A RuleSet is a \"nested\" set of `Rule` objects that can be used to create more complex AND/OR behavior. Think of the outcome of a `RuleSet` as the result of all of its run `Rule` objects (based on `condition`)",
"properties": {
@@ -2602,6 +3049,9 @@
{
"$ref": "#/definitions/RegexRuleJSONConfig"
},
{
"$ref": "#/definitions/RepostRuleJSONConfig"
},
{
"type": "string"
}
@@ -2616,6 +3066,111 @@
],
"type": "object"
},
"SearchAndReplaceRegExp": {
"properties": {
"replace": {
"description": "The replacement string/value to use when search is found\n\nThis can be a literal string like `'replace with this`, an empty string to remove the search value (`''`), or a special regex value\n\nSee replacement here for more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace",
"type": "string"
},
"search": {
"description": "The search value to test for\n\nCan be a normal string (converted to a case-sensitive literal) or a valid regular expression\n\nEX `[\"find this string\", \"/some string*\\/ig\"]`",
"examples": [
"find this string",
"/some string*/ig"
],
"type": "string"
}
},
"required": [
"replace",
"search"
],
"type": "object"
},
"SearchFacetJSONConfig": {
"properties": {
"caseSensitive": {
"default": false,
"description": "Should text matching be case sensitive?\n\nDefaults to false",
"type": "boolean"
},
"kind": {
"anyOf": [
{
"items": {
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
},
"type": "array"
},
{
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
}
]
},
"matchScore": {
"default": 85,
"description": "The percentage, as a whole number, of a repost title/comment that must match the title/comment being checked in order to consider both a match\n\nNote: Setting to 0 will make every candidate considered a match -- useful if you want to match if the URL has been reposted anywhere\n\nDefaults to `85` (85%)",
"type": "number"
},
"minWordCount": {
"default": 2,
"description": "The minimum number of words in the activity being checked for which this rule will run on\n\nIf the word count is below the minimum the rule fails\n\nDefaults to 2",
"type": "number"
},
"transformations": {
"description": "A set of search-and-replace operations to perform on text values before performing a match. Transformations are performed in the order they are defined.\n\n* If `transformationsActivity` IS NOT defined then these transformations will be performed on BOTH the activity text (submission title or comment) AND the repost candidate text\n* If `transformationsActivity` IS defined then these transformations are only performed on repost candidate text",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"transformationsActivity": {
"description": "Specify a separate set of transformations for the activity text (submission title or comment)\n\nTo perform no transformations when `transformations` is defined set this to an empty array (`[]`)",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/ActivityWindowCriteria"
},
{
"$ref": "#/definitions/DurationObject"
},
{
"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": [
"kind"
],
"type": "object"
},
"SubmissionCheckJson": {
"properties": {
"actions": {
@@ -2775,6 +3330,9 @@
{
"$ref": "#/definitions/RegexRuleJSONConfig"
},
{
"$ref": "#/definitions/RepostRuleJSONConfig"
},
{
"$ref": "#/definitions/RuleSetJson"
},
@@ -2802,6 +3360,11 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},
@@ -2870,6 +3433,9 @@
}
],
"properties": {
"isUserProfile": {
"type": "boolean"
},
"name": {
"anyOf": [
{
@@ -2900,6 +3466,33 @@
},
"type": "object"
},
"ThirdPartyCredentialsJsonConfig": {
"additionalProperties": {
},
"properties": {
"youtube": {
"properties": {
"apiKey": {
"type": "string"
}
},
"required": [
"apiKey"
],
"type": "object"
}
},
"type": "object"
},
"TimeBasedSelector": {
"enum": [
"all",
"any",
"newest",
"oldest"
],
"type": "string"
},
"UserNoteActionJson": {
"description": "Add a Toolbox User Note to the Author of this Activity",
"properties": {
@@ -3083,6 +3676,9 @@
"minItems": 1,
"type": "array"
},
"credentials": {
"$ref": "#/definitions/ThirdPartyCredentialsJsonConfig"
},
"dryRun": {
"default": "undefined",
"description": "Use this option to override the `dryRun` setting for all `Checks`",

View File

@@ -19,6 +19,28 @@
],
"type": "object"
},
"BotCredentialsJsonConfig": {
"properties": {
"reddit": {
"$ref": "#/definitions/RedditCredentials"
},
"youtube": {
"properties": {
"apiKey": {
"type": "string"
}
},
"required": [
"apiKey"
],
"type": "object"
}
},
"required": [
"reddit"
],
"type": "object"
},
"BotInstanceJsonConfig": {
"description": "The configuration for an **individual reddit account** ContextMod will run as a bot.\n\nMultiple bot configs may be specified (one per reddit account).\n\n**NOTE:** If `bots` is not specified in a `FILE` then a default `bot` is generated using `ENV/ARG` values IE `CLIENT_ID`, etc...but if `bots` IS specified the default is not generated.",
"properties": {
@@ -27,15 +49,12 @@
"description": "Settings to configure the default caching behavior for this bot\n\nEvery setting not specified will default to what is specified by the global operator caching config"
},
"credentials": {
"$ref": "#/definitions/RedditCredentials",
"description": "Credentials required for the bot to interact with Reddit's API\n\nThese credentials will provided to both the API and Web interface unless otherwise specified with the `web.credentials` property\n\nRefer to the [required credentials table](https://github.com/FoxxMD/context-mod/blob/master/docs/operatorConfiguration.md#minimum-required-configuration) to see what is necessary to run the bot.",
"examples": [
"anyOf": [
{
"accessToken": "p75_1c467b2",
"clientId": "f4b4df1_9oiu",
"clientSecret": "34v5q1c564_yt7",
"redirectUri": "http://localhost:8085/callback",
"refreshToken": "34_f1w1v4"
"$ref": "#/definitions/RedditCredentials"
},
{
"$ref": "#/definitions/BotCredentialsJsonConfig"
}
]
},
@@ -79,6 +98,10 @@
"default": false,
"description": "If set to `true` all subreddits polling unmoderated/modqueue with default polling settings will share a request to \"r/mod\"\notherwise each subreddit will poll its own mod view\n\n* ENV => `SHARE_MOD`\n* ARG => `--shareMod`",
"type": "boolean"
},
"stagger": {
"description": "If sharing a mod stream stagger pushing relevant Activities to individual subreddits.\n\nUseful when running many subreddits and rules are potentially cpu/memory/traffic heavy -- allows spreading out load",
"type": "number"
}
},
"type": "object"
@@ -506,6 +529,24 @@
},
"type": "object"
},
"ThirdPartyCredentialsJsonConfig": {
"additionalProperties": {
},
"properties": {
"youtube": {
"properties": {
"apiKey": {
"type": "string"
}
},
"required": [
"apiKey"
],
"type": "object"
}
},
"type": "object"
},
"WebCredentials": {
"description": "Separate credentials for the web interface can be provided when also running the api.\n\nAll properties not specified will default to values given in ENV/ARG credential properties\n\nRefer to the [required credentials table](https://github.com/FoxxMD/context-mod/blob/master/docs/operatorConfiguration.md#minimum-required-configuration) to see what is necessary for the web interface.",
"examples": [
@@ -575,6 +616,9 @@
"$ref": "#/definitions/OperatorCacheConfig",
"description": "Settings to configure the default caching behavior globally\n\nThese settings will be used by each bot, and subreddit, that does not specify their own"
},
"credentials": {
"$ref": "#/definitions/ThirdPartyCredentialsJsonConfig"
},
"logging": {
"description": "Settings to configure global logging defaults",
"properties": {

View File

@@ -19,6 +19,9 @@
{
"$ref": "#/definitions/RegexRuleJSONConfig"
},
{
"$ref": "#/definitions/RepostRuleJSONConfig"
},
{
"type": "string"
}
@@ -179,7 +182,7 @@
"properties": {
"aggregateOn": {
"default": "undefined",
"description": "This list determines which categories of domains should be aggregated on. All aggregated domains will be tested against `threshold`\n\n* If `media` is included then aggregate author's submission history which reddit recognizes as media (youtube, vimeo, etc.)\n* If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or reddit image/video (i.redd.it / v.redd.it)\n* If `link` is included then aggregate author's submission history which is external links but not media\n\nIf nothing is specified or list is empty (default) all domains are aggregated",
"description": "This list determines which categories of domains should be aggregated on. All aggregated domains will be tested against `threshold`\n\n* If `media` is included then aggregate author's submission history which reddit recognizes as media (youtube, vimeo, etc.)\n* If `redditMedia` is included then aggregate on author's submissions history which are media hosted on reddit: galleries, videos, and images (i.redd.it / v.redd.it)\n* If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or domain is `reddit.com`\n* If `link` is included then aggregate author's submission history which is external links and not recognized as `media` by reddit\n\nIf nothing is specified or list is empty (default) rule will only aggregate on `link` and `media` (ignores reddit-hosted content and self-posts)",
"examples": [
[
]
@@ -188,12 +191,23 @@
"enum": [
"link",
"media",
"redditMedia",
"self"
],
"type": "string"
},
"type": "array"
},
"commentState": {
"$ref": "#/definitions/CommentState",
"description": "When present, Comments from `window` will only be counted if they meet this criteria",
"examples": [
{
"op": true,
"removed": false
}
]
},
"consolidateMediaDomains": {
"default": false,
"description": "Should the criteria consolidate recognized media domains into the parent domain?\n\nSubmissions to major media domains (youtube, vimeo) can be identified by individual Channel/Author...\n\n* If `false` then domains will be aggregated at the channel level IE Youtube Channel A (2 counts), Youtube Channel B (3 counts)\n* If `true` then then media domains will be consolidated at domain level and then aggregated IE youtube.com (5 counts)",
@@ -222,27 +236,37 @@
"type": "boolean"
},
"exclude": {
"description": "Do not include Activities from this list of Subreddits (by name, case-insensitive)\n\nWill be ignored if `include` is present.\n\nEX `[\"mealtimevideos\",\"askscience\"]`",
"description": "When present, Activities WILL NOT be counted if they are found in this list of Subreddits\n\nEach value in the list can be either:\n\n * string (name of subreddit)\n * regular expression to run on the subreddit name\n * `SubredditState`\n\nEX `[\"mealtimevideos\",\"askscience\", \"/onlyfans*\\/i\", {\"over18\": true}]`",
"examples": [
"mealtimevideos",
"askscience"
[
"mealtimevideos",
"askscience",
"/onlyfans*/i",
{
"over18": true
}
]
],
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"include": {
"description": "Only include Activities from this list of Subreddits (by name, case-insensitive)\n\n\nEX `[\"mealtimevideos\",\"askscience\"]`",
"description": "When present, Activities WILL ONLY be counted if they are found in this list of Subreddits\n\nEach value in the list can be either:\n\n * string (name of subreddit)\n * regular expression to run on the subreddit name\n * `SubredditState`\n\nEX `[\"mealtimevideos\",\"askscience\", \"/onlyfans*\\/i\", {\"over18\": true}]`",
"examples": [
"mealtimevideos",
"askscience"
[
"mealtimevideos",
"askscience",
"/onlyfans*/i",
{
"over18": true
}
]
],
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"minActivityCount": {
@@ -253,6 +277,16 @@
"name": {
"type": "string"
},
"submissionState": {
"$ref": "#/definitions/SubmissionState",
"description": "When present, Submissions from `window` will only be counted if they meet this criteria",
"examples": [
{
"over_18": true,
"removed": false
}
]
},
"threshold": {
"default": "> 10%",
"description": "A string containing a comparison operator and a value to compare comments against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities originate from same attribution\n* EX `<= 10%` => less than 10% of all Activities have the same attribution",
@@ -364,11 +398,6 @@
],
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
"type": "string"
},
"useSubmissionAsReference": {
"default": true,
"description": "If activity is a Submission and is a link (not self-post) then only look at Submissions that contain this link, otherwise consider all activities.",
"type": "boolean"
}
},
"required": [
@@ -404,6 +433,26 @@
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
"type": "string"
},
"description": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "An (array of) string/regular expression to test contents of an Author's profile description against\n\nIf no flags are specified then the **insensitive** flag is used by default\n\nIf using an array then if **any** value in the array passes the description test passes",
"examples": [
[
"/test$/i",
"look for this string literal"
]
]
},
"flairCssClass": {
"description": "A list of (user) flair css class values from the subreddit to match against",
"examples": [
@@ -444,6 +493,10 @@
},
"type": "array"
},
"shadowBanned": {
"description": "Is the author shadowbanned?\n\nThis is determined by trying to retrieve the author's profile. If a 404 is returned it is likely they are shadowbanned",
"type": "boolean"
},
"totalKarma": {
"description": "A string containing a comparison operator and a value to compare against\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 100` => greater than 100",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
@@ -567,8 +620,6 @@
}
},
"required": [
"exclude",
"include",
"kind"
],
"type": "object"
@@ -582,12 +633,22 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},
"deleted": {
"type": "boolean"
},
"depth": {
"description": "The (nested) level of a comment.\n\n* 0 mean the comment is at top-level (replying to submission)\n* non-zero, Nth value means the comment has N parent comments",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"distinguished": {
"type": "boolean"
},
@@ -863,6 +924,147 @@
],
"type": "object"
},
"ImageDetection": {
"description": "When comparing submissions detect if the reference submission is an image and do a pixel-comparison to other detected image submissions.\n\n**Note:** This is an **experimental feature**",
"properties": {
"enable": {
"description": "Is image detection enabled?",
"type": "boolean"
},
"fetchBehavior": {
"default": "extension",
"description": "Determines how and when to check if a URL is an image\n\n**Note:** After fetching a URL the **Content-Type** is validated to contain `image` before detection occurs\n\n**When `extension`:** (default)\n\n* Only URLs that end in known image extensions (.png, .jpg, etc...) are fetched\n\n**When `unknown`:**\n\n* URLs that end in known image extensions (.png, .jpg, etc...) are fetched\n* URLs with no extension or unknown (IE non-video, non-doc, etc...) are fetched\n\n**When `all`:**\n\n* All submissions that have URLs (non-self) will be fetched, regardless of extension\n* **Note:** This can be bandwidth/CPU intensive if history window is large so use with care",
"enum": [
"all",
"extension",
"unknown"
],
"type": "string"
},
"hash": {
"description": "Use perceptual hashing (blockhash-js) to compare images\n\nPros:\n\n* very fast\n* low cpu/memory usage\n* results can be cached\n\nCons:\n\n* not as accurate as pixel comparison\n* weaker for text-heavy images\n* mostly color-blind\n\nBest uses:\n\n* Detecting (general) duplicate images\n* Comparing large number of images",
"properties": {
"bits": {
"default": 32,
"description": "Bit count determines accuracy of hash and granularity of hash comparison (comparison to other hashes)\n\nDefault is `32`\n\n**NOTE:** Hashes of different sizes (bits) cannot be compared. If you are caching results make sure all rules where results may be shared use the same bit count to ensure hashes can be compared. Otherwise hashes will be recomputed.",
"type": "number"
},
"enable": {
"default": true,
"description": "Enabled by default.\n\nIf both `hash` and `pixel` are enabled then `pixel` will be used to verify image comparison when hashes matches",
"type": "boolean"
},
"hardThreshold": {
"description": "High Confidence Threshold\n\nIf the difference in comparison is equal to or less than this number the images are considered the same and pixel comparison WILL NOT occur\n\nDefaults to the parent-level `threshold` value if not present\n\nUse `null` if you want pixel comparison to ALWAYS occur (softThreshold must be present)",
"type": [
"null",
"number"
]
},
"softThreshold": {
"description": "Low Confidence Threshold -- only used if `pixel` is enabled\n\nIf the difference in comparison is\n\n1) equal to or less than this value and\n2) the value is greater than `hardThreshold`\n\nthe images will be compared using the `pixel` method",
"type": "number"
},
"ttl": {
"description": "Number of seconds to cache image hash",
"type": "number"
}
},
"type": "object"
},
"pixel": {
"description": "Use pixel counting to compare images\n\nPros:\n\n* most accurate\n* strong with text or color-only changes\n\nCons:\n\n* much slower than hashing\n* memory/cpu intensive\n\nBest uses:\n\n* Comparison text-only images\n* Comparison requires high degree of accuracy or changes are subtle",
"properties": {
"enable": {
"default": false,
"description": "Disabled by default.",
"type": "boolean"
},
"threshold": {
"description": "The percentage, as a whole number, of pixels that are **different** between the two images at which point the images are not considered the same.",
"type": "number"
}
},
"type": "object"
},
"threshold": {
"default": 5,
"description": "The percentage, as a whole number, of difference between two images at which point they will not be considered the same.\n\nWill be used as `hash.hardThreshold` and `pixel.threshold` if those values are not specified\n\nDefault is `5`",
"type": "number"
}
},
"type": "object"
},
"OccurredAt": {
"properties": {
"condition": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"testOn": {
"$ref": "#/definitions/TimeBasedSelector",
"description": "Which repost to test on\n\n* `any` -- ANY repost passing `condition` will cause this criteria to be true\n* `all` -- ALL reposts must pass `condition` for this criteria to be true"
}
},
"required": [
"condition",
"testOn"
],
"type": "object"
},
"OccurrenceTests": {
"properties": {
"count": {
"properties": {
"condition": {
"enum": [
"AND",
"OR"
],
"type": "string"
},
"test": {
"description": "An array of strings containing a comparison operator and the number of repost occurrences to compare against\n\nExamples:\n\n* `\">= 7\"` -- TRUE if 7 or more reposts were found\n* `\"< 1\"` -- TRUE if less than 0 reposts were found",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"test"
],
"type": "object"
},
"time": {
"description": "Test the time the reposts occurred at",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"test": {
"description": "An array of time-based conditions to test against found reposts (test when a repost was made)",
"items": {
"$ref": "#/definitions/OccurredAt"
},
"type": "array"
}
},
"required": [
"test"
],
"type": "object"
}
},
"type": "object"
},
"RecentActivityRuleJSONConfig": {
"description": "Checks a user's history for any Activity (Submission/Comment) in the subreddits specified in thresholds\n\nAvailable data for [Action templating](https://github.com/FoxxMD/context-mod#action-templating):\n\n```\nsummary => comma-deliminated list of subreddits that hit the threshold and their count EX subredditA(1), subredditB(4),...\nsubCount => Total number of subreddits that hit the threshold\ntotalCount => Total number of all activity occurrences in subreddits\n```",
"properties": {
@@ -885,6 +1087,10 @@
}
]
},
"imageDetection": {
"$ref": "#/definitions/ImageDetection",
"description": "When comparing submissions detect if the reference submission is an image and do a pixel-comparison to other detected image submissions.\n\n**Note:** This is an **experimental feature**"
},
"itemIs": {
"anyOf": [
{
@@ -1358,6 +1564,329 @@
],
"type": "object"
},
"RepostCriteria": {
"description": "A set of criteria used to find reposts\n\nContains options and conditions used to define how candidate reposts are retrieved and if they are a match.",
"properties": {
"caseSensitive": {
"default": false,
"description": "Should text matching be case sensitive?\n\nDefaults to false",
"type": "boolean"
},
"matchScore": {
"default": 85,
"description": "The percentage, as a whole number, of a repost title/comment that must match the title/comment being checked in order to consider both a match\n\nNote: Setting to 0 will make every candidate considered a match -- useful if you want to match if the URL has been reposted anywhere\n\nDefaults to `85` (85%)",
"type": "number"
},
"maxExternalItems": {
"default": 50,
"description": "The maximum number of external items (youtube comments) to check (and cache for comment checks)",
"type": "number"
},
"maxRedditItems": {
"default": 50,
"description": "The maximum number of comments/submissions to check\n\nIn both cases this list is gathered from sorting all submissions or all comments from all submission by number of votes and taking the \"top\" maximum specified\n\nFor comment checks this is the number of comments cached",
"type": "number"
},
"minWordCount": {
"default": 2,
"description": "The minimum number of words in the activity being checked for which this rule will run on\n\nIf the word count is below the minimum the rule fails\n\nDefaults to 2",
"type": "number"
},
"occurredAt": {
"description": "Test the time the reposts occurred at",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"description": "An array of time-based conditions to test against found reposts (test when a repost was made)",
"items": {
"$ref": "#/definitions/OccurredAt"
},
"type": "array"
}
},
"required": [
"criteria"
],
"type": "object"
},
"occurrences": {
"description": "A set of comparisons to test against the number of reposts found\n\nIf not specified the default is \"AND [occurrences] > 0\" IE any reposts makes this test pass",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"items": {
"$ref": "#/definitions/OccurrenceTests"
},
"type": "array"
}
},
"type": "object"
},
"searchOn": {
"description": "Define how to find candidate reposts\n\n* **title** -- search reddit for submissions with the same title\n* **url** -- search reddit for submissions with the same url\n* **external** -- WHEN ACTIVITY IS A COMMENT - tries to get comments from external source (youtube, twitter, etc...)",
"items": {
"anyOf": [
{
"$ref": "#/definitions/SearchFacetJSONConfig"
},
{
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
}
]
},
"type": "array"
},
"transformations": {
"description": "A set of search-and-replace operations to perform on text values before performing a match. Transformations are performed in the order they are defined.\n\n* If `transformationsActivity` IS NOT defined then these transformations will be performed on BOTH the activity text (submission title or comment) AND the repost candidate text\n* If `transformationsActivity` IS defined then these transformations are only performed on repost candidate text",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"transformationsActivity": {
"description": "Specify a separate set of transformations for the activity text (submission title or comment)\n\nTo perform no transformations when `transformations` is defined set this to an empty array (`[]`)",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/ActivityWindowCriteria"
},
{
"$ref": "#/definitions/DurationObject"
},
{
"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"
]
}
},
"type": "object"
},
"RepostRuleJSONConfig": {
"description": "Search for reposts of a Submission or Comment\n\n* For submissions the title or URL can searched and matched against\n* For comments, candidate comments are gathered from similar reddit submissions and/or external sources (youtube, twitter, etc..) and then matched against",
"properties": {
"authorIs": {
"$ref": "#/definitions/AuthorOptions",
"description": "If present then these Author criteria are checked before running the rule. If criteria fails then the rule is skipped.",
"examples": [
{
"include": [
{
"flairText": [
"Contributor",
"Veteran"
]
},
{
"isMod": true
}
]
}
]
},
"condition": {
"default": "OR",
"description": "* If `OR` then any set of Criteria that pass will trigger the Rule\n* If `AND` then all Criteria sets must pass to trigger the Rule",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"description": "A list of Regular Expressions and conditions under which tested Activity(ies) are matched",
"examples": [
{
"matchThreshold": "> 3",
"regex": "/reddit/"
}
],
"items": {
"$ref": "#/definitions/RepostCriteria"
},
"minItems": 1,
"type": "array"
},
"itemIs": {
"anyOf": [
{
"items": {
"$ref": "#/definitions/SubmissionState"
},
"type": "array"
},
{
"items": {
"$ref": "#/definitions/CommentState"
},
"type": "array"
}
],
"description": "A list of criteria to test the state of the `Activity` against before running the Rule.\n\nIf any set of criteria passes the Rule will be run. If the criteria fails then the Rule is skipped."
},
"kind": {
"description": "The kind of rule to run",
"enum": [
"repost"
],
"examples": [
"repost"
],
"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"
},
"SearchAndReplaceRegExp": {
"properties": {
"replace": {
"description": "The replacement string/value to use when search is found\n\nThis can be a literal string like `'replace with this`, an empty string to remove the search value (`''`), or a special regex value\n\nSee replacement here for more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace",
"type": "string"
},
"search": {
"description": "The search value to test for\n\nCan be a normal string (converted to a case-sensitive literal) or a valid regular expression\n\nEX `[\"find this string\", \"/some string*\\/ig\"]`",
"examples": [
"find this string",
"/some string*/ig"
],
"type": "string"
}
},
"required": [
"replace",
"search"
],
"type": "object"
},
"SearchFacetJSONConfig": {
"properties": {
"caseSensitive": {
"default": false,
"description": "Should text matching be case sensitive?\n\nDefaults to false",
"type": "boolean"
},
"kind": {
"anyOf": [
{
"items": {
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
},
"type": "array"
},
{
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
}
]
},
"matchScore": {
"default": 85,
"description": "The percentage, as a whole number, of a repost title/comment that must match the title/comment being checked in order to consider both a match\n\nNote: Setting to 0 will make every candidate considered a match -- useful if you want to match if the URL has been reposted anywhere\n\nDefaults to `85` (85%)",
"type": "number"
},
"minWordCount": {
"default": 2,
"description": "The minimum number of words in the activity being checked for which this rule will run on\n\nIf the word count is below the minimum the rule fails\n\nDefaults to 2",
"type": "number"
},
"transformations": {
"description": "A set of search-and-replace operations to perform on text values before performing a match. Transformations are performed in the order they are defined.\n\n* If `transformationsActivity` IS NOT defined then these transformations will be performed on BOTH the activity text (submission title or comment) AND the repost candidate text\n* If `transformationsActivity` IS defined then these transformations are only performed on repost candidate text",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"transformationsActivity": {
"description": "Specify a separate set of transformations for the activity text (submission title or comment)\n\nTo perform no transformations when `transformations` is defined set this to an empty array (`[]`)",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/ActivityWindowCriteria"
},
{
"$ref": "#/definitions/DurationObject"
},
{
"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": [
"kind"
],
"type": "object"
},
"SubmissionState": {
"description": "Different attributes a `Submission` can be in. Only include a property if you want to check it.",
"examples": [
@@ -1367,6 +1896,11 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},
@@ -1435,6 +1969,9 @@
}
],
"properties": {
"isUserProfile": {
"type": "boolean"
},
"name": {
"anyOf": [
{
@@ -1465,6 +2002,15 @@
},
"type": "object"
},
"TimeBasedSelector": {
"enum": [
"all",
"any",
"newest",
"oldest"
],
"type": "string"
},
"UserNoteCriteria": {
"properties": {
"count": {

View File

@@ -156,7 +156,7 @@
"properties": {
"aggregateOn": {
"default": "undefined",
"description": "This list determines which categories of domains should be aggregated on. All aggregated domains will be tested against `threshold`\n\n* If `media` is included then aggregate author's submission history which reddit recognizes as media (youtube, vimeo, etc.)\n* If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or reddit image/video (i.redd.it / v.redd.it)\n* If `link` is included then aggregate author's submission history which is external links but not media\n\nIf nothing is specified or list is empty (default) all domains are aggregated",
"description": "This list determines which categories of domains should be aggregated on. All aggregated domains will be tested against `threshold`\n\n* If `media` is included then aggregate author's submission history which reddit recognizes as media (youtube, vimeo, etc.)\n* If `redditMedia` is included then aggregate on author's submissions history which are media hosted on reddit: galleries, videos, and images (i.redd.it / v.redd.it)\n* If `self` is included then aggregate on author's submission history which are self-post (`self.[subreddit]`) or domain is `reddit.com`\n* If `link` is included then aggregate author's submission history which is external links and not recognized as `media` by reddit\n\nIf nothing is specified or list is empty (default) rule will only aggregate on `link` and `media` (ignores reddit-hosted content and self-posts)",
"examples": [
[
]
@@ -165,12 +165,23 @@
"enum": [
"link",
"media",
"redditMedia",
"self"
],
"type": "string"
},
"type": "array"
},
"commentState": {
"$ref": "#/definitions/CommentState",
"description": "When present, Comments from `window` will only be counted if they meet this criteria",
"examples": [
{
"op": true,
"removed": false
}
]
},
"consolidateMediaDomains": {
"default": false,
"description": "Should the criteria consolidate recognized media domains into the parent domain?\n\nSubmissions to major media domains (youtube, vimeo) can be identified by individual Channel/Author...\n\n* If `false` then domains will be aggregated at the channel level IE Youtube Channel A (2 counts), Youtube Channel B (3 counts)\n* If `true` then then media domains will be consolidated at domain level and then aggregated IE youtube.com (5 counts)",
@@ -199,27 +210,37 @@
"type": "boolean"
},
"exclude": {
"description": "Do not include Activities from this list of Subreddits (by name, case-insensitive)\n\nWill be ignored if `include` is present.\n\nEX `[\"mealtimevideos\",\"askscience\"]`",
"description": "When present, Activities WILL NOT be counted if they are found in this list of Subreddits\n\nEach value in the list can be either:\n\n * string (name of subreddit)\n * regular expression to run on the subreddit name\n * `SubredditState`\n\nEX `[\"mealtimevideos\",\"askscience\", \"/onlyfans*\\/i\", {\"over18\": true}]`",
"examples": [
"mealtimevideos",
"askscience"
[
"mealtimevideos",
"askscience",
"/onlyfans*/i",
{
"over18": true
}
]
],
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"include": {
"description": "Only include Activities from this list of Subreddits (by name, case-insensitive)\n\n\nEX `[\"mealtimevideos\",\"askscience\"]`",
"description": "When present, Activities WILL ONLY be counted if they are found in this list of Subreddits\n\nEach value in the list can be either:\n\n * string (name of subreddit)\n * regular expression to run on the subreddit name\n * `SubredditState`\n\nEX `[\"mealtimevideos\",\"askscience\", \"/onlyfans*\\/i\", {\"over18\": true}]`",
"examples": [
"mealtimevideos",
"askscience"
[
"mealtimevideos",
"askscience",
"/onlyfans*/i",
{
"over18": true
}
]
],
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"minActivityCount": {
@@ -230,6 +251,16 @@
"name": {
"type": "string"
},
"submissionState": {
"$ref": "#/definitions/SubmissionState",
"description": "When present, Submissions from `window` will only be counted if they meet this criteria",
"examples": [
{
"over_18": true,
"removed": false
}
]
},
"threshold": {
"default": "> 10%",
"description": "A string containing a comparison operator and a value to compare comments against\n\nThe syntax is `(< OR > OR <= OR >=) <number>[percent sign]`\n\n* EX `> 12` => greater than 12 activities originate from same attribution\n* EX `<= 10%` => less than 10% of all Activities have the same attribution",
@@ -341,11 +372,6 @@
],
"pattern": "^[a-zA-Z]([\\w -]*[\\w])?$",
"type": "string"
},
"useSubmissionAsReference": {
"default": true,
"description": "If activity is a Submission and is a link (not self-post) then only look at Submissions that contain this link, otherwise consider all activities.",
"type": "boolean"
}
},
"required": [
@@ -381,6 +407,26 @@
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
"type": "string"
},
"description": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "string"
}
],
"description": "An (array of) string/regular expression to test contents of an Author's profile description against\n\nIf no flags are specified then the **insensitive** flag is used by default\n\nIf using an array then if **any** value in the array passes the description test passes",
"examples": [
[
"/test$/i",
"look for this string literal"
]
]
},
"flairCssClass": {
"description": "A list of (user) flair css class values from the subreddit to match against",
"examples": [
@@ -421,6 +467,10 @@
},
"type": "array"
},
"shadowBanned": {
"description": "Is the author shadowbanned?\n\nThis is determined by trying to retrieve the author's profile. If a 404 is returned it is likely they are shadowbanned",
"type": "boolean"
},
"totalKarma": {
"description": "A string containing a comparison operator and a value to compare against\n\nThe syntax is `(< OR > OR <= OR >=) <number>`\n\n* EX `> 100` => greater than 100",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(%?)(.*)$",
@@ -544,8 +594,6 @@
}
},
"required": [
"exclude",
"include",
"kind"
],
"type": "object"
@@ -559,12 +607,22 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},
"deleted": {
"type": "boolean"
},
"depth": {
"description": "The (nested) level of a comment.\n\n* 0 mean the comment is at top-level (replying to submission)\n* non-zero, Nth value means the comment has N parent comments",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"distinguished": {
"type": "boolean"
},
@@ -840,6 +898,147 @@
],
"type": "object"
},
"ImageDetection": {
"description": "When comparing submissions detect if the reference submission is an image and do a pixel-comparison to other detected image submissions.\n\n**Note:** This is an **experimental feature**",
"properties": {
"enable": {
"description": "Is image detection enabled?",
"type": "boolean"
},
"fetchBehavior": {
"default": "extension",
"description": "Determines how and when to check if a URL is an image\n\n**Note:** After fetching a URL the **Content-Type** is validated to contain `image` before detection occurs\n\n**When `extension`:** (default)\n\n* Only URLs that end in known image extensions (.png, .jpg, etc...) are fetched\n\n**When `unknown`:**\n\n* URLs that end in known image extensions (.png, .jpg, etc...) are fetched\n* URLs with no extension or unknown (IE non-video, non-doc, etc...) are fetched\n\n**When `all`:**\n\n* All submissions that have URLs (non-self) will be fetched, regardless of extension\n* **Note:** This can be bandwidth/CPU intensive if history window is large so use with care",
"enum": [
"all",
"extension",
"unknown"
],
"type": "string"
},
"hash": {
"description": "Use perceptual hashing (blockhash-js) to compare images\n\nPros:\n\n* very fast\n* low cpu/memory usage\n* results can be cached\n\nCons:\n\n* not as accurate as pixel comparison\n* weaker for text-heavy images\n* mostly color-blind\n\nBest uses:\n\n* Detecting (general) duplicate images\n* Comparing large number of images",
"properties": {
"bits": {
"default": 32,
"description": "Bit count determines accuracy of hash and granularity of hash comparison (comparison to other hashes)\n\nDefault is `32`\n\n**NOTE:** Hashes of different sizes (bits) cannot be compared. If you are caching results make sure all rules where results may be shared use the same bit count to ensure hashes can be compared. Otherwise hashes will be recomputed.",
"type": "number"
},
"enable": {
"default": true,
"description": "Enabled by default.\n\nIf both `hash` and `pixel` are enabled then `pixel` will be used to verify image comparison when hashes matches",
"type": "boolean"
},
"hardThreshold": {
"description": "High Confidence Threshold\n\nIf the difference in comparison is equal to or less than this number the images are considered the same and pixel comparison WILL NOT occur\n\nDefaults to the parent-level `threshold` value if not present\n\nUse `null` if you want pixel comparison to ALWAYS occur (softThreshold must be present)",
"type": [
"null",
"number"
]
},
"softThreshold": {
"description": "Low Confidence Threshold -- only used if `pixel` is enabled\n\nIf the difference in comparison is\n\n1) equal to or less than this value and\n2) the value is greater than `hardThreshold`\n\nthe images will be compared using the `pixel` method",
"type": "number"
},
"ttl": {
"description": "Number of seconds to cache image hash",
"type": "number"
}
},
"type": "object"
},
"pixel": {
"description": "Use pixel counting to compare images\n\nPros:\n\n* most accurate\n* strong with text or color-only changes\n\nCons:\n\n* much slower than hashing\n* memory/cpu intensive\n\nBest uses:\n\n* Comparison text-only images\n* Comparison requires high degree of accuracy or changes are subtle",
"properties": {
"enable": {
"default": false,
"description": "Disabled by default.",
"type": "boolean"
},
"threshold": {
"description": "The percentage, as a whole number, of pixels that are **different** between the two images at which point the images are not considered the same.",
"type": "number"
}
},
"type": "object"
},
"threshold": {
"default": 5,
"description": "The percentage, as a whole number, of difference between two images at which point they will not be considered the same.\n\nWill be used as `hash.hardThreshold` and `pixel.threshold` if those values are not specified\n\nDefault is `5`",
"type": "number"
}
},
"type": "object"
},
"OccurredAt": {
"properties": {
"condition": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"testOn": {
"$ref": "#/definitions/TimeBasedSelector",
"description": "Which repost to test on\n\n* `any` -- ANY repost passing `condition` will cause this criteria to be true\n* `all` -- ALL reposts must pass `condition` for this criteria to be true"
}
},
"required": [
"condition",
"testOn"
],
"type": "object"
},
"OccurrenceTests": {
"properties": {
"count": {
"properties": {
"condition": {
"enum": [
"AND",
"OR"
],
"type": "string"
},
"test": {
"description": "An array of strings containing a comparison operator and the number of repost occurrences to compare against\n\nExamples:\n\n* `\">= 7\"` -- TRUE if 7 or more reposts were found\n* `\"< 1\"` -- TRUE if less than 0 reposts were found",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"test"
],
"type": "object"
},
"time": {
"description": "Test the time the reposts occurred at",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"test": {
"description": "An array of time-based conditions to test against found reposts (test when a repost was made)",
"items": {
"$ref": "#/definitions/OccurredAt"
},
"type": "array"
}
},
"required": [
"test"
],
"type": "object"
}
},
"type": "object"
},
"RecentActivityRuleJSONConfig": {
"description": "Checks a user's history for any Activity (Submission/Comment) in the subreddits specified in thresholds\n\nAvailable data for [Action templating](https://github.com/FoxxMD/context-mod#action-templating):\n\n```\nsummary => comma-deliminated list of subreddits that hit the threshold and their count EX subredditA(1), subredditB(4),...\nsubCount => Total number of subreddits that hit the threshold\ntotalCount => Total number of all activity occurrences in subreddits\n```",
"properties": {
@@ -862,6 +1061,10 @@
}
]
},
"imageDetection": {
"$ref": "#/definitions/ImageDetection",
"description": "When comparing submissions detect if the reference submission is an image and do a pixel-comparison to other detected image submissions.\n\n**Note:** This is an **experimental feature**"
},
"itemIs": {
"anyOf": [
{
@@ -1335,6 +1538,329 @@
],
"type": "object"
},
"RepostCriteria": {
"description": "A set of criteria used to find reposts\n\nContains options and conditions used to define how candidate reposts are retrieved and if they are a match.",
"properties": {
"caseSensitive": {
"default": false,
"description": "Should text matching be case sensitive?\n\nDefaults to false",
"type": "boolean"
},
"matchScore": {
"default": 85,
"description": "The percentage, as a whole number, of a repost title/comment that must match the title/comment being checked in order to consider both a match\n\nNote: Setting to 0 will make every candidate considered a match -- useful if you want to match if the URL has been reposted anywhere\n\nDefaults to `85` (85%)",
"type": "number"
},
"maxExternalItems": {
"default": 50,
"description": "The maximum number of external items (youtube comments) to check (and cache for comment checks)",
"type": "number"
},
"maxRedditItems": {
"default": 50,
"description": "The maximum number of comments/submissions to check\n\nIn both cases this list is gathered from sorting all submissions or all comments from all submission by number of votes and taking the \"top\" maximum specified\n\nFor comment checks this is the number of comments cached",
"type": "number"
},
"minWordCount": {
"default": 2,
"description": "The minimum number of words in the activity being checked for which this rule will run on\n\nIf the word count is below the minimum the rule fails\n\nDefaults to 2",
"type": "number"
},
"occurredAt": {
"description": "Test the time the reposts occurred at",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"description": "An array of time-based conditions to test against found reposts (test when a repost was made)",
"items": {
"$ref": "#/definitions/OccurredAt"
},
"type": "array"
}
},
"required": [
"criteria"
],
"type": "object"
},
"occurrences": {
"description": "A set of comparisons to test against the number of reposts found\n\nIf not specified the default is \"AND [occurrences] > 0\" IE any reposts makes this test pass",
"properties": {
"condition": {
"default": "AND",
"description": "How to test all the specified comparisons\n\n* AND -- All criteria must be true\n* OR -- Any criteria must be true\n\nDefaults to AND",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"items": {
"$ref": "#/definitions/OccurrenceTests"
},
"type": "array"
}
},
"type": "object"
},
"searchOn": {
"description": "Define how to find candidate reposts\n\n* **title** -- search reddit for submissions with the same title\n* **url** -- search reddit for submissions with the same url\n* **external** -- WHEN ACTIVITY IS A COMMENT - tries to get comments from external source (youtube, twitter, etc...)",
"items": {
"anyOf": [
{
"$ref": "#/definitions/SearchFacetJSONConfig"
},
{
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
}
]
},
"type": "array"
},
"transformations": {
"description": "A set of search-and-replace operations to perform on text values before performing a match. Transformations are performed in the order they are defined.\n\n* If `transformationsActivity` IS NOT defined then these transformations will be performed on BOTH the activity text (submission title or comment) AND the repost candidate text\n* If `transformationsActivity` IS defined then these transformations are only performed on repost candidate text",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"transformationsActivity": {
"description": "Specify a separate set of transformations for the activity text (submission title or comment)\n\nTo perform no transformations when `transformations` is defined set this to an empty array (`[]`)",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/ActivityWindowCriteria"
},
{
"$ref": "#/definitions/DurationObject"
},
{
"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"
]
}
},
"type": "object"
},
"RepostRuleJSONConfig": {
"description": "Search for reposts of a Submission or Comment\n\n* For submissions the title or URL can searched and matched against\n* For comments, candidate comments are gathered from similar reddit submissions and/or external sources (youtube, twitter, etc..) and then matched against",
"properties": {
"authorIs": {
"$ref": "#/definitions/AuthorOptions",
"description": "If present then these Author criteria are checked before running the rule. If criteria fails then the rule is skipped.",
"examples": [
{
"include": [
{
"flairText": [
"Contributor",
"Veteran"
]
},
{
"isMod": true
}
]
}
]
},
"condition": {
"default": "OR",
"description": "* If `OR` then any set of Criteria that pass will trigger the Rule\n* If `AND` then all Criteria sets must pass to trigger the Rule",
"enum": [
"AND",
"OR"
],
"type": "string"
},
"criteria": {
"description": "A list of Regular Expressions and conditions under which tested Activity(ies) are matched",
"examples": [
{
"matchThreshold": "> 3",
"regex": "/reddit/"
}
],
"items": {
"$ref": "#/definitions/RepostCriteria"
},
"minItems": 1,
"type": "array"
},
"itemIs": {
"anyOf": [
{
"items": {
"$ref": "#/definitions/SubmissionState"
},
"type": "array"
},
{
"items": {
"$ref": "#/definitions/CommentState"
},
"type": "array"
}
],
"description": "A list of criteria to test the state of the `Activity` against before running the Rule.\n\nIf any set of criteria passes the Rule will be run. If the criteria fails then the Rule is skipped."
},
"kind": {
"description": "The kind of rule to run",
"enum": [
"repost"
],
"examples": [
"repost"
],
"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"
},
"SearchAndReplaceRegExp": {
"properties": {
"replace": {
"description": "The replacement string/value to use when search is found\n\nThis can be a literal string like `'replace with this`, an empty string to remove the search value (`''`), or a special regex value\n\nSee replacement here for more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace",
"type": "string"
},
"search": {
"description": "The search value to test for\n\nCan be a normal string (converted to a case-sensitive literal) or a valid regular expression\n\nEX `[\"find this string\", \"/some string*\\/ig\"]`",
"examples": [
"find this string",
"/some string*/ig"
],
"type": "string"
}
},
"required": [
"replace",
"search"
],
"type": "object"
},
"SearchFacetJSONConfig": {
"properties": {
"caseSensitive": {
"default": false,
"description": "Should text matching be case sensitive?\n\nDefaults to false",
"type": "boolean"
},
"kind": {
"anyOf": [
{
"items": {
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
},
"type": "array"
},
{
"enum": [
"crossposts",
"duplicates",
"external",
"title",
"url"
],
"type": "string"
}
]
},
"matchScore": {
"default": 85,
"description": "The percentage, as a whole number, of a repost title/comment that must match the title/comment being checked in order to consider both a match\n\nNote: Setting to 0 will make every candidate considered a match -- useful if you want to match if the URL has been reposted anywhere\n\nDefaults to `85` (85%)",
"type": "number"
},
"minWordCount": {
"default": 2,
"description": "The minimum number of words in the activity being checked for which this rule will run on\n\nIf the word count is below the minimum the rule fails\n\nDefaults to 2",
"type": "number"
},
"transformations": {
"description": "A set of search-and-replace operations to perform on text values before performing a match. Transformations are performed in the order they are defined.\n\n* If `transformationsActivity` IS NOT defined then these transformations will be performed on BOTH the activity text (submission title or comment) AND the repost candidate text\n* If `transformationsActivity` IS defined then these transformations are only performed on repost candidate text",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"transformationsActivity": {
"description": "Specify a separate set of transformations for the activity text (submission title or comment)\n\nTo perform no transformations when `transformations` is defined set this to an empty array (`[]`)",
"items": {
"$ref": "#/definitions/SearchAndReplaceRegExp"
},
"type": "array"
},
"window": {
"anyOf": [
{
"$ref": "#/definitions/ActivityWindowCriteria"
},
{
"$ref": "#/definitions/DurationObject"
},
{
"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": [
"kind"
],
"type": "object"
},
"SubmissionState": {
"description": "Different attributes a `Submission` can be in. Only include a property if you want to check it.",
"examples": [
@@ -1344,6 +1870,11 @@
}
],
"properties": {
"age": {
"description": "A duration and how to compare it against a value\n\nThe syntax is `(< OR > OR <= OR >=) <number> <unit>` EX `> 100 days`, `<= 2 months`\n\n* EX `> 100 days` => Passes if the date being compared is before 100 days ago\n* EX `<= 2 months` => Passes if the date being compared is after or equal to 2 months\n\nUnit must be one of [DayJS Duration units](https://day.js.org/docs/en/durations/creating)\n\n[See] https://regexr.com/609n8 for example",
"pattern": "^\\s*(>|>=|<|<=)\\s*(\\d+)\\s*(days|weeks|months|years|hours|minutes|seconds|milliseconds)\\s*$",
"type": "string"
},
"approved": {
"type": "boolean"
},
@@ -1412,6 +1943,9 @@
}
],
"properties": {
"isUserProfile": {
"type": "boolean"
},
"name": {
"anyOf": [
{
@@ -1442,6 +1976,15 @@
},
"type": "object"
},
"TimeBasedSelector": {
"enum": [
"all",
"any",
"newest",
"oldest"
],
"type": "string"
},
"UserNoteCriteria": {
"properties": {
"count": {
@@ -1516,6 +2059,9 @@
{
"$ref": "#/definitions/RegexRuleJSONConfig"
},
{
"$ref": "#/definitions/RepostRuleJSONConfig"
},
{
"type": "string"
}

View File

@@ -3,7 +3,7 @@ import {Logger} from "winston";
import {SubmissionCheck} from "../Check/SubmissionCheck";
import {CommentCheck} from "../Check/CommentCheck";
import {
cacheStats,
cacheStats, createHistoricalStatsDisplay,
createRetryHandler,
determineNewResults, findLastIndex, formatNumber,
mergeArr, parseFromJsonOrYamlToObject, pollingInfo, resultsSummary, sleep, totalFromMapStats, triggeredIndicator,
@@ -17,7 +17,7 @@ import {
ActionResult,
DEFAULT_POLLING_INTERVAL,
DEFAULT_POLLING_LIMIT, Invokee,
ManagerOptions, ManagerStateChangeOption, PAUSED,
ManagerOptions, ManagerStateChangeOption, ManagerStats, PAUSED,
PollingOptionsStrong, ResourceStats, RUNNING, RunState, STOPPED, SYSTEM, USER
} from "../Common/interfaces";
import Submission from "snoowrap/dist/objects/Submission";
@@ -39,6 +39,9 @@ import {JSONConfig} from "../JsonConfig";
import {CheckStructuredJson} from "../Check";
import NotificationManager from "../Notification/NotificationManager";
import action from "../Web/Server/routes/authenticated/user/action";
import {createHistoricalDefaults, historicalDefaults} from "../Common/defaults";
import {ExtendedSnoowrap} from "../Utils/SnoowrapClients";
import {isRateLimitError} from "../Utils/Errors";
export interface RunningState {
state: RunState,
@@ -65,48 +68,15 @@ export interface RuntimeManagerOptions extends ManagerOptions {
maxWorkers: number;
}
export interface ManagerStats {
eventsCheckedTotal: number
eventsCheckedSinceStartTotal: number
eventsAvg: number
checksRunTotal: number
checksRunSinceStartTotal: number
checksTriggered: number
checksTriggeredTotal: number
checksTriggeredSinceStart: number
checksTriggeredSinceStartTotal: number
rulesRunTotal: number
rulesRunSinceStartTotal: number
rulesCachedTotal: number
rulesCachedSinceStartTotal: number
rulesTriggeredTotal: number
rulesTriggeredSinceStartTotal: number
rulesAvg: number
actionsRun: number
actionsRunTotal: number
actionsRunSinceStart: number,
actionsRunSinceStartTotal: number
cache: {
provider: string,
currentKeyCount: number,
isShared: boolean,
totalRequests: number,
totalMiss: number,
missPercent: string,
requestRate: number,
types: ResourceStats
},
}
interface QueuedIdentifier {
id: string,
shouldRefresh: boolean
state: 'queued' | 'processing'
}
export class Manager {
export class Manager extends EventEmitter {
subreddit: Subreddit;
client: Snoowrap;
client: ExtendedSnoowrap;
logger: Logger;
botName: string;
pollOptions: PollingOptionsStrong[] = [];
@@ -125,7 +95,6 @@ export class Manager {
sharedModqueue: boolean;
cacheManager: BotResourcesManager;
globalDryRun?: boolean;
emitter: EventEmitter = new EventEmitter();
queue: QueueObject<CheckTask>;
// firehose is used to ensure all activities from different polling streams are unique
// that is -- if the same activities is in both modqueue and unmoderated we don't want to process the activity twice or use stale data
@@ -164,50 +133,22 @@ export class Manager {
// use by api nanny to slow event consumption
delayBy?: number;
eventsCheckedTotal: number = 0;
eventsCheckedSinceStartTotal: number = 0;
eventsSample: number[] = [];
eventsSampleInterval: any;
eventsRollingAvg: number = 0;
checksRunTotal: number = 0;
checksRunSinceStartTotal: number = 0;
checksTriggered: Map<string, number> = new Map();
checksTriggeredSinceStart: Map<string, number> = new Map();
rulesRunTotal: number = 0;
rulesRunSinceStartTotal: number = 0;
rulesCachedTotal: number = 0;
rulesCachedSinceStartTotal: number = 0;
rulesTriggeredTotal: number = 0;
rulesTriggeredSinceStartTotal: number = 0;
rulesUniqueSample: number[] = [];
rulesUniqueSampleInterval: any;
rulesUniqueRollingAvg: number = 0;
actionsRun: Map<string, number> = new Map();
actionsRunSinceStart: Map<string, number> = new Map();
actionedEvents: ActionedEvent[] = [];
getStats = async (): Promise<ManagerStats> => {
const data: any = {
eventsCheckedTotal: this.eventsCheckedTotal,
eventsCheckedSinceStartTotal: this.eventsCheckedSinceStartTotal,
eventsAvg: formatNumber(this.eventsRollingAvg),
checksRunTotal: this.checksRunTotal,
checksRunSinceStartTotal: this.checksRunSinceStartTotal,
checksTriggered: this.checksTriggered,
checksTriggeredTotal: totalFromMapStats(this.checksTriggered),
checksTriggeredSinceStart: this.checksTriggeredSinceStart,
checksTriggeredSinceStartTotal: totalFromMapStats(this.checksTriggeredSinceStart),
rulesRunTotal: this.rulesRunTotal,
rulesRunSinceStartTotal: this.rulesRunSinceStartTotal,
rulesCachedTotal: this.rulesCachedTotal,
rulesCachedSinceStartTotal: this.rulesCachedSinceStartTotal,
rulesTriggeredTotal: this.rulesTriggeredTotal,
rulesTriggeredSinceStartTotal: this.rulesTriggeredSinceStartTotal,
rulesAvg: formatNumber(this.rulesUniqueRollingAvg),
actionsRun: this.actionsRun,
actionsRunTotal: totalFromMapStats(this.actionsRun),
actionsRunSinceStart: this.actionsRunSinceStart,
actionsRunSinceStartTotal: totalFromMapStats(this.actionsRunSinceStart),
historical: {
lastReload: createHistoricalStatsDisplay(createHistoricalDefaults()),
allTime: createHistoricalStatsDisplay(createHistoricalDefaults()),
},
cache: {
provider: 'none',
currentKeyCount: 0,
@@ -223,6 +164,7 @@ export class Manager {
if (this.resources !== undefined) {
const resStats = await this.resources.getStats();
data.historical = this.resources.getHistoricalDisplayStats();
data.cache = resStats.cache;
data.cache.currentKeyCount = await this.resources.getCacheKeyCount();
data.cache.isShared = this.resources.cacheSettingsHash === 'default';
@@ -239,7 +181,9 @@ export class Manager {
return this.displayLabel;
}
constructor(sub: Subreddit, client: Snoowrap, logger: Logger, cacheManager: BotResourcesManager, opts: RuntimeManagerOptions = {botName: 'ContextMod', maxWorkers: 1}) {
constructor(sub: Subreddit, client: ExtendedSnoowrap, logger: Logger, cacheManager: BotResourcesManager, opts: RuntimeManagerOptions = {botName: 'ContextMod', maxWorkers: 1}) {
super();
const {dryRun, sharedModqueue = false, wikiLocation = 'botconfig/contextbot', botName, maxWorkers} = opts;
this.displayLabel = opts.nickname || `${sub.display_name_prefixed}`;
const getLabels = this.getCurrentLabels;
@@ -270,8 +214,9 @@ export class Manager {
this.eventsSampleInterval = setInterval((function(self) {
return function() {
const et = self.resources !== undefined ? self.resources.stats.historical.allTime.eventsCheckedTotal : 0;
const rollingSample = self.eventsSample.slice(0, 7)
rollingSample.unshift(self.eventsCheckedTotal)
rollingSample.unshift(et)
self.eventsSample = rollingSample;
const diff = self.eventsSample.reduceRight((acc: number[], curr, index) => {
if(self.eventsSample[index + 1] !== undefined) {
@@ -291,7 +236,8 @@ export class Manager {
this.rulesUniqueSampleInterval = setInterval((function(self) {
return function() {
const rollingSample = self.rulesUniqueSample.slice(0, 7)
rollingSample.unshift(self.rulesRunTotal - self.rulesCachedTotal);
const rt = self.resources !== undefined ? self.resources.stats.historical.allTime.rulesRunTotal - self.resources.stats.historical.allTime.rulesCachedTotal : 0;
rollingSample.unshift(rt);
self.rulesUniqueSample = rollingSample;
const diff = self.rulesUniqueSample.reduceRight((acc: number[], curr, index) => {
if(self.rulesUniqueSample[index + 1] !== undefined) {
@@ -387,7 +333,7 @@ export class Manager {
return q;
}
protected parseConfigurationFromObject(configObj: object) {
protected async parseConfigurationFromObject(configObj: object) {
try {
const configBuilder = new ConfigBuilder({logger: this.logger});
const validJson = configBuilder.validateJson(configObj);
@@ -395,6 +341,7 @@ export class Manager {
const {
polling = [{pollOn: 'unmoderated', limit: DEFAULT_POLLING_LIMIT, interval: DEFAULT_POLLING_INTERVAL}],
caching,
credentials,
dryRun,
footer,
nickname,
@@ -435,9 +382,10 @@ export class Manager {
logger: this.logger,
subreddit: this.subreddit,
caching,
credentials,
client: this.client,
};
this.resources = this.cacheManager.set(this.subreddit.display_name, resourceConfig);
this.resources = await this.cacheManager.set(this.subreddit.display_name, resourceConfig);
this.resources.setLogger(this.logger);
this.logger.info('Subreddit-specific options updated');
@@ -446,6 +394,10 @@ export class Manager {
const commentChecks: Array<CommentCheck> = [];
const subChecks: Array<SubmissionCheck> = [];
const structuredChecks = configBuilder.parseToStructured(validJson);
// TODO check that bot has permissions for subreddit for all specified actions
// can find permissions in this.subreddit.mod_permissions
for (const jCheck of structuredChecks) {
const checkConfig = {
...jCheck,
@@ -471,7 +423,7 @@ export class Manager {
this.logger.info(checkSummary);
}
this.validConfigLoaded = true;
} catch (err) {
} catch (err: any) {
this.validConfigLoaded = false;
throw err;
}
@@ -512,7 +464,7 @@ export class Manager {
this.lastWikiRevision = revisionDate;
sourceData = await wiki.content_md;
} catch (err) {
} catch (err: any) {
const msg = `Could not read wiki configuration. Please ensure the page https://reddit.com${this.subreddit.url}wiki/${this.wikiLocation} exists and is readable -- error: ${err.message}`;
this.logger.error(msg);
throw new ConfigParseError(msg);
@@ -532,7 +484,7 @@ export class Manager {
throw new ConfigParseError('Could not parse wiki page contents as JSON or YAML')
}
this.parseConfigurationFromObject(configObj);
await this.parseConfigurationFromObject(configObj);
this.logger.info('Checks updated');
if(!suppressNotification) {
@@ -540,7 +492,7 @@ export class Manager {
}
return true;
} catch (err) {
} catch (err: any) {
this.validConfigLoaded = false;
throw err;
}
@@ -549,8 +501,6 @@ export class Manager {
async runChecks(checkType: ('Comment' | 'Submission'), activity: (Submission | Comment), options?: runCheckOptions): Promise<void> {
const checks = checkType === 'Comment' ? this.commentChecks : this.submissionChecks;
let item = activity;
this.eventsCheckedTotal++;
this.eventsCheckedSinceStartTotal++;
const itemId = await item.id;
let allRuleResults: RuleResult[] = [];
const itemIdentifier = `${checkType === 'Submission' ? 'SUB' : 'COM'} ${itemId}`;
@@ -560,50 +510,10 @@ export class Manager {
const [peek, _] = await itemContentPeek(item);
ePeek = peek;
this.logger.info(`<EVENT> ${peek}`);
} catch (err) {
} catch (err: any) {
this.logger.error(`Error occurred while generate item peek for ${checkType} Activity ${itemId}`, err);
}
const {
checkNames = [],
delayUntil,
dryRun,
refresh = false,
} = options || {};
let wasRefreshed = false;
if (delayUntil !== undefined) {
const created = dayjs.unix(item.created_utc);
const diff = dayjs().diff(created, 's');
if (diff < delayUntil) {
this.logger.verbose(`Delaying processing until Activity is ${delayUntil} seconds old (${delayUntil - diff}s)`);
await sleep(delayUntil - diff);
// @ts-ignore
item = await activity.refresh();
wasRefreshed = true;
}
}
// refresh signal from firehose if activity was ingested multiple times before processing or re-queued while processing
// want to make sure we have the most recent data
if(!wasRefreshed && refresh === true) {
this.logger.verbose('Refreshed data (probably due to signal from firehose)');
// @ts-ignore
item = await activity.refresh();
}
const startingApiLimit = this.client.ratelimitRemaining;
if (item instanceof Submission) {
if (await item.removed_by_category === 'deleted') {
this.logger.warn('Submission was deleted, cannot process.');
return;
}
} else if (item.author.name === '[deleted]') {
this.logger.warn('Comment was deleted, cannot process.');
return;
}
let checksRun = 0;
let actionsRun = 0;
let totalRulesRun = 0;
@@ -622,8 +532,51 @@ export class Manager {
actionResults: [],
}
let triggered = false;
let triggeredCheckName;
const checksRunNames = [];
const cachedCheckNames = [];
const startingApiLimit = this.client.ratelimitRemaining;
const {
checkNames = [],
delayUntil,
dryRun,
refresh = false,
} = options || {};
let wasRefreshed = false;
try {
if (delayUntil !== undefined) {
const created = dayjs.unix(item.created_utc);
const diff = dayjs().diff(created, 's');
if (diff < delayUntil) {
this.logger.verbose(`Delaying processing until Activity is ${delayUntil} seconds old (${delayUntil - diff}s)`);
await sleep(delayUntil - diff);
// @ts-ignore
item = await activity.refresh();
wasRefreshed = true;
}
}
// refresh signal from firehose if activity was ingested multiple times before processing or re-queued while processing
// want to make sure we have the most recent data
if(!wasRefreshed && refresh === true) {
this.logger.verbose('Refreshed data (probably due to signal from firehose)');
// @ts-ignore
item = await activity.refresh();
}
if (item instanceof Submission) {
if (await item.removed_by_category === 'deleted') {
this.logger.warn('Submission was deleted, cannot process.');
return;
}
} else if (item.author.name === '[deleted]') {
this.logger.warn('Comment was deleted, cannot process.');
return;
}
for (const check of checks) {
if (checkNames.length > 0 && !checkNames.map(x => x.toLowerCase()).some(x => x === check.name.toLowerCase())) {
this.logger.warn(`Check ${check.name} not in array of requested checks to run, skipping...`);
@@ -633,6 +586,7 @@ export class Manager {
this.logger.info(`Check ${check.name} not run because it is not enabled, skipping...`);
continue;
}
checksRunNames.push(check.name);
checksRun++;
triggered = false;
let isFromCache = false;
@@ -642,6 +596,8 @@ export class Manager {
isFromCache = fromCache;
if(!fromCache) {
await check.setCacheResult(item, {result: checkTriggered, ruleResults: checkResults});
} else {
cachedCheckNames.push(check.name);
}
currentResults = checkResults;
totalRulesRun += checkResults.length;
@@ -651,13 +607,14 @@ export class Manager {
this.logger.info('Check was triggered but cache result options specified NOT to run actions...counting as check NOT triggered');
triggered = false;
}
} catch (e) {
} catch (e: any) {
if (e.logged !== true) {
this.logger.warn(`Running rules for Check ${check.name} failed due to uncaught exception`, e);
}
}
if (triggered) {
triggeredCheckName = check.name;
actionedEvent.check = check.name;
actionedEvent.ruleResults = currentResults;
if(isFromCache) {
@@ -665,8 +622,6 @@ export class Manager {
} else {
actionedEvent.ruleSummary = resultsSummary(currentResults, check.condition);
}
this.checksTriggered.set(check.name, (this.checksTriggered.get(check.name) || 0) + 1);
this.checksTriggeredSinceStart.set(check.name, (this.checksTriggeredSinceStart.get(check.name) || 0) + 1);
runActions = await check.runActions(item, currentResults.filter(x => x.triggered), dryRun);
actionsRun = runActions.length;
@@ -682,29 +637,13 @@ export class Manager {
this.logger.info('No checks triggered');
}
} catch (err) {
} catch (err: any) {
if (!(err instanceof LoggedError) && err.logged !== true) {
this.logger.error('An unhandled error occurred while running checks', err);
}
this.emit('error', err);
} finally {
try {
const cachedTotal = totalRulesRun - allRuleResults.length;
const triggeredRulesTotal = allRuleResults.filter(x => x.triggered).length;
this.checksRunTotal += checksRun;
this.checksRunSinceStartTotal += checksRun;
this.rulesRunTotal += totalRulesRun;
this.rulesRunSinceStartTotal += totalRulesRun;
this.rulesCachedTotal += cachedTotal;
this.rulesCachedSinceStartTotal += cachedTotal;
this.rulesTriggeredTotal += triggeredRulesTotal;
this.rulesTriggeredSinceStartTotal += triggeredRulesTotal;
for (const a of runActions) {
const name = a.name;
this.actionsRun.set(name, (this.actionsRun.get(name) || 0) + 1);
this.actionsRunSinceStart.set(name, (this.actionsRunSinceStart.get(name) || 0) + 1);
}
actionedEvent.actionResults = runActions;
if(triggered) {
await this.resources.addActionedEvent(actionedEvent);
@@ -713,8 +652,20 @@ export class Manager {
this.logger.verbose(`Run Stats: Checks ${checksRun} | Rules => Total: ${totalRulesRun} Unique: ${allRuleResults.length} Cached: ${totalRulesRun - allRuleResults.length} Rolling Avg: ~${formatNumber(this.rulesUniqueRollingAvg)}/s | Actions ${actionsRun}`);
this.logger.verbose(`Reddit API Stats: Initial ${startingApiLimit} | Current ${this.client.ratelimitRemaining} | Used ~${startingApiLimit - this.client.ratelimitRemaining} | Events ~${formatNumber(this.eventsRollingAvg)}/s`);
this.currentLabels = [];
} catch (err) {
} catch (err: any) {
this.logger.error('Error occurred while cleaning up Activity check and generating stats', err);
} finally {
this.resources.updateHistoricalStats({
eventsCheckedTotal: 1,
eventsActionedTotal: triggered ? 1 : 0,
checksTriggered: triggeredCheckName !== undefined ? [triggeredCheckName] : [],
checksRun: checksRunNames,
checksFromCache: cachedCheckNames,
actionsRun: runActions.map(x => x.name),
rulesRun: allRuleResults.map(x => x.name),
rulesTriggered: allRuleResults.filter(x => x.triggered).map(x => x.name),
rulesCachedTotal: totalRulesRun - allRuleResults.length,
});
}
}
}
@@ -723,7 +674,7 @@ export class Manager {
// give current handle() time to stop
//await sleep(1000);
const retryHandler = createRetryHandler({maxRequestRetry: 5, maxOtherRetry: 1}, this.logger);
const retryHandler = createRetryHandler({maxRequestRetry: 3, maxOtherRetry: 1}, this.logger);
const subName = this.subreddit.display_name;
@@ -732,7 +683,8 @@ export class Manager {
pollOn,
limit,
interval,
delayUntil
delayUntil,
clearProcessed,
} = pollOpt;
let stream: SPoll<Snoowrap.Submission | Snoowrap.Comment>;
let modStreamType: string | undefined;
@@ -748,6 +700,7 @@ export class Manager {
subreddit: this.subreddit.display_name,
limit: limit,
pollTime: interval * 1000,
clearProcessed,
});
}
break;
@@ -761,6 +714,7 @@ export class Manager {
subreddit: this.subreddit.display_name,
limit: limit,
pollTime: interval * 1000,
clearProcessed
});
}
break;
@@ -769,6 +723,7 @@ export class Manager {
subreddit: this.subreddit.display_name,
limit: limit,
pollTime: interval * 1000,
clearProcessed
});
break;
case 'newComm':
@@ -776,6 +731,7 @@ export class Manager {
subreddit: this.subreddit.display_name,
limit: limit,
pollTime: interval * 1000,
clearProcessed
});
break;
}
@@ -813,21 +769,26 @@ export class Manager {
}
};
stream.on('item', onItem);
if (modStreamType !== undefined) {
this.modStreamCallbacks.set(pollOn, onItem);
} else {
stream.on('item', onItem);
// @ts-ignore
stream.on('error', async (err: any) => {
this.emit('error', err);
if(isRateLimitError(err)) {
this.logger.error('Encountered rate limit while polling! Bot is all out of requests :( Stopping subreddit queue and polling.');
await this.stop();
}
this.logger.error('Polling error occurred', err);
const shouldRetry = await retryHandler(err);
if (shouldRetry) {
stream.startInterval();
} else {
this.logger.warn('Pausing event polling due to too many errors');
await this.pauseEvents();
this.logger.warn('Stopping subreddit processing/polling due to too many errors');
await this.stop();
}
});
this.streams.push(stream);
@@ -911,10 +872,19 @@ export class Manager {
} else {
const pauseWaitStart = dayjs();
this.logger.info(`Activity processing queue is stopping...waiting for ${this.queue.running()} activities to finish processing`);
const fullStopTime = dayjs().add(5, 'seconds');
let gracefulStop = true;
while (this.queue.running() > 0) {
gracefulStop = false;
if(dayjs().isAfter(fullStopTime)) {
break;
}
await sleep(1500);
this.logger.verbose(`Activity processing queue is stopping...waiting for ${this.queue.running()} activities to finish processing`);
}
if(!gracefulStop) {
this.logger.warn('Waited longer than 5 seconds to stop activities. Something isn\'t right so forcing stop :/ ');
}
this.logger.info(`Activity processing queue stopped by ${causedBy} and ${this.queue.length()} queued activities cleared (waited ${dayjs().diff(pauseWaitStart, 's')} seconds while activity processing finished)`);
this.firehose.kill();
this.queue.kill();
@@ -997,18 +967,12 @@ export class Manager {
s.end();
}
this.streams = [];
for (const [k, v] of this.modStreamCallbacks) {
const stream = this.cacheManager.modStreams.get(k) as Poll<Snoowrap.Submission | Snoowrap.Comment>;
stream.removeListener('item', v);
}
// for (const [k, v] of this.modStreamCallbacks) {
// const stream = this.cacheManager.modStreams.get(k) as Poll<Snoowrap.Submission | Snoowrap.Comment>;
// stream.removeListener('item', v);
// }
this.modStreamCallbacks = new Map();
this.startedAt = undefined;
this.eventsCheckedSinceStartTotal = 0;
this.checksRunSinceStartTotal = 0;
this.rulesRunSinceStartTotal = 0;
this.rulesCachedSinceStartTotal = 0;
this.rulesTriggeredSinceStartTotal = 0;
this.checksTriggeredSinceStart = new Map();
this.actionsRunSinceStart = new Map();
this.logger.info(`Events STOPPED by ${causedBy}`);
this.eventsState = {
state: STOPPED,

View File

@@ -2,51 +2,110 @@ import {Poll, SnooStormOptions} from "snoostorm"
import Snoowrap from "snoowrap";
import {EventEmitter} from "events";
import {PollConfiguration} from "snoostorm/out/util/Poll";
import {DEFAULT_POLLING_INTERVAL} from "../Common/interfaces";
import {ClearProcessedOptions, DEFAULT_POLLING_INTERVAL} from "../Common/interfaces";
import dayjs, {Dayjs} from "dayjs";
import { Duration } from "dayjs/plugin/duration";
import {parseDuration, setRandomInterval, sleep} from "../util";
type Awaitable<T> = Promise<T> | T;
interface RCBPollingOptions extends SnooStormOptions {
subreddit: string,
clearProcessed?: ClearProcessedOptions
}
interface RCBPollConfiguration<T> extends PollConfiguration<T> {
clearProcessed?: ClearProcessedOptions
}
export class SPoll<T extends object> extends Poll<T> {
identifier: keyof T;
getter: () => Awaitable<T[]>;
frequency;
running: boolean = false;
clearProcessedDuration?: Duration;
clearProcessedSize?: number;
clearProcessedAfter?: Dayjs;
retainProcessed: number = 0;
randInterval?: { clear: () => void };
constructor(options: PollConfiguration<T>) {
constructor(options: RCBPollConfiguration<T>) {
super(options);
this.identifier = options.identifier;
this.getter = options.get;
this.frequency = options.frequency;
const {
after,
size,
retain = 0,
} = options.clearProcessed || {};
if(after !== undefined) {
this.clearProcessedDuration = parseDuration(after);
}
this.clearProcessedSize = size;
this.retainProcessed = retain;
if (this.clearProcessedDuration !== undefined) {
this.clearProcessedAfter = dayjs().add(this.clearProcessedDuration.asSeconds(), 's');
}
clearInterval(this.interval);
}
startInterval = () => {
this.running = true;
this.interval = setInterval(async () => {
try {
const batch = await this.getter();
const newItems: T[] = [];
for (const item of batch) {
const id = item[this.identifier];
if (this.processed.has(id)) continue;
this.randInterval = setRandomInterval((function (self) {
return async () => {
try {
// DEBUGGING
//
// Removing processed clearing to see if it fixes weird, duplicate/delayed comment processing behavior
//
// clear the tracked, processed activity ids after a set period or number of activities have been processed
// because when RCB is long-running and has streams from high-volume subreddits this list never gets smaller...
// Emit for new items and add it to the list
newItems.push(item);
this.processed.add(id);
this.emit("item", item);
// so clear if after time period
// if ((self.clearProcessedAfter !== undefined && dayjs().isSameOrAfter(self.clearProcessedAfter))
// // or clear if processed list is larger than defined max allowable size (default setting, 2 * polling option limit)
// || (self.clearProcessedSize !== undefined && self.processed.size >= self.clearProcessedSize)) {
// if (self.retainProcessed === 0) {
// self.processed = new Set();
// } else {
// // retain some processed so we have continuity between processed list resets -- this is default behavior and retains polling option limit # of activities
// // we can slice from the set here because ID order is guaranteed for Set object so list is oldest -> newest
// // -- retain last LIMIT number of activities (or all if retain # is larger than list due to user config error)
// self.processed = new Set(Array.from(self.processed).slice(Math.max(0, self.processed.size - self.retainProcessed)));
// }
// // reset time interval if there is one
// if (self.clearProcessedAfter !== undefined && self.clearProcessedDuration !== undefined) {
// self.clearProcessedAfter = dayjs().add(self.clearProcessedDuration.asSeconds(), 's');
// }
// }
const batch = await self.getter();
const newItems: T[] = [];
for (const item of batch) {
const id = item[self.identifier];
if (self.processed.has(id)) continue;
// Emit for new items and add it to the list
newItems.push(item);
self.processed.add(id);
self.emit("item", item);
}
// Emit the new listing of all new items
self.emit("listing", newItems);
} catch (err: any) {
self.emit('error', err);
self.end();
}
// Emit the new listing of all new items
this.emit("listing", newItems);
} catch (err) {
this.emit('error', err);
this.end();
}
}, this.frequency);
})(this), this.frequency - 1, this.frequency + 1);
}
end = () => {
this.running = false;
if(this.randInterval !== undefined) {
this.randInterval.clear();
}
super.end();
}
}
@@ -54,11 +113,12 @@ export class SPoll<T extends object> extends Poll<T> {
export class UnmoderatedStream extends SPoll<Snoowrap.Submission | Snoowrap.Comment> {
constructor(
client: Snoowrap,
options: SnooStormOptions & { subreddit: string }) {
options: RCBPollingOptions) {
super({
frequency: options.pollTime || DEFAULT_POLLING_INTERVAL * 1000,
get: async () => client.getSubreddit(options.subreddit).getUnmoderated(options),
identifier: "id",
clearProcessed: options.clearProcessed
});
}
}
@@ -66,11 +126,12 @@ export class UnmoderatedStream extends SPoll<Snoowrap.Submission | Snoowrap.Comm
export class ModQueueStream extends SPoll<Snoowrap.Submission | Snoowrap.Comment> {
constructor(
client: Snoowrap,
options: SnooStormOptions & { subreddit: string }) {
options: RCBPollingOptions) {
super({
frequency: options.pollTime || DEFAULT_POLLING_INTERVAL * 1000,
get: async () => client.getSubreddit(options.subreddit).getModqueue(options),
identifier: "id",
clearProcessed: options.clearProcessed
});
}
}
@@ -78,11 +139,12 @@ export class ModQueueStream extends SPoll<Snoowrap.Submission | Snoowrap.Comment
export class SubmissionStream extends SPoll<Snoowrap.Submission | Snoowrap.Comment> {
constructor(
client: Snoowrap,
options: SnooStormOptions & { subreddit: string }) {
options: RCBPollingOptions) {
super({
frequency: options.pollTime || DEFAULT_POLLING_INTERVAL * 1000,
get: async () => client.getNew(options.subreddit, options),
identifier: "id",
clearProcessed: options.clearProcessed
});
}
}
@@ -90,11 +152,12 @@ export class SubmissionStream extends SPoll<Snoowrap.Submission | Snoowrap.Comme
export class CommentStream extends SPoll<Snoowrap.Submission | Snoowrap.Comment> {
constructor(
client: Snoowrap,
options: SnooStormOptions & { subreddit: string }) {
options: RCBPollingOptions) {
super({
frequency: options.pollTime || DEFAULT_POLLING_INTERVAL * 1000,
get: async () => client.getNewComments(options.subreddit, options),
identifier: "id",
clearProcessed: options.clearProcessed
});
}
}

View File

@@ -1,4 +1,4 @@
import Snoowrap, {RedditUser, Subreddit} from "snoowrap";
import Snoowrap, {RedditUser} from "snoowrap";
import objectHash from 'object-hash';
import {
activityIsDeleted, activityIsFiltered,
@@ -9,22 +9,38 @@ import {
testAuthorCriteria
} from "../Utils/SnoowrapUtils";
import winston, {Logger} from "winston";
import as from 'async';
import fetch from 'node-fetch';
import {
asSubmission,
buildCacheOptionsFromProvider, buildCachePrefix,
cacheStats, comparisonTextOp, createCacheManager,
cacheStats, compareDurationValue, comparisonTextOp, createCacheManager, createHistoricalStatsDisplay,
formatNumber, getActivityAuthorName, getActivitySubredditName, isStrongSubredditState,
mergeArr,
parseExternalUrl, parseGenericValueComparison,
parseWikiContext, toStrongSubredditState
mergeArr, parseDurationComparison,
parseExternalUrl, parseGenericValueComparison, parseRedditEntity,
parseWikiContext, shouldCacheSubredditStateCriteriaResult, subredditStateIsNameOnly, toStrongSubredditState
} from "../util";
import LoggedError from "../Utils/LoggedError";
import {
BotInstanceConfig,
CacheOptions, CommentState,
Footer, OperatorConfig, ResourceStats, StrongCache, SubmissionState,
CacheConfig, TTLConfig, TypedActivityStates, UserResultCache, ActionedEvent, SubredditState, StrongSubredditState
CacheOptions,
CommentState,
Footer,
OperatorConfig,
ResourceStats,
StrongCache,
SubmissionState,
CacheConfig,
TTLConfig,
TypedActivityStates,
UserResultCache,
ActionedEvent,
SubredditState,
StrongSubredditState,
HistoricalStats,
HistoricalStatUpdateData,
SubredditHistoricalStats,
SubredditHistoricalStatsDisplay, ThirdPartyCredentialsJsonConfig,
} from "../Common/interfaces";
import UserNotes from "./UserNotes";
import Mustache from "mustache";
@@ -32,9 +48,12 @@ import he from "he";
import {AuthorCriteria} from "../Author/Author";
import {SPoll} from "./Streams";
import {Cache} from 'cache-manager';
import {Submission, Comment} from "snoowrap/dist/objects";
import {cacheTTLDefaults} from "../Common/defaults";
import {Submission, Comment, Subreddit} from "snoowrap/dist/objects";
import {cacheTTLDefaults, createHistoricalDefaults, historicalDefaults} from "../Common/defaults";
import {check} from "tcp-port-used";
import {ExtendedSnoowrap} from "../Utils/SnoowrapClients";
import dayjs from "dayjs";
import ImageData from "../Common/ImageData";
export const DEFAULT_FOOTER = '\r\n*****\r\nThis action was performed by [a bot.]({{botLink}}) Mention a moderator or [send a modmail]({{modmailLink}}) if you any ideas, questions, or concerns about this action.';
@@ -42,7 +61,8 @@ export interface SubredditResourceConfig extends Footer {
caching?: CacheConfig,
subreddit: Subreddit,
logger: Logger;
client: Snoowrap
client: ExtendedSnoowrap
credentials?: ThirdPartyCredentialsJsonConfig
}
interface SubredditResourceOptions extends Footer {
@@ -52,9 +72,10 @@ interface SubredditResourceOptions extends Footer {
cacheSettingsHash: string
subreddit: Subreddit,
logger: Logger;
client: Snoowrap;
client: ExtendedSnoowrap;
prefix?: string;
actionedEventsMax: number;
thirdPartyCredentials: ThirdPartyCredentialsJsonConfig
}
export interface SubredditResourceSetOptions extends CacheConfig, Footer {
@@ -74,15 +95,20 @@ export class SubredditResources {
userNotes: UserNotes;
footer: false | string = DEFAULT_FOOTER;
subreddit: Subreddit
client: Snoowrap
client: ExtendedSnoowrap
cache: Cache
cacheType: string
cacheSettingsHash?: string;
pruneInterval?: any;
historicalSaveInterval?: any;
prefix?: string
actionedEventsMax: number;
thirdPartyCredentials: ThirdPartyCredentialsJsonConfig;
stats: { cache: ResourceStats };
stats: {
cache: ResourceStats
historical: SubredditHistoricalStats
};
constructor(name: string, options: SubredditResourceOptions) {
const {
@@ -103,6 +129,7 @@ export class SubredditResources {
actionedEventsMax,
cacheSettingsHash,
client,
thirdPartyCredentials,
} = options || {};
this.cacheSettingsHash = cacheSettingsHash;
@@ -118,6 +145,7 @@ export class SubredditResources {
this.wikiTTL = wikiTTL === true ? 0 : wikiTTL;
this.filterCriteriaTTL = filterCriteriaTTL === true ? 0 : filterCriteriaTTL;
this.subreddit = subreddit;
this.thirdPartyCredentials = thirdPartyCredentials;
this.name = name;
if (logger === undefined) {
const alogger = winston.loggers.get('app')
@@ -127,7 +155,11 @@ export class SubredditResources {
}
this.stats = {
cache: cacheStats()
cache: cacheStats(),
historical: {
allTime: createHistoricalDefaults(),
lastReload: createHistoricalDefaults()
}
};
const cacheUseCB = (miss: boolean) => {
@@ -151,10 +183,97 @@ export class SubredditResources {
}
}
async initHistoricalStats() {
const at = await this.cache.wrap(`${this.name}-historical-allTime`, () => createHistoricalDefaults(), {ttl: 0}) as object;
const rehydratedAt: any = {};
for(const [k, v] of Object.entries(at)) {
if(Array.isArray(v)) {
rehydratedAt[k] = new Map(v);
} else {
rehydratedAt[k] = v;
}
}
this.stats.historical.allTime = rehydratedAt as HistoricalStats;
// const lr = await this.cache.wrap(`${this.name}-historical-lastReload`, () => createHistoricalDefaults(), {ttl: 0}) as object;
// const rehydratedLr: any = {};
// for(const [k, v] of Object.entries(lr)) {
// if(Array.isArray(v)) {
// rehydratedLr[k] = new Map(v);
// } else {
// rehydratedLr[k] = v;
// }
// }
// this.stats.historical.lastReload = rehydratedLr;
}
updateHistoricalStats(data: HistoricalStatUpdateData) {
for(const [k, v] of Object.entries(data)) {
if(this.stats.historical.lastReload[k] !== undefined) {
if(typeof v === 'number') {
this.stats.historical.lastReload[k] += v;
} else if(this.stats.historical.lastReload[k] instanceof Map) {
const keys = Array.isArray(v) ? v : [v];
for(const key of keys) {
this.stats.historical.lastReload[k].set(key, (this.stats.historical.lastReload[k].get(key) || 0) + 1);
}
}
}
if(this.stats.historical.allTime[k] !== undefined) {
if(typeof v === 'number') {
this.stats.historical.allTime[k] += v;
} else if(this.stats.historical.allTime[k] instanceof Map) {
const keys = Array.isArray(v) ? v : [v];
for(const key of keys) {
this.stats.historical.allTime[k].set(key, (this.stats.historical.allTime[k].get(key) || 0) + 1);
}
}
}
}
}
getHistoricalDisplayStats(): SubredditHistoricalStatsDisplay {
return {
allTime: createHistoricalStatsDisplay(this.stats.historical.allTime),
lastReload: createHistoricalStatsDisplay(this.stats.historical.lastReload)
}
}
async saveHistoricalStats() {
const atSerializable: any = {};
for(const [k, v] of Object.entries(this.stats.historical.allTime)) {
if(v instanceof Map) {
atSerializable[k] = Array.from(v.entries());
} else {
atSerializable[k] = v;
}
}
await this.cache.set(`${this.name}-historical-allTime`, atSerializable, {ttl: 0});
// const lrSerializable: any = {};
// for(const [k, v] of Object.entries(this.stats.historical.lastReload)) {
// if(v instanceof Map) {
// lrSerializable[k] = Array.from(v.entries());
// } else {
// lrSerializable[k] = v;
// }
// }
// await this.cache.set(`${this.name}-historical-lastReload`, lrSerializable, {ttl: 0});
}
setHistoricalSaveInterval() {
this.historicalSaveInterval = setInterval((function(self) {
return async () => {
await self.saveHistoricalStats();
}
})(this),10000);
}
async getCacheKeyCount() {
if (this.cache.store.keys !== undefined) {
if(this.cacheType === 'redis') {
return (await this.cache.store.keys(`${this.prefix}*`)).length;
const keys = await this.cache.store.keys(`${this.prefix}*`);
return keys.length;
}
return (await this.cache.store.keys()).length;
}
@@ -266,7 +385,7 @@ export class SubredditResources {
// @ts-ignore
return await item.fetch();
}
} catch (err) {
} catch (err: any) {
this.logger.error('Error while trying to fetch a cached activity', err);
throw err.logged;
}
@@ -276,19 +395,20 @@ export class SubredditResources {
async getSubreddit(item: Submission | Comment) {
try {
let hash = '';
const subName = getActivitySubredditName(item);
if (this.subredditTTL !== false) {
hash = `sub-${getActivitySubredditName(item)}`;
hash = `sub-${subName}`;
await this.stats.cache.subreddit.identifierRequestCount.set(hash, (await this.stats.cache.subreddit.identifierRequestCount.wrap(hash, () => 0) as number) + 1);
this.stats.cache.subreddit.requestTimestamps.push(Date.now());
this.stats.cache.subreddit.requests++;
const cachedSubreddit = await this.cache.get(hash);
if (cachedSubreddit !== undefined && cachedSubreddit !== null) {
this.logger.debug(`Cache Hit: Subreddit ${item.subreddit.display_name}`);
this.logger.debug(`Cache Hit: Subreddit ${subName}`);
// @ts-ignore
return cachedSubreddit as Subreddit;
}
// @ts-ignore
const subreddit = await this.client.getSubreddit(getActivitySubredditName(item)).fetch() as Subreddit;
const subreddit = await this.client.getSubreddit(subName).fetch() as Subreddit;
this.stats.cache.subreddit.miss++;
// @ts-ignore
await this.cache.set(hash, subreddit, {ttl: this.subredditTTL});
@@ -296,16 +416,31 @@ export class SubredditResources {
return subreddit as Subreddit;
} else {
// @ts-ignore
let subreddit = await this.client.getSubreddit(getActivitySubredditName(item));
let subreddit = await this.client.getSubreddit(subName);
return subreddit as Subreddit;
}
} catch (err) {
} catch (err: any) {
this.logger.error('Error while trying to fetch a cached activity', err);
throw err.logged;
}
}
async hasSubreddit(name: string) {
if (this.subredditTTL !== false) {
const hash = `sub-${name}`;
this.stats.cache.subreddit.requests++
this.stats.cache.subreddit.requestTimestamps.push(Date.now());
await this.stats.cache.subreddit.identifierRequestCount.set(hash, (await this.stats.cache.subreddit.identifierRequestCount.wrap(hash, () => 0) as number) + 1);
const val = await this.cache.get(hash);
if(val === undefined || val === null) {
this.stats.cache.subreddit.miss++;
}
return val !== undefined && val !== null;
}
return false;
}
async getAuthorActivities(user: RedditUser, options: AuthorTypedActivitiesOptions): Promise<Array<Submission | Comment>> {
const userName = getActivityAuthorName(user);
if (this.authorTTL !== false) {
@@ -397,7 +532,7 @@ export class SubredditResources {
// @ts-ignore
const wikiPage = sub.getWikiPage(wikiContext.wiki);
wikiContent = await wikiPage.content_md;
} catch (err) {
} catch (err: any) {
let msg = `Could not read wiki page for an unknown reason. Please ensure the page 'https://reddit.com${sub.display_name_prefixed}/wiki/${wikiContext.wiki}' exists and is readable`;
if(err.statusCode !== undefined) {
if(err.statusCode === 404) {
@@ -413,7 +548,7 @@ export class SubredditResources {
try {
const response = await fetch(extUrl as string);
wikiContent = await response.text();
} catch (err) {
} catch (err: any) {
const msg = `Error occurred while trying to fetch the url ${extUrl}`;
this.logger.error(msg, err);
throw new LoggedError(msg);
@@ -427,6 +562,67 @@ export class SubredditResources {
return wikiContent;
}
async cacheSubreddits(subs: (Subreddit | string)[]) {
const allSubs = subs.map(x => typeof x !== 'string' ? x.display_name : x);
const subNames = [...new Set(allSubs)];
const uncachedSubs = [];
for(const s of subNames) {
if(!(await this.hasSubreddit(s))) {
uncachedSubs.push(s);
}
}
if(uncachedSubs.length > 0) {
// cache all uncached subs batchly-like
const subResults = await this.client.getManySubreddits(uncachedSubs);
for(const s of subResults) {
// @ts-ignore
await this.cache.set(`sub-${s.display_name}`, s, {ttl: this.subredditTTL});
}
}
}
async batchTestSubredditCriteria(items: (Comment | Submission)[], states: (SubredditState | StrongSubredditState)[]): Promise<(Comment | Submission)[]> {
let passedItems: (Comment | Submission)[] = [];
let unpassedItems: (Comment | Submission)[] = [];
const {nameOnly = [], full = []} = states.reduce((acc: {nameOnly: (SubredditState | StrongSubredditState)[], full: (SubredditState | StrongSubredditState)[]}, curr) => {
if(subredditStateIsNameOnly(curr)) {
return {...acc, nameOnly: acc.nameOnly.concat(curr)};
}
return {...acc, full: acc.full.concat(curr)};
}, {nameOnly: [], full: []});
if(nameOnly.length === 0) {
unpassedItems = items;
} else {
for(const item of items) {
const subName = getActivitySubredditName(item);
for(const state of nameOnly) {
if(await this.isSubreddit({display_name: subName} as Subreddit, state, this.logger)) {
passedItems.push(item);
break;
}
}
unpassedItems.push(item);
}
}
if(unpassedItems.length > 0 && full.length > 0) {
await this.cacheSubreddits(unpassedItems.map(x => x.subreddit));
for(const item of unpassedItems) {
for(const state of full) {
if(await this.isSubreddit(await this.getSubreddit(item), state, this.logger)) {
passedItems.push(item);
break;
}
}
}
}
return passedItems;
}
async testSubredditCriteria(item: (Comment | Submission), state: SubredditState | StrongSubredditState) {
if(Object.keys(state).length === 0) {
return true;
@@ -441,7 +637,8 @@ export class SubredditResources {
return await this.isSubreddit({display_name: subName} as Subreddit, state, this.logger);
}
if (this.filterCriteriaTTL !== false) {
// see comments on shouldCacheSubredditStateCriteriaResult() for why this is needed
if (this.filterCriteriaTTL !== false && shouldCacheSubredditStateCriteriaResult(state)) {
try {
const hash = `subredditCrit-${getActivitySubredditName(item)}-${objectHash.sha1(state)}`;
await this.stats.cache.subredditCrit.identifierRequestCount.set(hash, (await this.stats.cache.subredditCrit.identifierRequestCount.wrap(hash, () => 0) as number) + 1);
@@ -456,7 +653,7 @@ export class SubredditResources {
this.stats.cache.subredditCrit.miss++;
await this.cache.set(hash, itemResult, {ttl: this.filterCriteriaTTL});
return itemResult;
} catch (err) {
} catch (err: any) {
if (err.logged !== true) {
this.logger.error('Error occurred while testing subreddit criteria', err);
}
@@ -497,6 +694,10 @@ export class SubredditResources {
}
async testItemCriteria(i: (Comment | Submission), activityStates: TypedActivityStates) {
// return early if nothing is being checked for so we don't store an empty cache result for this (duh)
if(activityStates.length === 0) {
return true;
}
if (this.filterCriteriaTTL !== false) {
let item = i;
let states = activityStates;
@@ -522,7 +723,7 @@ export class SubredditResources {
this.stats.cache.itemCrit.miss++;
await this.cache.set(hash, itemResult, {ttl: this.filterCriteriaTTL});
return itemResult;
} catch (err) {
} catch (err: any) {
if (err.logged !== true) {
this.logger.error('Error occurred while testing item criteria', err);
}
@@ -555,9 +756,29 @@ export class SubredditResources {
return false;
}
break;
case 'isUserProfile':
const entity = parseRedditEntity(subreddit.display_name);
const entityIsUserProfile = entity.type === 'user';
if(crit[k] !== entityIsUserProfile) {
// @ts-ignore
log.debug(`Failed: Expected => ${k}:${crit[k]} | Found => ${k}:${entityIsUserProfile}`)
return false
}
break;
case 'over18':
case 'over_18':
// handling an edge case where user may have confused Comment/Submission state "over_18" with SubredditState "over18"
// @ts-ignore
if (crit[k] !== subreddit.over18) {
// @ts-ignore
log.debug(`Failed: Expected => ${k}:${crit[k]} | Found => ${k}:${subreddit.over18}`)
return false
}
break;
default:
// @ts-ignore
if (crit[k] !== undefined) {
if (subreddit[k] !== undefined) {
// @ts-ignore
if (crit[k] !== subreddit[k]) {
// @ts-ignore
@@ -614,6 +835,10 @@ export class SubredditResources {
}
break;
case 'reports':
if (!item.can_mod_post) {
log.debug(`Cannot test for reports on Activity in a subreddit bot account is not a moderato Activist. Skipping criteria...`);
break;
}
const reportCompare = parseGenericValueComparison(crit[k] as string);
if(!comparisonTextOp(item.num_reports, reportCompare.operator, reportCompare.value)) {
// @ts-ignore
@@ -638,6 +863,10 @@ export class SubredditResources {
}
break;
case 'filtered':
if (!item.can_mod_post) {
log.debug(`Cannot test for 'filtered' state on Activity in a subreddit bot account is not a moderator for. Skipping criteria...`);
break;
}
const filtered = activityIsFiltered(item);
if (filtered !== crit['filtered']) {
// @ts-ignore
@@ -645,6 +874,13 @@ export class SubredditResources {
return false
}
break;
case 'age':
const ageTest = compareDurationValue(parseDurationComparison(crit[k] as string), dayjs.unix(await item.created));
if (!ageTest) {
log.debug(`Failed: Activity did not pass age test "${crit[k] as string}"`);
return false;
}
break;
case 'title':
if((item instanceof Comment)) {
log.warn('`title` is not allowed in `itemIs` criteria when the main Activity is a Comment');
@@ -653,16 +889,54 @@ export class SubredditResources {
// @ts-ignore
const titleReg = crit[k] as string;
try {
if(null === item.title.match(titleReg)) {
if (null === item.title.match(titleReg)) {
// @ts-ignore
log.debug(`Failed to match title as regular expression: ${titleReg}`);
return false;
}
} catch (err) {
} catch (err: any) {
log.error(`An error occurred while attempting to match title against string as regular expression: ${titleReg}. Most likely the string does not make a valid regular expression.`, err);
return false
}
break;
case 'approved':
case 'spam':
if(!item.can_mod_post) {
log.debug(`Cannot test for '${k}' state on Activity in a subreddit bot account is not a moderator for. Skipping criteria...`);
break;
}
// @ts-ignore
if (item[k] !== crit[k]) {
// @ts-ignore
log.debug(`Failed: Expected => ${k}:${crit[k]} | Found => ${k}:${item[k]}`)
return false
}
break;
case 'op':
if(item instanceof Submission) {
log.warn(`On a Submission the 'op' property will always be true. Did you mean to use this on a comment instead?`);
break;
}
// @ts-ignore
if (item.is_submitter !== crit[k]) {
// @ts-ignore
log.debug(`Failed: Expected => ${k}:${crit[k]} | Found => ${k}:${item[k]}`)
return false
}
break;
case 'depth':
if(item instanceof Submission) {
log.warn(`Cannot test for 'depth' on a Submission`);
break;
}
// @ts-ignore
const depthCompare = parseGenericValueComparison(crit[k] as string);
if(!comparisonTextOp(item.score, depthCompare.operator, depthCompare.value)) {
// @ts-ignore
log.debug(`Failed: Expected => ${k}:${crit[k]} | Found => ${k}:${item.score}`)
return false
}
break;
default:
// @ts-ignore
if (item[k] !== undefined) {
@@ -673,7 +947,11 @@ export class SubredditResources {
return false
}
} else {
log.warn(`Tried to test for Item property '${k}' but it did not exist`);
if(!item.can_mod_post) {
log.warn(`Tried to test for Activity property '${k}' but it did not exist. This Activity is not in a subreddit the bot can mod so it may be that this property is only available to mods of that subreddit. Or the property may be misspelled.`);
} else {
log.warn(`Tried to test for Activity property '${k}' but it did not exist. Check the spelling of the property.`);
}
}
break;
}
@@ -693,6 +971,8 @@ export class SubredditResources {
const userName = getActivityAuthorName(item.author);
const hash = `commentUserResult-${userName}-${item.link_id}-${objectHash.sha1(checkConfig)}`;
this.stats.cache.commentCheck.requests++;
this.stats.cache.commentCheck.requestTimestamps.push(Date.now());
await this.stats.cache.commentCheck.identifierRequestCount.set(hash, (await this.stats.cache.commentCheck.identifierRequestCount.wrap(hash, () => 0) as number) + 1);
let result = await this.cache.get(hash) as UserResultCache | undefined | null;
if(result === null) {
result = undefined;
@@ -723,6 +1003,40 @@ export class SubredditResources {
const footerRawContent = await this.getContent(footer, item.subreddit);
return he.decode(Mustache.render(footerRawContent, {subName, permaLink, modmailLink, botLink: BOT_LINK}));
}
async getImageHash(img: ImageData): Promise<string|undefined> {
const hash = `imgHash-${img.baseUrl}`;
const result = await this.cache.get(hash) as string | undefined | null;
this.stats.cache.imageHash.requests++
this.stats.cache.imageHash.requestTimestamps.push(Date.now());
await this.stats.cache.imageHash.identifierRequestCount.set(hash, (await this.stats.cache.imageHash.identifierRequestCount.wrap(hash, () => 0) as number) + 1);
if(result !== undefined && result !== null) {
return result;
}
this.stats.cache.commentCheck.miss++;
return undefined;
// const hash = await this.cache.wrap(img.baseUrl, async () => await img.hash(true), { ttl }) as string;
// if(img.hashResult === undefined) {
// img.hashResult = hash;
// }
// return hash;
}
async setImageHash(img: ImageData, hash: string, ttl: number): Promise<void> {
await this.cache.set(`imgHash-${img.baseUrl}`, hash, {ttl});
// const hash = await this.cache.wrap(img.baseUrl, async () => await img.hash(true), { ttl }) as string;
// if(img.hashResult === undefined) {
// img.hashResult = hash;
// }
// return hash;
}
getThirdPartyCredentials(name: string) {
if(this.thirdPartyCredentials[name] !== undefined) {
return this.thirdPartyCredentials[name];
}
return undefined;
}
}
export class BotResourcesManager {
@@ -738,6 +1052,7 @@ export class BotResourcesManager {
actionedEventsMaxDefault?: number;
actionedEventsDefault: number;
pruneInterval: any;
defaultThirdPartyCredentials: ThirdPartyCredentialsJsonConfig;
constructor(config: BotInstanceConfig) {
const {
@@ -754,13 +1069,17 @@ export class BotResourcesManager {
actionedEventsDefault,
},
name,
credentials,
credentials: {
reddit,
...thirdParty
},
caching,
} = config;
caching.provider.prefix = buildCachePrefix([caching.provider.prefix, 'SHARED']);
const {actionedEventsMax: eMax, actionedEventsDefault: eDef, ...relevantCacheSettings} = caching;
this.cacheHash = objectHash.sha1(relevantCacheSettings);
this.defaultCacheConfig = caching;
this.defaultThirdPartyCredentials = thirdParty;
this.ttlDefaults = {authorTTL, userNotesTTL, wikiTTL, commentTTL, submissionTTL, filterCriteriaTTL, subredditTTL};
const options = provider;
@@ -791,15 +1110,16 @@ export class BotResourcesManager {
return undefined;
}
set(subName: string, initOptions: SubredditResourceConfig): SubredditResources {
async set(subName: string, initOptions: SubredditResourceConfig): Promise<SubredditResources> {
let hash = 'default';
const { caching, ...init } = initOptions;
const { caching, credentials, ...init } = initOptions;
let opts: SubredditResourceOptions = {
cache: this.defaultCache,
cacheType: this.cacheType,
cacheSettingsHash: hash,
ttl: this.ttlDefaults,
thirdPartyCredentials: credentials ?? this.defaultThirdPartyCredentials,
prefix: this.defaultCacheConfig.provider.prefix,
actionedEventsMax: this.actionedEventsMaxDefault !== undefined ? Math.min(this.actionedEventsDefault, this.actionedEventsMaxDefault) : this.actionedEventsDefault,
...init,
@@ -827,6 +1147,7 @@ export class BotResourcesManager {
actionedEventsMax: eventsMax,
cacheType: trueProvider.store,
cacheSettingsHash: hash,
thirdPartyCredentials: credentials ?? this.defaultThirdPartyCredentials,
prefix: subPrefix,
...init,
...trueRest,
@@ -841,6 +1162,8 @@ export class BotResourcesManager {
res.cache.reset();
}
resource = new SubredditResources(subName, opts);
await resource.initHistoricalStats();
resource.setHistoricalSaveInterval();
this.resources.set(subName, resource);
} else {
// just set non-cache related settings
@@ -851,6 +1174,7 @@ export class BotResourcesManager {
// reset cache stats when configuration is reloaded
resource.stats.cache = cacheStats();
}
resource.stats.historical.lastReload = createHistoricalDefaults();
return resource;
}

View File

@@ -4,7 +4,6 @@ import {
COMMENT_URL_ID,
deflateUserNotes, getActivityAuthorName,
inflateUserNotes,
isScopeError,
parseLinkIdentifier,
SUBMISSION_URL_ID
} from "../util";
@@ -14,6 +13,7 @@ import LoggedError from "../Utils/LoggedError";
import Submission from "snoowrap/dist/objects/Submission";
import {RichContent} from "../Common/interfaces";
import {Cache} from 'cache-manager';
import {isScopeError} from "../Utils/Errors";
interface RawUserNotesPayload {
ver: number,
@@ -185,7 +185,7 @@ export class UserNotes {
}
return userNotes as RawUserNotesPayload;
} catch (err) {
} catch (err: any) {
const msg = `Could not read usernotes. Make sure at least one moderator has used toolbox and usernotes before.`;
this.logger.error(msg, err);
throw new LoggedError(msg);
@@ -235,7 +235,7 @@ export class UserNotes {
}
return payload as RawUserNotesPayload;
} catch (err) {
} catch (err: any) {
let msg = 'Could not edit usernotes.';
// Make sure at least one moderator has used toolbox and usernotes before and that this account has editing permissions`;
if(isScopeError(err)) {

18
src/Utils/Errors.ts Normal file
View File

@@ -0,0 +1,18 @@
import {StatusCodeError} from "../Common/interfaces";
export const isRateLimitError = (err: any) => {
return typeof err === 'object' && err.name === 'RateLimitError';
}
export const isScopeError = (err: any): boolean => {
if(typeof err === 'object' && err.name === 'StatusCodeError' && err.response !== undefined) {
const authHeader = err.response.headers['www-authenticate'];
return authHeader !== undefined && authHeader.includes('insufficient_scope');
}
return false;
}
export const isStatusError = (err: any): err is StatusCodeError => {
return typeof err === 'object' && err.name === 'StatusCodeError' && err.response !== undefined;
}

View File

@@ -1,4 +1,6 @@
import Snoowrap from "snoowrap";
import Snoowrap, {Listing} from "snoowrap";
import {Subreddit} from "snoowrap/dist/objects";
import {parseSubredditName} from "../util";
// const proxyFactory = (endpoint: string) => {
// return class ProxiedSnoowrap extends Snoowrap {
@@ -12,7 +14,40 @@ import Snoowrap from "snoowrap";
// }
// }
export class RequestTrackingSnoowrap extends Snoowrap {
export class ExtendedSnoowrap extends Snoowrap {
/**
* https://www.reddit.com/r/redditdev/comments/jfltfx/comment/g9le48w/?utm_source=reddit&utm_medium=web2x&context=3
* */
async getManySubreddits(subs: (Subreddit | string)[]): Promise<Listing<Subreddit>> {
// parse all names
const names = subs.map(x => {
if(typeof x !== 'string') {
return x.display_name;
}
try {
return parseSubredditName(x);
} catch (err: any) {
return x;
}
});
return await this.oauthRequest({uri: '/api/info', method: 'get', qs: { sr_name: names.join(',')}}) as Listing<Subreddit>;
}
async assignUserFlairByTemplateId(options: { flairTemplateId: string, username: string, subredditName: string }): Promise<any> {
return await this.oauthRequest({
uri: `/r/${options.subredditName}/api/selectflair`,
method: 'post',
form: {
api_type: 'json',
name: options.username,
flair_template_id: options.flairTemplateId,
}
});
}
}
export class RequestTrackingSnoowrap extends ExtendedSnoowrap {
requestCount: number = 0;
oauthRequest(...args: any) {

View File

@@ -1,4 +1,4 @@
import Snoowrap, {RedditUser} from "snoowrap";
import Snoowrap, {Listing, RedditUser} from "snoowrap";
import Submission from "snoowrap/dist/objects/Submission";
import Comment from "snoowrap/dist/objects/Comment";
import {Duration, DurationUnitsObjectType} from "dayjs/plugin/duration";
@@ -14,16 +14,16 @@ import {
} from "../Common/interfaces";
import {
compareDurationValue,
comparisonTextOp,
comparisonTextOp, escapeRegex, getActivityAuthorName,
isActivityWindowCriteria,
normalizeName,
parseDuration,
parseDurationComparison,
parseGenericValueComparison,
parseGenericValueOrPercentComparison,
parseRuleResultsToMarkdownSummary,
parseRuleResultsToMarkdownSummary, parseStringToRegex,
parseSubredditName,
truncateStringToLength
truncateStringToLength, windowToActivityWindowCriteria
} from "../util";
import UserNotes from "../Subreddit/UserNotes";
import {Logger} from "winston";
@@ -31,6 +31,7 @@ import InvalidRegexError from "./InvalidRegexError";
import SimpleError from "./SimpleError";
import {AuthorCriteria} from "../Author/Author";
import {URL} from "url";
import {isStatusError} from "./Errors";
export const BOT_LINK = 'https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot';
@@ -43,14 +44,16 @@ export interface AuthorActivitiesOptions {
chunkSize?: number,
// TODO maybe move this into window
keepRemoved?: boolean,
[key: string]: any,
}
export async function getAuthorActivities(user: RedditUser, options: AuthorTypedActivitiesOptions): Promise<Array<Submission | Comment>> {
export async function getActivities(listingFunc: (limit: number) => Promise<Listing<Submission | Comment>>, options: AuthorActivitiesOptions): Promise<Array<Submission | Comment>> {
const {
chunkSize: cs = 100,
window: optWindow,
keepRemoved = true,
...restFetchOptions
} = options;
let satisfiedCount: number | undefined,
@@ -64,33 +67,56 @@ export async function getAuthorActivities(user: RedditUser, options: AuthorTyped
let includes: string[] = [];
let excludes: string[] = [];
if (isActivityWindowCriteria(optWindow)) {
const {
satisfyOn = 'any',
count,
duration,
subreddits: {
include = [],
exclude = [],
} = {},
} = optWindow;
const strongWindow = windowToActivityWindowCriteria(optWindow);
includes = include.map(x => parseSubredditName(x).toLowerCase());
excludes = exclude.map(x => parseSubredditName(x).toLowerCase());
const {
satisfyOn = 'any',
count,
duration: oDuration,
subreddits: {
include = [],
exclude = [],
} = {},
} = strongWindow;
if (includes.length > 0 && excludes.length > 0) {
// TODO add logger so this can be logged...
// this.logger.warn('include and exclude both specified, exclude will be ignored');
}
satisfiedCount = count;
durVal = duration;
satisfy = satisfyOn
} else if (typeof optWindow === 'number') {
satisfiedCount = optWindow;
} else {
durVal = optWindow as DurationVal;
satisfy = satisfyOn;
satisfiedCount = count;
includes = include;
excludes = exclude;
durVal = oDuration;
if (includes.length > 0 && excludes.length > 0) {
// TODO add logger so this can be logged...
// this.logger.warn('include and exclude both specified, exclude will be ignored');
}
// if (isActivityWindowCriteria(optWindow)) {
// const {
// satisfyOn = 'any',
// count,
// duration,
// subreddits: {
// include = [],
// exclude = [],
// } = {},
// } = optWindow;
//
// includes = include.map(x => parseSubredditName(x).toLowerCase());
// excludes = exclude.map(x => parseSubredditName(x).toLowerCase());
//
// if (includes.length > 0 && excludes.length > 0) {
// // TODO add logger so this can be logged...
// // this.logger.warn('include and exclude both specified, exclude will be ignored');
// }
// satisfiedCount = count;
// durVal = duration;
// satisfy = satisfyOn
// } else if (typeof optWindow === 'number') {
// satisfiedCount = optWindow;
// } else {
// durVal = optWindow as DurationVal;
// }
// if count is less than max limit (100) go ahead and just get that many. may result in faster response time for low numbers
if (satisfiedCount !== undefined) {
chunkSize = Math.min(chunkSize, satisfiedCount);
@@ -124,19 +150,8 @@ export async function getAuthorActivities(user: RedditUser, options: AuthorTyped
}
let items: Array<Submission | Comment> = [];
//let count = 1;
let listing;
switch (options.type) {
case 'comment':
listing = await user.getComments({limit: chunkSize});
break;
case 'submission':
listing = await user.getSubmissions({limit: chunkSize});
break;
default:
listing = await user.getOverview({limit: chunkSize});
break;
}
let listing = await listingFunc(chunkSize);
let hitEnd = false;
let offset = chunkSize;
while (!hitEnd) {
@@ -211,12 +226,35 @@ export async function getAuthorActivities(user: RedditUser, options: AuthorTyped
if (!hitEnd) {
offset += chunkSize;
listing = await listing.fetchMore({amount: chunkSize});
listing = await listing.fetchMore({amount: chunkSize, ...restFetchOptions});
}
}
return Promise.resolve(items);
}
export async function getAuthorActivities(user: RedditUser, options: AuthorTypedActivitiesOptions): Promise<Array<Submission | Comment>> {
const listFunc = (chunkSize: number): Promise<Listing<Submission | Comment>> => {
switch (options.type) {
case 'comment':
return user.getComments({limit: chunkSize});
case 'submission':
return user.getSubmissions({limit: chunkSize});
default:
return user.getOverview({limit: chunkSize});
}
};
try {
return await getActivities(listFunc, options);
} catch (err: any) {
if(isStatusError(err) && err.statusCode === 404) {
throw new SimpleError('Reddit returned a 404 for user history. Likely this user is shadowbanned.');
} else {
throw err;
}
}
}
export const getAuthorComments = async (user: RedditUser, options: AuthorActivitiesOptions): Promise<Comment[]> => {
return await getAuthorActivities(user, {...options, type: 'comment'}) as unknown as Promise<Comment[]>;
}
@@ -317,179 +355,233 @@ export const renderContent = async (template: string, data: (Submission | Commen
}
export const testAuthorCriteria = async (item: (Comment | Submission), authorOpts: AuthorCriteria, include = true, userNotes: UserNotes) => {
// @ts-ignore
const author: RedditUser = await item.author;
for (const k of Object.keys(authorOpts)) {
// @ts-ignore
if (authorOpts[k] !== undefined) {
switch (k) {
case 'name':
const authPass = () => {
// @ts-ignore
for (const n of authorOpts[k]) {
if (n.toLowerCase() === author.name.toLowerCase()) {
return true;
}
}
return false;
}
const authResult = authPass();
if ((include && !authResult) || (!include && authResult)) {
return false;
}
break;
case 'flairCssClass':
const css = await item.author_flair_css_class;
const cssPass = () => {
// @ts-ignore
for (const c of authorOpts[k]) {
if (c === css) {
return;
}
}
return false;
}
const cssResult = cssPass();
if ((include && !cssResult) || (!include && cssResult)) {
return false;
}
break;
case 'flairText':
const text = await item.author_flair_text;
const textPass = () => {
// @ts-ignore
for (const c of authorOpts[k]) {
if (c === text) {
return
}
}
return false;
};
const textResult = textPass();
if ((include && !textResult) || (!include && textResult)) {
return false;
}
break;
case 'isMod':
const mods: RedditUser[] = await item.subreddit.getModerators();
const isModerator = mods.some(x => x.name === item.author.name);
const modMatch = authorOpts.isMod === isModerator;
if ((include && !modMatch) || (!include && modMatch)) {
return false;
}
break;
case 'age':
const ageTest = compareDurationValue(parseDurationComparison(await authorOpts.age as string), dayjs.unix(await item.author.created));
if ((include && !ageTest) || (!include && ageTest)) {
return false;
}
break;
case 'linkKarma':
const lkCompare = parseGenericValueOrPercentComparison(await authorOpts.linkKarma as string);
let lkMatch;
if (lkCompare.isPercent) {
// @ts-ignore
const tk = author.total_karma as number;
lkMatch = comparisonTextOp(author.link_karma / tk, lkCompare.operator, lkCompare.value / 100);
} else {
lkMatch = comparisonTextOp(author.link_karma, lkCompare.operator, lkCompare.value);
}
if ((include && !lkMatch) || (!include && lkMatch)) {
return false;
}
break;
case 'commentKarma':
const ckCompare = parseGenericValueOrPercentComparison(await authorOpts.commentKarma as string);
let ckMatch;
if (ckCompare.isPercent) {
// @ts-ignore
const ck = author.total_karma as number;
ckMatch = comparisonTextOp(author.comment_karma / ck, ckCompare.operator, ckCompare.value / 100);
} else {
ckMatch = comparisonTextOp(author.comment_karma, ckCompare.operator, ckCompare.value);
}
if ((include && !ckMatch) || (!include && ckMatch)) {
return false;
}
break;
case 'totalKarma':
const tkCompare = parseGenericValueComparison(await authorOpts.totalKarma as string);
if (tkCompare.isPercent) {
throw new SimpleError(`'totalKarma' value on AuthorCriteria cannot be a percentage`);
}
// @ts-ignore
const totalKarma = author.total_karma as number;
const tkMatch = comparisonTextOp(totalKarma, tkCompare.operator, tkCompare.value);
if ((include && !tkMatch) || (!include && tkMatch)) {
return false;
}
break;
case 'verified':
const vMatch = await author.has_verified_mail === authorOpts.verified as boolean;
if ((include && !vMatch) || (!include && vMatch)) {
return false;
}
break;
case 'userNotes':
const notes = await userNotes.getUserNotes(item.author);
const notePass = () => {
for (const noteCriteria of authorOpts[k] as UserNoteCriteria[]) {
const {count = '>= 1', search = 'current', type} = noteCriteria;
const {
value,
operator,
isPercent,
extra = ''
} = parseGenericValueOrPercentComparison(count);
const order = extra.includes('asc') ? 'ascending' : 'descending';
switch (search) {
case 'current':
if (notes.length > 0 && notes[notes.length - 1].noteType === type) {
return true;
}
break;
case 'consecutive':
let orderedNotes = notes;
if (order === 'descending') {
orderedNotes = [...notes];
orderedNotes.reverse();
}
let currCount = 0;
for (const note of orderedNotes) {
if (note.noteType === type) {
currCount++;
} else {
currCount = 0;
}
if (isPercent) {
throw new SimpleError(`When comparing UserNotes with 'consecutive' search 'count' cannot be a percentage. Given: ${count}`);
}
if (comparisonTextOp(currCount, operator, value)) {
return true;
}
}
break;
case 'total':
if (isPercent) {
if (comparisonTextOp(notes.filter(x => x.noteType === type).length / notes.length, operator, value / 100)) {
return true;
}
} else if (comparisonTextOp(notes.filter(x => x.noteType === type).length, operator, value)) {
return true;
}
}
}
return false;
}
const noteResult = notePass();
if ((include && !noteResult) || (!include && noteResult)) {
return false;
}
break;
const {shadowBanned, ...rest} = authorOpts;
if(shadowBanned !== undefined) {
try {
// @ts-ignore
await item.author.fetch();
// user is not shadowbanned
// if criteria specifies they SHOULD be shadowbanned then return false now
if(shadowBanned) {
return false;
}
} catch (err: any) {
if(isStatusError(err) && err.statusCode === 404) {
// user is shadowbanned
// if criteria specifies they should not be shadowbanned then return false now
if(!shadowBanned) {
return false;
}
} else {
throw err;
}
}
}
return true;
try {
const authorName = getActivityAuthorName(item.author);
for (const k of Object.keys(rest)) {
// @ts-ignore
if (authorOpts[k] !== undefined) {
switch (k) {
case 'name':
const authPass = () => {
// @ts-ignore
for (const n of authorOpts[k]) {
if (n.toLowerCase() === authorName.toLowerCase()) {
return true;
}
}
return false;
}
const authResult = authPass();
if ((include && !authResult) || (!include && authResult)) {
return false;
}
break;
case 'flairCssClass':
const css = await item.author_flair_css_class;
const cssPass = () => {
// @ts-ignore
for (const c of authorOpts[k]) {
if (c === css) {
return true;
}
}
return false;
}
const cssResult = cssPass();
if ((include && !cssResult) || (!include && cssResult)) {
return false;
}
break;
case 'flairText':
const text = await item.author_flair_text;
const textPass = () => {
// @ts-ignore
for (const c of authorOpts[k]) {
if (c === text) {
return true;
}
}
return false;
};
const textResult = textPass();
if ((include && !textResult) || (!include && textResult)) {
return false;
}
break;
case 'isMod':
const mods: RedditUser[] = await item.subreddit.getModerators();
const isModerator = mods.some(x => x.name === authorName);
const modMatch = authorOpts.isMod === isModerator;
if ((include && !modMatch) || (!include && modMatch)) {
return false;
}
break;
case 'age':
const ageTest = compareDurationValue(parseDurationComparison(await authorOpts.age as string), dayjs.unix(await item.author.created));
if ((include && !ageTest) || (!include && ageTest)) {
return false;
}
break;
case 'linkKarma':
const lkCompare = parseGenericValueOrPercentComparison(await authorOpts.linkKarma as string);
let lkMatch;
if (lkCompare.isPercent) {
// @ts-ignore
const tk = await item.author.total_karma as number;
lkMatch = comparisonTextOp(item.author.link_karma / tk, lkCompare.operator, lkCompare.value / 100);
} else {
lkMatch = comparisonTextOp(item.author.link_karma, lkCompare.operator, lkCompare.value);
}
if ((include && !lkMatch) || (!include && lkMatch)) {
return false;
}
break;
case 'commentKarma':
const ckCompare = parseGenericValueOrPercentComparison(await authorOpts.commentKarma as string);
let ckMatch;
if (ckCompare.isPercent) {
// @ts-ignore
const ck = await item.author.total_karma as number;
ckMatch = comparisonTextOp(item.author.comment_karma / ck, ckCompare.operator, ckCompare.value / 100);
} else {
ckMatch = comparisonTextOp(item.author.comment_karma, ckCompare.operator, ckCompare.value);
}
if ((include && !ckMatch) || (!include && ckMatch)) {
return false;
}
break;
case 'totalKarma':
const tkCompare = parseGenericValueComparison(await authorOpts.totalKarma as string);
if (tkCompare.isPercent) {
throw new SimpleError(`'totalKarma' value on AuthorCriteria cannot be a percentage`);
}
// @ts-ignore
const totalKarma = await item.author.total_karma as number;
const tkMatch = comparisonTextOp(totalKarma, tkCompare.operator, tkCompare.value);
if ((include && !tkMatch) || (!include && tkMatch)) {
return false;
}
break;
case 'verified':
const vMatch = await item.author.has_verified_mail === authorOpts.verified as boolean;
if ((include && !vMatch) || (!include && vMatch)) {
return false;
}
break;
case 'description':
// @ts-ignore
const desc = await item.author.subreddit?.display_name.public_description;
const dVals = authorOpts[k] as string[];
let passed = false;
for(const val of dVals) {
let reg = parseStringToRegex(val, 'i');
if(reg === undefined) {
reg = parseStringToRegex(`/.*${escapeRegex(val.trim())}.*/`, 'i');
if(reg === undefined) {
throw new SimpleError(`Could not convert 'description' value to a valid regex: ${authorOpts[k] as string}`);
}
}
if(reg.test(desc)) {
passed = true;
break;
}
}
if(!passed) {
return false;
}
break;
case 'userNotes':
const notes = await userNotes.getUserNotes(item.author);
const notePass = () => {
for (const noteCriteria of authorOpts[k] as UserNoteCriteria[]) {
const {count = '>= 1', search = 'current', type} = noteCriteria;
const {
value,
operator,
isPercent,
extra = ''
} = parseGenericValueOrPercentComparison(count);
const order = extra.includes('asc') ? 'ascending' : 'descending';
switch (search) {
case 'current':
if (notes.length > 0 && notes[notes.length - 1].noteType === type) {
return true;
}
break;
case 'consecutive':
let orderedNotes = notes;
if (order === 'descending') {
orderedNotes = [...notes];
orderedNotes.reverse();
}
let currCount = 0;
for (const note of orderedNotes) {
if (note.noteType === type) {
currCount++;
} else {
currCount = 0;
}
if (isPercent) {
throw new SimpleError(`When comparing UserNotes with 'consecutive' search 'count' cannot be a percentage. Given: ${count}`);
}
if (comparisonTextOp(currCount, operator, value)) {
return true;
}
}
break;
case 'total':
if (isPercent) {
if (comparisonTextOp(notes.filter(x => x.noteType === type).length / notes.length, operator, value / 100)) {
return true;
}
} else if (comparisonTextOp(notes.filter(x => x.noteType === type).length, operator, value)) {
return true;
}
}
}
return false;
}
const noteResult = notePass();
if ((include && !noteResult) || (!include && noteResult)) {
return false;
}
break;
}
}
}
return true;
} catch (err: any) {
if(isStatusError(err) && err.statusCode === 404) {
throw new SimpleError('Reddit returned a 404 while trying to retrieve User profile. It is likely this user is shadowbanned.');
} else {
throw err;
}
}
}
export interface ItemContent {
@@ -509,7 +601,7 @@ export const itemContentPeek = async (item: (Comment | Submission), peekLength =
submissionTitle = item.title;
peek = `${truncatePeek(item.title)} by ${author} https://reddit.com${item.permalink}`;
} else if (item instanceof Comment) {
} else {
// replace newlines with spaces to make peek more compact
content = truncatePeek(item.body.replaceAll('\n', ' '));
peek = `${truncatePeek(content)} by ${author} in https://reddit.com${item.permalink}`;
@@ -621,13 +713,21 @@ export const getAttributionIdentifier = (sub: Submission, useParentMediaDomain =
}
export const activityIsRemoved = (item: Submission | Comment): boolean => {
if (item instanceof Submission) {
// when automod filters a post it gets this category
return item.banned_at_utc !== null && item.removed_by_category !== 'automod_filtered';
if(item.can_mod_post) {
if (item instanceof Submission) {
// when automod filters a post it gets this category
return item.banned_at_utc !== null && item.removed_by_category !== 'automod_filtered';
}
// when automod filters a comment item.removed === false
// so if we want to processing filtered comments we need to check for this
return item.banned_at_utc !== null && item.removed;
} else {
if (item instanceof Submission) {
return item.removed_by_category === 'moderator' || item.removed_by_category === 'deleted';
}
// in subreddits the bot does not mod it is not possible to tell the difference between a comment that was removed by the user and one that was removed by a mod
return item.body === '[removed]';
}
// when automod filters a comment item.removed === false
// so if we want to processing filtered comments we need to check for this
return item.banned_at_utc !== null && item.removed;
}
export const activityIsFiltered = (item: Submission | Comment): boolean => {

View File

@@ -0,0 +1,70 @@
// reproduced from https://github.com/sumn2u/string-comparison/blob/master/jscosine.js
// https://sumn2u.medium.com/string-similarity-comparision-in-js-with-examples-4bae35f13968
interface StrMap {
[key: string]: number
}
interface BoolMap {
[key: string]: boolean
}
function termFreqMap(str: string) {
var words = str.split(' ');
var termFreq: StrMap = {};
words.forEach(function(w) {
termFreq[w] = (termFreq[w] || 0) + 1;
});
return termFreq;
}
function addKeysToDict(map: StrMap, dict: BoolMap) {
for (var key in map) {
dict[key] = true;
}
}
function termFreqMapToVector(map: StrMap, dict: StrMap): number[] {
var termFreqVector = [];
for (var term in dict) {
termFreqVector.push(map[term] || 0);
}
return termFreqVector;
}
function vecDotProduct(vecA: number[], vecB: number[]) {
var product = 0;
for (var i = 0; i < vecA.length; i++) {
product += vecA[i] * vecB[i];
}
return product;
}
function vecMagnitude(vec: number[]) {
var sum = 0;
for (var i = 0; i < vec.length; i++) {
sum += vec[i] * vec[i];
}
return Math.sqrt(sum);
}
function cosineSimilarity(vecA: number[], vecB: number[]) {
return vecDotProduct(vecA, vecB) / (vecMagnitude(vecA) * vecMagnitude(vecB));
}
const calculateCosineSimilarity = function textCosineSimilarity(strA: string, strB: string) {
var termFreqA = termFreqMap(strA);
var termFreqB = termFreqMap(strB);
var dict = {};
addKeysToDict(termFreqA, dict);
addKeysToDict(termFreqB, dict);
var termFreqVecA = termFreqMapToVector(termFreqA, dict);
var termFreqVecB = termFreqMapToVector(termFreqB, dict);
return cosineSimilarity(termFreqVecA, termFreqVecB);
}
export default calculateCosineSimilarity;

View File

@@ -0,0 +1,19 @@
import leven from "leven";
const levenSimilarity = (valA: string, valB: string) => {
let longer: string;
let shorter: string;
if (valA.length > valB.length) {
longer = valA;
shorter = valB;
} else {
longer = valB;
shorter = valA;
}
const distance = leven(longer, shorter);
const diff = (distance / longer.length) * 100;
return [distance, 100 - diff];
}
export default levenSimilarity;

59
src/Utils/ThirdParty/YoutubeClient.ts vendored Normal file
View File

@@ -0,0 +1,59 @@
import {URLSearchParams} from "url";
import fetch from "node-fetch";
import {parseUsableLinkIdentifier} from "../../util";
import dayjs from "dayjs";
import {youtube, youtube_v3 } from '@googleapis/youtube';
import Schema$CommentThread = youtube_v3.Schema$CommentThread;
import {RepostItem} from "../../Common/interfaces";
const parseYtIdentifier = parseUsableLinkIdentifier();
export class YoutubeClient {
apiKey: string;
client: youtube_v3.Youtube
constructor(key: string) {
this.apiKey = key;
this.client = youtube({version: 'v3', auth: key});
}
getVideoTopComments = async (url: string, maxResults: number = 50): Promise<Schema$CommentThread[]> => {
const videoId = parseYtIdentifier(url);
const res = await this.client.commentThreads.list({
part: ['snippet'],
videoId,
maxResults: maxResults,
textFormat: 'plainText',
order: 'relevance',
});
const items = res.data.items as Schema$CommentThread[];
items.sort((a, b) => (a.snippet?.topLevelComment?.snippet?.likeCount as number) - (b.snippet?.topLevelComment?.snippet?.likeCount as number)).reverse();
return items;
}
}
export const commentsAsRepostItems = (comments: Schema$CommentThread[]): RepostItem[] => {
return comments.map((x) => {
const textDisplay = x.snippet?.topLevelComment?.snippet?.textDisplay;
const publishedAt = x.snippet?.topLevelComment?.snippet?.publishedAt;
const id = x.snippet?.topLevelComment?.id;
const videoId = x.snippet?.topLevelComment?.snippet?.videoId;
return {
value: textDisplay as string,
createdOn: dayjs(publishedAt as string).unix(),
source: 'Youtube',
id: x.snippet?.topLevelComment?.id as string,
sourceUrl: `https://youtube.com/watch?v=${videoId}&lc=${id}`,
score: x.snippet?.topLevelComment?.snippet?.likeCount as number,
acquisitionType: 'external',
itemType: 'comment'
};
})
}

View File

@@ -15,7 +15,6 @@ export const getLogger = (options: any, name = 'app'): Logger => {
const consoleTransport = new transports.Console({
handleExceptions: true,
// @ts-expect-error
handleRejections: true,
});
@@ -31,7 +30,6 @@ export const getLogger = (options: any, name = 'app'): Logger => {
name: 'duplex',
dump: false,
handleExceptions: true,
// @ts-expect-error
handleRejections: true,
}),
...additionalTransports,

View File

@@ -44,6 +44,7 @@ import {BotInstance, CMInstance} from "../interfaces";
import { URL } from "url";
import {MESSAGE} from "triple-beam";
import Autolinker from "autolinker";
import path from "path";
const emitter = new EventEmitter();
@@ -572,7 +573,7 @@ const webClient = async (options: OperatorConfig) => {
try {
server = await app.listen(port);
io = new SocketServer(server);
} catch (err) {
} catch (err: any) {
logger.error('Error occurred while initializing web or socket.io server', err);
err.logged = true;
throw err;
@@ -761,7 +762,7 @@ const webClient = async (options: OperatorConfig) => {
},
}).json() as any;
} catch(err) {
} catch(err: any) {
logger.error(`Error occurred while retrieving bot information. Will update heartbeat -- ${err.message}`, {instance: instance.friendly});
refreshClient(clients.find(x => normalizeUrl(x.host) === instance.normalUrl) as BotConnection);
return res.render('offline', {
@@ -812,8 +813,10 @@ const webClient = async (options: OperatorConfig) => {
});
app.getAsync('/config', async (req: express.Request, res: express.Response) => {
const {format = 'json'} = req.query as any;
res.render('config', {
title: `Configuration Editor`
title: `Configuration Editor`,
format,
});
});
@@ -989,7 +992,7 @@ const webClient = async (options: OperatorConfig) => {
}
}).json() as object;
io.to(session.id).emit('opStats', resp);
} catch (err) {
} catch (err: any) {
logger.error(`Could not retrieve stats ${err.message}`, {instance: bot.friendly});
clearInterval(interval);
}
@@ -1027,7 +1030,7 @@ const webClient = async (options: OperatorConfig) => {
}
}).json() as object;
return {success: true, ...resp};
} catch (err) {
} catch (err: any) {
return {success: false, error: err.message};
}
}
@@ -1096,7 +1099,7 @@ const webClient = async (options: OperatorConfig) => {
// botStat.indicator = 'red';
// }
logger.verbose(`Heartbeat detected`, {instance: botStat.friendly});
} catch (err) {
} catch (err: any) {
botStat.error = err.message;
logger.error(`Heartbeat response from ${botStat.friendly} was not ok: ${err.message}`, {instance: botStat.friendly});
} finally {

View File

@@ -1,13 +1,10 @@
import {BotStats, BotStatusResponse, SubredditDataResponse} from "./interfaces";
import {ManagerStats, RunningState} from "../../Subreddit/Manager";
import {Invokee, RunState} from "../../Common/interfaces";
import {cacheStats} from "../../util";
import {RunningState} from "../../Subreddit/Manager";
import {Invokee, ManagerStats, RunState} from "../../Common/interfaces";
import {cacheStats, createHistoricalStatsDisplay} from "../../util";
import {createHistoricalDefaults, historicalDefaults} from "../../Common/defaults";
const managerStats: ManagerStats = {
actionsRun: 0,
actionsRunSinceStart: 0,
actionsRunSinceStartTotal: 0,
actionsRunTotal: 0,
cache: {
currentKeyCount: 0,
isShared: false,
@@ -18,22 +15,12 @@ const managerStats: ManagerStats = {
totalRequests: 0,
types: cacheStats()
},
checksRunSinceStartTotal: 0,
checksRunTotal: 0,
checksTriggered: 0,
checksTriggeredSinceStart: 0,
checksTriggeredSinceStartTotal: 0,
checksTriggeredTotal: 0,
historical: {
lastReload: createHistoricalStatsDisplay(createHistoricalDefaults()),
allTime: createHistoricalStatsDisplay(createHistoricalDefaults()),
},
eventsAvg: 0,
eventsCheckedSinceStartTotal: 0,
eventsCheckedTotal: 0,
rulesAvg: 0,
rulesCachedSinceStartTotal: 0,
rulesCachedTotal: 0,
rulesRunSinceStartTotal: 0,
rulesRunTotal: 0,
rulesTriggeredSinceStartTotal: 0,
rulesTriggeredTotal: 0,
};
const botStats: BotStats = {
apiAvg: '-',

View File

@@ -1,4 +1,5 @@
import {ManagerStats, RunningState} from "../../Subreddit/Manager";
import {RunningState} from "../../Subreddit/Manager";
import {ManagerStats} from "../../Common/interfaces";
export interface BotStats {
startedAtHuman: string,

View File

@@ -83,7 +83,7 @@ const action = async (req: express.Request, res: express.Response) => {
}
break;
}
} catch (err) {
} catch (err: any) {
if (!(err instanceof LoggedError)) {
mLogger.error(err, {subreddit: manager.displayLabel});
}

View File

@@ -32,7 +32,7 @@ const addBot = () => {
req.botApp.logger.error(err);
}
});
} catch (err) {
} catch (err: any) {
if (newBot.error === undefined) {
newBot.error = err.message;
result.error = err.message;

View File

@@ -46,7 +46,7 @@ const logs = (subLogMap: Map<string, LogEntry[]>) => {
console.log('Request closed detected with "close" listener');
res.destroy();
return;
} catch (e) {
} catch (e: any) {
if (e.code !== 'ECONNRESET') {
logger.error(e);
}

View File

@@ -160,13 +160,19 @@ const status = () => {
submissions: acc.checks.submissions + curr.checks.submissions,
comments: acc.checks.comments + curr.checks.comments,
},
eventsCheckedTotal: acc.eventsCheckedTotal + curr.stats.eventsCheckedTotal,
checksRunTotal: acc.checksRunTotal + curr.stats.checksRunTotal,
checksTriggeredTotal: acc.checksTriggeredTotal + curr.stats.checksTriggeredTotal,
rulesRunTotal: acc.rulesRunTotal + curr.stats.rulesRunTotal,
rulesCachedTotal: acc.rulesCachedTotal + curr.stats.rulesCachedTotal,
rulesTriggeredTotal: acc.rulesTriggeredTotal + curr.stats.rulesTriggeredTotal,
actionsRunTotal: acc.actionsRunTotal + curr.stats.actionsRunTotal,
historical: {
allTime: {
eventsCheckedTotal: acc.historical.allTime.eventsCheckedTotal + curr.stats.historical.allTime.eventsCheckedTotal,
eventsActionedTotal: acc.historical.allTime.eventsActionedTotal + curr.stats.historical.allTime.eventsActionedTotal,
checksRunTotal: acc.historical.allTime.checksRunTotal + curr.stats.historical.allTime.checksRunTotal,
checksFromCacheTotal: acc.historical.allTime.checksFromCacheTotal + curr.stats.historical.allTime.checksFromCacheTotal,
checksTriggeredTotal: acc.historical.allTime.checksTriggeredTotal + curr.stats.historical.allTime.checksTriggeredTotal,
rulesRunTotal: acc.historical.allTime.rulesRunTotal + curr.stats.historical.allTime.rulesRunTotal,
rulesCachedTotal: acc.historical.allTime.rulesCachedTotal + curr.stats.historical.allTime.rulesCachedTotal,
rulesTriggeredTotal: acc.historical.allTime.rulesTriggeredTotal + curr.stats.historical.allTime.rulesTriggeredTotal,
actionsRunTotal: acc.historical.allTime.actionsRunTotal + curr.stats.historical.allTime.actionsRunTotal,
}
},
maxWorkers: acc.maxWorkers + curr.maxWorkers,
subMaxWorkers: acc.subMaxWorkers + curr.subMaxWorkers,
globalMaxWorkers: acc.globalMaxWorkers + curr.globalMaxWorkers,
@@ -178,13 +184,19 @@ const status = () => {
submissions: 0,
comments: 0,
},
eventsCheckedTotal: 0,
checksRunTotal: 0,
checksTriggeredTotal: 0,
rulesRunTotal: 0,
rulesCachedTotal: 0,
rulesTriggeredTotal: 0,
actionsRunTotal: 0,
historical: {
allTime: {
eventsCheckedTotal: 0,
eventsActionedTotal: 0,
checksRunTotal: 0,
checksFromCacheTotal: 0,
checksTriggeredTotal: 0,
rulesRunTotal: 0,
rulesCachedTotal: 0,
rulesTriggeredTotal: 0,
actionsRunTotal: 0,
}
},
maxWorkers: 0,
subMaxWorkers: 0,
globalMaxWorkers: 0,

View File

@@ -114,7 +114,7 @@ const rcbServer = async function (options: OperatorConfig) {
try {
httpServer = await server.listen(port);
io = new SocketServer(httpServer);
} catch (err) {
} catch (err: any) {
logger.error('Error occurred while initializing web or socket.io server', err);
err.logged = true;
throw err;
@@ -206,7 +206,7 @@ const rcbServer = async function (options: OperatorConfig) {
if(newApp.error === undefined) {
try {
await newApp.initBots(causedBy);
} catch (err) {
} catch (err: any) {
if(newApp.error === undefined) {
newApp.error = err.message;
}

View File

@@ -4,7 +4,7 @@ a {
.loading {
height: 35px;
fill: black;
fill: white;
display: none;
}
@@ -12,10 +12,6 @@ a {
display: inline;
}
.dark .loading {
fill: white;
}
.sub {
display: none;
}
@@ -91,3 +87,58 @@ a {
pointer-events: initial;
text-decoration: initial;
}
.blue {
color: rgb(97, 175, 239)
}
.red {
color: rgb(255 123 133);
}
.green {
color: rgb(170 255 109);
}
.purple {
color: rgb(224 124 253);
}
.yellow {
color: rgb(253 198 94);
}
.breadcrumb {
cursor: pointer;
}
#breadcrumbs::before,
.breadcrumb:not(:last-child)::after {
content: '';
margin: 0 0.2rem;
}
.breadcrumb.array::before {
content: '[]';
}
.breadcrumb.object::before {
content: '{}';
}
#problems {
background-color: #474646;
padding: 10px;
user-select: text;
}
.problem {
align-items: center;
cursor: pointer;
display: flex;
padding: 0.25rem;
}
.problem-text {
margin-left: 0.5rem;
}
.problem .codicon-warning {
color: orange;
}

View File

@@ -0,0 +1,10 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="q" viewBox="0 0 24 24">
<path stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</symbol>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 486 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[1569],{1569:(e,t,n)=>{n.r(t),n.d(t,{conf:()=>s,language:()=>o});var s={comments:{lineComment:"#"}},o={defaultToken:"keyword",ignoreCase:!0,tokenPostfix:".azcli",str:/[^#\s]/,tokenizer:{root:[{include:"@comment"},[/\s-+@str*\s*/,{cases:{"@eos":{token:"key.identifier",next:"@popall"},"@default":{token:"key.identifier",next:"@type"}}}],[/^-+@str*\s*/,{cases:{"@eos":{token:"key.identifier",next:"@popall"},"@default":{token:"key.identifier",next:"@type"}}}]],type:[{include:"@comment"},[/-+@str*\s*/,{cases:{"@eos":{token:"key.identifier",next:"@popall"},"@default":"key.identifier"}}],[/@str+\s*/,{cases:{"@eos":{token:"string",next:"@popall"},"@default":"string"}}]],comment:[[/#.*$/,{cases:{"@eos":{token:"comment",next:"@popall"}}}]]}}}}]);
//# sourceMappingURL=1569.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[1585],{1585:(e,s,o)=>{o.r(s),o.d(s,{conf:()=>n,language:()=>l});var n={brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}]},l={defaultToken:"",tokenPostfix:".dockerfile",variable:/\${?[\w]+}?/,tokenizer:{root:[{include:"@whitespace"},{include:"@comment"},[/(ONBUILD)(\s+)/,["keyword",""]],[/(ENV)(\s+)([\w]+)/,["keyword","",{token:"variable",next:"@arguments"}]],[/(FROM|MAINTAINER|RUN|EXPOSE|ENV|ADD|ARG|VOLUME|LABEL|USER|WORKDIR|COPY|CMD|STOPSIGNAL|SHELL|HEALTHCHECK|ENTRYPOINT)/,{token:"keyword",next:"@arguments"}]],arguments:[{include:"@whitespace"},{include:"@strings"},[/(@variable)/,{cases:{"@eos":{token:"variable",next:"@popall"},"@default":"variable"}}],[/\\/,{cases:{"@eos":"","@default":""}}],[/./,{cases:{"@eos":{token:"",next:"@popall"},"@default":""}}]],whitespace:[[/\s+/,{cases:{"@eos":{token:"",next:"@popall"},"@default":""}}]],comment:[[/(^#.*$)/,"comment","@popall"]],strings:[[/\\'$/,"","@popall"],[/\\'/,""],[/'$/,"string","@popall"],[/'/,"string","@stringBody"],[/"$/,"string","@popall"],[/"/,"string","@dblStringBody"]],stringBody:[[/[^\\\$']/,{cases:{"@eos":{token:"string",next:"@popall"},"@default":"string"}}],[/\\./,"string.escape"],[/'$/,"string","@popall"],[/'/,"string","@pop"],[/(@variable)/,"variable"],[/\\$/,"string"],[/$/,"string","@popall"]],dblStringBody:[[/[^\\\$"]/,{cases:{"@eos":{token:"string",next:"@popall"},"@default":"string"}}],[/\\./,"string.escape"],[/"$/,"string","@popall"],[/"/,"string","@pop"],[/(@variable)/,"variable"],[/\\$/,"string"],[/$/,"string","@popall"]]}}}}]);
//# sourceMappingURL=1585.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[1593],{1593:(e,s,o)=>{o.r(s),o.d(s,{conf:()=>t,language:()=>E});var t={comments:{blockComment:["(*","*)"]},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"[",close:"]"},{open:"{",close:"}"},{open:"(",close:")"},{open:"(*",close:"*)"},{open:"<*",close:"*>"},{open:"'",close:"'",notIn:["string","comment"]},{open:'"',close:'"',notIn:["string","comment"]}]},E={defaultToken:"",tokenPostfix:".m3",brackets:[{token:"delimiter.curly",open:"{",close:"}"},{token:"delimiter.parenthesis",open:"(",close:")"},{token:"delimiter.square",open:"[",close:"]"}],keywords:["AND","ANY","ARRAY","AS","BEGIN","BITS","BRANDED","BY","CASE","CONST","DIV","DO","ELSE","ELSIF","END","EVAL","EXCEPT","EXCEPTION","EXIT","EXPORTS","FINALLY","FOR","FROM","GENERIC","IF","IMPORT","IN","INTERFACE","LOCK","LOOP","METHODS","MOD","MODULE","NOT","OBJECT","OF","OR","OVERRIDES","PROCEDURE","RAISE","RAISES","READONLY","RECORD","REF","REPEAT","RETURN","REVEAL","SET","THEN","TO","TRY","TYPE","TYPECASE","UNSAFE","UNTIL","UNTRACED","VALUE","VAR","WHILE","WITH"],reservedConstNames:["ABS","ADR","ADRSIZE","BITSIZE","BYTESIZE","CEILING","DEC","DISPOSE","FALSE","FIRST","FLOAT","FLOOR","INC","ISTYPE","LAST","LOOPHOLE","MAX","MIN","NARROW","NEW","NIL","NUMBER","ORD","ROUND","SUBARRAY","TRUE","TRUNC","TYPECODE","VAL"],reservedTypeNames:["ADDRESS","ANY","BOOLEAN","CARDINAL","CHAR","EXTENDED","INTEGER","LONGCARD","LONGINT","LONGREAL","MUTEX","NULL","REAL","REFANY","ROOT","TEXT"],operators:["+","-","*","/","&","^","."],relations:["=","#","<","<=",">",">=","<:",":"],delimiters:["|","..","=>",",",";",":="],symbols:/[>=<#.,:;+\-*/&^]+/,escapes:/\\(?:[\\fnrt"']|[0-7]{3})/,tokenizer:{root:[[/_\w*/,"invalid"],[/[a-zA-Z][a-zA-Z0-9_]*/,{cases:{"@keywords":{token:"keyword.$0"},"@reservedConstNames":{token:"constant.reserved.$0"},"@reservedTypeNames":{token:"type.reserved.$0"},"@default":"identifier"}}],{include:"@whitespace"},[/[{}()\[\]]/,"@brackets"],[/[0-9]+\.[0-9]+(?:[DdEeXx][\+\-]?[0-9]+)?/,"number.float"],[/[0-9]+(?:\_[0-9a-fA-F]+)?L?/,"number"],[/@symbols/,{cases:{"@operators":"operators","@relations":"operators","@delimiters":"delimiter","@default":"invalid"}}],[/'[^\\']'/,"string.char"],[/(')(@escapes)(')/,["string.char","string.escape","string.char"]],[/'/,"invalid"],[/"([^"\\]|\\.)*$/,"invalid"],[/"/,"string.text","@text"]],text:[[/[^\\"]+/,"string.text"],[/@escapes/,"string.escape"],[/\\./,"invalid"],[/"/,"string.text","@pop"]],comment:[[/\(\*/,"comment","@push"],[/\*\)/,"comment","@pop"],[/./,"comment"]],pragma:[[/<\*/,"keyword.pragma","@push"],[/\*>/,"keyword.pragma","@pop"],[/./,"keyword.pragma"]],whitespace:[[/[ \t\r\n]+/,"white"],[/\(\*/,"comment","@comment"],[/<\*/,"keyword.pragma","@pragma"]]}}}}]);
//# sourceMappingURL=1593.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[1594],{1594:(e,o,n)=>{n.r(o),n.d(o,{conf:()=>t,language:()=>r});var t={comments:{lineComment:"'"},brackets:[["(",")"],["[","]"],["If","EndIf"],["While","EndWhile"],["For","EndFor"],["Sub","EndSub"]],autoClosingPairs:[{open:'"',close:'"',notIn:["string","comment"]},{open:"(",close:")",notIn:["string","comment"]},{open:"[",close:"]",notIn:["string","comment"]}]},r={defaultToken:"",tokenPostfix:".sb",ignoreCase:!0,brackets:[{token:"delimiter.array",open:"[",close:"]"},{token:"delimiter.parenthesis",open:"(",close:")"},{token:"keyword.tag-if",open:"If",close:"EndIf"},{token:"keyword.tag-while",open:"While",close:"EndWhile"},{token:"keyword.tag-for",open:"For",close:"EndFor"},{token:"keyword.tag-sub",open:"Sub",close:"EndSub"}],keywords:["Else","ElseIf","EndFor","EndIf","EndSub","EndWhile","For","Goto","If","Step","Sub","Then","To","While"],tagwords:["If","Sub","While","For"],operators:[">","<","<>","<=",">=","And","Or","+","-","*","/","="],identifier:/[a-zA-Z_][\w]*/,symbols:/[=><:+\-*\/%\.,]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,tokenizer:{root:[{include:"@whitespace"},[/(@identifier)(?=[.])/,"type"],[/@identifier/,{cases:{"@keywords":{token:"keyword.$0"},"@operators":"operator","@default":"variable.name"}}],[/([.])(@identifier)/,{cases:{$2:["delimiter","type.member"],"@default":""}}],[/\d*\.\d+/,"number.float"],[/\d+/,"number"],[/[()\[\]]/,"@brackets"],[/@symbols/,{cases:{"@operators":"operator","@default":"delimiter"}}],[/"([^"\\]|\\.)*$/,"string.invalid"],[/"/,"string","@string"]],whitespace:[[/[ \t\r\n]+/,""],[/(\').*$/,"comment"]],string:[[/[^\\"]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/"C?/,"string","@pop"]]}}}}]);
//# sourceMappingURL=1594.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[162],{162:(e,s,t)=>{t.r(s),t.d(s,{conf:()=>n,language:()=>r});var n={comments:{lineComment:"#"},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"'",close:"'",notIn:["string"]},{open:'"',close:'"',notIn:["string"]},{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"}]},r={defaultToken:"",tokenPostfix:".rq",brackets:[{token:"delimiter.curly",open:"{",close:"}"},{token:"delimiter.parenthesis",open:"(",close:")"},{token:"delimiter.square",open:"[",close:"]"},{token:"delimiter.angle",open:"<",close:">"}],keywords:["add","as","asc","ask","base","by","clear","construct","copy","create","data","delete","desc","describe","distinct","drop","false","filter","from","graph","group","having","in","insert","limit","load","minus","move","named","not","offset","optional","order","prefix","reduced","select","service","silent","to","true","undef","union","using","values","where","with"],builtinFunctions:["a","abs","avg","bind","bnode","bound","ceil","coalesce","concat","contains","count","datatype","day","encode_for_uri","exists","floor","group_concat","hours","if","iri","isblank","isiri","isliteral","isnumeric","isuri","lang","langmatches","lcase","max","md5","min","minutes","month","now","rand","regex","replace","round","sameterm","sample","seconds","sha1","sha256","sha384","sha512","str","strafter","strbefore","strdt","strends","strlang","strlen","strstarts","struuid","substr","sum","timezone","tz","ucase","uri","uuid","year"],ignoreCase:!0,tokenizer:{root:[[/<[^\s\u00a0>]*>?/,"tag"],{include:"@strings"},[/#.*/,"comment"],[/[{}()\[\]]/,"@brackets"],[/[;,.]/,"delimiter"],[/[_\w\d]+:(\.(?=[\w_\-\\%])|[:\w_-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-f\d][a-f\d])*/,"tag"],[/:(\.(?=[\w_\-\\%])|[:\w_-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-f\d][a-f\d])+/,"tag"],[/[$?]?[_\w\d]+/,{cases:{"@keywords":{token:"keyword"},"@builtinFunctions":{token:"predefined.sql"},"@default":"identifier"}}],[/\^\^/,"operator.sql"],[/\^[*+\-<>=&|^\/!?]*/,"operator.sql"],[/[*+\-<>=&|\/!?]/,"operator.sql"],[/@[a-z\d\-]*/,"metatag.html"],[/\s+/,"white"]],strings:[[/'([^'\\]|\\.)*$/,"string.invalid"],[/'$/,"string.sql","@pop"],[/'/,"string.sql","@stringBody"],[/"([^"\\]|\\.)*$/,"string.invalid"],[/"$/,"string.sql","@pop"],[/"/,"string.sql","@dblStringBody"]],stringBody:[[/[^\\']+/,"string.sql"],[/\\./,"string.escape"],[/'/,"string.sql","@pop"]],dblStringBody:[[/[^\\"]+/,"string.sql"],[/\\./,"string.escape"],[/"/,"string.sql","@pop"]]}}}}]);
//# sourceMappingURL=162.entry.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[1649],{1649:(e,t,n)=>{n.r(t),n.d(t,{conf:()=>o,language:()=>s});var o={brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}]},s={tokenPostfix:".tcl",specialFunctions:["set","unset","rename","variable","proc","coroutine","foreach","incr","append","lappend","linsert","lreplace"],mainFunctions:["if","then","elseif","else","case","switch","while","for","break","continue","return","package","namespace","catch","exit","eval","expr","uplevel","upvar"],builtinFunctions:["file","info","concat","join","lindex","list","llength","lrange","lsearch","lsort","split","array","parray","binary","format","regexp","regsub","scan","string","subst","dict","cd","clock","exec","glob","pid","pwd","close","eof","fblocked","fconfigure","fcopy","fileevent","flush","gets","open","puts","read","seek","socket","tell","interp","after","auto_execok","auto_load","auto_mkindex","auto_reset","bgerror","error","global","history","load","source","time","trace","unknown","unset","update","vwait","winfo","wm","bind","event","pack","place","grid","font","bell","clipboard","destroy","focus","grab","lower","option","raise","selection","send","tk","tkwait","tk_bisque","tk_focusNext","tk_focusPrev","tk_focusFollowsMouse","tk_popup","tk_setPalette"],symbols:/[=><!~?:&|+\-*\/\^%]+/,brackets:[{open:"(",close:")",token:"delimiter.parenthesis"},{open:"{",close:"}",token:"delimiter.curly"},{open:"[",close:"]",token:"delimiter.square"}],escapes:/\\(?:[abfnrtv\\"'\[\]\{\};\$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,variables:/(?:\$+(?:(?:\:\:?)?[a-zA-Z_]\w*)+)/,tokenizer:{root:[[/[a-zA-Z_]\w*/,{cases:{"@specialFunctions":{token:"keyword.flow",next:"@specialFunc"},"@mainFunctions":"keyword","@builtinFunctions":"variable","@default":"operator.scss"}}],[/\s+\-+(?!\d|\.)\w*|{\*}/,"metatag"],{include:"@whitespace"},[/[{}()\[\]]/,"@brackets"],[/@symbols/,"operator"],[/\$+(?:\:\:)?\{/,{token:"identifier",next:"@nestedVariable"}],[/@variables/,"type.identifier"],[/\.(?!\d|\.)[\w\-]*/,"operator.sql"],[/\d+(\.\d+)?/,"number"],[/\d+/,"number"],[/;/,"delimiter"],[/"/,{token:"string.quote",bracket:"@open",next:"@dstring"}],[/'/,{token:"string.quote",bracket:"@open",next:"@sstring"}]],dstring:[[/\[/,{token:"@brackets",next:"@nestedCall"}],[/\$+(?:\:\:)?\{/,{token:"identifier",next:"@nestedVariable"}],[/@variables/,"type.identifier"],[/[^\\$\[\]"]+/,"string"],[/@escapes/,"string.escape"],[/"/,{token:"string.quote",bracket:"@close",next:"@pop"}]],sstring:[[/\[/,{token:"@brackets",next:"@nestedCall"}],[/\$+(?:\:\:)?\{/,{token:"identifier",next:"@nestedVariable"}],[/@variables/,"type.identifier"],[/[^\\$\[\]']+/,"string"],[/@escapes/,"string.escape"],[/'/,{token:"string.quote",bracket:"@close",next:"@pop"}]],whitespace:[[/[ \t\r\n]+/,"white"],[/#.*\\$/,{token:"comment",next:"@newlineComment"}],[/#.*(?!\\)$/,"comment"]],newlineComment:[[/.*\\$/,"comment"],[/.*(?!\\)$/,{token:"comment",next:"@pop"}]],nestedVariable:[[/[^\{\}\$]+/,"type.identifier"],[/\}/,{token:"identifier",next:"@pop"}]],nestedCall:[[/\[/,{token:"@brackets",next:"@nestedCall"}],[/\]/,{token:"@brackets",next:"@pop"}],{include:"root"}],specialFunc:[[/"/,{token:"string",next:"@dstring"}],[/'/,{token:"string",next:"@sstring"}],[/\S+/,{token:"type",next:"@pop"}]]}}}}]);
//# sourceMappingURL=1649.entry.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[2014],{1218:(e,n,t)=>{t.r(n),t.d(n,{conf:()=>r,language:()=>o});var r={comments:{lineComment:"#"},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],folding:{offSide:!0}},o={tokenPostfix:".yaml",brackets:[{token:"delimiter.bracket",open:"{",close:"}"},{token:"delimiter.square",open:"[",close:"]"}],keywords:["true","True","TRUE","false","False","FALSE","null","Null","Null","~"],numberInteger:/(?:0|[+-]?[0-9]+)/,numberFloat:/(?:0|[+-]?[0-9]+)(?:\.[0-9]+)?(?:e[-+][1-9][0-9]*)?/,numberOctal:/0o[0-7]+/,numberHex:/0x[0-9a-fA-F]+/,numberInfinity:/[+-]?\.(?:inf|Inf|INF)/,numberNaN:/\.(?:nan|Nan|NAN)/,numberDate:/\d{4}-\d\d-\d\d([Tt ]\d\d:\d\d:\d\d(\.\d+)?(( ?[+-]\d\d?(:\d\d)?)|Z)?)?/,escapes:/\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/,tokenizer:{root:[{include:"@whitespace"},{include:"@comment"},[/%[^ ]+.*$/,"meta.directive"],[/---/,"operators.directivesEnd"],[/\.{3}/,"operators.documentEnd"],[/[-?:](?= )/,"operators"],{include:"@anchor"},{include:"@tagHandle"},{include:"@flowCollections"},{include:"@blockStyle"},[/@numberInteger(?![ \t]*\S+)/,"number"],[/@numberFloat(?![ \t]*\S+)/,"number.float"],[/@numberOctal(?![ \t]*\S+)/,"number.octal"],[/@numberHex(?![ \t]*\S+)/,"number.hex"],[/@numberInfinity(?![ \t]*\S+)/,"number.infinity"],[/@numberNaN(?![ \t]*\S+)/,"number.nan"],[/@numberDate(?![ \t]*\S+)/,"number.date"],[/(".*?"|'.*?'|.*?)([ \t]*)(:)( |$)/,["type","white","operators","white"]],{include:"@flowScalars"},[/[^#]+/,{cases:{"@keywords":"keyword","@default":"string"}}]],object:[{include:"@whitespace"},{include:"@comment"},[/\}/,"@brackets","@pop"],[/,/,"delimiter.comma"],[/:(?= )/,"operators"],[/(?:".*?"|'.*?'|[^,\{\[]+?)(?=: )/,"type"],{include:"@flowCollections"},{include:"@flowScalars"},{include:"@tagHandle"},{include:"@anchor"},{include:"@flowNumber"},[/[^\},]+/,{cases:{"@keywords":"keyword","@default":"string"}}]],array:[{include:"@whitespace"},{include:"@comment"},[/\]/,"@brackets","@pop"],[/,/,"delimiter.comma"],{include:"@flowCollections"},{include:"@flowScalars"},{include:"@tagHandle"},{include:"@anchor"},{include:"@flowNumber"},[/[^\],]+/,{cases:{"@keywords":"keyword","@default":"string"}}]],multiString:[[/^( +).+$/,"string","@multiStringContinued.$1"]],multiStringContinued:[[/^( *).+$/,{cases:{"$1==$S2":"string","@default":{token:"@rematch",next:"@popall"}}}]],whitespace:[[/[ \t\r\n]+/,"white"]],comment:[[/#.*$/,"comment"]],flowCollections:[[/\[/,"@brackets","@array"],[/\{/,"@brackets","@object"]],flowScalars:[[/"([^"\\]|\\.)*$/,"string.invalid"],[/'([^'\\]|\\.)*$/,"string.invalid"],[/'[^']*'/,"string"],[/"/,"string","@doubleQuotedString"]],doubleQuotedString:[[/[^\\"]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/"/,"string","@pop"]],blockStyle:[[/[>|][0-9]*[+-]?$/,"operators","@multiString"]],flowNumber:[[/@numberInteger(?=[ \t]*[,\]\}])/,"number"],[/@numberFloat(?=[ \t]*[,\]\}])/,"number.float"],[/@numberOctal(?=[ \t]*[,\]\}])/,"number.octal"],[/@numberHex(?=[ \t]*[,\]\}])/,"number.hex"],[/@numberInfinity(?=[ \t]*[,\]\}])/,"number.infinity"],[/@numberNaN(?=[ \t]*[,\]\}])/,"number.nan"],[/@numberDate(?=[ \t]*[,\]\}])/,"number.date"]],tagHandle:[[/\![^ ]*/,"tag"]],anchor:[[/[&*][^ ]+/,"namespace"]]}}}}]);
//# sourceMappingURL=2014.entry.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
/*! For license information please see 2906.entry.js.LICENSE.txt */
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[2906],{2906:(e,t,o)=>{o.r(t),o.d(t,{conf:()=>n,language:()=>i});var n={comments:{lineComment:"//",blockComment:["/*","*/"]},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"},{open:"`",close:"`"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"},{open:"`",close:"`"}]},i={defaultToken:"",tokenPostfix:".swift",identifier:/[a-zA-Z_][\w$]*/,attributes:["@autoclosure","@noescape","@noreturn","@NSApplicationMain","@NSCopying","@NSManaged","@objc","@UIApplicationMain","@noreturn","@availability","@IBAction","@IBDesignable","@IBInspectable","@IBOutlet"],accessmodifiers:["public","private","fileprivate","internal"],keywords:["__COLUMN__","__FILE__","__FUNCTION__","__LINE__","as","as!","as?","associativity","break","case","catch","class","continue","convenience","default","deinit","didSet","do","dynamic","dynamicType","else","enum","extension","fallthrough","fileprivate","final","for","func","get","guard","if","import","in","infix","init","inout","internal","is","lazy","left","let","mutating","nil","none","nonmutating","operator","optional","override","postfix","precedence","prefix","private","protocol","Protocol","public","repeat","required","return","right","self","Self","set","static","struct","subscript","super","switch","throw","throws","try","try!","Type","typealias","unowned","var","weak","where","while","willSet","FALSE","TRUE"],symbols:/[=(){}\[\].,:;@#\_&\-<>`?!+*\\\/]/,operatorstart:/[\/=\-+!*%<>&|^~?\u00A1-\u00A7\u00A9\u00AB\u00AC\u00AE\u00B0-\u00B1\u00B6\u00BB\u00BF\u00D7\u00F7\u2016-\u2017\u2020-\u2027\u2030-\u203E\u2041-\u2053\u2055-\u205E\u2190-\u23FF\u2500-\u2775\u2794-\u2BFF\u2E00-\u2E7F\u3001-\u3003\u3008-\u3030]/,operatorend:/[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE00-\uFE0F\uFE20-\uFE2F\uE0100-\uE01EF]/,operators:/(@operatorstart)((@operatorstart)|(@operatorend))*/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,tokenizer:{root:[{include:"@whitespace"},{include:"@comment"},{include:"@attribute"},{include:"@literal"},{include:"@keyword"},{include:"@invokedmethod"},{include:"@symbol"}],whitespace:[[/\s+/,"white"],[/"""/,"string.quote","@endDblDocString"]],endDblDocString:[[/[^"]+/,"string"],[/\\"/,"string"],[/"""/,"string.quote","@popall"],[/"/,"string"]],symbol:[[/[{}()\[\]]/,"@brackets"],[/[<>](?!@symbols)/,"@brackets"],[/[.]/,"delimiter"],[/@operators/,"operator"],[/@symbols/,"operator"]],comment:[[/\/\/\/.*$/,"comment.doc"],[/\/\*\*/,"comment.doc","@commentdocbody"],[/\/\/.*$/,"comment"],[/\/\*/,"comment","@commentbody"]],commentdocbody:[[/\/\*/,"comment","@commentbody"],[/\*\//,"comment.doc","@pop"],[/\:[a-zA-Z]+\:/,"comment.doc.param"],[/./,"comment.doc"]],commentbody:[[/\/\*/,"comment","@commentbody"],[/\*\//,"comment","@pop"],[/./,"comment"]],attribute:[[/@@@identifier/,{cases:{"@attributes":"keyword.control","@default":""}}]],literal:[[/"/,{token:"string.quote",next:"@stringlit"}],[/0[b]([01]_?)+/,"number.binary"],[/0[o]([0-7]_?)+/,"number.octal"],[/0[x]([0-9a-fA-F]_?)+([pP][\-+](\d_?)+)?/,"number.hex"],[/(\d_?)*\.(\d_?)+([eE][\-+]?(\d_?)+)?/,"number.float"],[/(\d_?)+/,"number"]],stringlit:[[/\\\(/,{token:"operator",next:"@interpolatedexpression"}],[/@escapes/,"string"],[/\\./,"string.escape.invalid"],[/"/,{token:"string.quote",next:"@pop"}],[/./,"string"]],interpolatedexpression:[[/\(/,{token:"operator",next:"@interpolatedexpression"}],[/\)/,{token:"operator",next:"@pop"}],{include:"@literal"},{include:"@keyword"},{include:"@symbol"}],keyword:[[/`/,{token:"operator",next:"@escapedkeyword"}],[/@identifier/,{cases:{"@keywords":"keyword","[A-Z][a-zA-Z0-9$]*":"type.identifier","@default":"identifier"}}]],escapedkeyword:[[/`/,{token:"operator",next:"@pop"}],[/./,"identifier"]],invokedmethod:[[/([.])(@identifier)/,{cases:{$2:["delimeter","type.identifier"],"@default":""}}]]}}}}]);
//# sourceMappingURL=2906.entry.js.map

View File

@@ -0,0 +1,3 @@
/*!---------------------------------------------------------------------------------------------
* Copyright (C) David Owens II, owensd.io. All rights reserved.
*--------------------------------------------------------------------------------------------*/

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[3008],{3008:(e,n,s)=>{s.r(n),s.d(n,{conf:()=>i,language:()=>t});var i={brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"<",close:">",notIn:["string"]}],surroundingPairs:[{open:"(",close:")"},{open:"[",close:"]"},{open:"`",close:"`"}],folding:{markers:{start:new RegExp("^\\s*\x3c!--\\s*#?region\\b.*--\x3e"),end:new RegExp("^\\s*\x3c!--\\s*#?endregion\\b.*--\x3e")}}},t={defaultToken:"",tokenPostfix:".rst",control:/[\\`*_\[\]{}()#+\-\.!]/,escapes:/\\(?:@control)/,empty:["area","base","basefont","br","col","frame","hr","img","input","isindex","link","meta","param"],alphanumerics:/[A-Za-z0-9]/,simpleRefNameWithoutBq:/(?:@alphanumerics[-_+:.]*@alphanumerics)+|(?:@alphanumerics+)/,simpleRefName:/(?:`@phrase`|@simpleRefNameWithoutBq)/,phrase:/@simpleRefNameWithoutBq(?:\s@simpleRefNameWithoutBq)*/,citationName:/[A-Za-z][A-Za-z0-9-_.]*/,blockLiteralStart:/(?:[!"#$%&'()*+,-./:;<=>?@\[\]^_`{|}~]|[\s])/,precedingChars:/(?:[ -:/'"<([{])/,followingChars:/(?:[ -.,:;!?/'")\]}>]|$)/,punctuation:/(=|-|~|`|#|"|\^|\+|\*|:|\.|'|_|\+)/,tokenizer:{root:[[/^(@punctuation{3,}$){1,1}?/,"keyword"],[/^\s*([\*\-+‣•]|[a-zA-Z0-9]+\.|\([a-zA-Z0-9]+\)|[a-zA-Z0-9]+\))\s/,"keyword"],[/([ ]::)\s*$/,"keyword","@blankLineOfLiteralBlocks"],[/(::)\s*$/,"keyword","@blankLineOfLiteralBlocks"],{include:"@tables"},{include:"@explicitMarkupBlocks"},{include:"@inlineMarkup"}],explicitMarkupBlocks:[{include:"@citations"},{include:"@footnotes"},[/^(\.\.\s)(@simpleRefName)(::\s)(.*)$/,[{token:"",next:"subsequentLines"},"keyword","",""]],[/^(\.\.)(\s+)(_)(@simpleRefName)(:)(\s+)(.*)/,[{token:"",next:"hyperlinks"},"","","string.link","","","string.link"]],[/^((?:(?:\.\.)(?:\s+))?)(__)(:)(\s+)(.*)/,[{token:"",next:"subsequentLines"},"","","","string.link"]],[/^(__\s+)(.+)/,["","string.link"]],[/^(\.\.)( \|)([^| ]+[^|]*[^| ]*)(\| )(@simpleRefName)(:: .*)/,[{token:"",next:"subsequentLines"},"","string.link","","keyword",""],"@rawBlocks"],[/(\|)([^| ]+[^|]*[^| ]*)(\|_{0,2})/,["","string.link",""]],[/^(\.\.)([ ].*)$/,[{token:"",next:"@comments"},"comment"]]],inlineMarkup:[{include:"@citationsReference"},{include:"@footnotesReference"},[/(@simpleRefName)(_{1,2})/,["string.link",""]],[/(`)([^<`]+\s+)(<)(.*)(>)(`)(_)/,["","string.link","","string.link","","",""]],[/\*\*([^\\*]|\*(?!\*))+\*\*/,"strong"],[/\*[^*]+\*/,"emphasis"],[/(``)((?:[^`]|\`(?!`))+)(``)/,["","keyword",""]],[/(__\s+)(.+)/,["","keyword"]],[/(:)((?:@simpleRefNameWithoutBq)?)(:`)([^`]+)(`)/,["","keyword","","",""]],[/(`)([^`]+)(`:)((?:@simpleRefNameWithoutBq)?)(:)/,["","","","keyword",""]],[/(`)([^`]+)(`)/,""],[/(_`)(@phrase)(`)/,["","string.link",""]]],citations:[[/^(\.\.\s+\[)((?:@citationName))(\]\s+)(.*)/,[{token:"",next:"@subsequentLines"},"string.link","",""]]],citationsReference:[[/(\[)(@citationName)(\]_)/,["","string.link",""]]],footnotes:[[/^(\.\.\s+\[)((?:[0-9]+))(\]\s+.*)/,[{token:"",next:"@subsequentLines"},"string.link",""]],[/^(\.\.\s+\[)((?:#@simpleRefName?))(\]\s+)(.*)/,[{token:"",next:"@subsequentLines"},"string.link","",""]],[/^(\.\.\s+\[)((?:\*))(\]\s+)(.*)/,[{token:"",next:"@subsequentLines"},"string.link","",""]]],footnotesReference:[[/(\[)([0-9]+)(\])(_)/,["","string.link","",""]],[/(\[)(#@simpleRefName?)(\])(_)/,["","string.link","",""]],[/(\[)(\*)(\])(_)/,["","string.link","",""]]],blankLineOfLiteralBlocks:[[/^$/,"","@subsequentLinesOfLiteralBlocks"],[/^.*$/,"","@pop"]],subsequentLinesOfLiteralBlocks:[[/(@blockLiteralStart+)(.*)/,["keyword",""]],[/^(?!blockLiteralStart)/,"","@popall"]],subsequentLines:[[/^[\s]+.*/,""],[/^(?!\s)/,"","@pop"]],hyperlinks:[[/^[\s]+.*/,"string.link"],[/^(?!\s)/,"","@pop"]],comments:[[/^[\s]+.*/,"comment"],[/^(?!\s)/,"","@pop"]],tables:[[/\+-[+-]+/,"keyword"],[/\+=[+=]+/,"keyword"]]}}}}]);
//# sourceMappingURL=3008.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[3315],{3315:(e,o,n)=>{n.r(o),n.d(o,{conf:()=>t,language:()=>s});var t={comments:{lineComment:"//",blockComment:["(*","*)"]},brackets:[["{","}"],["[","]"],["(",")"],["<",">"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"<",close:">"},{open:"'",close:"'"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"<",close:">"},{open:"'",close:"'"}]},s={defaultToken:"",tokenPostfix:".pascaligo",ignoreCase:!0,brackets:[{open:"{",close:"}",token:"delimiter.curly"},{open:"[",close:"]",token:"delimiter.square"},{open:"(",close:")",token:"delimiter.parenthesis"},{open:"<",close:">",token:"delimiter.angle"}],keywords:["begin","block","case","const","else","end","fail","for","from","function","if","is","nil","of","remove","return","skip","then","type","var","while","with","option","None","transaction"],typeKeywords:["bool","int","list","map","nat","record","string","unit","address","map","mtz","xtz"],operators:["=",">","<","<=",">=","<>",":",":=","and","mod","or","+","-","*","/","@","&","^","%"],symbols:/[=><:@\^&|+\-*\/\^%]+/,tokenizer:{root:[[/[a-zA-Z_][\w]*/,{cases:{"@keywords":{token:"keyword.$0"},"@default":"identifier"}}],{include:"@whitespace"},[/[{}()\[\]]/,"@brackets"],[/[<>](?!@symbols)/,"@brackets"],[/@symbols/,{cases:{"@operators":"delimiter","@default":""}}],[/\d*\.\d+([eE][\-+]?\d+)?/,"number.float"],[/\$[0-9a-fA-F]{1,16}/,"number.hex"],[/\d+/,"number"],[/[;,.]/,"delimiter"],[/'([^'\\]|\\.)*$/,"string.invalid"],[/'/,"string","@string"],[/'[^\\']'/,"string"],[/'/,"string.invalid"],[/\#\d+/,"string"]],comment:[[/[^\(\*]+/,"comment"],[/\*\)/,"comment","@pop"],[/\(\*/,"comment"]],string:[[/[^\\']+/,"string"],[/\\./,"string.escape.invalid"],[/'/,{token:"string.quote",bracket:"@close",next:"@pop"}]],whitespace:[[/[ \t\r\n]+/,"white"],[/\(\*/,"comment","@comment"],[/\/\/.*$/,"comment"]]}}}}]);
//# sourceMappingURL=3315.entry.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[3399],{3399:(e,t,s)=>{s.r(t),s.d(t,{conf:()=>n,language:()=>o});var n={wordPattern:/(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,comments:{lineComment:"//",blockComment:["/*","*/"]},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"},{open:"<",close:">"}],folding:{markers:{start:new RegExp("^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))"),end:new RegExp("^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))")}}},o={defaultToken:"",tokenPostfix:".java",keywords:["abstract","continue","for","new","switch","assert","default","goto","package","synchronized","boolean","do","if","private","this","break","double","implements","protected","throw","byte","else","import","public","throws","case","enum","instanceof","return","transient","catch","extends","int","short","try","char","final","interface","static","void","class","finally","long","strictfp","volatile","const","float","native","super","while","true","false","yield","record","sealed","non-sealed","permits"],operators:["=",">","<","!","~","?",":","==","<=",">=","!=","&&","||","++","--","+","-","*","/","&","|","^","%","<<",">>",">>>","+=","-=","*=","/=","&=","|=","^=","%=","<<=",">>=",">>>="],symbols:/[=><!~?:&|+\-*\/\^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,digits:/\d+(_+\d+)*/,octaldigits:/[0-7]+(_+[0-7]+)*/,binarydigits:/[0-1]+(_+[0-1]+)*/,hexdigits:/[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,tokenizer:{root:[["non-sealed","keyword.non-sealed"],[/[a-zA-Z_$][\w$]*/,{cases:{"@keywords":{token:"keyword.$0"},"@default":"identifier"}}],{include:"@whitespace"},[/[{}()\[\]]/,"@brackets"],[/[<>](?!@symbols)/,"@brackets"],[/@symbols/,{cases:{"@operators":"delimiter","@default":""}}],[/@\s*[a-zA-Z_\$][\w\$]*/,"annotation"],[/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/,"number.float"],[/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/,"number.float"],[/0[xX](@hexdigits)[Ll]?/,"number.hex"],[/0(@octaldigits)[Ll]?/,"number.octal"],[/0[bB](@binarydigits)[Ll]?/,"number.binary"],[/(@digits)[fFdD]/,"number.float"],[/(@digits)[lL]?/,"number"],[/[;,.]/,"delimiter"],[/"([^"\\]|\\.)*$/,"string.invalid"],[/"""/,"string","@multistring"],[/"/,"string","@string"],[/'[^\\']'/,"string"],[/(')(@escapes)(')/,["string","string.escape","string"]],[/'/,"string.invalid"]],whitespace:[[/[ \t\r\n]+/,""],[/\/\*\*(?!\/)/,"comment.doc","@javadoc"],[/\/\*/,"comment","@comment"],[/\/\/.*$/,"comment"]],comment:[[/[^\/*]+/,"comment"],[/\*\//,"comment","@pop"],[/[\/*]/,"comment"]],javadoc:[[/[^\/*]+/,"comment.doc"],[/\/\*/,"comment.doc.invalid"],[/\*\//,"comment.doc","@pop"],[/[\/*]/,"comment.doc"]],string:[[/[^\\"]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/"/,"string","@pop"]],multistring:[[/[^\\"]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/"""/,"string","@pop"],[/./,"string"]]}}}}]);
//# sourceMappingURL=3399.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[3504],{3504:(E,S,e)=>{e.r(S),e.d(S,{conf:()=>T,language:()=>R});var T={brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}]},R={defaultToken:"",tokenPostfix:".redis",ignoreCase:!0,brackets:[{open:"[",close:"]",token:"delimiter.square"},{open:"(",close:")",token:"delimiter.parenthesis"}],keywords:["APPEND","AUTH","BGREWRITEAOF","BGSAVE","BITCOUNT","BITFIELD","BITOP","BITPOS","BLPOP","BRPOP","BRPOPLPUSH","CLIENT","KILL","LIST","GETNAME","PAUSE","REPLY","SETNAME","CLUSTER","ADDSLOTS","COUNT-FAILURE-REPORTS","COUNTKEYSINSLOT","DELSLOTS","FAILOVER","FORGET","GETKEYSINSLOT","INFO","KEYSLOT","MEET","NODES","REPLICATE","RESET","SAVECONFIG","SET-CONFIG-EPOCH","SETSLOT","SLAVES","SLOTS","COMMAND","COUNT","GETKEYS","CONFIG","GET","REWRITE","SET","RESETSTAT","DBSIZE","DEBUG","OBJECT","SEGFAULT","DECR","DECRBY","DEL","DISCARD","DUMP","ECHO","EVAL","EVALSHA","EXEC","EXISTS","EXPIRE","EXPIREAT","FLUSHALL","FLUSHDB","GEOADD","GEOHASH","GEOPOS","GEODIST","GEORADIUS","GEORADIUSBYMEMBER","GETBIT","GETRANGE","GETSET","HDEL","HEXISTS","HGET","HGETALL","HINCRBY","HINCRBYFLOAT","HKEYS","HLEN","HMGET","HMSET","HSET","HSETNX","HSTRLEN","HVALS","INCR","INCRBY","INCRBYFLOAT","KEYS","LASTSAVE","LINDEX","LINSERT","LLEN","LPOP","LPUSH","LPUSHX","LRANGE","LREM","LSET","LTRIM","MGET","MIGRATE","MONITOR","MOVE","MSET","MSETNX","MULTI","PERSIST","PEXPIRE","PEXPIREAT","PFADD","PFCOUNT","PFMERGE","PING","PSETEX","PSUBSCRIBE","PUBSUB","PTTL","PUBLISH","PUNSUBSCRIBE","QUIT","RANDOMKEY","READONLY","READWRITE","RENAME","RENAMENX","RESTORE","ROLE","RPOP","RPOPLPUSH","RPUSH","RPUSHX","SADD","SAVE","SCARD","SCRIPT","FLUSH","LOAD","SDIFF","SDIFFSTORE","SELECT","SETBIT","SETEX","SETNX","SETRANGE","SHUTDOWN","SINTER","SINTERSTORE","SISMEMBER","SLAVEOF","SLOWLOG","SMEMBERS","SMOVE","SORT","SPOP","SRANDMEMBER","SREM","STRLEN","SUBSCRIBE","SUNION","SUNIONSTORE","SWAPDB","SYNC","TIME","TOUCH","TTL","TYPE","UNSUBSCRIBE","UNLINK","UNWATCH","WAIT","WATCH","ZADD","ZCARD","ZCOUNT","ZINCRBY","ZINTERSTORE","ZLEXCOUNT","ZRANGE","ZRANGEBYLEX","ZREVRANGEBYLEX","ZRANGEBYSCORE","ZRANK","ZREM","ZREMRANGEBYLEX","ZREMRANGEBYRANK","ZREMRANGEBYSCORE","ZREVRANGE","ZREVRANGEBYSCORE","ZREVRANK","ZSCORE","ZUNIONSTORE","SCAN","SSCAN","HSCAN","ZSCAN"],operators:[],builtinFunctions:[],builtinVariables:[],pseudoColumns:[],tokenizer:{root:[{include:"@whitespace"},{include:"@pseudoColumns"},{include:"@numbers"},{include:"@strings"},{include:"@scopes"},[/[;,.]/,"delimiter"],[/[()]/,"@brackets"],[/[\w@#$]+/,{cases:{"@keywords":"keyword","@operators":"operator","@builtinVariables":"predefined","@builtinFunctions":"predefined","@default":"identifier"}}],[/[<>=!%&+\-*/|~^]/,"operator"]],whitespace:[[/\s+/,"white"]],pseudoColumns:[[/[$][A-Za-z_][\w@#$]*/,{cases:{"@pseudoColumns":"predefined","@default":"identifier"}}]],numbers:[[/0[xX][0-9a-fA-F]*/,"number"],[/[$][+-]*\d*(\.\d*)?/,"number"],[/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/,"number"]],strings:[[/'/,{token:"string",next:"@string"}],[/"/,{token:"string.double",next:"@stringDouble"}]],string:[[/[^']+/,"string"],[/''/,"string"],[/'/,{token:"string",next:"@pop"}]],stringDouble:[[/[^"]+/,"string.double"],[/""/,"string.double"],[/"/,{token:"string.double",next:"@pop"}]],scopes:[]}}}}]);
//# sourceMappingURL=3504.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[3553],{3553:(e,s,o)=>{o.r(s),o.d(s,{conf:()=>t,language:()=>n});var t={comments:{lineComment:"REM"},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}],surroundingPairs:[{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}],folding:{markers:{start:new RegExp("^\\s*(::\\s*|REM\\s+)#region"),end:new RegExp("^\\s*(::\\s*|REM\\s+)#endregion")}}},n={defaultToken:"",ignoreCase:!0,tokenPostfix:".bat",brackets:[{token:"delimiter.bracket",open:"{",close:"}"},{token:"delimiter.parenthesis",open:"(",close:")"},{token:"delimiter.square",open:"[",close:"]"}],keywords:/call|defined|echo|errorlevel|exist|for|goto|if|pause|set|shift|start|title|not|pushd|popd/,symbols:/[=><!~?&|+\-*\/\^;\.,]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,tokenizer:{root:[[/^(\s*)(rem(?:\s.*|))$/,["","comment"]],[/(\@?)(@keywords)(?!\w)/,[{token:"keyword"},{token:"keyword.$2"}]],[/[ \t\r\n]+/,""],[/setlocal(?!\w)/,"keyword.tag-setlocal"],[/endlocal(?!\w)/,"keyword.tag-setlocal"],[/[a-zA-Z_]\w*/,""],[/:\w*/,"metatag"],[/%[^%]+%/,"variable"],[/%%[\w]+(?!\w)/,"variable"],[/[{}()\[\]]/,"@brackets"],[/@symbols/,"delimiter"],[/\d*\.\d+([eE][\-+]?\d+)?/,"number.float"],[/0[xX][0-9a-fA-F_]*[0-9a-fA-F]/,"number.hex"],[/\d+/,"number"],[/[;,.]/,"delimiter"],[/"/,"string",'@string."'],[/'/,"string","@string.'"]],string:[[/[^\\"'%]+/,{cases:{"@eos":{token:"string",next:"@popall"},"@default":"string"}}],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/%[\w ]+%/,"variable"],[/%%[\w]+(?!\w)/,"variable"],[/["']/,{cases:{"$#==$S2":{token:"string",next:"@pop"},"@default":"string"}}],[/$/,"string","@popall"]]}}}}]);
//# sourceMappingURL=3553.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[3673],{3673:(e,t,r)=>{r.r(t),r.d(t,{conf:()=>s,language:()=>n});var s={wordPattern:/(-?\d*\.\d\w*)|([^\`\~\!\@\#%\^\&\*\(\)\=\$\-\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,comments:{blockComment:["###","###"],lineComment:"#"},folding:{markers:{start:new RegExp("^\\s*#region\\b"),end:new RegExp("^\\s*#endregion\\b")}}},n={defaultToken:"",ignoreCase:!1,tokenPostfix:".mips",regEx:/\/(?!\/\/)(?:[^\/\\]|\\.)*\/[igm]*/,keywords:[".data",".text","syscall","trap","add","addu","addi","addiu","and","andi","div","divu","mult","multu","nor","or","ori","sll","slv","sra","srav","srl","srlv","sub","subu","xor","xori","lhi","lho","lhi","llo","slt","slti","sltu","sltiu","beq","bgtz","blez","bne","j","jal","jalr","jr","lb","lbu","lh","lhu","lw","li","la","sb","sh","sw","mfhi","mflo","mthi","mtlo","move"],symbols:/[\.,\:]+/,escapes:/\\(?:[abfnrtv\\"'$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,tokenizer:{root:[[/\$[a-zA-Z_]\w*/,"variable.predefined"],[/[.a-zA-Z_]\w*/,{cases:{this:"variable.predefined","@keywords":{token:"keyword.$0"},"@default":""}}],[/[ \t\r\n]+/,""],[/#.*$/,"comment"],["///",{token:"regexp",next:"@hereregexp"}],[/^(\s*)(@regEx)/,["","regexp"]],[/(\,)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\:)(\s*)(@regEx)/,["delimiter","","regexp"]],[/@symbols/,"delimiter"],[/\d+[eE]([\-+]?\d+)?/,"number.float"],[/\d+\.\d+([eE][\-+]?\d+)?/,"number.float"],[/0[xX][0-9a-fA-F]+/,"number.hex"],[/0[0-7]+(?!\d)/,"number.octal"],[/\d+/,"number"],[/[,.]/,"delimiter"],[/"""/,"string",'@herestring."""'],[/'''/,"string","@herestring.'''"],[/"/,{cases:{"@eos":"string","@default":{token:"string",next:'@string."'}}}],[/'/,{cases:{"@eos":"string","@default":{token:"string",next:"@string.'"}}}]],string:[[/[^"'\#\\]+/,"string"],[/@escapes/,"string.escape"],[/\./,"string.escape.invalid"],[/\./,"string.escape.invalid"],[/#{/,{cases:{'$S2=="':{token:"string",next:"root.interpolatedstring"},"@default":"string"}}],[/["']/,{cases:{"$#==$S2":{token:"string",next:"@pop"},"@default":"string"}}],[/#/,"string"]],herestring:[[/("""|''')/,{cases:{"$1==$S2":{token:"string",next:"@pop"},"@default":"string"}}],[/[^#\\'"]+/,"string"],[/['"]+/,"string"],[/@escapes/,"string.escape"],[/\./,"string.escape.invalid"],[/#{/,{token:"string.quote",next:"root.interpolatedstring"}],[/#/,"string"]],comment:[[/[^#]+/,"comment"],[/#/,"comment"]],hereregexp:[[/[^\\\/#]+/,"regexp"],[/\\./,"regexp"],[/#.*$/,"comment"],["///[igm]*",{token:"regexp",next:"@pop"}],[/\//,"regexp"]]}}}}]);
//# sourceMappingURL=3673.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[3855],{3855:(e,t,i)=>{i.r(t),i.d(t,{conf:()=>o,language:()=>n});var o={comments:{lineComment:"COMMENT"},brackets:[["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:":",close:"."}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"`",close:"`"},{open:'"',close:'"'},{open:"'",close:"'"},{open:":",close:"."}],folding:{markers:{start:new RegExp("^\\s*(::\\s*|COMMENT\\s+)#region"),end:new RegExp("^\\s*(::\\s*|COMMENT\\s+)#endregion")}}},n={tokenPostfix:".lexon",ignoreCase:!0,keywords:["lexon","lex","clause","terms","contracts","may","pay","pays","appoints","into","to"],typeKeywords:["amount","person","key","time","date","asset","text"],operators:["less","greater","equal","le","gt","or","and","add","added","subtract","subtracted","multiply","multiplied","times","divide","divided","is","be","certified"],symbols:/[=><!~?:&|+\-*\/\^%]+/,tokenizer:{root:[[/^(\s*)(comment:?(?:\s.*|))$/,["","comment"]],[/"/,{token:"identifier.quote",bracket:"@open",next:"@quoted_identifier"}],["LEX$",{token:"keyword",bracket:"@open",next:"@identifier_until_period"}],["LEXON",{token:"keyword",bracket:"@open",next:"@semver"}],[":",{token:"delimiter",bracket:"@open",next:"@identifier_until_period"}],[/[a-z_$][\w$]*/,{cases:{"@operators":"operator","@typeKeywords":"keyword.type","@keywords":"keyword","@default":"identifier"}}],{include:"@whitespace"},[/[{}()\[\]]/,"@brackets"],[/[<>](?!@symbols)/,"@brackets"],[/@symbols/,"delimiter"],[/\d*\.\d*\.\d*/,"number.semver"],[/\d*\.\d+([eE][\-+]?\d+)?/,"number.float"],[/0[xX][0-9a-fA-F]+/,"number.hex"],[/\d+/,"number"],[/[;,.]/,"delimiter"]],quoted_identifier:[[/[^\\"]+/,"identifier"],[/"/,{token:"identifier.quote",bracket:"@close",next:"@pop"}]],space_identifier_until_period:[[":","delimiter"],[" ",{token:"white",next:"@identifier_rest"}]],identifier_until_period:[{include:"@whitespace"},[":",{token:"delimiter",next:"@identifier_rest"}],[/[^\\.]+/,"identifier"],[/\./,{token:"delimiter",bracket:"@close",next:"@pop"}]],identifier_rest:[[/[^\\.]+/,"identifier"],[/\./,{token:"delimiter",bracket:"@close",next:"@pop"}]],semver:[{include:"@whitespace"},[":","delimiter"],[/\d*\.\d*\.\d*/,{token:"number.semver",bracket:"@close",next:"@pop"}]],whitespace:[[/[ \t\r\n]+/,"white"]]}}}}]);
//# sourceMappingURL=3855.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[4035],{4035:(e,n,t)=>{t.r(n),t.d(n,{conf:()=>o,language:()=>r});var o={comments:{lineComment:"//",blockComment:["/*","*/"]},brackets:[["{","}"],["[","]"],["(",")"]],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"'",close:"'"},{open:"'''",close:"'''"}],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"'",close:"'",notIn:["string","comment"]},{open:"'''",close:"'''",notIn:["string","comment"]}],autoCloseBefore:":.,=}])' \n\t",indentationRules:{increaseIndentPattern:new RegExp("^((?!\\/\\/).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$"),decreaseIndentPattern:new RegExp("^((?!.*?\\/\\*).*\\*/)?\\s*[\\}\\]].*$")}},r={defaultToken:"",tokenPostfix:".bicep",brackets:[{open:"{",close:"}",token:"delimiter.curly"},{open:"[",close:"]",token:"delimiter.square"},{open:"(",close:")",token:"delimiter.parenthesis"}],symbols:/[=><!~?:&|+\-*/^%]+/,keywords:["targetScope","resource","module","param","var","output","for","in","if","existing"],namedLiterals:["true","false","null"],escapes:"\\\\(u{[0-9A-Fa-f]+}|n|r|t|\\\\|'|\\${)",tokenizer:{root:[{include:"@expression"},{include:"@whitespace"}],stringVerbatim:[{regex:"(|'|'')[^']",action:{token:"string"}},{regex:"'''",action:{token:"string.quote",next:"@pop"}}],stringLiteral:[{regex:"\\${",action:{token:"delimiter.bracket",next:"@bracketCounting"}},{regex:"[^\\\\'$]+",action:{token:"string"}},{regex:"@escapes",action:{token:"string.escape"}},{regex:"\\\\.",action:{token:"string.escape.invalid"}},{regex:"'",action:{token:"string",next:"@pop"}}],bracketCounting:[{regex:"{",action:{token:"delimiter.bracket",next:"@bracketCounting"}},{regex:"}",action:{token:"delimiter.bracket",next:"@pop"}},{include:"expression"}],comment:[{regex:"[^\\*]+",action:{token:"comment"}},{regex:"\\*\\/",action:{token:"comment",next:"@pop"}},{regex:"[\\/*]",action:{token:"comment"}}],whitespace:[{regex:"[ \\t\\r\\n]"},{regex:"\\/\\*",action:{token:"comment",next:"@comment"}},{regex:"\\/\\/.*$",action:{token:"comment"}}],expression:[{regex:"'''",action:{token:"string.quote",next:"@stringVerbatim"}},{regex:"'",action:{token:"string.quote",next:"@stringLiteral"}},{regex:"[0-9]+",action:{token:"number"}},{regex:"\\b[_a-zA-Z][_a-zA-Z0-9]*\\b",action:{cases:{"@keywords":{token:"keyword"},"@namedLiterals":{token:"keyword"},"@default":{token:"identifier"}}}}]}}}}]);
//# sourceMappingURL=4035.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[4073],{4073:(e,o,r)=>{r.r(o),r.d(o,{conf:()=>t,language:()=>a});var t={comments:{lineComment:"#"},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}]},a={defaultToken:"",tokenPostfix:".r",roxygen:["@alias","@aliases","@assignee","@author","@backref","@callGraph","@callGraphDepth","@callGraphPrimitives","@concept","@describeIn","@description","@details","@docType","@encoding","@evalNamespace","@evalRd","@example","@examples","@export","@exportClass","@exportMethod","@exportPattern","@family","@field","@formals","@format","@import","@importClassesFrom","@importFrom","@importMethodsFrom","@include","@inherit","@inheritDotParams","@inheritParams","@inheritSection","@keywords","@md","@method","@name","@noMd","@noRd","@note","@param","@rawNamespace","@rawRd","@rdname","@references","@return","@S3method","@section","@seealso","@setClass","@slot","@source","@template","@templateVar","@title","@TODO","@usage","@useDynLib"],constants:["NULL","FALSE","TRUE","NA","Inf","NaN","NA_integer_","NA_real_","NA_complex_","NA_character_","T","F","LETTERS","letters","month.abb","month.name","pi","R.version.string"],keywords:["break","next","return","if","else","for","in","repeat","while","array","category","character","complex","double","function","integer","list","logical","matrix","numeric","vector","data.frame","factor","library","require","attach","detach","source"],special:["\\n","\\r","\\t","\\b","\\a","\\f","\\v","\\'",'\\"',"\\\\"],brackets:[{open:"{",close:"}",token:"delimiter.curly"},{open:"[",close:"]",token:"delimiter.bracket"},{open:"(",close:")",token:"delimiter.parenthesis"}],tokenizer:{root:[{include:"@numbers"},{include:"@strings"},[/[{}\[\]()]/,"@brackets"],{include:"@operators"},[/#'$/,"comment.doc"],[/#'/,"comment.doc","@roxygen"],[/(^#.*$)/,"comment"],[/\s+/,"white"],[/[,:;]/,"delimiter"],[/@[a-zA-Z]\w*/,"tag"],[/[a-zA-Z]\w*/,{cases:{"@keywords":"keyword","@constants":"constant","@default":"identifier"}}]],roxygen:[[/@\w+/,{cases:{"@roxygen":"tag","@eos":{token:"comment.doc",next:"@pop"},"@default":"comment.doc"}}],[/\s+/,{cases:{"@eos":{token:"comment.doc",next:"@pop"},"@default":"comment.doc"}}],[/.*/,{token:"comment.doc",next:"@pop"}]],numbers:[[/0[xX][0-9a-fA-F]+/,"number.hex"],[/-?(\d*\.)?\d+([eE][+\-]?\d+)?/,"number"]],operators:[[/<{1,2}-/,"operator"],[/->{1,2}/,"operator"],[/%[^%\s]+%/,"operator"],[/\*\*/,"operator"],[/%%/,"operator"],[/&&/,"operator"],[/\|\|/,"operator"],[/<</,"operator"],[/>>/,"operator"],[/[-+=&|!<>^~*/:$]/,"operator"]],strings:[[/'/,"string.escape","@stringBody"],[/"/,"string.escape","@dblStringBody"]],stringBody:[[/\\./,{cases:{"@special":"string","@default":"error-token"}}],[/'/,"string.escape","@popall"],[/./,"string"]],dblStringBody:[[/\\./,{cases:{"@special":"string","@default":"error-token"}}],[/"/,"string.escape","@popall"],[/./,"string"]]}}}}]);
//# sourceMappingURL=4073.entry.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[4369],{4369:(e,o,t)=>{t.r(o),t.d(o,{conf:()=>n,language:()=>s});var n={comments:{lineComment:"#"},brackets:[["[","]"],["<",">"],["(",")"]],autoClosingPairs:[{open:"[",close:"]"},{open:"<",close:">"},{open:"(",close:")"}],surroundingPairs:[{open:"[",close:"]"},{open:"<",close:">"},{open:"(",close:")"}]},s={defaultToken:"",tokenPostfix:".pla",brackets:[{open:"[",close:"]",token:"delimiter.square"},{open:"<",close:">",token:"delimiter.angle"},{open:"(",close:")",token:"delimiter.parenthesis"}],keywords:[".i",".o",".mv",".ilb",".ob",".label",".type",".phase",".pair",".symbolic",".symbolic-output",".kiss",".p",".e",".end"],comment:/#.*$/,identifier:/[a-zA-Z]+[a-zA-Z0-9_\-]*/,plaContent:/[01\-~\|]+/,tokenizer:{root:[{include:"@whitespace"},[/@comment/,"comment"],[/\.([a-zA-Z_\-]+)/,{cases:{"@eos":{token:"keyword.$1"},"@keywords":{cases:{".type":{token:"keyword.$1",next:"@type"},"@default":{token:"keyword.$1",next:"@keywordArg"}}},"@default":{token:"keyword.$1"}}}],[/@identifier/,"identifier"],[/@plaContent/,"string"]],whitespace:[[/[ \t\r\n]+/,""]],type:[{include:"@whitespace"},[/\w+/,{token:"type",next:"@pop"}]],keywordArg:[[/[ \t\r\n]+/,{cases:{"@eos":{token:"",next:"@pop"},"@default":""}}],[/@comment/,"comment","@pop"],[/[<>()\[\]]/,{cases:{"@eos":{token:"@brackets",next:"@pop"},"@default":"@brackets"}}],[/\-?\d+/,{cases:{"@eos":{token:"number",next:"@pop"},"@default":"number"}}],[/@identifier/,{cases:{"@eos":{token:"identifier",next:"@pop"},"@default":"identifier"}}],[/[;=]/,{cases:{"@eos":{token:"delimiter",next:"@pop"},"@default":"delimiter"}}]]}}}}]);
//# sourceMappingURL=4369.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[4454],{4454:(e,t,n)=>{n.r(t),n.d(t,{conf:()=>o,language:()=>s});var o={comments:{lineComment:"//",blockComment:["/*","*/"]},brackets:[["{","}"],["[","]"],["(",")"],["<",">"]],autoClosingPairs:[{open:'"',close:'"',notIn:["string","comment"]},{open:"{",close:"}",notIn:["string","comment"]},{open:"[",close:"]",notIn:["string","comment"]},{open:"(",close:")",notIn:["string","comment"]}]},s={defaultToken:"",tokenPostfix:".aes",brackets:[{token:"delimiter.curly",open:"{",close:"}"},{token:"delimiter.parenthesis",open:"(",close:")"},{token:"delimiter.square",open:"[",close:"]"},{token:"delimiter.angle",open:"<",close:">"}],keywords:["contract","library","entrypoint","function","stateful","state","hash","signature","tuple","list","address","string","bool","int","record","datatype","type","option","oracle","oracle_query","Call","Bits","Bytes","Oracle","String","Crypto","Address","Auth","Chain","None","Some","bits","bytes","event","let","map","private","public","true","false","var","if","else","throw"],operators:["=",">","<","!","~","?","::",":","==","<=",">=","!=","&&","||","++","--","+","-","*","/","&","|","^","%","<<",">>",">>>","+=","-=","*=","/=","&=","|=","^=","%=","<<=",">>=",">>>="],symbols:/[=><!~?:&|+\-*\/\^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,integersuffix:/(ll|LL|u|U|l|L)?(ll|LL|u|U|l|L)?/,floatsuffix:/[fFlL]?/,tokenizer:{root:[[/[a-zA-Z_]\w*/,{cases:{"@keywords":{token:"keyword.$0"},"@default":"identifier"}}],{include:"@whitespace"},[/\[\[.*\]\]/,"annotation"],[/^\s*#\w+/,"keyword"],[/int\d*/,"keyword"],[/[{}()\[\]]/,"@brackets"],[/[<>](?!@symbols)/,"@brackets"],[/@symbols/,{cases:{"@operators":"delimiter","@default":""}}],[/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/,"number.float"],[/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/,"number.float"],[/0[xX][0-9a-fA-F']*[0-9a-fA-F](@integersuffix)/,"number.hex"],[/0[0-7']*[0-7](@integersuffix)/,"number.octal"],[/0[bB][0-1']*[0-1](@integersuffix)/,"number.binary"],[/\d[\d']*\d(@integersuffix)/,"number"],[/\d(@integersuffix)/,"number"],[/[;,.]/,"delimiter"],[/"([^"\\]|\\.)*$/,"string.invalid"],[/"/,"string","@string"],[/'[^\\']'/,"string"],[/(')(@escapes)(')/,["string","string.escape","string"]],[/'/,"string.invalid"]],whitespace:[[/[ \t\r\n]+/,""],[/\/\*\*(?!\/)/,"comment.doc","@doccomment"],[/\/\*/,"comment","@comment"],[/\/\/.*$/,"comment"]],comment:[[/[^\/*]+/,"comment"],[/\*\//,"comment","@pop"],[/[\/*]/,"comment"]],doccomment:[[/[^\/*]+/,"comment.doc"],[/\*\//,"comment.doc","@pop"],[/[\/*]/,"comment.doc"]],string:[[/[^\\"]+/,"string"],[/@escapes/,"string.escape"],[/\\./,"string.escape.invalid"],[/"/,"string","@pop"]]}}}}]);
//# sourceMappingURL=4454.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[4511],{4511:(e,r,n)=>{n.r(r),n.d(r,{conf:()=>t,language:()=>s});var t={wordPattern:/(-?\d*\.\d\w*)|([^\`\~\!\@\#%\^\&\*\(\)\=\$\-\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,comments:{blockComment:["###","###"],lineComment:"#"},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],folding:{markers:{start:new RegExp("^\\s*#region\\b"),end:new RegExp("^\\s*#endregion\\b")}}},s={defaultToken:"",ignoreCase:!0,tokenPostfix:".coffee",brackets:[{open:"{",close:"}",token:"delimiter.curly"},{open:"[",close:"]",token:"delimiter.square"},{open:"(",close:")",token:"delimiter.parenthesis"}],regEx:/\/(?!\/\/)(?:[^\/\\]|\\.)*\/[igm]*/,keywords:["and","or","is","isnt","not","on","yes","@","no","off","true","false","null","this","new","delete","typeof","in","instanceof","return","throw","break","continue","debugger","if","else","switch","for","while","do","try","catch","finally","class","extends","super","undefined","then","unless","until","loop","of","by","when"],symbols:/[=><!~?&%|+\-*\/\^\.,\:]+/,escapes:/\\(?:[abfnrtv\\"'$]|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,tokenizer:{root:[[/\@[a-zA-Z_]\w*/,"variable.predefined"],[/[a-zA-Z_]\w*/,{cases:{this:"variable.predefined","@keywords":{token:"keyword.$0"},"@default":""}}],[/[ \t\r\n]+/,""],[/###/,"comment","@comment"],[/#.*$/,"comment"],["///",{token:"regexp",next:"@hereregexp"}],[/^(\s*)(@regEx)/,["","regexp"]],[/(\()(\s*)(@regEx)/,["@brackets","","regexp"]],[/(\,)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\=)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\:)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\[)(\s*)(@regEx)/,["@brackets","","regexp"]],[/(\!)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\&)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\|)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\?)(\s*)(@regEx)/,["delimiter","","regexp"]],[/(\{)(\s*)(@regEx)/,["@brackets","","regexp"]],[/(\;)(\s*)(@regEx)/,["","","regexp"]],[/}/,{cases:{"$S2==interpolatedstring":{token:"string",next:"@pop"},"@default":"@brackets"}}],[/[{}()\[\]]/,"@brackets"],[/@symbols/,"delimiter"],[/\d+[eE]([\-+]?\d+)?/,"number.float"],[/\d+\.\d+([eE][\-+]?\d+)?/,"number.float"],[/0[xX][0-9a-fA-F]+/,"number.hex"],[/0[0-7]+(?!\d)/,"number.octal"],[/\d+/,"number"],[/[,.]/,"delimiter"],[/"""/,"string",'@herestring."""'],[/'''/,"string","@herestring.'''"],[/"/,{cases:{"@eos":"string","@default":{token:"string",next:'@string."'}}}],[/'/,{cases:{"@eos":"string","@default":{token:"string",next:"@string.'"}}}]],string:[[/[^"'\#\\]+/,"string"],[/@escapes/,"string.escape"],[/\./,"string.escape.invalid"],[/\./,"string.escape.invalid"],[/#{/,{cases:{'$S2=="':{token:"string",next:"root.interpolatedstring"},"@default":"string"}}],[/["']/,{cases:{"$#==$S2":{token:"string",next:"@pop"},"@default":"string"}}],[/#/,"string"]],herestring:[[/("""|''')/,{cases:{"$1==$S2":{token:"string",next:"@pop"},"@default":"string"}}],[/[^#\\'"]+/,"string"],[/['"]+/,"string"],[/@escapes/,"string.escape"],[/\./,"string.escape.invalid"],[/#{/,{token:"string.quote",next:"root.interpolatedstring"}],[/#/,"string"]],comment:[[/[^#]+/,"comment"],[/###/,"comment","@pop"],[/#/,"comment"]],hereregexp:[[/[^\\\/#]+/,"regexp"],[/\\./,"regexp"],[/#.*$/,"comment"],["///[igm]*",{token:"regexp",next:"@pop"}],[/\//,"regexp"]]}}}}]);
//# sourceMappingURL=4511.entry.js.map

View File

@@ -0,0 +1,2 @@
"use strict";(self.webpackChunkdemo=self.webpackChunkdemo||[]).push([[4558],{4558:(e,t,n)=>{n.r(t),n.d(t,{conf:()=>o,language:()=>d});var i=n(2526),r=["area","base","br","col","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],o={wordPattern:/(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,comments:{blockComment:["\x3c!--","--\x3e"]},brackets:[["\x3c!--","--\x3e"],["<",">"],["{","}"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"}],surroundingPairs:[{open:'"',close:'"'},{open:"'",close:"'"},{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:"<",close:">"}],onEnterRules:[{beforeText:new RegExp("<(?!(?:"+r.join("|")+"))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$","i"),afterText:/^<\/([_:\w][_:\w-.\d]*)\s*>$/i,action:{indentAction:i.Mj.IndentAction.IndentOutdent}},{beforeText:new RegExp("<(?!(?:"+r.join("|")+"))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$","i"),action:{indentAction:i.Mj.IndentAction.Indent}}],folding:{markers:{start:new RegExp("^\\s*\x3c!--\\s*#region\\b.*--\x3e"),end:new RegExp("^\\s*\x3c!--\\s*#endregion\\b.*--\x3e")}}},d={defaultToken:"",tokenPostfix:".html",ignoreCase:!0,tokenizer:{root:[[/<!DOCTYPE/,"metatag","@doctype"],[/<!--/,"comment","@comment"],[/(<)((?:[\w\-]+:)?[\w\-]+)(\s*)(\/>)/,["delimiter","tag","","delimiter"]],[/(<)(script)/,["delimiter",{token:"tag",next:"@script"}]],[/(<)(style)/,["delimiter",{token:"tag",next:"@style"}]],[/(<)((?:[\w\-]+:)?[\w\-]+)/,["delimiter",{token:"tag",next:"@otherTag"}]],[/(<\/)((?:[\w\-]+:)?[\w\-]+)/,["delimiter",{token:"tag",next:"@otherTag"}]],[/</,"delimiter"],[/[^<]+/]],doctype:[[/[^>]+/,"metatag.content"],[/>/,"metatag","@pop"]],comment:[[/-->/,"comment","@pop"],[/[^-]+/,"comment.content"],[/./,"comment.content"]],otherTag:[[/\/?>/,"delimiter","@pop"],[/"([^"]*)"/,"attribute.value"],[/'([^']*)'/,"attribute.value"],[/[\w\-]+/,"attribute.name"],[/=/,"delimiter"],[/[ \t\r\n]+/]],script:[[/type/,"attribute.name","@scriptAfterType"],[/"([^"]*)"/,"attribute.value"],[/'([^']*)'/,"attribute.value"],[/[\w\-]+/,"attribute.name"],[/=/,"delimiter"],[/>/,{token:"delimiter",next:"@scriptEmbedded",nextEmbedded:"text/javascript"}],[/[ \t\r\n]+/],[/(<\/)(script\s*)(>)/,["delimiter","tag",{token:"delimiter",next:"@pop"}]]],scriptAfterType:[[/=/,"delimiter","@scriptAfterTypeEquals"],[/>/,{token:"delimiter",next:"@scriptEmbedded",nextEmbedded:"text/javascript"}],[/[ \t\r\n]+/],[/<\/script\s*>/,{token:"@rematch",next:"@pop"}]],scriptAfterTypeEquals:[[/"([^"]*)"/,{token:"attribute.value",switchTo:"@scriptWithCustomType.$1"}],[/'([^']*)'/,{token:"attribute.value",switchTo:"@scriptWithCustomType.$1"}],[/>/,{token:"delimiter",next:"@scriptEmbedded",nextEmbedded:"text/javascript"}],[/[ \t\r\n]+/],[/<\/script\s*>/,{token:"@rematch",next:"@pop"}]],scriptWithCustomType:[[/>/,{token:"delimiter",next:"@scriptEmbedded.$S2",nextEmbedded:"$S2"}],[/"([^"]*)"/,"attribute.value"],[/'([^']*)'/,"attribute.value"],[/[\w\-]+/,"attribute.name"],[/=/,"delimiter"],[/[ \t\r\n]+/],[/<\/script\s*>/,{token:"@rematch",next:"@pop"}]],scriptEmbedded:[[/<\/script/,{token:"@rematch",next:"@pop",nextEmbedded:"@pop"}],[/[^<]+/,""]],style:[[/type/,"attribute.name","@styleAfterType"],[/"([^"]*)"/,"attribute.value"],[/'([^']*)'/,"attribute.value"],[/[\w\-]+/,"attribute.name"],[/=/,"delimiter"],[/>/,{token:"delimiter",next:"@styleEmbedded",nextEmbedded:"text/css"}],[/[ \t\r\n]+/],[/(<\/)(style\s*)(>)/,["delimiter","tag",{token:"delimiter",next:"@pop"}]]],styleAfterType:[[/=/,"delimiter","@styleAfterTypeEquals"],[/>/,{token:"delimiter",next:"@styleEmbedded",nextEmbedded:"text/css"}],[/[ \t\r\n]+/],[/<\/style\s*>/,{token:"@rematch",next:"@pop"}]],styleAfterTypeEquals:[[/"([^"]*)"/,{token:"attribute.value",switchTo:"@styleWithCustomType.$1"}],[/'([^']*)'/,{token:"attribute.value",switchTo:"@styleWithCustomType.$1"}],[/>/,{token:"delimiter",next:"@styleEmbedded",nextEmbedded:"text/css"}],[/[ \t\r\n]+/],[/<\/style\s*>/,{token:"@rematch",next:"@pop"}]],styleWithCustomType:[[/>/,{token:"delimiter",next:"@styleEmbedded.$S2",nextEmbedded:"$S2"}],[/"([^"]*)"/,"attribute.value"],[/'([^']*)'/,"attribute.value"],[/[\w\-]+/,"attribute.name"],[/=/,"delimiter"],[/[ \t\r\n]+/],[/<\/style\s*>/,{token:"@rematch",next:"@pop"}]],styleEmbedded:[[/<\/style/,{token:"@rematch",next:"@pop",nextEmbedded:"@pop"}],[/[^<]+/,""]]}}}}]);
//# sourceMappingURL=4558.entry.js.map

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