Changes to enable always on and trigger emthod. also updated to yaml config structure
This commit is contained in:
@@ -1,24 +1,98 @@
|
||||
# Reddit TestPostsBot
|
||||
|
||||
## Usage
|
||||
A Reddit bot that makes test posts to your subreddit when triggered via private messages by moderators.
|
||||
|
||||
1. Fill in your Reddit API credentials and subreddit name in `bot.py`.
|
||||
2. Create a wiki page in your subreddit named `testpostsbot_config` with JSON like:
|
||||
## How It Works
|
||||
|
||||
```
|
||||
{
|
||||
"posts": [
|
||||
{"title": "Test Post 1", "body": "Body for post 1"},
|
||||
{"title": "Test Post 2", "body": "Body for post 2"}
|
||||
]
|
||||
}
|
||||
1. The bot runs continuously and listens for private messages sent to its account
|
||||
2. When a moderator sends a message containing a trigger keyword, the bot checks the wiki config
|
||||
3. If the trigger is found and valid, the bot posts the configured posts to the subreddit
|
||||
4. The bot replies to the moderator confirming success or failure
|
||||
|
||||
## Setup
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Set these variables via environment or directly in `bot.py`:
|
||||
|
||||
- `REDDIT_CLIENT_ID`: Your Reddit app's client ID
|
||||
- `REDDIT_CLIENT_SECRET`: Your Reddit app's client secret
|
||||
- `REDDIT_USERNAME`: The bot account's username
|
||||
- `REDDIT_PASSWORD`: The bot account's password
|
||||
- `REDDIT_USER_AGENT`: (Optional) Custom user agent string
|
||||
- `SUBREDDIT`: The subreddit to post to (without the /r/)
|
||||
- `WIKI_PAGE`: (Optional) Wiki page for config (default: `testpostsbot_config`)
|
||||
|
||||
### Wiki Configuration
|
||||
|
||||
Create a wiki page in your subreddit named `testpostsbot_config` (or set `WIKI_PAGE` env var) with YAML formatted triggers and posts:
|
||||
|
||||
```yaml
|
||||
posts:
|
||||
- trigger: "summer-schedule"
|
||||
posts:
|
||||
- title: "Summer Announcement Post"
|
||||
body: "This is the summer announcement."
|
||||
- title: "Summer Rules Update"
|
||||
body: "New summer rules are now in effect."
|
||||
|
||||
- trigger: "test"
|
||||
posts:
|
||||
- title: "Test Post"
|
||||
body: "This is a test post."
|
||||
|
||||
- trigger: "weekly-thread"
|
||||
posts:
|
||||
- title: "Weekly Discussion Thread"
|
||||
body: |
|
||||
This is the weekly discussion thread.
|
||||
Feel free to discuss anything related to the subreddit.
|
||||
```
|
||||
|
||||
3. Build and run with Docker:
|
||||
Each trigger can have one or multiple posts. Posts are made in order with a 2-second delay between each to avoid rate limiting.
|
||||
|
||||
```
|
||||
### Triggering Posts
|
||||
|
||||
To trigger posts, send a private message to the bot account containing the trigger keyword. For example:
|
||||
|
||||
- Message: "Can you run summer-schedule?" → Posts the summer schedule posts
|
||||
- Message: "Trigger: test" → Posts the test post
|
||||
- Message: "Please post weekly-thread" → Posts the weekly discussion thread
|
||||
|
||||
Only moderators of the subreddit can trigger posts.
|
||||
|
||||
## Running the Bot
|
||||
|
||||
### Docker
|
||||
|
||||
```bash
|
||||
docker build -t testpostsbot .
|
||||
docker run --env REDDIT_CLIENT_ID=... --env REDDIT_CLIENT_SECRET=... --env REDDIT_USERNAME=... --env REDDIT_PASSWORD=... --env SUBREDDIT=... testpostsbot
|
||||
docker run \
|
||||
--env REDDIT_CLIENT_ID=your_client_id \
|
||||
--env REDDIT_CLIENT_SECRET=your_client_secret \
|
||||
--env REDDIT_USERNAME=bot_username \
|
||||
--env REDDIT_PASSWORD=bot_password \
|
||||
--env SUBREDDIT=your_subreddit \
|
||||
testpostsbot
|
||||
```
|
||||
|
||||
Or edit the variables directly in `bot.py` for quick testing.
|
||||
### Docker Compose
|
||||
|
||||
```bash
|
||||
# Edit docker-compose.yml with your credentials
|
||||
docker-compose up
|
||||
```
|
||||
|
||||
### Standalone
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
python bot.py
|
||||
```
|
||||
|
||||
## Configuration Notes
|
||||
|
||||
- The wiki config is validated on startup. If the YAML is malformed, the bot will not start.
|
||||
- The config is fetched fresh for each trigger, so you can update the wiki while the bot is running.
|
||||
- Only the first matching trigger per message is processed.
|
||||
- All processed messages are tracked in `DB/chat_wiki_requests.txt` to avoid duplicate processing.
|
||||
|
||||
Reference in New Issue
Block a user