* Add votes, reports, upvote ratio, nsfw, op, and spoiler * Update templating documentation
5.7 KiB
Actions that can submit text (Report, Comment, UserNote) will have their content values run through a Mustache Template. This means you can insert data generated by Rules into your text before the Action is performed.
See here for a cheatsheet and here for a more thorough tutorial.
Template Data
Activity Data
Activity data can be accessed using the item variable. Example
This activity is a {{item.kind}} with {{item.votes}} votes, created {{item.age}} ago.
Produces:
This activity is a submission with 10 votes created 5 minutes ago.
Common
All Actions with content have access to this data:
| Name | Description | Example |
|---|---|---|
kind |
The Activity type (submission or comment) | submission |
author |
Name of the Author of the Activity being processed | FoxxMD |
permalink |
URL to the Activity | https://reddit.com/r/mySuibreddit/comments/ab23f/my_post |
votes |
Number of upvotes | 69 |
age |
The age of the Activity in a human friendly format | 5 minutes |
botLink |
A URL to CM's introduction thread | https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot |
Submissions
If the Activity is a Submission these additional properties are accessible:
| Name | Description | Example |
|---|---|---|
upvoteRatio |
The upvote ratio | 100% |
nsfw |
If the submission is marked as NSFW | true |
spoiler |
If the submission is marked as a spoiler | true |
url |
If the submission was a link then this is the URL for that link | http://example.com |
title |
The title of the submission | Test post please ignore |
Comments
If the Activity is a Comment these additional properties are accessible:
| Name | Description | Example |
|---|---|---|
op |
If the Author is the OP of the Submission this comment is in | true |
Moderator
If the Activity occurred in a Subreddit the Bot moderates these properties are accessible:
| Name | Description | Example |
|---|---|---|
reports |
The number of reports recieved | 1 |
modReports |
The number of reports by moderators | 1 |
userReports |
The number of reports by users | 1 |
Rule Data
Summary
A summary of what rules were processed and which were triggered, with results, is available using the ruleSummary variable. Example:
A summary of rules processed for this activity:
{{ruleSummary}}
Would produce:
A summary of rules processed for this activity:
- namedRegexRule - ✘
- nameAttributionRule - ✓ - 1 Attribution(s) met the threshold of < 20%, with 1 (3%) of 32 Total -- window: 6 months
- noXPost ✓ - ✓ 1 of 1 unique items repeated <= 3 times, largest repeat: 1
Individual
Individual Rules can be accessed using the name of the rule, lower-cased, with all spaces/dashes/underscores. Example:
Submission was repeated {{rules.noxpost.largestRepeat}} times
Produces
Submission was repeated 7 times
Quick Templating Tutorial
As a quick example for how you will most likely be using templating -- wrapping a variable in curly brackets, {{variable}}, will cause the variable value to be rendered instead of the brackets:
myVariable = 50;
myOtherVariable = "a text fragment"
template = "This is my template, the variable is {{myVariable}}, my other variable is {{myOtherVariable}}, and that's it!";
console.log(Mustache.render(template, {myVariable});
// will render...
"This is my template, the variable is 50, my other variable is a text fragment, and that's it!";
Note: When accessing an object or its properties you must use dot notation
const item = {
aProperty: 'something',
anotherObject: {
bProperty: 'something else'
}
}
const content = "My content will render the property {{item.aProperty}} like this, and another nested property {{item.anotherObject.bProperty}} like this."