Modularized reddit moderation bot with a focus on spam prevention.
- Ability to create individual "filters" to perform individual functions
- Filters customizable through a subreddit wiki page using YAML
- Default filters
- YouTube channel bans and monitors: affects link posts, text posts, and comments
- Python 3.4+
- praw
- PyYAML
- YouTube channel bans:
youtube-channel
- YouTube vote manipulation monitor:
youtube-votemanip
To create a new filter, create or edit a python file in the filters
directory. Create a class extending spam_shark.Filter
and one or more filter types.
from spam_shark import Filter, FilterResult, LinkFilter
class TemplateFilter(Filter, LinkFilter):
filter_id = "filter-template" # Required, used in wiki config
def init_filter(self, configs):
# Do filter initialization here
# A list of parsed YAML rules are passed in through 'configs'
def update(self):
# OPTIONAL
# Do stuff each iteration before posts and comments are processed
def process_link(self, link, thing):
# Process a link within a thing (post or comment)
# Returns a filter result and map of message actions
if "domain.spam" in link:
return FilterResult.REMOVE, {"log": (log_title, log_body), "reply": reply_body}
Defined in module spam_shark
-
LinkFilter
: Requires definition ofprocess_link(self, link, thing)
-
PostFilter
: Requires definition ofprocess_post(self, link)
-
CommentFilter
: Requires definition ofprocess_comment(self, comment)
-
MessageFilter
: Requires definition ofprocess_message(self, message)
Defined in enum spam_shark.FilterResult
-
REMOVE
: Removes the processed thing, performs message actions, and logs the action -
MESSAGE
orFLAIR
: Performs message actions (including flair) and logs the actionRequires one or more of the following defined in message actions:
"modmail": (modmail_title, modmail_body)
"reply": reply_body
"pm": (pm_title, pm_body)
"flair_user": (flair_text, flair_css_class)
"flair_post": (flair_text, flair_css_class)
(only applies to posts)
-
LOG
: Logs the actionRequires
"log": (log_title, log_body)
defined in message actions -
REPORT
: Reports the submission and does nothing elseRequires
"reason": reason_msg
defined in message actions
All message texts (title and body) are auto-formatted with basic post information using Python format syntax. The available values are:
author
permalink
title
: Not available for comment actions.body
link
: Only available on posts (empty if self post).subreddit
Filters can be configured through a subreddit wiki page (defaults to /wiki/spamshark
) using YAML syntax. Exact format of a configuration section depends on the filter, but every section must specify a filter ID to which the config applies.
After the configuration page is edited, send a PM to the bot account with the name of the subreddit as a subject and "update" in the body.
Example using the template above:
# Template configuration
---
filter: "filter-template"
# Filter custom stuff
# ...