@@ -29,7 +29,8 @@ def load_env():
2929PROXY_URL = env_vars .get ("PROXY_URL" , "https://api.codetabs.com/v1/proxy/?quest=" )
3030RATE_LIMIT = int (env_vars .get ("DISCORD_INVITE_RATE_LIMIT" , 20 ))
3131JSON_FILE_PATH = os .path .join (
32- os .path .dirname (__file__ ), "../Database-Files/Edit-Database/Compromised-Discord-Accounts.json"
32+ os .path .dirname (__file__ ),
33+ "../Database-Files/Edit-Database/Compromised-Discord-Accounts.json" ,
3334)
3435PRINT_RESPONSE = True # Set to True to see full API responses
3536
@@ -130,34 +131,30 @@ def process_accounts():
130131 print ("No accounts found in the JSON file." )
131132 return
132133
133- # Get user's choice for scanning
134134 start_index = get_starting_point (total_accounts )
135135
136136 processed = 0
137137 updated_accounts = 0
138138 skipped_accounts = 0
139139
140- # Calculate delay between requests to evenly distribute them
141- if RATE_LIMIT > 0 :
142- request_delay = 60.0 / RATE_LIMIT # Spread requests evenly over a minute
143- else :
144- request_delay = 0
140+ request_delay = 60.0 / RATE_LIMIT if RATE_LIMIT > 0 else 0
145141
146142 print (f"\n Starting processing of accounts..." )
147143 print (f"Starting from account number: { start_index + 1 } " )
148144 print (f"Rate limit configured: { RATE_LIMIT } requests/minute" )
149145 print (f"Request delay: { request_delay :.2f} seconds between requests" )
150146
151- # Convert dict to list of items for easier slicing
152147 accounts_items = list (data .items ())
153148
149+ # Cache for already checked invites
150+ checked_invites = {}
151+
154152 for i in range (start_index , total_accounts ):
155153 account_id , account_data = accounts_items [i ]
156154 processed += 1
157155 surface_url = account_data .get ("SURFACE_URL" , "" )
158156 surface_domain = account_data .get ("SURFACE_URL_DOMAIN" , "" )
159157
160- # Skip if not a Discord invite URL
161158 if not (
162159 surface_domain in ["discord.gg" , "discord.com" ]
163160 and surface_url .startswith (("http://" , "https://" ))
@@ -180,11 +177,24 @@ def process_accounts():
180177 f"[{ i + 1 } /{ total_accounts } ] Processing { account_id } : Checking invite { invite_code } "
181178 )
182179
183- # Check invite status
184- start_time = time .time ()
185- is_active , final_url = check_invite (invite_code )
180+ # Check if invite was already checked
181+ if invite_code in checked_invites :
182+ is_active , final_url = checked_invites [invite_code ]
183+ print (f"Invite { invite_code } already checked. Using cached result." )
184+ else :
185+ start_time = time .time ()
186+ is_active , final_url = check_invite (invite_code )
187+ checked_invites [invite_code ] = (is_active , final_url )
188+
189+ # Adjust delay to respect rate limit
190+ request_time = time .time () - start_time
191+ remaining_delay = max (0 , request_delay - request_time )
192+ if remaining_delay > 0 :
193+ print (
194+ f"Waiting { remaining_delay :.2f} seconds to maintain rate limit..."
195+ )
196+ time .sleep (remaining_delay )
186197
187- # Update account data
188198 status = "ACTIVE" if is_active else "INACTIVE"
189199 account_data ["SURFACE_URL_STATUS" ] = status
190200 account_data ["FINAL_URL" ] = final_url
@@ -195,21 +205,13 @@ def process_accounts():
195205 updated_accounts += 1
196206 print (f"Updated { account_id } : Status = { status } " )
197207
198- # Write changes after each check to prevent data loss
199208 try :
200209 with open (JSON_FILE_PATH , "w" , encoding = "utf-8" ) as f :
201210 json .dump (data , f , indent = 4 , ensure_ascii = False )
202211 print ("Changes saved to file" )
203212 except Exception as e :
204213 print (f"Error saving changes to file: { str (e )} " )
205214
206- # Calculate time taken for the request and adjust delay
207- request_time = time .time () - start_time
208- remaining_delay = max (0 , request_delay - request_time )
209- if remaining_delay > 0 :
210- print (f"Waiting { remaining_delay :.2f} seconds to maintain rate limit..." )
211- time .sleep (remaining_delay )
212-
213215 print (f"\n Processing complete!" )
214216 print (f"Total accounts: { total_accounts } " )
215217 print (f"Processed: { processed } " )
0 commit comments