From 4952579c6b3b88472d2afd40dff9da5e8f6cb6ed Mon Sep 17 00:00:00 2001 From: olijeffers0n <69084614+olijeffers0n@users.noreply.github.com> Date: Sun, 19 Dec 2021 19:49:16 +0000 Subject: [PATCH] Fix In-Game Commands more --- rustplus/__init__.py | 2 +- rustplus/api/base_rust_api.py | 14 ++++++++++++++ rustplus/api/remote/rustws.py | 2 +- rustplus/commands/command_handler.py | 4 +--- setup.py | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/rustplus/__init__.py b/rustplus/__init__.py index 8c70410..cff31b6 100644 --- a/rustplus/__init__.py +++ b/rustplus/__init__.py @@ -8,5 +8,5 @@ __name__ = "rustplus" __author__ = "olijefferson" -__version__ = "5.0.2" +__version__ = "5.0.3" __support__ = "Discord: https://discord.gg/nQqJe8qvP8" diff --git a/rustplus/api/base_rust_api.py b/rustplus/api/base_rust_api.py index 1898ef6..0240e62 100644 --- a/rustplus/api/base_rust_api.py +++ b/rustplus/api/base_rust_api.py @@ -69,6 +69,7 @@ async def connect(self) -> None: """ try: self.ws.connect() + await self._send_wakeup_request() except ConnectionRefusedError: raise ServerNotResponsiveError("Cannot Connect") @@ -84,6 +85,19 @@ async def disconnect(self) -> None: Disconnects from the Rust Server """ await self.close_connection() + + async def _send_wakeup_request(self) -> None: + """ + Sends a request to the server to wake up broadcast responses + """ + await self._handle_ratelimit() + + app_request = self._generate_protobuf() + app_request.checkSubscription.CopyFrom(AppEmpty()) + + self.ws.ignored_responses.append(app_request.seq) + + await self.ws.send_message(app_request) def command(self, coro) -> None: """ diff --git a/rustplus/api/remote/rustws.py b/rustplus/api/remote/rustws.py index b445a36..8ff9612 100644 --- a/rustplus/api/remote/rustws.py +++ b/rustplus/api/remote/rustws.py @@ -90,7 +90,7 @@ async def get_response(self, seq) -> AppMessage: attempts = 0 while seq not in self.responses: - if attempts == 20: + if attempts == 50: raise ResponseNotRecievedError("Not Recieved") attempts += 1 diff --git a/rustplus/commands/command_handler.py b/rustplus/commands/command_handler.py index ba809d6..e1eda90 100644 --- a/rustplus/commands/command_handler.py +++ b/rustplus/commands/command_handler.py @@ -20,9 +20,7 @@ def registerCommand(self, command, coro) -> None: setattr(self, command, coro) def _schedule_event(self, coro, arg) -> None: - - # I would like to find a replacement for the following, as it can be a bit slow to execute but it will do for now - self.loop.create_task(coro(arg)) + asyncio.run_coroutine_threadsafe(coro(arg), self.loop) def run_command(self, message : RustChatMessage) -> None: diff --git a/setup.py b/setup.py index 99c6f9d..7618a9b 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ project_urls={ "Issue tracker": "https://github.com/olijeffers0n/rustplus/issues", }, - version="5.0.2", + version="5.0.3", include_package_data=True, packages = find_packages(include=['rustplus', 'rustplus.*']), license='MIT',