mirror of
https://github.com/FoxxMD/context-mod.git
synced 2026-04-19 03:00:07 -04:00
* Reorganize some main readme contents into separate docs * Add full bot authentication guide * Add screenshots and web interface section Some link fixes and clarifications Fix another link Fix another link More doc cleanup More doc cleanup More doc cleanup Add link to docs in main readme summary
73 lines
2.5 KiB
Markdown
73 lines
2.5 KiB
Markdown
Actions that can submit text (Report, Comment) will have their `content` values run through a [Mustache Template](https://mustache.github.io/). This means you can insert data generated by Rules into your text before the Action is performed.
|
|
|
|
See here for a [cheatsheet](https://gist.github.com/FoxxMD/d365707cf99fdb526a504b8b833a5b78) and [here](https://www.tsmean.com/articles/mustache/the-ultimate-mustache-tutorial/) for a more thorough tutorial.
|
|
|
|
All Actions with `content` have access to this data:
|
|
|
|
```json5
|
|
|
|
{
|
|
item: {
|
|
kind: 'string', // the type of item (comment/submission)
|
|
author: 'string', // name of the item author (reddit user)
|
|
permalink: 'string', // a url to the item
|
|
url: 'string', // if the item is a Submission then its URL (external for link type submission, reddit link for self-posts)
|
|
title: 'string', // if the item is a Submission, then the title of the Submission,
|
|
botLink: 'string' // a link to the bot's FAQ
|
|
},
|
|
rules: {
|
|
// contains all rules that were run and are accessible using the name, lowercased, with all spaces/dashes/underscores removed
|
|
}
|
|
}
|
|
|
|
```
|
|
|
|
The properties of `rules` are accessible using the name, lower-cased, with all spaces/dashes/underscores. If no name is given `kind` is used as `name` Example:
|
|
|
|
```
|
|
|
|
"rules": [
|
|
{
|
|
"name": "My Custom-Recent Activity Rule", // mycustomrecentactivityrule
|
|
"kind": "recentActivity"
|
|
},
|
|
{
|
|
// name = repeatsubmission
|
|
"kind": "repeatActivity",
|
|
}
|
|
]
|
|
|
|
```
|
|
|
|
**To see what data is available for individual Rules [consult the schema](#configuration) for each Rule.**
|
|
|
|
#### 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."
|
|
|
|
```
|