8.8 KiB
8.8 KiB
Changelog - TestPostsBot
Version 2.1.0 - Update Checker System
New Features
1. Update Checker System
- Bot now periodically checks for new versions from a centralized update server
- Automatically sends modmail notifications to subreddit modteam when updates are available
- Includes changelog URL in notification for easy reference
- 24-hour cooldown prevents spam (max 1 notification per day)
- Runs as a background daemon thread alongside main bot operations
- Tracks last update notification timestamp to file for persistence across restarts
2. Version Management
- Bot version is now centralized at the top of
bot.pyin a dedicated section BOT_VERSIONandBOT_NAMEconstants used throughout the bot- Easy single-location reference for version updates
- Version automatically included in update checker calls and user agent string
3. Infrastructure
- Created separate
update_server/project for version management service - Flask-based REST API serving version information via
/api/version/<bot_name> versions.jsonfile stores version details for all bots- Docker support with Dockerfile for containerized deployment
- Includes comprehensive README with deployment options
New Files
- update_checker.py - Background module that checks for and notifies about updates
Modified Files
bot.py
- Added version constants section at top for easy reference
- Added import for
update_checkermodule - Added
start_update_checker()call inmain()function - User agent now uses version constants:
{BOT_NAME}/{BOT_VERSION}
requirements.txt
- Added
requestslibrary for HTTP requests to update server
docker-compose.yml
- Volume mounts for persistent
versions.jsonand log files
Configuration
Update checker timing is configurable in update_checker.py:
UPDATE_CHECK_INTERVAL = 60seconds (check frequency)UPDATE_COOLDOWN = 86400seconds (24 hours between notifications)
How It Works
- On startup, bot creates background thread running update checker
- Every hour, thread polls
https://updts.slfhstd.uk/api/version/TestPostsBot - If version differs from current
BOT_VERSION, and 24 hours have passed since last notification, sends modmail - Modmail includes current version, available version, and changelog URL
- Last notification timestamp stored in
DB/.last_update_check.txt
Version 2.0.0 - Trigger-Based Redesign
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-configcommand 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
postskey with proper trigger/post structure - Prevents bot from running with invalid configuration
reload-configcommand 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-configspecial command - Validates config on startup
- Graceful shutdown on KeyboardInterrupt
Key Functions:
chat_message_watcher()- Monitors inbox stream for moderator messagesmake_posts()- Posts to subreddit with rate limit delaysmain()- 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 ofjson.loads() fetch_config_from_wiki()- Fetches and parses YAML configvalidate_config_from_wiki()- Validates config format and required keysget_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-configcommand - 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):
{
"posts": [
{"title": "Test Post 1", "body": "Body for post 1"},
{"title": "Test Post 2", "body": "Body for post 2"}
]
}
New Format (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-configcommand 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
- Concurrency: Uses threading for background message monitoring while keeping main thread alive
- Deduplication: Tracks processed message IDs in
DB/chat_wiki_requests.txtto prevent duplicate processing - Recovery: Graceful error handling with continue on failures in message stream
- Validation: Comprehensive config validation before any operations
- Logging: Detailed logging for debugging and monitoring
Compatibility Notes
- Requires
prawandPyYAMLpackages - 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
- Update wiki config from JSON to YAML format
- Restructure config to use triggers (see
example_config.yaml) - Redeploy bot with updated code
- Send "reload-config" to verify new config works
- Use trigger keywords to post instead of restarting bot
Version: 2.0
Date: March 11, 2026
Status: Production Ready