|
181 | 181 | # Set to True to enable verbose output for HTTP jitter/back-off wrappers |
182 | 182 | JITTER_VERBOSE = False |
183 | 183 |
|
| 184 | +# Optional Privacy Substitutions |
| 185 | +# This allows you to substitute any string for another in all messaging, logging, and emailing. |
| 186 | +# For instance, you may want to change a particular Instagram username to a more friendy name, or you could mask a name. |
| 187 | +# |
| 188 | +# Provide a list of (search, replace) tuples. Any search term will be substituted with the replace term. |
| 189 | +# |
| 190 | +# Example: |
| 191 | +# PRIVACY_SUBSTITIONS = [ ("a.username", "XXX"), ("sdfsdf747475475", "Bobby") ] |
| 192 | +# |
| 193 | +PRIVACY_SUBSTITIONS = [ ] |
| 194 | +
|
184 | 195 | # Optional: specify web browser user agent manually |
185 | 196 | # |
186 | 197 | # For session login using Firefox cookies, ensure this matches your Firefox web browser's user agent |
@@ -664,6 +675,7 @@ def generate_config_with_current_values() -> str: |
664 | 675 | THUMBNAILS_FORCED_BY_WEB = False |
665 | 676 | FOLLOWERS_CHURN_DETECTION = False |
666 | 677 | TIME_FORMAT_12H = False |
| 678 | +PRIVACY_SUBSTITIONS = [] |
667 | 679 | mode_of_the_tool = "Unknown" |
668 | 680 |
|
669 | 681 | exec(CONFIG_BLOCK, globals()) |
@@ -2865,6 +2877,7 @@ def write(self, message): |
2865 | 2877 | global last_output |
2866 | 2878 | with STDOUT_LOCK: |
2867 | 2879 | # Apply color for terminal |
| 2880 | + message = process_message_substitutions(message) |
2868 | 2881 | colorized_message = apply_color_to_text(message) |
2869 | 2882 |
|
2870 | 2883 | if message != '\n': |
@@ -3101,6 +3114,10 @@ def send_email(subject, body, body_html, use_ssl, image_file="", image_name="ima |
3101 | 3114 | fqdn_re = re.compile(r'(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}\.?$)') |
3102 | 3115 | email_re = re.compile(r'[^@]+@[^@]+\.[^@]+') |
3103 | 3116 |
|
| 3117 | + subject = process_message_substitutions(subject) |
| 3118 | + body = process_message_substitutions(body) |
| 3119 | + body_html = process_message_substitutions(body_html) |
| 3120 | + |
3104 | 3121 | try: |
3105 | 3122 | ipaddress.ip_address(str(SMTP_HOST)) |
3106 | 3123 | except ValueError: |
@@ -3333,6 +3350,9 @@ def send_webhook(title, description, color=0x7289DA, fields=None, image_url=None |
3333 | 3350 | if not WEBHOOK_ENABLED or not WEBHOOK_URL: |
3334 | 3351 | return 1 |
3335 | 3352 |
|
| 3353 | + title = process_message_substitutions(title) |
| 3354 | + description = process_message_substitutions(description) |
| 3355 | + |
3336 | 3356 | # Validate webhook URL |
3337 | 3357 | if not validate_webhook_url(WEBHOOK_URL): |
3338 | 3358 | debug_print("* Webhook error: Invalid webhook URL format") |
@@ -3453,12 +3473,31 @@ def send_webhook(title, description, color=0x7289DA, fields=None, image_url=None |
3453 | 3473 | return 1 |
3454 | 3474 |
|
3455 | 3475 |
|
| 3476 | +def process_message_substitutions(message: str) -> str: |
| 3477 | + """ |
| 3478 | + Perform search/replace on a message using the PRIVACY_SUBSTITIONS global variable. |
| 3479 | + PRIVACY_SUBSTITIONS should be a list of (search, replace) tuples. |
| 3480 | + Returns the original message if PRIVACY_SUBSTITIONS doesn't exist or is empty. |
| 3481 | + """ |
| 3482 | + try: |
| 3483 | + if not PRIVACY_SUBSTITIONS: |
| 3484 | + return message |
| 3485 | + except NameError: |
| 3486 | + return message |
| 3487 | + |
| 3488 | + for search, replace in PRIVACY_SUBSTITIONS: |
| 3489 | + message = message.replace(search, replace) |
| 3490 | + |
| 3491 | + return message |
| 3492 | + |
| 3493 | + |
3456 | 3494 | # Debug print helper - only prints if DEBUG_MODE is enabled |
3457 | 3495 | def debug_print(message): |
3458 | 3496 | if DEBUG_MODE: |
| 3497 | + message = process_message_substitutions(message) |
3459 | 3498 | timestamp = get_hour_min_from_ts(now_local(), show_seconds=True) |
3460 | 3499 | user = getattr(_thread_local, 'user', None) |
3461 | | - user_prefix = f" [{user}]" if user else "" |
| 3500 | + user_prefix = f" [{process_message_substitutions(user)}]" if user else "" |
3462 | 3501 |
|
3463 | 3502 | # If we just printed a partial line (no newline), add one before the debug message to avoid clobbering |
3464 | 3503 | if getattr(_thread_local, 'in_partial_line', False): |
|
0 commit comments