Reddit ModLog Wiki Publisher
This skill helps you work with a Python-based Reddit moderation log publisher that automatically scrapes moderation actions from a subreddit and publishes them to a wiki page.
What This Skill Does
Assists with development, configuration, and maintenance of a Reddit bot that:
Scrapes moderation actions using PRAW (Python Reddit API Wrapper)Stores actions in SQLite database for deduplication and retentionPublishes formatted modlog to a Reddit wiki pageSupports multi-subreddit trackingHandles removal reasons, approvals, and AutoMod actionsAnonymizes moderator identities for privacyCore Architecture
**Main application**: `modlog_wiki_publisher.py` - Single-file application with all core functionality**Database**: `ModlogDatabase` class handles SQLite operations**Configuration**: JSON-based config with CLI override support and environment variable support**Logging**: Per-subreddit log files in `logs/` directory with rotating handlers**Authentication**: Reddit OAuth2 script-type app authenticationStep-by-Step Instructions
1. Python Environment Setup
**CRITICAL**: Always use `/opt/.venv/redditbot/bin/python` for all Python commands in this project.
When running Python commands:
Use full path: `/opt/.venv/redditbot/bin/python`Never use system python or generic `python` commandDependencies are pre-installed in the venv2. Configuration Management
The application supports three configuration methods with priority order:
1. Command line arguments (highest priority)
2. Environment variables (override config file)
3. JSON config file (base configuration)
**First-time setup:**
```bash
cp config_template.json config.json
```
**Environment variables available:**
`REDDIT_CLIENT_ID`, `REDDIT_CLIENT_SECRET`, `REDDIT_USERNAME`, `REDDIT_PASSWORD``SOURCE_SUBREDDIT`, `WIKI_PAGE`, `RETENTION_DAYS`, `BATCH_SIZE``UPDATE_INTERVAL`, `DATABASE_PATH`, `LOGS_DIR``ANONYMIZE_MODERATORS` (must be "true" - enforced for security)`WIKI_ACTIONS`, `IGNORED_MODERATORS`3. Running the Application
**Test configuration and connectivity:**
```bash
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --test
```
**Single run:**
```bash
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME
```
**Continuous daemon mode:**
```bash
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME --continuous
```
**Force wiki update using existing database data:**
```bash
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME --force-wiki
```
**Debug authentication issues:**
```bash
/opt/.venv/redditbot/bin/python scripts/debug_auth.py
```
4. Database Operations
**View recent processed actions:**
```bash
sqlite3 modlog.db "SELECT action_id, action_type, moderator, removal_reason, subreddit, created_at FROM processed_actions ORDER BY created_at DESC LIMIT 10;"
```
**View actions by specific subreddit:**
```bash
sqlite3 modlog.db "SELECT action_type, moderator, target_author, removal_reason FROM processed_actions WHERE subreddit = 'SUBREDDIT_NAME' ORDER BY created_at DESC LIMIT 5;"
```
**Track content lifecycle by target ID:**
```bash
sqlite3 modlog.db "SELECT target_id, action_type, moderator, removal_reason, datetime(created_at, 'unixepoch') FROM processed_actions WHERE target_id LIKE '%CONTENT_ID%' ORDER BY created_at;"
```
**Manual cleanup of old entries:**
```bash
sqlite3 modlog.db "DELETE FROM processed_actions WHERE created_at < date('now', '-30 days');"
```
5. Development and Code Changes
**Git workflow:**
Use conventional commits for all changesIf branch is not main, may commit and push if PR is draft or not openUse multiple commits if neededAlways update CLAUDE.md and README.md when making changes**Code standards:**
Always escape markdown table values (especially removal reasons) for pipesStore pipe-free data in database to prevent markdown issuesConfirm cache file of wiki page and warn if same, interactively ask to force refreshAlways use the specified virtual environment path6. Common Command Line Options
`--source-subreddit`: Target subreddit for reading/writing logs`--wiki-page`: Wiki page name (default: "modlog")`--retention-days`: Database cleanup period (default: 30)`--batch-size`: Entries fetched per run (default: 100)`--interval`: Seconds between updates in daemon mode (default: 300)`--debug`: Enable verbose logging`--test`: Verify configuration without making changes`--force-wiki`: Update wiki using existing database data7. Authentication Requirements
The bot account needs:
Moderator status on the target subredditWiki edit permissions for the specified wiki pageReddit app credentials (script type, NOT web app)8. Security and Privacy Guidelines
**CRITICAL SECURITY REQUIREMENT:**
`anonymize_moderators` MUST be `true` (enforced)Application will refuse to start if set to `false`Shows "AutoModerator", "Reddit", or "HumanModerator" instead of actual usernames**Content linking:**
NEVER point to user profiles (`/u/username`)Only link to actual posts (`/comments/postid/`) or comments (`/comments/postid/_/commentid/`)No link if no actual content is available9. Action Types and Display
**Default tracked actions:**
Removals: `removelink`, `removecomment`, `spamlink`, `spamcomment`Approvals: `approvelink`, `approvecomment`Reasons: `addremovalreason`**Display behavior:**
Manual actions shown as-isAutoMod filters shown with `filter-` prefix (e.g., `filter-removelink`)Removal reasons combined with removal actionsHuman approvals only shown for reversals of Reddit/AutoMod actionsApproval context shows original removal reason and moderator10. File Structure
`modlog_wiki_publisher.py`: Main application`scripts/debug_auth.py`: Authentication debugging utility`tests/test_removal_reasons.py`: Test suite for removal reason processing`config.json`: Runtime configuration (created from template)`data/`: Runtime data directory (database files)`logs/`: Per-subreddit log files`requirements.txt`: Python dependencies11. Troubleshooting Common Issues
**401 errors:**
Check app type is "script" (not web app)Verify client_id and client_secret are correct**Wiki permission denied:**
Ensure bot has moderator or wiki contributor accessCheck wiki page permissions in subreddit settings**Rate limiting:**
Increase `--interval` valueReduce `--batch-size`**Module not found:**
Always use `/opt/.venv/redditbot/bin/python` instead of system pythonExamples
**Run single update with debug logging:**
```bash
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit mysubreddit --debug
```
**Run in daemon mode with custom interval:**
```bash
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit mysubreddit --continuous --interval 600
```
**Check recent removals in database:**
```bash
sqlite3 modlog.db "SELECT action_type, target_author, removal_reason FROM processed_actions WHERE action_type LIKE '%remove%' ORDER BY created_at DESC LIMIT 5;"
```
Important Notes
Database schema is at version 5 with all required columnsSingle database safely handles multiple subreddits with proper data separationAll removal reasons show full transparency (actual text, not just "Removal reason applied")Content IDs are unique for precise tracking (comments show comment IDs, posts show post IDs)AutoModerator displays as "AutoModerator" (not anonymized)Human moderators are anonymized to "HumanModerator"