Skip to content

Commit d3b28c8

Browse files
bakerboy448claudeCopilot
authored
Major improvements to modlog publisher - multi-subreddit support, removal reason fixes, and transparency (#1)
* Add major improvements to modlog publisher - Add configuration limits and validation system with automatic enforcement - Implement database schema versioning and migration system (v0 -> v2) - Add improved action tracking with display IDs (P1a2b3c format) and metadata - Update wiki table format with new ID column for better content tracking - Add error handling improvements for continuous mode with exponential backoff - Add new CLI options: --show-config-limits, --force-migrate - Update configuration template with new defaults and additional options - Update README with comprehensive documentation for all new features - Replace OOP architecture with simpler functional approach - Add comprehensive database queries for content lifecycle tracking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add automatic config file update functionality - Auto-updates config file when new defaults are available - Creates backup before making changes (.backup extension) - Preserves existing user settings - Add --no-auto-update-config flag to disable if needed - Update documentation with auto-update information - Handles errors gracefully with fallback to in-memory defaults 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix modlog data type handling and add configurable action filtering - Fix timestamp handling for both datetime objects and Unix timestamps - Fix moderator name handling for both string and object types - Fix target attribute handling to prevent 'str' object has no attribute 'name' errors - Add moderator name censoring: AutoMod, Reddit, HumanModerator - Add configurable wiki_actions filter (default: removals and removal reasons only) - Preserve original wiki content formatting 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add force refresh functionality for wiki rebuilding from database * Improve modlog output with markdown links and configurable moderator anonymization - Convert inquiry URLs to markdown format ([Inquire](url) instead of plain URLs) - Add configurable moderator anonymization (anonymize_moderators setting) - Store removal reasons from Reddit API in database (new removal_reason column) - Update database schema to version 3 with proper migration - Update CLAUDE.md and README.md with new features and configuration options 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix removal reason storage to show content instead of numbers - Process removal reasons properly by stripping whitespace before storage - Update database query in get_recent_actions_from_db to include removal_reason column - Use actual removal reason content in MockAction instead of hardcoded text - Add test script to verify removal reason processing without Reddit API calls - Fix database schema query to use created_at instead of timestamp for consistency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add wiki hash caching to avoid unnecessary Reddit updates - Cache SHA-256 hashes of wiki content per subreddit/page in database - Skip Reddit API calls when content hasn't changed - Add --force option to bypass hash check when needed - Add v4 database migration for wiki_hash_cache table - Update all wiki update calls to use hash caching 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix critical bugs: subreddit mixing and invalid IDs - Add subreddit column to database to prevent mixing modlogs from different subreddits - Fix ID generation to never use user IDs, always use post/comment/action IDs - Add email address censoring in removal reasons - Update database schema to version 5 - Fix get_recent_actions_from_db to filter by subreddit - Update store_processed_action to include subreddit context 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix critical modlog bugs: proper IDs, removal reasons, and subreddit safety - Fixed removal reasons showing as numbers by checking mod_note field - Fixed display IDs to use permalinks instead of user IDs - Added strict subreddit validation to prevent mixed subreddit wiki corruption - Enhanced target ID extraction to get actual post/comment IDs - Added bot attribution footer to wiki pages - Improved permalink generation for better content linking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix --force-refresh functionality and improve permalink handling - Fix case-insensitive subreddit matching in database queries - Add subreddit extraction from permalinks - Simplify content link formatting to match main branch approach - Use actual Reddit permalinks for removed content - Add database update function for missing subreddit entries - Improve safety checks to prevent mixed subreddit data 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Improve force-refresh to fetch all modlog actions and update database - Force-refresh now fetches all modlog actions from Reddit to populate database - Store ALL action types in database but only show removal actions in wiki - Separate database population from wiki display logic - Ensure comprehensive modlog data collection while maintaining wiki focus Testing with Usenet subreddit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix content links and align modmail with main branch - Remove user profile fallback links - NEVER link to user profiles - Prioritize actual content permalinks (posts/comments) over user profiles - Implement proper content ID extraction for markdown ID field - Align modmail inquiry format with main branch (detailed prefilled message) - Add content link guidelines to CLAUDE.md - Fix case sensitivity in subreddit validation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix wiki table to match requirements: proper content IDs and no user profile links - ID field now shows actual Reddit content IDs (t3_abc123, t1_def456) instead of user-based IDs - Content links only point to actual removed posts/comments, never user profiles - Show '-' for ID field when no content ID available (unlinkable actions) - Remove action ID fallback - only use actual content IDs for linking removals - Enable proper linking of removal actions with their removal reasons via content ID 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix content field formatting to match main branch approach - Use main branch logic for comment/post detection (permalink slash count) - Show actual titles when available - Show 'Comment by u/username' for comments without titles - Show 'Post by u/username' for posts without titles - Only create links for actual content URLs, not user profiles - Maintain main branch content field behavior while adding ID column 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix removal reason display to show actual text instead of numbers - Always prioritize mod_note (actual removal reason text) over numeric details - Show 'Removal reason applied' instead of 'Removal reason #7' for numeric details - Improve ID extraction to handle more cases (though many will still be '-' due to Reddit API limitations) - Apply consistent removal reason handling in both storage and display functions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix modlog markdown format to match main branch requirements - Add ID column back for tracking actions across the table - Fix removal reason prioritization to show text first, not numbers - For addremovalreason actions, use mod_note instead of details - Extract short content IDs from permalinks for table tracking - Ensure AutoModerator shows correctly (not HumanModerator) - Content links point to actual posts/comments, not user profiles 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update documentation to reflect v2.0 improvements and fixes - Update README.md with current wiki output format examples - Add section on recent improvements including content linking fixes - Update database query examples to include subreddit column - Document intelligent removal reason handling (text over numbers) - Add multi-subreddit support documentation - Update CLAUDE.md with new database operations and schema info - Document content ID extraction and tracking features 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Add content ID to modmail inquiries for easier tracking - Include content ID in modmail subject line: [ID: 1mkz4jm] - Add Content ID field to modmail body for moderator reference - Enables moderators to quickly cross-reference inquiries with modlog entries - Improves modmail workflow and response efficiency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Rename and improve force command options for clarity - Replace --force with more intuitive options: - --force-modlog: Fetch ALL from Reddit API and rebuild - --force-wiki: Force wiki update (bypass cache) - --force-all: Do both (replaces old --force) - Update documentation with clear explanations and examples - Add usage guidance for when to use each force option - Maintain backwards compatibility during transition 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix multi-subreddit database support Removes the erroneous error condition that prevented the application from working with databases containing multiple subreddits. The application now properly supports multi-subreddit databases by filtering results by the requested subreddit while providing informational logging about available subreddits. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix target_author display showing [deleted] instead of actual usernames Updates the database query to include target_author column and properly populates MockAction objects with actual usernames from the database, preventing the fallback to [deleted] placeholder text. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update CLAUDE.md * fixes * Update modlog_wiki_publisher.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modlog_wiki_publisher.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: don't force wiki just because modlog * human fixups * Update modlog_wiki_publisher.py * Update modlog_wiki_publisher.py * Update modlog_wiki_publisher.py * Update modlog_wiki_publisher.py * Update modlog_wiki_publisher.py * Update modlog_wiki_publisher.py * Update modlog_wiki_publisher.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update modlog_wiki_publisher.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix removal reason display to show actual text instead of generic message Changes action.description to action.details (Reddit API field) and updates logic to only show generic message for removal reason template numbers 1-15, allowing actual removal reason text to display properly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Show all removal reason information, never use generic message Removes logic that hides removal reason template numbers (1-15) behind generic "Removal reason applied" message. Now shows all available removal reason data including template numbers for full transparency. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix duplicate IDs and removal reason display consistency - Reorder regex patterns to extract comment IDs before post IDs, fixing duplicate ID issue - Fix display logic to use action.details consistently with storage logic - Ensures removal reasons show properly in wiki output 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update documentation and fix --force-wiki functionality - Update README.md with latest improvements and multi-subreddit support - Update CLAUDE.md with v2.1 improvements summary - Fix --force-wiki to rebuild from database without API calls - Ensure --force-wiki always recreates wiki using existing data 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove fallback text in MockAction details * docs: refactor CLAUDE.md for better organization - Reorganized sections for clarity and logical flow - Added prominent venv path requirement - Grouped configuration options by category - Enhanced development guidelines section - Improved formatting and structure 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: addremovalreason actions now show actual removal reason text instead of template numbers - For addremovalreason actions, use description field which contains actual text like 'Invites - No asking' - Fixes template numbers (6, 9, etc) showing instead of meaningful removal reasons - Maintains existing logic for other action types using mod_note and details fields - Improves removal reason transparency for manual moderator actions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: update README with latest transparency improvements - Updated sample wiki output to show actual removal reasons - Enhanced database schema documentation with transparency details - Updated features to highlight complete removal reason transparency - Shows AutoModerator rule text and addremovalreason descriptions - Documents unique content ID tracking improvements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: resolve undefined variables and code quality issues - Add missing BASE_BACKOFF_WAIT and MAX_BACKOFF_WAIT constants for exponential backoff - Initialize first_run_force variable in continuous mode function - Add sanitize_for_markdown() helper function to eliminate code duplication - Replace all instances of pipe character replacement with consistent helper function - Improves code maintainability and prevents NameError exceptions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: add helper function for config access with default fallback - Add get_config_with_default() helper to eliminate code duplication - Replace 7 instances of config.get(key, CONFIG_LIMITS[key]['default']) pattern - Improve code maintainability and consistency - Add validation for unknown config keys - Reduces repetitive nested dictionary access throughout codebase 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: correct database column name mismatch in force refresh query Fixed incorrect variable name 'timestamp' to 'created_at' to match the database schema. This was causing force-wiki operations to fail with "table processed_actions has no column named timestamp" error. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add TRACE level logging for Reddit API debugging Added TRACE level (level 5) logging for prawcore and urllib3 when debug mode is enabled, providing detailed Reddit API request/response information for troubleshooting authentication and API issues. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: ensure regular wiki updates show all relevant actions not just new ones Modified regular operation logic to rebuild wiki from ALL relevant actions in database (within retention period) rather than only new actions, matching the behavior of force operations for consistent wiki display. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d8e0bc0 commit d3b28c8

5 files changed

Lines changed: 1651 additions & 870 deletions

File tree

CLAUDE.md

Lines changed: 96 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,43 @@ This is a Python-based Reddit moderation log publisher that automatically scrape
1616

1717
## Development Commands
1818

19+
**IMPORTANT**: Always use `/opt/.venv/redditbot/bin/python` for all Python commands in this project.
20+
1921
### Setup and Dependencies
2022
```bash
21-
# Install dependencies
22-
pip install praw
23-
23+
# Dependencies are pre-installed in the venv
2424
# Copy template config (required for first run)
2525
cp config_template.json config.json
2626
```
2727

2828
### Running the Application
2929
```bash
3030
# Test connection and configuration
31-
python modlog_wiki_publisher.py --test
31+
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --test
3232

3333
# Single run
34-
python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME
34+
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME
3535

3636
# Continuous daemon mode
37-
python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME --continuous
37+
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME --continuous
38+
39+
# Force wiki update only (using existing database data)
40+
/opt/.venv/redditbot/bin/python modlog_wiki_publisher.py --source-subreddit SUBREDDIT_NAME --force-wiki
3841

3942
# Debug authentication issues
40-
python debug_auth.py
43+
/opt/.venv/redditbot/bin/python debug_auth.py
4144
```
4245

4346
### Database Operations
4447
```bash
45-
# View recent processed actions
46-
sqlite3 modlog.db "SELECT * FROM processed_actions ORDER BY created_at DESC LIMIT 10;"
48+
# View recent processed actions with removal reasons
49+
sqlite3 modlog.db "SELECT action_id, action_type, moderator, removal_reason, subreddit, created_at FROM processed_actions ORDER BY created_at DESC LIMIT 10;"
50+
51+
# View actions by subreddit
52+
sqlite3 modlog.db "SELECT action_type, moderator, target_author, removal_reason FROM processed_actions WHERE subreddit = 'usenet' ORDER BY created_at DESC LIMIT 5;"
53+
54+
# Track content lifecycle by target ID
55+
sqlite3 modlog.db "SELECT target_id, action_type, moderator, removal_reason, datetime(created_at, 'unixepoch') FROM processed_actions WHERE target_id LIKE '%1mkz4jm%' ORDER BY created_at;"
4756

4857
# Manual cleanup of old entries
4958
sqlite3 modlog.db "DELETE FROM processed_actions WHERE created_at < date('now', '-30 days');"
@@ -53,13 +62,26 @@ sqlite3 modlog.db "DELETE FROM processed_actions WHERE created_at < date('now',
5362

5463
The application supports both JSON config files and CLI arguments (CLI overrides JSON):
5564

65+
### Core Options
5666
- `--source-subreddit`: Target subreddit for reading/writing logs
5767
- `--wiki-page`: Wiki page name (default: "modlog")
5868
- `--retention-days`: Database cleanup period (default: 30)
5969
- `--batch-size`: Entries fetched per run (default: 100)
6070
- `--interval`: Seconds between updates in daemon mode (default: 300)
6171
- `--debug`: Enable verbose logging
6272

73+
### Display Options
74+
- `anonymize_moderators`: Whether to show "HumanModerator" for human mods (default: true)
75+
- `true` (default): Shows "AutoMod", "Reddit", or "HumanModerator"
76+
- `false`: Shows actual moderator usernames
77+
78+
### Database Features
79+
- **Multi-subreddit support**: Single database handles multiple subreddits safely
80+
- **Removal reason storage**: Full text/number handling from Reddit API
81+
- **Target author tracking**: Actual usernames stored and displayed
82+
- **Content ID extraction**: Unique IDs from permalinks for precise tracking
83+
- **Data separation**: Subreddit column prevents cross-contamination
84+
6385
## Authentication Requirements
6486

6587
The bot account needs:
@@ -80,8 +102,70 @@ The bot account needs:
80102

81103
Use `--test` flag to verify configuration and Reddit API connectivity without making changes.
82104

105+
## Content Link Guidelines
106+
107+
**CRITICAL**: Content links in the modlog should NEVER point to user profiles (`/u/username`). Links should only point to:
108+
- Actual removed posts (`/comments/postid/`)
109+
- Actual removed comments (`/comments/postid/_/commentid/`)
110+
- No link at all if no actual content is available
111+
112+
User profile links are a privacy concern and not useful for modlog purposes.
113+
114+
## Recent Improvements (v2.1)
115+
116+
### Multi-Subreddit Database Support
117+
- ✅ Fixed critical error that prevented multi-subreddit databases from working
118+
- ✅ Single database now safely handles multiple subreddits with proper data separation
119+
- ✅ Per-subreddit wiki updates without cross-contamination
120+
- ✅ Subreddit-specific logging and error handling
121+
122+
### Removal Reason Transparency
123+
- ✅ Fixed "Removal reason applied" showing instead of actual text
124+
- ✅ Full transparency - shows ALL available removal reason data including template numbers
125+
- ✅ Consistent handling between storage and display logic using correct Reddit API fields
126+
- ✅ Displays actual removal reasons like "Invites - No asking", "This comment has been filtered due to crowd control"
127+
128+
### Unique Content ID Tracking
129+
- ✅ Fixed duplicate IDs in markdown tables where all comments showed same post ID
130+
- ✅ Comments now show unique comment IDs (e.g., "n7ravg2") for precise tracking
131+
- ✅ Posts show post IDs for clear content identification
132+
- ✅ Each modlog entry has a unique identifier for easy reference
133+
134+
### Content Linking and Display
135+
- ✅ Content links point to actual Reddit posts/comments, never user profiles for privacy
136+
- ✅ Fixed target authors showing as [deleted] - now displays actual usernames
137+
- ✅ Proper content titles extracted from Reddit API data
138+
- ✅ AutoModerator displays as "AutoModerator" (not anonymized)
139+
- ✅ Configurable anonymization for human moderators
140+
141+
### Data Integrity
142+
- ✅ Pipe character escaping for markdown table compatibility
143+
- ✅ Robust error handling for mixed subreddit scenarios
144+
- ✅ Database schema at version 5 with all required columns
145+
- ✅ Consistent Reddit API field usage (action.details vs action.description)
146+
147+
## Development Guidelines
148+
149+
### Git Workflow
150+
- If branch is not main, you may commit and push if a PR is draft or not open
151+
- Use conventional commits for all changes
152+
- Use multiple commits if needed, or patch if easier
153+
- Always update CLAUDE.md and README.md when making changes
154+
155+
### Code Standards
156+
- Always escape markdown table values like removal reasons for pipes
157+
- Store pipe-free data in database to prevent markdown issues
158+
- Confirm cache file of wiki page and warn if same, interactively ask to force refresh
159+
- Always use the specified virtual environment path
160+
161+
### Documentation
162+
- Always update commands and flags in documentation
163+
- Remove CHANGELOG from CLAUDE.md (keep separate)
164+
- Create and update changelog based on git tags (should be scripted)
165+
83166
## Common Issues
84167

85-
- 401 errors: Check app type is "script" and verify client_id/client_secret
86-
- Wiki permission denied: Ensure bot has moderator or wiki contributor access
87-
- Rate limiting: Increase `--interval` and/or reduce `--batch-size`
168+
- **401 errors**: Check app type is "script" and verify client_id/client_secret
169+
- **Wiki permission denied**: Ensure bot has moderator or wiki contributor access
170+
- **Rate limiting**: Increase `--interval` and/or reduce `--batch-size`
171+
- **Module not found**: Always use `/opt/.venv/redditbot/bin/python` instead of system python

README.md

Lines changed: 101 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ Automatically publishes Reddit moderation logs to a subreddit wiki page with mod
44

55
## Features
66

7-
* 📊 Publishes modlogs as organized markdown tables
8-
* 📧 Pre-populated modmail links for removal inquiries
9-
* 🗄️ SQLite database for deduplication and retention
10-
* ⏰ Configurable update intervals
11-
* 🔒 Automatic cleanup of old entries
12-
* ⚡ Handles Reddit's 524KB wiki size limit
7+
* 📊 Publishes modlogs as organized markdown tables with unique content tracking IDs
8+
* 📧 Pre-populated modmail links for removal inquiries (formatted as clickable markdown links)
9+
* 🗄️ SQLite database for deduplication and retention with **multi-subreddit support**
10+
* ⏰ Configurable update intervals with continuous daemon mode
11+
* 🔒 Automatic cleanup of old entries with configurable retention
12+
* ⚡ Handles Reddit's 524KB wiki size limit automatically
1313
* 🧩 Fully CLI-configurable (no need to edit `config.json`)
14-
* 📁 Per-subreddit log files for debugging
14+
* 📁 Per-subreddit log files for debugging and monitoring
15+
* 🔒 Configurable moderator anonymization (AutoModerator/HumanModerator)
16+
* 📝 **Complete removal reason transparency** - AutoModerator rule text, addremovalreason descriptions, all actual removal text (never generic messages or template numbers)
17+
* 🔗 Links directly to actual content (posts/comments), never user profiles for privacy
18+
* 🆔 **Unique content IDs** - comments show comment IDs, posts show post IDs for precise tracking
19+
***Multi-subreddit database support** - single database handles multiple subreddits safely
1520

1621
## Quick Start
1722

@@ -67,33 +72,52 @@ Create `config.json`:
6772
"ignored_moderators": ["AutoModerator"],
6873
"update_interval": 300,
6974
"batch_size": 100,
70-
"retention_days": 30
75+
"retention_days": 30,
76+
"anonymize_moderators": true
7177
}
7278
```
7379

7480
### Configurable via CLI
7581

76-
| CLI Option | JSON Key | Description | Default |
77-
| -------------------- | ------------------ | -------------------------------------- | ------------- |
78-
| `--source-subreddit` | `source_subreddit` | Subreddit to read and write logs | required |
79-
| `--wiki-page` | `wiki_page` | Wiki page name | `modlog` |
80-
| `--retention-days` | `retention_days` | Keep entries this many days | `30` |
81-
| `--batch-size` | `batch_size` | Entries to fetch per run | `100` |
82-
| `--interval` | `update_interval` | Seconds between updates in daemon mode | `300` |
83-
| `--config` || Path to config file | `config.json` |
82+
| CLI Option | JSON Key | Description | Default | Min | Max |
83+
|------------|----------|-------------|---------|-----|-----|
84+
| `--source-subreddit` | `source_subreddit` | Subreddit to read and write logs | required | - | - |
85+
| `--wiki-page` | `wiki_page` | Wiki page name | modlog | - | - |
86+
| `--retention-days` | `retention_days` | Keep entries this many days | 90 | 1 | 365 |
87+
| `--batch-size` | `batch_size` | Entries to fetch per run | 50 | 10 | 500 |
88+
| `--interval` | `update_interval` | Seconds between updates in daemon mode | 600 | 60 | 3600 |
89+
| `--config` || Path to config file | config.json | - | - |
90+
| `--debug` || Enable verbose output | false | - | - |
91+
| `--show-config-limits` || Show configuration limits and defaults | false | - | - |
92+
| `--force-migrate` || Force database migration | false | - | - |
93+
| `--no-auto-update-config` || Disable automatic config file updates | false | - | - |
8494

8595
CLI values override config file values.
8696

97+
## Configuration Limits
98+
99+
All configuration values are automatically validated and enforced within safe limits. Use `--show-config-limits` to see current limits and defaults.
100+
101+
## Automatic Config Updates
102+
103+
The application automatically updates your config file when new configuration options are added, while preserving your existing settings. A backup is created before any changes. Use `--no-auto-update-config` to disable this behavior.
104+
105+
## Database Migration
106+
107+
The database will automatically migrate to the latest schema version on startup. Use `--force-migrate` to manually trigger migration.
108+
87109
## Wiki Output
88110

89111
Sample wiki table output:
90112

91113
```markdown
92-
## 2025-01-15
114+
## 2025-08-09
93115

94-
| Time | Action | Moderator | Content | Reason | Inquire |
95-
|------|--------|-----------|---------|--------|---------|
96-
| 14:25:33 UTC | removepost | ModName | [Post Title](url) | spam | [Contact Mods](modmail_url) |
116+
| Time | Action | ID | Moderator | Content | Reason | Inquire |
117+
|------|--------|----|-----------|---------|--------|---------|
118+
| 08:15:42 UTC | removecomment | n7ravg2 | AutoModerator | [Comment by u/user123](https://www.reddit.com/r/opensignups/comments/1ab2cd3/title/n7ravg2/) | Possibly requesting an invite - [invited] Offers must be [O] 3x Invites to MyAwesomeTracker | [Contact Mods](https://www.reddit.com/message/compose?to=/r/opensignups&subject=Comment%20Removal%20Inquiry...) |
119+
| 07:45:18 UTC | addremovalreason | 1ab2cd3 | Bakerboy448 | [Post title here](https://www.reddit.com/r/opensignups/comments/1ab2cd3/title/) | Invites - No asking | [Contact Mods](https://www.reddit.com/message/compose?to=/r/opensignups&subject=Removal%20Reason%20Inquiry...) |
120+
| 06:32:15 UTC | removelink | 1xy9def | AutoModerator | [Another post](https://www.reddit.com/r/opensignups/comments/1xy9def/another/) | No standalone URL in post body | [Contact Mods](https://www.reddit.com/message/compose?to=/r/opensignups&subject=Post%20Removal%20Inquiry...) |
97121
```
98122

99123
## Logging
@@ -122,20 +146,76 @@ Options:
122146
--debug Enable debug logging
123147
--test Run a test and exit
124148
--continuous Run continuously
149+
--force-modlog Fetch ALL actions from Reddit API and rebuild wiki
150+
--force-wiki Update wiki even if content appears unchanged
151+
--force-all Do both --force-modlog and --force-wiki
152+
```
153+
154+
### Force Commands Explained
155+
156+
**--force-modlog**: Complete rebuild from Reddit
157+
- Fetches ALL recent modlog actions from Reddit API
158+
- Stores them in database
159+
- Rebuilds entire wiki page from database
160+
- Use when: Starting fresh, major updates, or troubleshooting
161+
162+
**--force-wiki**: Force wiki update only
163+
- Uses existing database data
164+
- Forces wiki update even if content hash matches
165+
- Use when: Format changes, modmail updates, or cache issues
166+
167+
**--force-all**: Complete refresh (replaces old --force)
168+
- Combines both --force-modlog and --force-wiki
169+
- Fetches from Reddit AND forces wiki update
170+
- Use when: Major changes, troubleshooting, or unsure which force to use
171+
172+
```bash
173+
# Complete rebuild from Reddit API
174+
python modlog_wiki_publisher.py --source-subreddit usenet --force-modlog
175+
176+
# Update wiki with current database data (bypass cache)
177+
python modlog_wiki_publisher.py --source-subreddit usenet --force-wiki
178+
179+
# Do both (equivalent to old --force)
180+
python modlog_wiki_publisher.py --source-subreddit usenet --force-all
125181
```
126182
127183
## Database
128184
129185
Uses `modlog.db` (SQLite) for deduplication and history:
130186
131187
```bash
132-
# View recent actions
188+
# View recent actions with removal reasons
189+
sqlite3 modlog.db "SELECT action_id, action_type, moderator, removal_reason, subreddit, created_at FROM processed_actions ORDER BY created_at DESC LIMIT 10;"
190+
191+
# View all columns including removal reasons and target author
133192
sqlite3 modlog.db "SELECT * FROM processed_actions ORDER BY created_at DESC LIMIT 10;"
134193
194+
# View actions by subreddit
195+
sqlite3 modlog.db "SELECT action_type, moderator, target_author, removal_reason FROM processed_actions WHERE subreddit = 'usenet' ORDER BY created_at DESC LIMIT 5;"
196+
197+
# Track content lifecycle by target ID
198+
sqlite3 modlog.db "SELECT target_id, action_type, moderator, removal_reason, datetime(created_at, 'unixepoch') FROM processed_actions WHERE target_id LIKE '%1mkz4jm%' ORDER BY created_at;"
199+
200+
# View removal reasons that are text (not numbers)
201+
sqlite3 modlog.db "SELECT action_type, removal_reason FROM processed_actions WHERE removal_reason NOT LIKE '%[0-9]%' AND removal_reason != 'remove' LIMIT 5;"
202+
135203
# Clean manually
136204
sqlite3 modlog.db "DELETE FROM processed_actions WHERE created_at < date('now', '-30 days');"
137205
```
138206
207+
### Database Schema
208+
209+
The database includes comprehensive moderation data with full transparency:
210+
211+
- **`removal_reason` column**: Stores actual removal reason text from Reddit's API
212+
- AutoModerator actions: Full rule text (e.g., "Possibly requesting an invite - [invited] Offers must be [O]")
213+
- addremovalreason actions: Readable removal reason (e.g., "Invites - No asking") instead of template numbers
214+
- Manual removals: Moderator-provided text or rule details
215+
- **`target_author` column**: Actual usernames of content authors (never shows [deleted])
216+
- **`subreddit` column**: Multi-subreddit support with proper data separation
217+
- **Unique content IDs**: Comments show comment IDs (e.g., n7ravg2), posts show post IDs
218+
139219
## Systemd Service (Optional)
140220
141221
```ini

config_template.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
"password": "YOUR_BOT_PASSWORD"
77
},
88
"source_subreddit": "YourSubreddit",
9-
"target_subreddit": "YourSubreddit",
109
"wiki_page": "modlog",
11-
"ignored_moderators": ["AutoModerator", "BotDefense"],
12-
"update_interval": 300,
13-
"batch_size": 100,
14-
"retention_days": 30
10+
"retention_days": 90,
11+
"batch_size": 50,
12+
"update_interval": 600,
13+
"max_wiki_entries_per_page": 1000,
14+
"max_continuous_errors": 5,
15+
"rate_limit_buffer": 60,
16+
"max_batch_retries": 3,
17+
"archive_threshold_days": 7,
18+
"ignored_moderators": ["AutoModerator"],
19+
"display_format": {
20+
"show_full_ids": false,
21+
"id_format": "prefixed"
22+
}
1523
}

0 commit comments

Comments
 (0)