Skip to content

Commit 0007a9e

Browse files
committed
Bug Fixes
1 parent b7778f1 commit 0007a9e

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

docs/source/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Releases
4141
=======================
4242
- Fixed *Unclosed client session* warning when removing an user account.
4343
- Fixed documentation of :func:`daf.core.shutdown` - removed information about non existent parameters.
44+
- Selenium better waiting avoidance
45+
- Fixed ACCOUNT not being removed from the list if the update failed and the re-login after update failed.
4446

4547

4648
v2.10.1

src/daf/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ async def update_servers(self_):
550550
await async_util.update_obj_param(self, **kwargs)
551551
await update_servers(self)
552552
except Exception:
553-
await self.initialize() # re-login
554-
await update_servers(self)
553+
try:
554+
await self.initialize() # re-login
555+
await update_servers(self)
556+
except Exception:
557+
self._delete()
558+
555559
raise

src/daf/web.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class GLOBALS:
6565
WD_TIMEOUT_30 = 30
6666
WD_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+
6971
WD_RD_CLICK_UPPER_N = 5
7072
WD_RD_CLICK_LOWER_N = 2
7173
WD_OUTPUT_PATH = pathlib.Path.home().joinpath("daf/daf_web_data")
@@ -78,7 +80,6 @@ class GLOBALS:
7880

7981
TOP_GG_SEARCH_URL = "https://top.gg/api/client/entities/search"
8082
TOP_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

Comments
 (0)