Skip to content

Commit 4a22a1e

Browse files
committed
Missing change from /dev
1 parent 2dd8110 commit 4a22a1e

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

instagram_monitor.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,6 +3807,46 @@ def refresh_proxy_if_needed(bot, user):
38073807
log_activity(f"Proxy refresh failed: {error_msg}", user=user, level='error')
38083808

38093809

3810+
TPrivacyContent = TypeVar("TPrivacyContent")
3811+
3812+
3813+
# Apply PRIVACY_SUBSTITIONS to any content type
3814+
def apply_privacy_substitutions(content: TPrivacyContent) -> TPrivacyContent:
3815+
"""
3816+
- Recurses into dict values and list items
3817+
- For strings, performs search/replace using PRIVACY_SUBSTITIONS
3818+
- Preserves dictionary keys to keep API object identity stable
3819+
- Ignores invalid substitution entries to avoid runtime crashes
3820+
- Non-string primitives are returned unchanged
3821+
"""
3822+
global PRIVACY_SUBSTITIONS_INVALID_WARNED
3823+
if not PRIVACY_SUBSTITIONS:
3824+
return content
3825+
if isinstance(content, str):
3826+
content_str = content
3827+
for item in PRIVACY_SUBSTITIONS:
3828+
if not isinstance(item, (list, tuple)) or len(item) != 2:
3829+
if not PRIVACY_SUBSTITIONS_INVALID_WARNED:
3830+
if sys.__stderr__ is not None:
3831+
sys.__stderr__.write("* Warning: Ignoring invalid PRIVACY_SUBSTITIONS entry, expected (search, replace) with both values as strings\n")
3832+
PRIVACY_SUBSTITIONS_INVALID_WARNED = True
3833+
continue
3834+
search, replace = item
3835+
if not isinstance(search, str) or not isinstance(replace, str) or not search:
3836+
if not PRIVACY_SUBSTITIONS_INVALID_WARNED:
3837+
if sys.__stderr__ is not None:
3838+
sys.__stderr__.write("* Warning: Ignoring invalid PRIVACY_SUBSTITIONS entry, expected non-empty string search and string replace values\n")
3839+
PRIVACY_SUBSTITIONS_INVALID_WARNED = True
3840+
continue
3841+
content_str = content_str.replace(search, replace)
3842+
return cast(TPrivacyContent, content_str)
3843+
if isinstance(content, dict):
3844+
return cast(TPrivacyContent, {k: apply_privacy_substitutions(v) for k, v in content.items()})
3845+
if isinstance(content, list):
3846+
return cast(TPrivacyContent, [apply_privacy_substitutions(item) for item in content])
3847+
return content
3848+
3849+
38103850
# Debug print helper - only prints if DEBUG_MODE is enabled
38113851
def debug_print(message):
38123852
if DEBUG_MODE:

0 commit comments

Comments
 (0)