|
19 | 19 |
|
20 | 20 | DB_PATH = "modlog.db" |
21 | 21 | LOGS_DIR = "logs" |
| 22 | +BASE_BACKOFF_WAIT = 30 |
| 23 | +MAX_BACKOFF_WAIT = 300 |
22 | 24 | logger = logging.getLogger(__name__) |
23 | 25 |
|
24 | 26 | # Configuration limits and defaults |
@@ -309,6 +311,12 @@ def censor_email_addresses(text): |
309 | 311 | # Replace email addresses with [EMAIL] |
310 | 312 | return re.sub(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', '[EMAIL]', text) |
311 | 313 |
|
| 314 | +def sanitize_for_markdown(text: str) -> str: |
| 315 | + """Sanitize text for use in markdown tables by escaping pipe characters""" |
| 316 | + if text is None: |
| 317 | + return "" |
| 318 | + return str(text).replace("|", " ") |
| 319 | + |
312 | 320 | def get_action_datetime(action): |
313 | 321 | """Convert action.created_utc to datetime object regardless of input type""" |
314 | 322 | if isinstance(action.created_utc, (int, float)): |
@@ -516,7 +524,7 @@ def store_processed_action(action, subreddit_name=None): |
516 | 524 | get_target_type(action), |
517 | 525 | generate_display_id(action), |
518 | 526 | target_permalink, |
519 | | - removal_reason.replace("|"," ") if removal_reason is not None else None, # Store properly processed removal reason |
| 527 | + sanitize_for_markdown(removal_reason), # Store properly processed removal reason |
520 | 528 | target_author, |
521 | 529 | int(action.created_utc) if isinstance(action.created_utc, (int, float)) else int(action.created_utc.timestamp()), |
522 | 530 | subreddit_name or 'unknown' |
@@ -728,7 +736,7 @@ def format_content_link(action) -> str: |
728 | 736 | # Format with link like main branch |
729 | 737 | if formatted_link: |
730 | 738 | formatted_title = f"[{formatted_title}]({formatted_link})" |
731 | | - return formatted_title.replace("|"," ") |
| 739 | + return sanitize_for_markdown(formatted_title) |
732 | 740 |
|
733 | 741 | def extract_content_id_from_permalink(permalink): |
734 | 742 | """Extract the actual post/comment ID from Reddit permalink URL""" |
@@ -783,7 +791,7 @@ def format_modlog_entry(action, config: Dict[str, Any]) -> Dict[str, str]: |
783 | 791 | 'id': content_id, |
784 | 792 | 'moderator': get_moderator_name(action, config.get('anonymize_moderators', True)) or 'Unknown', |
785 | 793 | 'content': format_content_link(action), |
786 | | - 'reason': str(reason_text).replace("|"," "), |
| 794 | + 'reason': sanitize_for_markdown(str(reason_text)), |
787 | 795 | 'inquire': generate_modmail_link(config['source_subreddit'], action) |
788 | 796 | } |
789 | 797 |
|
@@ -1158,6 +1166,7 @@ def run_continuous_mode(reddit, config: Dict[str, Any], force: bool = False): |
1158 | 1166 |
|
1159 | 1167 | error_count = 0 |
1160 | 1168 | max_errors = config.get('max_continuous_errors', CONFIG_LIMITS['max_continuous_errors']['default']) |
| 1169 | + first_run_force = force |
1161 | 1170 |
|
1162 | 1171 | while True: |
1163 | 1172 | try: |
|
0 commit comments