Reddit modbot is a relatively lightweight script for automating reddit moderating tasks. It was written as a simpler alternative to AutoModerator by Deimos.
- Does not require a database or other semi-complicated setup.
- Runs continously to avoid startup penalty
- Defining rules is fairly simple due to simple rules files format
- Automatically updates rules when you edit/add/remove them on disk
- Will never re-evaluate an item, which saves time
- Built with single-subreddit usage in mind. Though this could likely be fixed without too many changes.
- Rules files are not as flexible as AutoModerator rules
- All rules are regex, which makes matching numbers slightly convoluted
- Will never re-evaluate an item, which means it's not really possible to react to items getting downvoted or reported.
Requirements (both available in pypi):
Run it like this:
modbot.py -r /path/to/rules/dir mysubreddit
Additionally, you may pass in the username and password for your reddit user.
A rules file is a file ending in .rule, placed in the rules dir.
For every item the bot inspects, it will try to match it against each rule, in order by filename of each rule. If a rule matches, no further rules will be applied.
A rules file contains any number of line of the form "Key: value". After these lines, you may include a rule body, which should be preceded by a blank line. The purpose of this will be described later.
The value of a rule is a regular expression that will be applied to the given value of the item in question (case-insensitively).
Rule lines in the header of the rule, starting with a # character are ignored. The order of rule lines is ignored.
The header lines describe what conditions the comment or post much fullfil to match the rule - or which actions to take. All of these can be negated by adding a ! in front of the field name. In that case, the rule will only match if that condition doesn't. Possible conditions are:
Field | Description |
---|---|
Username | name of the author |
Numreports | number of reports (this is not too useful currently) |
Domain | domain of the post |
Title | title of post |
Upvotes | number of upvotes |
Downvotes | number of downvotes |
Score | upvotes-downvotes |
Type | 'comment' or 'submission' |
Body | content of comment or self-post |
Bodylength | length of body |
Dayhour | time of submission on the form Tue-19 in UTC |
Userage | Age of author account in days |
Userkarma | Combined karma of the author account |
In addition to any number of these, you should include a line named "Actions", with the value being a comma seperated list of actions to take when the rule matches. Possible actions are:
Action | Description> |
---|---|
upvote | upvote the item |
log | write an entry to the rulelogger logging logger |
spam | mark the item as spam |
remove | remove the item (but don't mark as spam) |
approve | approve the item |
respond | post a distinguished comment, using the body of the rule as a template, using new style python string formatting with the objects "rule", "thing" and "matches"available. See below for an example. |
messagemods:target | message the mods of the subreddit "target", using the rule body. |
beep | write a BEL character to the terminal |
messageauthor | message the author, using the rule body as template. |
report | report the item |
none | do nothing |
linkflair:flairclass:flairtext | set the linkflair class "flairclass" and text "flairtext" on the item |
Domain: (quickmeme.com|qkme.me|memegenerator.net|weknowmemes.com)
Actions: log,spam,respond
Please do not submit memes to this subreddit.
***
I am an automated bot - please [contact the mods](http://www.reddit.com/message/compose?to=%2Fr%2Fmysubreddit) if you believe I made a mistake.
This rules matches any post submitted from a number of meme sites and posts a comment in the thread, as well as marks the submission as spam to train the spam filter.
Type: comment
Body: digg
Actions: log,messagemods
Description: Burn the witch!
Subject: Someone mentioned digg
User /u/{thing.author.name} in [this comment]({thing.permalink}?context=3) (thread *{thing.submission.title}*)
***
{thing.body}
This rule will match any comment including the word "digg" and alert the mods. Note the use of Python string formatting to include the object's content and a permalink. "thing" is either a Comment or Submission object as defined by the praw library (https://github.com/praw-dev/praw).
The "Description" line is not used, but simply there as a human-readable explanation.
Type: comment
Body: (Batman|Bruce Wayne|Dark Knight)
Actions: log,messagemods
Subject: Someone talking about batman
A user mentioned batman in [this comment]({thing.permalink}), using {matches[body][full]} to refer to him.
This rule uses the matches dict, which includes a key for each matching rule. For each rule, it includes a key named "full", containing the entire match, plus a key for each named group the regex contains (in this case none).