@@ -116,6 +116,7 @@ def rate_limit_retry(func, *args, **kwargs):
116116 system .print_debug (args , f"Checking messages in channels: { ', ' .join ([channel ['name' ] for channel in channels ])} " )
117117
118118 for channel in channels :
119+ total_results = 0
119120 channel_name = channel ["name" ]
120121 channel_id = channel ["id" ]
121122 latest_time = int (time .time ())
@@ -142,12 +143,28 @@ def rate_limit_retry(func, *args, **kwargs):
142143 # Get messages from the channel within the time range
143144 system .print_info (args , f"Checking messages in channel { channel_name } ({ channel_id } )" )
144145 system .print_info (args , f"Fetching messages from { time .strftime ('%Y-%m-%d %H:%M:%S' , time .gmtime (oldest_time ))} to { time .strftime ('%Y-%m-%d %H:%M:%S' , time .gmtime (latest_time ))} " )
145- messages = rate_limit_retry (client .conversations_history , channel = channel_id , oldest = oldest_time , latest = latest_time )["messages" ]
146- system .print_debug (args , f"Found { len (messages )} messages in channel { channel_name } ({ channel_id } )" )
146+ messages = []
147+ cursor = None # Start without a cursor
148+
149+ while True :
150+ response = rate_limit_retry (client .conversations_history ,
151+ channel = channel_id ,
152+ oldest = oldest_time ,
153+ latest = latest_time ,
154+ limit = 200 ,
155+ cursor = cursor )
156+
157+ messages .extend (response .get ("messages" , []))
158+
159+ cursor = response .get ("response_metadata" , {}).get ("next_cursor" )
160+ if not cursor :
161+ break # Stop if there's no more data
162+
163+ system .print_debug (args , f"Fetched { len (messages )} messages from { channel_name } ({ channel_id } )" )
147164 for message in messages :
148- if quick_exit and len ( results ) >= max_matches :
165+ if quick_exit and total_results >= max_matches :
149166 system .print_info (args , f"Quick exit enabled. Found { max_matches } matches. Exiting..." )
150- return results
167+ break
151168 user = message .get ("user" , "" )
152169 text = message .get ("text" )
153170 message_ts = message .get ("ts" )
@@ -160,6 +177,7 @@ def rate_limit_retry(func, *args, **kwargs):
160177 matches = system .read_match_strings (args , file_addr , 'slack' )
161178 if matches :
162179 for match in matches :
180+ total_results += 1
163181 results .append ({
164182 'channel_id' : channel_id ,
165183 'channel_name' : channel_name ,
@@ -177,6 +195,7 @@ def rate_limit_retry(func, *args, **kwargs):
177195 matches = system .match_strings (args , text )
178196 if matches :
179197 for match in matches :
198+ total_results += 1
180199 results .append ({
181200 'channel_id' : channel_id ,
182201 'channel_name' : channel_name ,
@@ -207,6 +226,7 @@ def rate_limit_retry(func, *args, **kwargs):
207226 matches = system .read_match_strings (args , file_addr , 'slack' )
208227 if matches :
209228 for match in matches :
229+ total_results += 1
210230 results .append ({
211231 'channel_id' : channel_id ,
212232 'channel_name' : channel_name ,
@@ -223,6 +243,7 @@ def rate_limit_retry(func, *args, **kwargs):
223243 reply_matches = system .match_strings (args , reply_text )
224244 if reply_matches :
225245 for match in reply_matches :
246+ total_results += 1
226247 results .append ({
227248 'channel_id' : channel_id ,
228249 'channel_name' : channel_name ,
@@ -250,7 +271,6 @@ def download_file(args, client, file_info, folder_path) -> str:
250271 # Use the Slack client to get file info
251272 file_url = file_info ['url_private_download' ]
252273 file_name = file_info ['name' ]
253-
254274 # Create the full path to save the file
255275 file_path = os .path .join (folder_path , file_name )
256276
0 commit comments