Skip to content

Commit d06292b

Browse files
author
rohitcoder
committed
v0.3.34
1 parent 8438ad8 commit d06292b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

hawk_scanner/commands/slack.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "0.3.33"
1+
VERSION = "0.3.34"
22

33
from setuptools import setup, find_packages
44

0 commit comments

Comments
 (0)