Skip to content

Commit

Permalink
Back to old reconnect real
Browse files Browse the repository at this point in the history
  • Loading branch information
Shell1010 committed Jan 20, 2024
1 parent dbc0f77 commit 8b39cc5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 55 deletions.
83 changes: 29 additions & 54 deletions selfcord/api/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ async def send_json(self, payload: dict):
if e.rcvd.code == 4008:
await aprint(f"RECEIVE: {e.rcvd.code} --- {e.rcvd.reason}")
await self.close()
raise ReconnectWebsocket("Ratelimited", resume=True, op=self.op)

await asyncio.sleep(2)
await self.connect(self.bot.resume_url)
await self.resume()

if e.sent is not None:
if e.sent.code == 4008:
await aprint(f"SENT: {e.sent.code} --- {e.sent.reason}")
await self.close()
raise ReconnectWebsocket("Ratelimited", resume=True, op=self.op)
await asyncio.sleep(2)
await self.connect(self.bot.resume_url)
await self.resume()

await self.close()
raise ReconnectWebsocket("Unknown", resume=False, op=False)
Expand Down Expand Up @@ -130,9 +134,9 @@ async def recv_json(self):
await aprint(f"Attempting reconnect???? {self.bot.user.username}")
# await self.linux_run(f"notify-send 'RECONNECT HAPPENING NOW CHECK CONSOLE {data} {op}'")
await self.close()


raise ReconnectWebsocket("Reconnect Sent", resume=True, op=self.op)
await asyncio.sleep(2)
await self.connect(self.bot.resume_url)
await self.resume()


elif self.op == self.DISPATCH:
Expand Down Expand Up @@ -167,39 +171,17 @@ async def start(self, token: str, resume: bool = False):
if e.rcvd.code == 4008:
await aprint(f"RECEIVE: {e.rcvd.code} --- {e.rcvd.reason}")
await self.close()
raise ReconnectWebsocket("Ratelimited", resume=True, op=self.op)
await asyncio.sleep(2)
await self.connect(self.bot.resume_url)
await self.resume()

if e.sent is not None:
if e.sent.code == 4008:
await aprint(f"SENT: {e.sent.code} --- {e.sent.reason}")
await self.close()
raise ReconnectWebsocket("Ratelimited", resume=True, op=self.op)

await self.close()
raise ReconnectWebsocket("Unknown", resume=False, op=False)
else:
await self.connect(self.bot.resume_url)
await asyncio.sleep(1)
await self.resume()
while self.alive:
try:

await self.recv_json()

except ConnectionClosed as e:

await aprint(f"Closing because fail recv. Attempting reconnect {self.bot.user.username}\n{e}")
if e.rcvd is not None:
if e.rcvd.code == 4008:
await aprint(f"RECEIVE: {e.rcvd.code} --- {e.rcvd.reason}")
await self.close()
raise ReconnectWebsocket("Ratelimited", resume=True, op=self.op)

if e.sent is not None:
if e.sent.code == 4008:
await aprint(f"SENT: {e.sent.code} --- {e.sent.reason}")
await self.close()
raise ReconnectWebsocket("Ratelimited", resume=True, op=self.op)
await asyncio.sleep(2)
await self.connect(self.bot.resume_url)
await self.resume()

await self.close()
raise ReconnectWebsocket("Unknown", resume=False, op=False)
Expand Down Expand Up @@ -265,28 +247,21 @@ async def identify(self):
},
"properties": {
"os": "Linux",
"browser": "Discord Client",
"browser_version": "22.3.12",
"client_build_number": 221132,
"client_event_source": None,
"client_version": "0.0.162",
"browser_useragent": (
"Mozilla/5.0 (X11; Linux x86_64)"
"AppleWebKit/537.36 "
"(KHTML, like Gecko) "
"discord/0.0.157 "
"Chrome/108.0.5359.215 "
"Electron/22.3.2 "
"Safari/537.36"
),
"distro": '"Manjaro Linux"',
"native_build_number": None,
"os_version": "5.10.189-1-MANJARO",
"browser": "Chrome",
"device": "",
"system_locale": "en-GB",
"browser_user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"browser_version": "118.0.0.0",
"os_version": "",
"referrer": "",
"referring_domain": "",
"referrer_current": "",
"referring_domain_current": "",
"release_channel": "canary",
"window_manager": "KDE, unknown",
"system-locale": "en-GB",
"os_arch": "x64",
"client_build_number": 259975,
"client_event_source": None
},

},
}
await self.send_json(payload)
Expand Down
2 changes: 1 addition & 1 deletion selfcord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ async def get_user(self, user_id: str) -> Optional[User]:
return

async def join_invite(self, invite_code: str) -> Optional[Guild|GroupChannel]:
json = await self.http.request(method="post", endpoint=f"/invites/{invite_code}")
json = await self.http.request(method="post", endpoint=f"/invites/{invite_code}", json={})

if json is not None:
if "guild" in json:
Expand Down

0 comments on commit 8b39cc5

Please sign in to comment.