7.3 KiB
PointsBot
Table of Contents
Description
This is a bot for Reddit that monitors solutions to questions or problems in a subreddit and awards points to the user responsible for the solution.
This bot was conceived as a response to this request.
The bot will award a point to a redditor when the OP of a submission includes "!Solved" or "!solved" somewhere in a reply to the redditor's comment on that submission. These points will allow the redditor to advance to different levels.
At each level, the redditor's flair for the subreddit will be updated to reflect their current level. However, the bot should not change a mod's flair.
Each time a point is awarded, the bot will reply to the solution comment to notify the redditor of their total points, with a progress bar to show how many points they need to reach the next level and a reminder of the title of the next level. In order to prevent the progress bar from being excessively long, some points will be consolidated into stars instead. Right now, stars are hard-coded to represent 100 points each, but this behavior may be configurable in the future.
The first time a point is awarded, the bot's reply comment will also include a brief message detailing the points system.
Only the submission OP's first "!Solved" comment should result in a point being awarded for each submission.
Installation
Requirements:
- Python 3 (specifically version 3.7 or greater)
- pip (should be installed automatically with Python)
- pipenv
- After installying Python & pip, install by running
pip install pipenv - For other installation options, see here
- After installying Python & pip, install by running
First, download this project using git or by downloading a ZIP archive from
the Github repository using the green Clone or download button. If ZIP, be
sure to extract the files from the archive before moving on.
To install the packages necessary for running the bot, navigate to the project
root directory and run pipenv install.
To uninstall (i.e. delete the project's virtual environment and the installed
python packages), navigate to the project root directory and instead run
pipenv --rm.
Configuration
The bot can be configured by changing the values in the configuration files in the project root directory:
praw.ini- Contains the account information for the bot
pointsbot.ini- Contains settings for bot behavior
You shouldn't have to worry about it, but if you need it, the syntax for the config files can be found on the INI file format's Wikipedia page.
If this is your first time running the bot, you will need to copy
praw.sample.ini to a new file called praw.ini, and likewise copy
pointsbot.sample.ini to a new file called pointsbot.ini. Any instances of
the word "REDACTED" should be replaced with the desired values; other values
should work as-is, but can be changed as desired.
The reason for this is that these config files (especially praw.ini) can
contain sensitive information, and maintaining only sample versions of these
files helps developers to avoid accidentally uploading that sensitive
information to a public (or even private) code repository.
praw.ini
Several credentials are needed for running your bot, each of which is listed in
the praw.ini config file:
client_id: Copy from your app preferences, as specified in the steps below.client_secret: Copy from your app preferences, as specified in the steps below.user-agent: This field can be left as-is, thought if you'd like, you can change it by following these guidelines.username: The username for the bot account.password: The password for the bot account.
In order to make a bot, you must first have a bot account. This could be a personal account, but it is wise to create a dedicate account for the bot, especially one with the word "bot" somewhere in the name.
Once you have that, you can create a Reddit app for the bot. This is needed for authenticating with Reddit.
- First, go to your app preferences.
- Select the "are you a developer? create an app..." button.
- Provide a name for the bot, which could probably be the same as the account's username.
- Select the "script" radio button.
- Provide a brief description.
- For the "about url", you can provide a link to this Github repository: https://github.com/cur33/PointsBot
- Since it is unused, the "redirect uri" can be set to something like: http://www.example.com/unused/redirect/uri
- Select "create app".
Now you should be redirected to a page which contains the credentials you will
need; under the name of the bot is the unlabeled client_id, and below that
with the label "secret" is the client_secret.
If you have already done this in the past, the client_id and client_secret
can be found by navigating to your
app preferences and selecting the "edit"
button for the app under the "developed applications" section.
pointsbot.ini
For now, these settings are pretty straightforward.
The Core section:
subreddit_name: The name of the subreddit to monitorpraw_site_name: This should probably be left alone; it tells the bot which credentials to use when authenticating with Reddit. It's useful for development and easy testing with different accounts without having to modify values in the code.database_name: This is the filepath to the SQLite database file, which ends with the.dbfile extension.
The Levels section is used to determine the available user levels and
corresponding flair texts.
- The key on the left-hand side specifies the title and flair text for the level; the case is ignored, and the text is converted to title case (first letter of each word capitalized, and the rest lowercase).
- The value on the right-hand side of each line is the total number of points required to reach that level.
The order of these lines doesn't matter; the bot will sort them in order of point totals.
Make the bot a mod in your subreddit
Some of the bot's behaviors, e.g. altering redditor flairs, require moderator permissions. It should require just the "Flair" and "Posts" permissions, so you don't need to grant it full permissions.
Usage
The simplest way to run the bot is to navigate to the project root directory and run:
pipenv run python -m pointsbot
Terms of Use for a bot for Reddit
Since this is an open-source, unmonetized program, it should be considered non-commercial, and is thus allowed to use the Reddit API without registration. However, this bot is provided under the permissive MIT license. Therefore, if your use of the bot becomes commercial, you should read the Reddit API terms and register here.
License
Copyright ©2020 Collin U. Rapp. This repository is released under the MIT license.