Skip to content

Moderation

Tommaso Ornato edited this page Sep 7, 2023 · 17 revisions

Only moderators may set AutoMod rules and only for communities where they are a mod themselves.

Example:
Bob is a mod in c/memes. Bob is allowed to enable the AutoMod and set its rules in c/memes.
However Bob is NOT a moderator in c/general, so he won't be able to set any rules in that community.

Prerequisites

Before any AutoMod configuration rule can be submitted, the bot needs to be a moderator in the target community. As a pre-release measure, it will be necessary to manually comment on the target community from the AutoMod's account and manually appoint it as a moderator. This process will be automated in further releases.

Interacting with the bot

Interaction happens through Lemmy DMs, accessible through the "Send Message" button (not "Send Secure Message"!) on the bot's profile.

immagine

Configurations should be set up in the form of JSON objects. The content of the object will be discussed in the syntax paragraph.

Once an object containing one or more rules has been written, it should be pasted in the message box without any further formatting. The bot will then process it and reply to the message with either an error message or a confirmation. Error messages will be discussed in the error handling paragraph.

immagine

Syntax

The syntax of configurations follows a strict set of rules to unambiguously highlight what is a valid configuration and what isn't.

Currently, the AutoMod allows four configuration options:

  • comment.json, dictates the removal of comments
  • post.json, dictates the removal of posts
  • exception.json, lists exceptions to the two aforementioned rules
  • mention.json, describes commands available to the moderators to easily "pin" and "lock" posts

All rules include a rule field, detailing which of the four configuration options it represents (can be one of "comment","post","exception",mention").

Each of these configurations has to follow a JSON schema, available in this repository. Various examples of valid configurations are also available in the lemmy-automoderator-examples repository.

Optionally, a $schema proprety might be added. This will add JSON schema support (automatic, real time validation) in code editors like Visual Studio Code, therefore this is the reccomended setup for writing new rules. An online editor is also available at this link (requires a GitHub account).

Comment

A Comment rule prescribes the automated removal of a comment, based on its content.

{
    "rule": "comment",
    "community": "memes",
    "match": "pizza",
    "type": "exact",
    "whitelist_exempt": false,
    "mod_exempt": false,
    "message": "Your comment has been removed because discussions about pizza are prohibited in this community",
    "removal_reason": "Said the word 'pizza'"
}

Explanation:
This rule removes all comments containing the word "pizza" posted in the community c/memes. The bot will then reply to the removed comment explaining that it was removed because discussion about pizza are prohibited. Lastly, it will report the removal in the modlog giving "Said the word 'pizza'" as a removal reason. This rule will be valid for all users, including whitelisted users and moderators.

Keys

Field Name Type Description
community string Community where the rule will be active
match string Depending on the value of type it should be either a string or a Regular Expression
type string, either "regex" or "exact" Type of filter applied in match. If the filter is set to "regex", match will be treated as a Regular Expression; if set to "exact" all comments containing the string specified in match will be removed
whitelist_exempt boolean, either true or false Set to true if whitelisted users should be exempt from the rule. See Exception for more information on the whitelist
mod_exempt boolean, either true or false Set to true if community moderators should be exempt from the rule
message either string or null The message with which the bot will reply to the removed content. If set to null no reply will be sent
removal_reason either string or null The removal reason which will appear in the modlog. If set to null the reason will be left empty

Note: when type is set to "exact", the search will NOT be CaSe SeNsItIvE. In other words, comments including the word "pizza" will get removed, but comments including the word "Pizza" will NOT.

Additional examples

Bad words

{
    "rule": "comment",
    "community": "general",
    "match": "/stink|fudge/",
    "type": "regex",
    "whitelist_exempt": true,
    "mod_exempt": false,
    "message": "Watch your language!",
    "removal_reason": null
}

Explanation:
This rule removes all comments containing either the word "stink" or the word "fudge" posted in the c/general community. When it does so, it also warns telling them to watch their language. The removal reason in the modlog is left blank. Whitelisted users are immune to this rule, so they will be able to use the words "stink" and fudge" freely, however moderators are not, so their comments will be removed.
This example uses a match based on a Regular Expression.

Prequel posting

{
    "rule": "comment",
    "community": "starwars",
    "match": "/high ground/i",
    "type": "regex",
    "whitelist_exempt": false,
    "mod_exempt": true,
    "message": null,
    "removal_reason": null
}

Explanation:
This rule removes all comments containing the string "high ground", case insensitive. If the user is a moderator in the community their comment will NOT be removed, otherwise it will, even if the user is among those whitelisted in the community. The bot will NOT comment under the removed comment, nor specify a removal reason in the modlog.

Post

A Post rule prescribes the automated removal of a post, based on its title, its content or the link attached to it.

The structure of the rule remains largely unchanged from the Comment rule, having only one additional field not present in the former: the field key.

{
    "rule": "post",
    "community": "memes",
    "field": "title",
    "type": "exact",
    "match": "pizza",
    "whitelist_exempt": false,
    "mod_exempt": false,
    "message": "Your post has been removed because discussions about pizza are prohibited in this community",
    "removal_reason": "Said the word 'pizza'"
}

Explanation:
This rule removes all posts containing the word "pizza" in their title, posted in the community c/memes. The bot will then reply to the removed post explaining that it was removed because discussion about pizza are prohibited. Lastly, it will report the removal in the modlog giving "Said the word 'pizza'" as a removal reason. This rule will be valid for all users, including whitelisted users and moderators.

Keys

Same as Comment, save for one additional key:

Field Name Type Description
field string, either "title", "body", "link" or their combinations Field or fields to be checked by the rule

Example: the sample rule posted above will remove all posts containing the word "pizza" in their title, but it will NOT remove those containing the word "pizza" in their body, such as a text post saying "I really like pizza" NOR their links, such as attaching the URL "pizza.example.com".

To remove these last two occurrences, the bot will require two additional rules with respectively "field": "body" and "field": "link", or a single rule on multiple fields.

Rules on multiple fields

Suppose you wanted to create a rule to remove a post if a keyword was included in either its title, body or link. Instead of having to create multiple rules for separate fields, you can use the shorthand + operator in the field, allowing you to combine multiple fields.

The order of the fields isn't important.

{
    "rule": "post",
    "community": "general",
    "field": "body+title+link",
    "type": "exact",
    "match": "cat",
    "whitelist_exempt": false,
    "mod_exempt": false,
    "message": null,
    "removal_reason": null
}

Explanation:
This rule automatically removes all posts containing the word "cat" in either their title, body or link.

Additional examples

Discord link

{
    "rule": "post",
    "community": "general",
    "field": "link",
    "type": "exact",
    "match": "discord",
    "whitelist_exempt": true,
    "mod_exempt": true,
    "message": "To avoid spam, Discord links are automatically removed",
    "removal_reason": "Contained a Discord link"
}

Explanation:
This rule automatically removes all posts whose link contains the word "discord". This means that any post with a https://discord.com URL will be removed, however posts with the word "discord" in their title or body will NOT be removed. This rule is lifted for whitelisted users and moderators.

Bad word

{
    "rule": "post",
    "community": "general",
    "field": "title+body",
    "type": "regex",
    "match": "/frick/i",
    "whitelist_exempt": false,
    "mod_exempt": false,
    "message": "Watch your language!",
    "removal_reason": null
}

Explanation:
This rule automatically removes all posts containing the word "frick" (case insensitive) in their title or body. It's an example of a rule on multiple fields.

Exception

Mention

Error handling

Clone this wiki locally