2323MAX_BACKOFF_WAIT = 300
2424logger = 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
2733CONFIG_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