From 4f9243ff5916c5fde8c5f9e9b5d8f9c161d80b40 Mon Sep 17 00:00:00 2001 From: Slfhstd Date: Wed, 11 Mar 2026 17:29:08 +0000 Subject: [PATCH] changelog added --- CHANGELOG.md | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ea5c723 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,194 @@ +# Changelog - TestPostsBot V2 + +## Overview +Complete refactor of TestPostsBot to be a continuously running, trigger-based posting bot that responds to moderator commands via chat messages. + +## Major Features Added + +### 1. Trigger-Based Posting System +- Bot now runs continuously and listens for chat messages instead of executing once and exiting +- Moderators can trigger posts by sending chat messages containing configured trigger keywords +- Each trigger can post one or multiple posts in sequence +- Posts are made with 2-second delays between submissions to respect rate limiting + +### 2. YAML Configuration Format +- **Changed from:** JSON configuration format +- **Changed to:** YAML configuration format for better readability and maintainability +- New config structure supports nested trigger/post relationships +- Example YAML config provided in `example_config.yaml` + +### 3. Chat Message Handler +- Added chat message watcher that runs as a background thread +- Listens for messages sent to the bot account by moderators +- Implements special `reload-config` command for validating wiki config without making posts +- Validates that sender is a moderator before processing commands +- Tracks processed message IDs to prevent duplicate processing + +### 4. Configuration Validation +- New `validate_config_from_wiki()` function validates YAML format and required structure +- Validates that config has a `posts` key with proper trigger/post structure +- Prevents bot from running with invalid configuration +- `reload-config` command provides feedback on config validity + +### 5. Enhanced Logging +- Added prefixed logging for different operations: `[STARTUP]`, `[POSTING]`, `[CHAT WATCH]` +- Detailed debug output showing: + - Messages received and who sent them + - Moderator status verification + - Trigger matching and posting status + - Config validation results + - Error messages with full tracebacks + +## File Changes + +### New Files +- **example_config.yaml** - Comprehensive example showing trigger and post configuration with multiple scenarios +- **.gitignore** - Added to exclude common files +- **example.env** - Environment configuration template + +### Modified Files + +#### bot.py +**Old Behavior:** +- Ran once, fetched posts from hardcoded config, made posts, and exited +- No continuous operation +- No trigger system + +**New Behavior:** +- Runs continuously in infinite loop +- Spawns chat message watcher as background daemon thread +- Loads triggers from wiki config dynamically +- Only posts when a moderator sends a matching trigger +- Implements `reload-config` special command +- Validates config on startup +- Graceful shutdown on KeyboardInterrupt + +**Key Functions:** +- `chat_message_watcher()` - Monitors inbox stream for moderator messages +- `make_posts()` - Posts to subreddit with rate limit delays +- `main()` - Continuous operation loop with thread management + +#### config.py +**Old Behavior:** +- Fetched JSON config from wiki +- Simple error handling with fallback empty dict + +**New Behavior:** +- Uses `yaml.safe_load()` instead of `json.loads()` +- `fetch_config_from_wiki()` - Fetches and parses YAML config +- `validate_config_from_wiki()` - Validates config format and required keys +- `get_trigger_posts()` - Retrieves posts associated with specific trigger +- Better error messages for YAML parsing failures + +#### requirements.txt +**Added:** +- `PyYAML` - Required for YAML config parsing + +#### README.md +**Complete Rewrite:** +- Added comprehensive documentation for trigger-based system +- Documented new YAML config format with examples +- Explained how moderators trigger posts +- Added setup instructions for environment variables +- Documented `reload-config` command +- Added Docker and standalone running instructions +- Clarified that only moderators can trigger posts + +#### docker-compose.yml +**Updated:** +- Environment variables now leverage .env file +- Updated service configuration for continuous operation + +#### Dockerfile +**Updated:** +- Adjusted for continuous operation mode +- Ensures proper signal handling for graceful shutdown + +### Configuration Examples + +**Old Format (JSON):** +```json +{ + "posts": [ + {"title": "Test Post 1", "body": "Body for post 1"}, + {"title": "Test Post 2", "body": "Body for post 2"} + ] +} +``` + +**New Format (YAML):** +```yaml +posts: + - trigger: "test" + posts: + - title: "Test Post 1" + body: "Body for post 1" + - title: "Test Post 2" + body: "Body for post 2" + + - trigger: "weekly-thread" + posts: + - title: "Weekly Thread 1" + body: "Content" + - title: "Weekly Thread 2" + body: "Content" +``` + +## Operational Changes + +### Before (V1) +- Bot runs, posts hardcoded posts, exits +- Single execution cycle +- Config loaded once at startup +- No way to trigger posts without restarting bot + +### After (V2) +- Bot runs continuously +- Moderators send chat messages to trigger posts +- Config is fetched fresh for each trigger (allows live updates) +- Special `reload-config` command validates configuration +- Background thread handles message monitoring +- Main thread keeps bot alive indefinitely + +## Chat Commands + +### Trigger Posts +Send chat message containing trigger keyword (e.g., "modtestposts", "weekly-thread") +- Bot fetches configured posts for that trigger +- Posts them to the subreddit in sequence +- Replies with confirmation of posts made + +### Reload Config +Send chat message containing "reload-config" +- Bot validates wiki config YAML format +- Replies with success/failure status +- Useful for verifying config before using triggers + +## Technical Improvements + +1. **Concurrency:** Uses threading for background message monitoring while keeping main thread alive +2. **Deduplication:** Tracks processed message IDs in `DB/chat_wiki_requests.txt` to prevent duplicate processing +3. **Recovery:** Graceful error handling with continue on failures in message stream +4. **Validation:** Comprehensive config validation before any operations +5. **Logging:** Detailed logging for debugging and monitoring + +## Compatibility Notes + +- Requires `praw` and `PyYAML` packages +- PRAW version should support `inbox.stream()` method +- Reddit bot account must be moderator of target subreddit +- Reddit bot account must be added to chat conversations where triggers will be sent + +## Upgrade Path from V1 + +1. Update wiki config from JSON to YAML format +2. Restructure config to use triggers (see `example_config.yaml`) +3. Redeploy bot with updated code +4. Send "reload-config" to verify new config works +5. Use trigger keywords to post instead of restarting bot + +--- + +**Version:** 2.0 +**Date:** March 11, 2026 +**Status:** Production Ready