Skip to main content

Rules

Rules are the backbone of Modegator's automation engine. They allow you to define an Event-Condition-Action (ECA) flow. When a specific event occurs, Modegator evaluates the provided conditions, and if they match, it executes a set of actions.

Event Triggers​

Every rule must listen to a specific event. Modegator natively supports the following events:

  • PostSubmit
  • CommentSubmit
  • PostReport
  • CommentReport
  • PostUpdate
  • CommentUpdate
  • ModMail

Conditions​

The conditions array dictates whether a rule's actions should run by evaluating logic nodes against the triggering event.

Advanced Condition Evaluation​

Modegator's condition evaluator supports advanced logical grouping and dynamic array matching:

Logical Grouping​

Conditions can be nested using logical operator blocks. By default, the top-level array acts as an implicit all_of (meaning all conditions must pass), so you only need to use explicit blocks when building OR logic.

Example 1: Implicit all_of (AND Logic)

conditions:
- field: "author_karma"
operator: "<"
value: 50
- field: "author_age_days"
operator: "<"
value: 7

Example 2: Explicit any_of (OR Logic)

conditions:
- any_of:
- field: "author_karma"
operator: "<"
value: 50
- field: "author_age_days"
operator: "<"
value: 7

Example 3: Complex Nested Matching (Regex arrays + Logic)

conditions:
- any_of:
- field: "post_title"
operator: "regex"
value: ["buy.*crypto", "free.*followers"]
- all_of:
- field: "author_karma"
operator: "<"
value: 10
- field: "post_domain"
operator: "=="
value: "shady-link.com"

Array Matching​

For the ==, !=, contains, and regex operators, you can provide an array of values instead of a single string or number. The engine evaluates the array dynamically:

  • ==: Acts as an "IN" operator. Passes if the actual value exactly matches any item in the array.
  • !=: Acts as a "NOT IN" operator. Passes if the actual value matches none of the items in the array.
  • contains: Passes if any string in the array is a substring of the actual value.
  • regex: Evaluates each regex pattern in the array. Passes if any pattern matches.

Dynamic Field Resolution​

The field property itself is resolved dynamically using Modegator's placeholder engine before the condition is evaluated. This allows you to evaluate user-specific or dynamic keys (e.g., field: "counter_warnings_{{author}}").

Case Insensitivity​

All string comparisons (including contains and regex matching) are performed case-insensitively by default.


Allowed Fields Reference​

The following fields can be evaluated dynamically within any rule condition block. Every field strictly enforces its associated data type during execution.

Author Fields​

FieldTypeDescription
author_namestringThe username of the user who triggered the event.
author_karmanumberThe total numeric karma score of the author.
author_age_daysnumberThe age of the author's account in days.
author_is_bannedbooleantrue if the author is currently banned in the subreddit.
author_is_modbooleantrue if the author is a moderator of the subreddit.
author_is_approvedbooleantrue if the author is an approved submitter.
author_has_user_flairstringThe text of the user's assigned flair.
author_has_mod_notebooleantrue if the user has any existing Mod Notes on their profile.
author_mod_note_labelstringThe text label of the user's most recent Mod Note (e.g., SPAM_WARNING).

Post Fields​

FieldTypeDescription
post_titlestringThe title of the post.
post_bodystringThe text body of the post.
post_domainstringThe domain of the link (if the post is a link submission).
post_domain_tagstringThe custom text label (e.g., Under Review, Approved) assigned to this post's domain in the Domain Tracker database.
post_scorenumberThe current upvote score of the post.
post_report_countnumberThe number of reports the post has received.
post_link_typestringThe type of post submission. Either 'link' (an external URL post) or 'self' (a text/self-post, including gallery and poll posts).
post_is_nsfwbooleantrue if the post is marked Not Safe For Work.
post_is_spoilerbooleantrue if the post is marked as a spoiler.
post_flair_textstringThe text of the post's assigned flair.

Comment Fields​

FieldTypeDescription
comment_bodystringThe text content of the comment.
comment_scorenumberThe current upvote score of the comment.
comment_is_top_levelbooleantrue if the comment is a direct reply to the post (not nested).
comment_report_countnumberThe number of reports the comment has received.

ModMail Fields​

FieldTypeDescription
modmail_subjectstringThe subject line of the ModMail conversation.
modmail_bodystringThe body text of the most recent ModMail message.
modmail_body_lengthnumberThe character length of the ModMail body text.

Custom State Fields​

FieldTypeDescription
counter_[key]numberQueries the dynamic numeric value of a custom Redis counter stored under [key] (e.g., counter_warnings_{{author}}).
custom_[key]stringQueries the string value of a custom Redis entry stored under [key] (e.g., custom_last_violation).

Allowed Operators​

  • == (Equals)
  • != (Not Equals)
  • <, <=, >, >= (Numerical Comparisons)
  • contains (Substring Match)
  • regex (Regular Expression)

Note: All string comparisons are case-insensitive by default.

Rule Example​

Here is an example of an automated rule filtering new accounts posting links:

rules:
- name: "Ban new link-posting accounts"
trigger:
event: "PostSubmit"
conditions:
- field: "author_age_days"
operator: "<"
value: 7
- field: "author_karma"
operator: "<"
value: 50
- field: "post_link_type"
operator: "=="
value: "link"
actions:
- type: "remove_post"
spam: true
- type: "ban_user"
duration: "permanent"
reason: "Spam account"

Fallback Actions (Optional)​

You can define a fallback_actions block which executes if the primary conditions are NOT met. This is useful for building simple "if/else" logic.

Rules in YAML Editor