@@ -22,7 +22,7 @@ def connect_slack(args, token):
2222 system .print_error (args , f"Failed to connect to Slack with error: { e .response ['error' ]} " )
2323 return None
2424
25- def check_slack_messages (args , client , patterns , profile_name , channel_types , isExternal , read_from , channel_ids = None , limit_mins = 60 , archived_channels = False , onlyArchived = False ):
25+ def check_slack_messages (args , client , patterns , profile_name , channel_types , isExternal , read_from , channel_ids = None , limit_mins = 60 , archived_channels = False , onlyArchived = False , blacklisted_channel_ids = None ):
2626 results = []
2727 try :
2828 connection = system .get_connection (args )
@@ -35,6 +35,11 @@ def check_slack_messages(args, client, patterns, profile_name, channel_types, is
3535
3636 team_info = client .team_info ()
3737 workspace_url = team_info ["team" ]["url" ].rstrip ('/' )
38+
39+ # Initalize blacklisted_channel_ids if not provided
40+ if blacklisted_channel_ids is None :
41+ blacklisted_channel_ids = []
42+
3843 # Helper function to handle rate limits
3944 hawk_args = args
4045 def rate_limit_retry (func , * args , ** kwargs ):
@@ -89,6 +94,9 @@ def rate_limit_retry(func, *args, **kwargs):
8994 else :
9095 system .print_info (args , "Getting channels by channel_ids" )
9196 for channel_id in channel_ids :
97+ if channel_id in blacklisted_channel_ids :
98+ system .print_debug (args , f"Skipping blacklisted channel: { channel_id } " )
99+ continue
92100 try :
93101 channel = rate_limit_retry (client .conversations_info , channel = channel_id )["channel" ]
94102 if archived_channels or not channel .get ("is_archived" ):
@@ -365,10 +373,11 @@ def execute(args):
365373 onlyArchived = config .get ('onlyArchived' , False )
366374 archived_channels = config .get ('archived_channels' , False )
367375
368- # check if channel_ids has blacklisted channel ids, then remove them
369- for blacklisted_channel_id in blacklisted_channel_ids :
370- if blacklisted_channel_id in channel_ids :
371- channel_ids .remove (blacklisted_channel_id )
376+ # Filter out blacklisted channels, If specific channels are specified
377+ if channel_ids :
378+ system .print_info (args , f"Filtering out blacklisted channels from { channel_ids } " )
379+ channel_ids = [channel_id for channel_id in channel_ids if channel_id not in blacklisted_channel_ids ]
380+ system .print_info (args , f"Filtered channel IDs after blacklist removal: { channel_ids } " )
372381
373382 if token :
374383 system .print_info (args , f"Checking Slack Profile { key } " )
@@ -378,10 +387,10 @@ def execute(args):
378387
379388 client = connect_slack (args , token )
380389 if client :
381- results += check_slack_messages (args , client , patterns , key , channel_types , isExternal , read_from , channel_ids , limit_mins , archived_channels , onlyArchived )
390+ results += check_slack_messages (args , client , patterns , key , channel_types , isExternal , read_from , channel_ids , limit_mins , archived_channels , onlyArchived , blacklisted_channel_ids )
382391 else :
383392 system .print_error (args , "No Slack connection details found in connection.yml" )
384393 else :
385394 system .print_error (args , "No 'sources' section found in connection.yml" )
386395
387- return results
396+ return results
0 commit comments