Reddit 机器人用于预览和以评论的形式发布超链接
A Reddit bot that previews hyperlinks and posts their contents as a comment. It should never spam or double-post, and will skip a comment if it is too long.
PRs are always welcome.
release-v1.2.3) from the develop branchconfig.py to the release branchmaster and developThis project follows this Git branching workflow.
The program requires an environmental variable SUBREDDIT to be set.
This specifies the subreddit that the bot will monitor.
If it's not set, the default subreddit /r/all will be monitored.
At the moment, only 1 subreddit may be specified.
All the commands below assume that the virtual environment has been activated
(pipenv shell).
SUBREDDIT=name python main.py (or SUBREDDIT=name nohup python main.py &)invoke testThis application can be built and run as a Docker image.
main.py starts the bot and calls scan(subreddit) (in scan.py),
which monitors for new submissions in the provided subreddit.
For each new submission, scan checks if they qualify for preview
by calling qualify (in qualify.py).
A submission qualifies for preview if it:
If a submission qualifies, scan calls the handle method of the Handler
to generate the raw comment, then format_comment(comment) in the
comments module to generate the final comment in Markdown.
If the final comment in Markdown does not exceed a pre-configured comment length
(config.COMMENT_LENGTH_LIMIT), the comment is posted, and the action written
to the database (through DatabaseManager) to prevent double-posting.
Logging is written to standard output, and logging level can be configured in
config.py.
handler.py contains a HandlerManager that checks if a website has a Handler.
A Handler is a class with a @classmethod handle(cls, url) that accepts a URL
and returns a Comment. All Handlers must inherit from AbstractBaseHandler.
The Handler can be part of a module or package, and have as many supporting sub-modules or sub-packages as necessary.
The comments module (in comment.py) exports the Comment class,
which all Handlers must return. A Comment class requires a title and body,
and accepts a byline and attribution (which are optional).
暂无开放 Issues,或尚未同步最近议题。