Skip to content

Commit

Permalink
Merge pull request #21 from Flamer01/main
Browse files Browse the repository at this point in the history
Update remoteauthclient.py
  • Loading branch information
RuslanUC authored Nov 5, 2022
2 parents e1e4e5e + 78587ae commit 2fcc282
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions remoteauthclient/remoteauthclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def getAvatarURL(self) -> str:
return f"https://cdn.discord.com/avatars/{self.id}/{self.avatar}.png"

class RemoteAuthClient:
def __init__(self, proxy=None, proxy_auth=None, user_agent=None):
def __init__(self, proxy=None, proxy_auth=None, proxy_type="http", user_agent=None, captcha_attempts=1):
if proxy_type not in ["http", "socks5"]:
raise ValueError('The proxy type is not supported, choose "http" or "socks5".')
self._task = None
self._heartbeatTask = None
self._ws = None
Expand All @@ -51,7 +53,10 @@ def __init__(self, proxy=None, proxy_auth=None, user_agent=None):
self._retries = 0
self._rqtoken = None

self.captcha_attempts = captcha_attempts
self.captcha_attempts_use = 0
self.proxy = proxy
self.proxy_type = proxy_type
self.proxy_auth = proxy_auth
self.user_agent = user_agent or "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"

Expand Down Expand Up @@ -157,7 +162,7 @@ async def _getHeaders(self) -> dict:
async def _getToken(self, ticket: str, captcha_key: Optional[str]=None) -> Optional[str]:
_proxy = {}
if self.proxy:
_proxy["proxy"] = f"http://{self.proxy}"
_proxy["proxy"] = f"{self.proxy_type}://{self.proxy}"
if self.proxy_auth:
_proxy["proxy_auth"] = BasicAuth(**self.proxy_auth)
async with ClientSession(headers=await self._getHeaders()) as sess:
Expand All @@ -170,9 +175,10 @@ async def _getToken(self, ticket: str, captcha_key: Optional[str]=None) -> Optio
j = await resp.json()
log.debug(f"Response code: {resp.status}")
log.debug(f"Response body: {j}")
if "encrypted_token" not in j and captcha_key is None and "captcha_key" in j:
if "encrypted_token" not in j and "captcha_key" in j and self.captcha_attempts_use < self.captcha_attempts:
log.debug(f"Detected captcha response. Calling on_captcha method with {j}")
del j["captcha_key"]
self.captcha_attempts_use += 1
self._rqtoken = j["captcha_rqtoken"]
captcha_key = await self._event("captcha", captcha_data=j)
log.debug(f"on_captcha result: {captcha_key}")
Expand Down Expand Up @@ -251,4 +257,4 @@ async def run_task(self) -> None:

async def cancel(self) -> None:
await self._cleanup()
await self._event("cancel")
await self._event("cancel")

0 comments on commit 2fcc282

Please sign in to comment.