@@ -65,7 +65,9 @@ class GLOBALS:
6565WD_TIMEOUT_30 = 30
6666WD_TIMEOUT_LONG = 90
6767
68- WD_FETCH_INVITE_CLOUDFLARE_TRIES = 5
68+ WD_FETCH_INVITE_CLOUDFLARE_TRIES = 3
69+ WD_FETCH_INVITE_CLOUDFLARE_DELAY = 7
70+
6971WD_RD_CLICK_UPPER_N = 5
7072WD_RD_CLICK_LOWER_N = 2
7173WD_OUTPUT_PATH = pathlib .Path .home ().joinpath ("daf/daf_web_data" )
@@ -78,7 +80,6 @@ class GLOBALS:
7880
7981TOP_GG_SEARCH_URL = "https://top.gg/api/client/entities/search"
8082TOP_GG_SERVER_JOIN_URL = "https://top.gg/servers/{id}/join"
81- TOP_GG_REFRESH_TIME = timedelta (hours = 1 )
8283
8384
8485@doc .doc_category ("Clients" )
@@ -155,7 +156,8 @@ async def initialize(self) -> None:
155156 opts .add_argument ("--no-first-run" )
156157 opts .add_argument ("--disable-background-networking" )
157158 opts .add_argument ("--disable-sync" )
158- opts .add_argument ("--disable-popup-blocking" )
159+ opts .add_argument ("--disable-popup-blocking" ) # For purposes of opening a new window with JavaScript
160+
159161
160162 if self ._proxy is not None :
161163 proxy = self ._proxy .split ("://" ) # protocol, url
@@ -305,7 +307,7 @@ async def fetch_invite_link(self, url: str):
305307 driver = self .driver
306308 main_window_handle = driver .current_window_handle
307309 # Open a new tab with javascript to bypass detection
308- driver .execute_script ("window.open('https://top.gg ', '_blank');" ) # Open a new tab
310+ driver .execute_script (f "window.open('{ url } ', '_blank');" ) # Open a new tab
309311 await asyncio .sleep (3 )
310312 new_handle = driver .window_handles [- 1 ]
311313 try :
@@ -315,17 +317,20 @@ async def fetch_invite_link(self, url: str):
315317 trace ("Finding 'challenge-running' cloudflare ID" , TraceLEVELS .DEBUG )
316318 driver .find_element (By .ID , "challenge-running" )
317319 driver .switch_to .window (main_window_handle )
318- await asyncio .sleep (5 * (i + 1 ))
320+ await asyncio .sleep (WD_FETCH_INVITE_CLOUDFLARE_DELAY * (i + 1 ))
319321 continue
320322
321323 await asyncio .sleep (2 )
322324 driver .switch_to .window (new_handle )
323325 trace ("No 'challenge-running' found. Checks suceeded" , TraceLEVELS .DEBUG )
324326 break
325327 else :
328+ driver .switch_to .window (new_handle )
329+ driver .close ()
330+ driver .switch_to .window (main_window_handle )
326331 raise RuntimeError ("Could not complete cloudflare checks" )
327332
328- await self .async_execute (driver .get , url )
333+ # await self.async_execute(driver.get, url)
329334 await self .async_execute (
330335 WebDriverWait (driver , WD_TIMEOUT_LONG ).until ,
331336 url_contains ("discord.com" )
0 commit comments