diff --git a/README.md b/README.md index 785b51a..f49190b 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ await rust_socket.turn_on_smart_switch(ENTITYID) await rust_socket.promote_to_team_leader(SteamID) #Getting the contents of a TC: -tc_contents = await rust_socket.get_tc__storage_contents(ENTITYID, MERGESTACKS : bool) +tc_contents = await rust_socket.get_tc_storage_contents(ENTITYID, MERGESTACKS : bool) #Getting Current Map Events events = await rust_socket.get_current_events() @@ -84,7 +84,7 @@ async def hi(command : Command): #Used to just stop a script from ending. Use this if you are using commands await rust_socket.hang() -await rust_socket.closeConnection() +await rust_socket.close_connection() ``` # For information on all of the above methods, see the [Wiki](https://github.com/olijeffers0n/rustplus/wiki) diff --git a/rustplus/api/base_rust_api.py b/rustplus/api/base_rust_api.py index 76f37e4..1898ef6 100644 --- a/rustplus/api/base_rust_api.py +++ b/rustplus/api/base_rust_api.py @@ -78,6 +78,12 @@ async def close_connection(self) -> None: """ self.ws.close() self.ws.responses.clear() + + async def disconnect(self) -> None: + """ + Disconnects from the Rust Server + """ + await self.close_connection() def command(self, coro) -> None: """ diff --git a/rustplus/api/remote/rustws.py b/rustplus/api/remote/rustws.py index bbdc4df..b445a36 100644 --- a/rustplus/api/remote/rustws.py +++ b/rustplus/api/remote/rustws.py @@ -2,12 +2,13 @@ from asyncio import AbstractEventLoop from ws4py.client.threadedclient import WebSocketClient +from rustplus.exceptions.exceptions import ClientNotConnectedError + from .rustplus_pb2 import AppMessage, AppRequest from .token_bucket import RateLimiter from ..structures import RustChatMessage from ...commands import CommandOptions, CommandHandler from ...exceptions import ResponseNotRecievedError - class RustWsClient(WebSocketClient): def __init__(self, ip, port, command_options : CommandOptions, loop : AbstractEventLoop, protocols=None, extensions=None, heartbeat_freq=None, ssl_options=None, headers=None, exclude_headers=None): @@ -76,7 +77,10 @@ async def send_message(self, request : AppRequest) -> None: """ raw_data = request.SerializeToString() - self.send(raw_data, binary=True) + try: + self.send(raw_data, binary=True) + except: + raise ClientNotConnectedError("Not Connected") async def get_response(self, seq) -> AppMessage: """ diff --git a/rustplus/exceptions/__init__.py b/rustplus/exceptions/__init__.py index fe5dd57..6e15a9b 100644 --- a/rustplus/exceptions/__init__.py +++ b/rustplus/exceptions/__init__.py @@ -1 +1 @@ -from .exceptions import RateLimitError, ServerNotResponsiveError, CommandsNotEnabledError, ResponseNotRecievedError, PrefixNotDefinedError, ImageError +from .exceptions import RateLimitError, ServerNotResponsiveError, CommandsNotEnabledError, ResponseNotRecievedError, PrefixNotDefinedError, ImageError, ClientNotConnectedError diff --git a/rustplus/exceptions/exceptions.py b/rustplus/exceptions/exceptions.py index 3f69803..4158601 100644 --- a/rustplus/exceptions/exceptions.py +++ b/rustplus/exceptions/exceptions.py @@ -25,3 +25,7 @@ class PrefixNotDefinedError(Error): class ImageError(Error): """Raised when the bytes received are not valid""" pass + +class ClientNotConnectedError(Error): + """Raised when you are not connected to the Rust server""" + pass \ No newline at end of file