@@ -116,6 +116,7 @@ def rate_limit_retry(func, *args, **kwargs):
116
116
system .print_debug (args , f"Checking messages in channels: { ', ' .join ([channel ['name' ] for channel in channels ])} " )
117
117
118
118
for channel in channels :
119
+ total_results = 0
119
120
channel_name = channel ["name" ]
120
121
channel_id = channel ["id" ]
121
122
latest_time = int (time .time ())
@@ -142,12 +143,28 @@ def rate_limit_retry(func, *args, **kwargs):
142
143
# Get messages from the channel within the time range
143
144
system .print_info (args , f"Checking messages in channel { channel_name } ({ channel_id } )" )
144
145
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 } )" )
147
164
for message in messages :
148
- if quick_exit and len ( results ) >= max_matches :
165
+ if quick_exit and total_results >= max_matches :
149
166
system .print_info (args , f"Quick exit enabled. Found { max_matches } matches. Exiting..." )
150
- return results
167
+ break
151
168
user = message .get ("user" , "" )
152
169
text = message .get ("text" )
153
170
message_ts = message .get ("ts" )
@@ -160,6 +177,7 @@ def rate_limit_retry(func, *args, **kwargs):
160
177
matches = system .read_match_strings (args , file_addr , 'slack' )
161
178
if matches :
162
179
for match in matches :
180
+ total_results += 1
163
181
results .append ({
164
182
'channel_id' : channel_id ,
165
183
'channel_name' : channel_name ,
@@ -177,6 +195,7 @@ def rate_limit_retry(func, *args, **kwargs):
177
195
matches = system .match_strings (args , text )
178
196
if matches :
179
197
for match in matches :
198
+ total_results += 1
180
199
results .append ({
181
200
'channel_id' : channel_id ,
182
201
'channel_name' : channel_name ,
@@ -207,6 +226,7 @@ def rate_limit_retry(func, *args, **kwargs):
207
226
matches = system .read_match_strings (args , file_addr , 'slack' )
208
227
if matches :
209
228
for match in matches :
229
+ total_results += 1
210
230
results .append ({
211
231
'channel_id' : channel_id ,
212
232
'channel_name' : channel_name ,
@@ -223,6 +243,7 @@ def rate_limit_retry(func, *args, **kwargs):
223
243
reply_matches = system .match_strings (args , reply_text )
224
244
if reply_matches :
225
245
for match in reply_matches :
246
+ total_results += 1
226
247
results .append ({
227
248
'channel_id' : channel_id ,
228
249
'channel_name' : channel_name ,
@@ -250,7 +271,6 @@ def download_file(args, client, file_info, folder_path) -> str:
250
271
# Use the Slack client to get file info
251
272
file_url = file_info ['url_private_download' ]
252
273
file_name = file_info ['name' ]
253
-
254
274
# Create the full path to save the file
255
275
file_path = os .path .join (folder_path , file_name )
256
276
0 commit comments