diff --git a/rustplus/__init__.py b/rustplus/__init__.py index ab50e5a..dfc17a0 100644 --- a/rustplus/__init__.py +++ b/rustplus/__init__.py @@ -8,5 +8,5 @@ __name__ = "rustplus" __author__ = "olijefferson" -__version__ = "5.0.5" +__version__ = "5.0.6" __support__ = "Discord: https://discord.gg/nQqJe8qvP8" diff --git a/rustplus/api/remote/rustws.py b/rustplus/api/remote/rustws.py index 8ff9612..cd77c87 100644 --- a/rustplus/api/remote/rustws.py +++ b/rustplus/api/remote/rustws.py @@ -17,6 +17,7 @@ def __init__(self, ip, port, command_options : CommandOptions, loop : AbstractEv self.responses = {} self.ignored_responses = [] self.ratelimiter = None + self.open = False if command_options is None: self.use_commands = False @@ -41,6 +42,14 @@ def closed(self, code, reason): """ return + def connect(self) -> None: + super().connect() + self.open = True + + def close(self, code=1000, reason='') -> None: + super().close(code=code, reason=reason) + self.open = False + def received_message(self, message): """ Called when a message is recieved from the server @@ -71,7 +80,7 @@ def is_command(self, app_message) -> bool: def is_message(self, app_message) -> bool: return str(app_message.broadcast.teamMessage.message.message) != "" - async def send_message(self, request : AppRequest) -> None: + async def send_message(self, request : AppRequest, depth = 1) -> None: """ Send the Protobuf to the server """ @@ -80,7 +89,10 @@ async def send_message(self, request : AppRequest) -> None: try: self.send(raw_data, binary=True) except: - raise ClientNotConnectedError("Not Connected") + if not self.open or depth >= 10: + raise ClientNotConnectedError("Not Connected") + self.connect() + await self.send_message(request=request) async def get_response(self, seq) -> AppMessage: """ diff --git a/rustplus/api/structures/rust_chat_message.py b/rustplus/api/structures/rust_chat_message.py index 77f1b6f..73f5808 100644 --- a/rustplus/api/structures/rust_chat_message.py +++ b/rustplus/api/structures/rust_chat_message.py @@ -2,11 +2,11 @@ class RustChatMessage(): def __init__(self, data): - self.steamId = int(data.steamId) - self.name = str(data.name) - self.message = str(data.message) - self.colour = data.color - self.time = int(data.time) + self.steamId : int = data.steamId + self.name : str = data.name + self.message : str = data.message + self.colour : str = data.color + self.time : int = data.time def __repr__(self): return "RustChatMessage[steamId={}, senderName={}, message={}, colour={}, time={}]".format(self.steamId, self.name, self.message, self.colour, self.time) \ No newline at end of file diff --git a/rustplus/api/structures/rust_contents.py b/rustplus/api/structures/rust_contents.py index c6fb313..f5c3048 100644 --- a/rustplus/api/structures/rust_contents.py +++ b/rustplus/api/structures/rust_contents.py @@ -1,10 +1,14 @@ +from typing import List +from datetime import timedelta +from .rust_item import RustItem + class RustContents: def __init__(self, protectionTime, hasProtection, contents) -> None: - self.protectionTime = protectionTime - self.hasProtection = hasProtection - self.contents = contents + self.protectionTime : timedelta = protectionTime + self.hasProtection : bool = hasProtection + self.contents : List[RustItem] = contents def __str__(self) -> str: return "RustContents[protectionTime={}, hasProtection={}, contents={}]".format(self.protectionTime, self.hasProtection, self.contents) diff --git a/rustplus/api/structures/rust_entity_info.py b/rustplus/api/structures/rust_entity_info.py index 5f04e8e..0f7fea4 100644 --- a/rustplus/api/structures/rust_entity_info.py +++ b/rustplus/api/structures/rust_entity_info.py @@ -2,12 +2,12 @@ class RustEntityInfo: def __init__(self, data) -> None: - self.type = data.type - self.value = data.payload.value + self.type : int = data.type + self.value : bool = data.payload.value self.items = [RustEntityInfoItem(item) for item in data.payload.items] - self.capacity = data.payload.capacity - self.hasProtection = data.payload.hasProtection - self.protectionExpiry = data.payload.protectionExpiry + self.capacity : int = data.payload.capacity + self.hasProtection : bool = data.payload.hasProtection + self.protectionExpiry : int = data.payload.protectionExpiry def __str__(self) -> str: return "RustEntityInfo[type={}, value={}, items={}, capacity={}, hasProtection={}, protectionExpiry={}]".format(self.type, self.value, self.items, self.capacity, self.hasProtection, self.protectionExpiry) @@ -17,9 +17,9 @@ class RustEntityInfoItem: def __init__(self, data) -> None: - self.itemId = data.itemId - self.quantity = data.quantity - self.itemIsBlueprint = data.itemIsBlueprint + self.itemId : int = data.itemId + self.quantity : int = data.quantity + self.itemIsBlueprint : bool = data.itemIsBlueprint def __str__(self) -> str: return "RustEntityInfoItem[itemId={}, quantity={}, itemIsBlueprint={}]".format(self.itemId, self.quantity, self.itemIsBlueprint) \ No newline at end of file diff --git a/rustplus/api/structures/rust_info.py b/rustplus/api/structures/rust_info.py index 19da4ec..0cd9ab3 100644 --- a/rustplus/api/structures/rust_info.py +++ b/rustplus/api/structures/rust_info.py @@ -2,14 +2,14 @@ class RustInfo: def __init__(self, data) -> None: - self.url = data.url - self.name = data.name - self.map = data.map - self.size = data.mapSize - self.players = data.players - self.max_players = data.maxPlayers - self.queued_players = data.queuedPlayers - self.seed = data.seed + self.url : str = data.url + self.name : str = data.name + self.map : str = data.map + self.size : int = data.mapSize + self.players : int = data.players + self.max_players : int = data.maxPlayers + self.queued_players : int = data.queuedPlayers + self.seed : int = data.seed def __str__(self) -> str: return "RustInfo[url={}, name={}, map={}, size={}, players={}, max_players={}, queued_players={}, seed={}]".format(self.url, self.name, self.map, self.size, self.players, self.max_players, self.queued_players, self.seed) \ No newline at end of file diff --git a/rustplus/api/structures/rust_item.py b/rustplus/api/structures/rust_item.py index bdc7259..ba49fd0 100644 --- a/rustplus/api/structures/rust_item.py +++ b/rustplus/api/structures/rust_item.py @@ -2,10 +2,10 @@ class RustItem: def __init__(self, name : str, itemId : int, quantity : int, isBlueprint : bool) -> None: - self.name = name - self.itemId = itemId - self.quantity = quantity - self.isBlueprint = isBlueprint + self.name : str = name + self.itemId : int = itemId + self.quantity : int = quantity + self.isBlueprint : bool = isBlueprint def __str__(self) -> str: return "RustItem[name={}, itemId={}, quantity={}, isBlueprint={}]".format(self.name, self.itemId, self.quantity, self.isBlueprint) \ No newline at end of file diff --git a/rustplus/api/structures/rust_map.py b/rustplus/api/structures/rust_map.py index 5ee28b8..63a10ba 100644 --- a/rustplus/api/structures/rust_map.py +++ b/rustplus/api/structures/rust_map.py @@ -2,12 +2,12 @@ class RustMap: def __init__(self, data) -> None: - self.width = data.width - self.height = data.height - self.jpgImage = data.jpgImage - self.margin = data.oceanMargin + self.width : int = data.width + self.height : int = data.height + self.jpgImage : float = data.jpgImage + self.margin : int = data.oceanMargin self.monuments = [RustMonument(monument.token, monument.x, monument.y) for monument in data.monuments] - self.background = None if data.background == "" else data.background + self.background : str = None if data.background == "" else data.background def __str__(self) -> str: return "RustMap[width={}, height={}, jpgImage={}, margin={}, monuments={}, background={}]".format(self.width, self.height, len(self.jpgImage), self.margin, self.monuments, self.background) @@ -17,9 +17,9 @@ class RustMonument: def __init__(self, token, x, y) -> None: - self.token = token - self.x = x - self.y = y + self.token : str = token + self.x : float = x + self.y : float = y def __str__(self) -> str: return "RustMonument[token={}, x={}, y={}]" \ No newline at end of file diff --git a/rustplus/api/structures/rust_marker.py b/rustplus/api/structures/rust_marker.py index 29a77fd..b75456c 100644 --- a/rustplus/api/structures/rust_marker.py +++ b/rustplus/api/structures/rust_marker.py @@ -2,31 +2,31 @@ class RustMarker: def __init__(self, data) -> None: - self.id = data.id - self.type = data.type - self.x = data.x - self.y = data.y - self.steamId = data.steamId - self.rotation = data.rotation - self.radius = data.radius + self.id : int = data.id + self.type : int = data.type + self.x : float = data.x + self.y : float = data.y + self.steamId : int = data.steamId + self.rotation : float = data.rotation + self.radius : float = data.radius self.colour1 = RustColour(data.color1) self.colour2 = RustColour(data.color2) - self.alpha = data.alpha - self.name = data.name + self.alpha : float = data.alpha + self.name : str = data.name self.sellOrders = [RustSellOrder(order) for order in data.sellOrders] def __str__(self) -> str: - return "RustMarker[id={}, type={}, x={}, y={}, steamId={}, rotation={}, radius={}, colour1={}, colour2={}, alpha={}, name={}, sellOrders={}]".format(self.id, self.type, self.x, self.y, self.steamId, self.rotation, self.radius, self.colour1, self.colour2, self.alpha, self.name, len(self.sellOrders)) + return "RustMarker[id={}, type={}, x={}, y={}, steamId={}, rotation={}, radius={}, colour1={}, colour2={}, alpha={}, name={}, sellOrders={}]".format(self.id, self.type, self.x, self.y, self.steamId, self.rotation, self.radius, self.colour1, self.colour2, self.alpha, self.name, self.sellOrders) class RustColour: def __init__(self, data) -> None: - self.x = data.x - self.y = data.y - self.z = data.z - self.w = data.w + self.x : float = data.x + self.y : float = data.y + self.z : float = data.z + self.w : float = data.w def __str__(self) -> str: return "RustColour[x={}, y={}, z={}, w={}]".format(self.x, self.y, self.z, self.w) @@ -36,12 +36,12 @@ class RustSellOrder: def __init__(self, data) -> None: - self.itemId = data.itemId - self.quantity = data.quantity - self.currencyId = data.currencyId - self.costPerItem = data.costPerItem - self.itemIsBlueprint = data.itemIsBlueprint - self.currencyIsBlueprint = data.currencyIsBlueprint + self.itemId : int = data.itemId + self.quantity : int = data.quantity + self.currencyId : int = data.currencyId + self.costPerItem : int = data.costPerItem + self.itemIsBlueprint : bool = data.itemIsBlueprint + self.currencyIsBlueprint : bool = data.currencyIsBlueprint def __str__(self) -> str: return "RustSellOrder[itemId={}, quantity={}, currencyId={}, costPerItem={}, itemIsBlueprint={}, currencyIsBlueprint={}]".format(self.itemId, self.quantity, self.currencyId, self.costPerItem, self.itemIsBlueprint, self.currencyIsBlueprint) \ No newline at end of file diff --git a/rustplus/api/structures/rust_team_info.py b/rustplus/api/structures/rust_team_info.py index d679fe7..37c6e9c 100644 --- a/rustplus/api/structures/rust_team_info.py +++ b/rustplus/api/structures/rust_team_info.py @@ -2,7 +2,7 @@ class RustTeamInfo: def __init__(self, data) -> None: - self.leaderSteamId = data.leaderSteamId + self.leaderSteamId : int = data.leaderSteamId self.members = [RustTeamMember(member) for member in data.members] self.mapNotes = [RustTeamNote(note) for note in data.mapNotes] self.leaderMapNotes = [RustTeamNote(note) for note in data.leaderMapNotes] @@ -14,14 +14,14 @@ class RustTeamMember: def __init__(self, data) -> None: - self.steamId = data.steamId - self.name = data.name - self.x = data.x - self.y = data.y - self.isOnline = data.isOnline - self.spawnTime = data.spawnTime - self.isAlive = data.isAlive - self.deathTime = data.deathTime + self.steamId : int = data.steamId + self.name : str= data.name + self.x : float = data.x + self.y : float = data.y + self.isOnline : bool = data.isOnline + self.spawnTime : int = data.spawnTime + self.isAlive : bool = data.isAlive + self.deathTime : int = data.deathTime def __str__(self) -> str: return "RustTeamMember[steamId={}, name={}, x={}, y={}, isOnline={}, spawnTime={}, isAlive={}, deathTime={}]".format(self.steamId, self.name, self.x, self.y, self.isOnline, self.spawnTime, self.isAlive, self.deathTime) @@ -30,9 +30,9 @@ class RustTeamNote: def __init__(self, data) -> None: - self.type = data.type - self.x = data.x - self.y = data.y + self.type : int = data.type + self.x : float = data.x + self.y : float = data.y def __str__(self) -> str: return "RustTeamNote[type={}, x={}, y={}]".format(self.type, self.x, self.y) \ No newline at end of file diff --git a/rustplus/api/structures/rust_time.py b/rustplus/api/structures/rust_time.py index a21994f..f0cf22a 100644 --- a/rustplus/api/structures/rust_time.py +++ b/rustplus/api/structures/rust_time.py @@ -2,11 +2,11 @@ class RustTime: def __init__(self, day_length, sunrise, sunset, time, raw_time) -> None: - self.day_length = day_length - self.sunrise = sunrise - self.sunset = sunset - self.time = time - self.raw_time = raw_time + self.day_length : float = day_length + self.sunrise : str = sunrise + self.sunset : str = sunset + self.time : str = time + self.raw_time : float = raw_time def __str__(self) -> str: return f"RustTime[day_length={self.day_length}, sunrise={self.sunrise}, sunset={self.sunset}, time={self.time}, raw_time={self.raw_time}]" \ No newline at end of file diff --git a/setup.py b/setup.py index 52690b3..83d2fa8 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ project_urls={ "Issue tracker": "https://github.com/olijeffers0n/rustplus/issues", }, - version="5.0.5", + version="5.0.6", include_package_data=True, packages = find_packages(include=['rustplus', 'rustplus.*']), license='MIT',