Skip to main content Link Search Menu Expand Document (external link)

Action Templating

Actions that can submit text (Report, Comment, UserNote, Message, Ban, Submission) 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

Some data can always be accessed at the top-level. Example

This action was run from  in Check .

The bot intro post is 

Message the moderators of this subreddit using this [compose link]()
Name Description Example
manager The name of the subreddit the bot is running in mealtimevideos
check The name of the Check that was triggered myCheck
botLink A link to the bot introduction https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot
modmailLink A link that opens reddit’s DM compose with the subject line as the Activity being processed https://www.reddit.com/message/compose?to=/r/mealtimevideos&message=https://www.reddit.com/r/ContextModBot/comments/otz396/introduction_to_contextmodbot

Activity Data

Activity data can be accessed using the item variable. Example

This activity is a  with  votes, created  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
subreddit The name of the subreddit the Activity is from mealtimevideos
id The Reddit Thing ID for the Activity t3_0tin1
title As comments => the body of the comment. As Submission => title Test post please ignore
shortTitle The same as title but truncated to 15 characters test post pleas…

Common Author

Additionally, author has these properties accessible:

Name Description Example
age (Approximate) Age of account 3 months
linkKarma Amount of link karma 10
commentKarma Amount of comment karma 3
totalKarma Combined link+comment karma 13
verified Does account have a verified email? true

NOTE: Accessing these properties may require an additional API call so use sparingly on high-volume comments

Example Usage
The user  has been a redditor for 

Produces:

The user FoxxMD has been a redditor for 3 months

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:


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  times

Produces

Submission was repeated 7 times

Action Data

Summary

A summary of what actions have already been run when the template is rendered is available using the actionSummary variable. It is therefore important that the Action you want to produce the summary is run after any other Actions you want to get a summary for.

Example:

A summary of actions processed for this activity, so far:


Would produce:

A summary of actions processed for this activity, so far:

  • approve - ✘ - Item is already approved??
  • lock - ✓
  • modnote - ✓ - (SOLID_CONTRIBUTOR) User is good

Individual

Individual Actions can be accessed using the name of the action, lower-cased, with all spaces/dashes/underscores. Example:

User was banned for  for 

Produces

User was banned for 4 days for toxic behavior

Quick Templating Tutorial

As a quick example for how you will most likely be using templating – wrapping a variable in curly brackets, ``, 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 , my other variable is , 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  like this, and another nested property  like this."