Skip to content

Commit 74d93d5

Browse files
committed
refactor: consolidate action types into configurable variables
- Add REMOVAL_ACTIONS, APPROVAL_ACTIONS, REASON_ACTIONS constants - Replace hardcoded lists with DEFAULT_WIKI_ACTIONS variable - Eliminate duplication across multiple functions - Update documentation with new variable structure - Maintain backward compatibility while improving maintainability
1 parent b88dcb7 commit 74d93d5

2 files changed

Lines changed: 33 additions & 22 deletions

File tree

CLAUDE.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,21 @@ The application supports both JSON config files and CLI arguments (CLI overrides
7676
- `false`: Shows actual moderator usernames
7777

7878
### Action Types Displayed
79-
- **Manual Actions**: `removelink`, `removecomment`, `spamlink`, `spamcomment`
80-
- **AutoMod Filters**: `filter-removelink`, `filter-removecomment` (displayed when moderator is AutoModerator)
81-
- **Removal Reasons**: `addremovalreason` (combined with removal action when possible)
82-
- **Human Approvals**: `approvelink`, `approvecomment` (only for reversals of Reddit/AutoMod actions)
83-
- **Context**: Approval actions show original removal reason and moderator
79+
80+
The application uses configurable action type variables for flexibility:
81+
82+
#### Default Configuration
83+
- **REMOVAL_ACTIONS**: `removelink`, `removecomment`, `spamlink`, `spamcomment`
84+
- **APPROVAL_ACTIONS**: `approvelink`, `approvecomment`
85+
- **REASON_ACTIONS**: `addremovalreason`
86+
- **DEFAULT_WIKI_ACTIONS**: All above combined
87+
88+
#### Display Behavior
89+
- **Manual Actions**: Show as-is (e.g., `removelink`, `removecomment`)
90+
- **AutoMod Filters**: Show with `filter-` prefix (e.g., `filter-removelink`, `filter-removecomment`)
91+
- **Removal Reasons**: Combined with removal action when targeting same content
92+
- **Human Approvals**: Only shown for reversals of Reddit/AutoMod actions
93+
- **Approval Context**: Shows original removal reason and moderator (e.g., "Approved AutoModerator removal: Rule violation")
8494

8595
### Database Features
8696
- **Multi-subreddit support**: Single database handles multiple subreddits safely

modlog_wiki_publisher.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
MAX_BACKOFF_WAIT = 300
2424
logger = logging.getLogger(__name__)
2525

26+
# Action type configurations
27+
REMOVAL_ACTIONS = ['removelink', 'removecomment', 'spamlink', 'spamcomment']
28+
APPROVAL_ACTIONS = ['approvelink', 'approvecomment']
29+
REASON_ACTIONS = ['addremovalreason']
30+
DEFAULT_WIKI_ACTIONS = REMOVAL_ACTIONS + REASON_ACTIONS + APPROVAL_ACTIONS
31+
2632
# Configuration limits and defaults
2733
CONFIG_LIMITS = {
2834
'retention_days': {'min': 1, 'max': 365, 'default': 90},
@@ -111,7 +117,7 @@ def apply_config_defaults_and_limits(config):
111117

112118
# Set default wiki actions if not specified
113119
if 'wiki_actions' not in config:
114-
config['wiki_actions'] = ['removelink', 'removecomment', 'addremovalreason', 'spamlink', 'spamcomment', 'approvelink', 'approvecomment']
120+
config['wiki_actions'] = DEFAULT_WIKI_ACTIONS
115121
logger.info("Using default wiki_actions: removals, removal reasons, and approvals")
116122

117123
# Validate required fields
@@ -612,14 +618,10 @@ def get_recent_actions_from_db(config: Dict[str, Any], force_all_actions: bool =
612618
wiki_actions = set(row[0] for row in cursor.fetchall())
613619
logger.info(f"Force refresh: including all action types: {wiki_actions}")
614620
elif show_only_removals:
615-
wiki_actions = set([
616-
'removelink', 'removecomment', 'addremovalreason', 'spamlink', 'spamcomment', 'approvelink', 'approvecomment'
617-
])
621+
wiki_actions = set(DEFAULT_WIKI_ACTIONS)
618622
else:
619623
# Get configurable list of actions to show in wiki
620-
wiki_actions = set(config.get('wiki_actions', [
621-
'removelink', 'removecomment', 'addremovalreason', 'spamlink', 'spamcomment', 'approvelink', 'approvecomment'
622-
]))
624+
wiki_actions = set(config.get('wiki_actions', DEFAULT_WIKI_ACTIONS))
623625

624626
# Get recent actions within retention period
625627
retention_days = get_config_with_default(config, 'retention_days')
@@ -792,7 +794,7 @@ def format_modlog_entry(action, config: Dict[str, Any]) -> Dict[str, str]:
792794
content_id = extracted_id.replace('t3_', '').replace('t1_', '')[:8]
793795

794796
display_action = action.action
795-
if action.action in ['removelink', 'removecomment'] and get_moderator_name(action, False) == 'AutoModerator':
797+
if action.action in REMOVAL_ACTIONS and get_moderator_name(action, False) == 'AutoModerator':
796798
display_action = f"filter-{action.action}"
797799

798800
return {
@@ -889,7 +891,7 @@ def build_wiki_content(actions: List, config: Dict[str, Any]) -> str:
889891

890892
filtered_actions = []
891893
for action in actions:
892-
if action.action in ['approvelink', 'approvecomment']:
894+
if action.action in APPROVAL_ACTIONS:
893895
should_include = False
894896
content_id = extract_content_id_from_permalink(get_target_permalink(action))
895897
if content_id:
@@ -900,12 +902,13 @@ def build_wiki_content(actions: List, config: Dict[str, Any]) -> str:
900902
conn = sqlite3.connect(DB_PATH)
901903
cursor = conn.cursor()
902904

903-
cursor.execute("""
905+
removal_placeholders = ','.join(['?'] * len(REMOVAL_ACTIONS))
906+
cursor.execute(f"""
904907
SELECT moderator, removal_reason FROM processed_actions
905-
WHERE target_permalink LIKE ? AND action_type IN ('removelink', 'removecomment', 'spamlink', 'spamcomment')
908+
WHERE target_permalink LIKE ? AND action_type IN ({removal_placeholders})
906909
AND LOWER(moderator) IN ('reddit', 'automoderator')
907910
ORDER BY created_at DESC LIMIT 1
908-
""", (f'%{content_id}%',))
911+
""", [f'%{content_id}%'] + REMOVAL_ACTIONS)
909912

910913
prior_removal = cursor.fetchone()
911914
conn.close()
@@ -954,12 +957,12 @@ def build_wiki_content(actions: List, config: Dict[str, Any]) -> str:
954957
other_actions = []
955958

956959
for action in target_actions:
957-
if action.action in ['removelink', 'removecomment', 'spamlink', 'spamcomment']:
960+
if action.action in REMOVAL_ACTIONS:
958961
if not removal_action:
959962
removal_action = action
960963
else:
961964
other_actions.append(action)
962-
elif action.action == 'addremovalreason':
965+
elif action.action in REASON_ACTIONS:
963966
if not removal_reason_action:
964967
removal_reason_action = action
965968
else:
@@ -1087,9 +1090,7 @@ def process_modlog_actions(reddit, config: Dict[str, Any]) -> List:
10871090
logger.info(f"Fetching modlog entries from /r/{config['source_subreddit']}")
10881091

10891092
# Get configurable list of actions to show in wiki
1090-
wiki_actions = set(config.get('wiki_actions', [
1091-
'removelink', 'removecomment', 'addremovalreason', 'spamlink', 'spamcomment', 'approvelink', 'approvecomment'
1092-
]))
1093+
wiki_actions = set(config.get('wiki_actions', DEFAULT_WIKI_ACTIONS))
10931094

10941095
for action in subreddit.mod.log(limit=batch_size):
10951096
mod_name = get_moderator_name(action, False) # Use actual name for ignore check

0 commit comments

Comments
 (0)