From 8b39cc562bba4a462060d2ebdab770048f4af1f6 Mon Sep 17 00:00:00 2001 From: Shell1010 Date: Sat, 20 Jan 2024 19:03:29 +0000 Subject: [PATCH] Back to old reconnect real --- selfcord/api/gateway.py | 83 ++++++++++++++--------------------------- selfcord/bot.py | 2 +- 2 files changed, 30 insertions(+), 55 deletions(-) diff --git a/selfcord/api/gateway.py b/selfcord/api/gateway.py index ee5bd61..bf7b2f2 100644 --- a/selfcord/api/gateway.py +++ b/selfcord/api/gateway.py @@ -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) @@ -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: @@ -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) @@ -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) diff --git a/selfcord/bot.py b/selfcord/bot.py index a33ea7c..c399267 100644 --- a/selfcord/bot.py +++ b/selfcord/bot.py @@ -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: