rustplus 6.0.2__tar.gz → 6.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. {rustplus-6.0.2/rustplus.egg-info → rustplus-6.0.4}/PKG-INFO +11 -2
  2. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/__init__.py +3 -2
  3. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/websocket/ws.py +28 -14
  4. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/rust_api.py +79 -43
  5. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/__init__.py +1 -0
  6. rustplus-6.0.4/rustplus/structs/rust_error.py +33 -0
  7. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/__init__.py +1 -0
  8. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/utils.py +16 -0
  9. {rustplus-6.0.2 → rustplus-6.0.4/rustplus.egg-info}/PKG-INFO +11 -2
  10. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus.egg-info/SOURCES.txt +1 -0
  11. {rustplus-6.0.2 → rustplus-6.0.4}/LICENSE +0 -0
  12. {rustplus-6.0.2 → rustplus-6.0.4}/MANIFEST.in +0 -0
  13. {rustplus-6.0.2 → rustplus-6.0.4}/README.md +0 -0
  14. {rustplus-6.0.2 → rustplus-6.0.4}/requirements.txt +0 -0
  15. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/annotations/__init__.py +0 -0
  16. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/annotations/chat_event.py +0 -0
  17. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/annotations/command.py +0 -0
  18. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/annotations/entity_event.py +0 -0
  19. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/annotations/protobuf_event.py +0 -0
  20. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/annotations/team_event.py +0 -0
  21. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/commands/__init__.py +0 -0
  22. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/commands/chat_command.py +0 -0
  23. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/commands/chat_command_data.py +0 -0
  24. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/commands/command_options.py +0 -0
  25. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/events/__init__.py +0 -0
  26. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/events/chat_event.py +0 -0
  27. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/events/entity_event.py +0 -0
  28. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/events/protobuf_event.py +0 -0
  29. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/events/team_event.py +0 -0
  30. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/exceptions/__init__.py +0 -0
  31. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/exceptions/exceptions.py +0 -0
  32. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/__init__.py +0 -0
  33. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/airfield.png +0 -0
  34. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/arctic_base.png +0 -0
  35. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/bandit.png +0 -0
  36. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/barn.png +0 -0
  37. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/cargo.png +0 -0
  38. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/chinook.png +0 -0
  39. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/chinook_blades.png +0 -0
  40. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/crate.png +0 -0
  41. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/desert_base.png +0 -0
  42. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/dome.png +0 -0
  43. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/excavator.png +0 -0
  44. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/explosion.png +0 -0
  45. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/ferryterminal.png +0 -0
  46. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/fishing.png +0 -0
  47. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/harbour.png +0 -0
  48. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/icon.png +0 -0
  49. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/junkyard.png +0 -0
  50. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/large_oil_rig.png +0 -0
  51. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/launchsite.png +0 -0
  52. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/lighthouse.png +0 -0
  53. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/military_tunnels.png +0 -0
  54. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/mining_outpost.png +0 -0
  55. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/mining_quarry_hqm.png +0 -0
  56. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/mining_quarry_stone.png +0 -0
  57. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/mining_quarry_sulfur.png +0 -0
  58. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/missile_silo.png +0 -0
  59. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/outpost.png +0 -0
  60. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/oxums.png +0 -0
  61. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/patrol.png +0 -0
  62. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/power_plant.png +0 -0
  63. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/satellite.png +0 -0
  64. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/sewer.png +0 -0
  65. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/small_oil_rig.png +0 -0
  66. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/stables.png +0 -0
  67. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/supermarket.png +0 -0
  68. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/swamp.png +0 -0
  69. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/train.png +0 -0
  70. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/train_yard.png +0 -0
  71. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/underwater_lab.png +0 -0
  72. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/vending_machine.png +0 -0
  73. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/icons/water_treatment.png +0 -0
  74. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/identification/__init__.py +0 -0
  75. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/identification/handler_list.py +0 -0
  76. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/identification/registered_listener.py +0 -0
  77. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/identification/server_details.py +0 -0
  78. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/__init__.py +0 -0
  79. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/camera/__init__.py +0 -0
  80. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/camera/camera_constants.py +0 -0
  81. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/camera/camera_manager.py +0 -0
  82. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/camera/camera_parser.py +0 -0
  83. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/camera/structures.py +0 -0
  84. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/fcm/__init__.py +0 -0
  85. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/fcm/fcm_listener.py +0 -0
  86. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/proxy/__init__.py +0 -0
  87. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/proxy/proxy_value_grabber.py +0 -0
  88. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/ratelimiter/__init__.py +0 -0
  89. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/rustplus_proto/__init__.py +0 -0
  90. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/rustplus_proto/rustplus.py +0 -0
  91. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/remote/websocket/__init__.py +0 -0
  92. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_chat_message.py +0 -0
  93. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_contents.py +0 -0
  94. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_entity_info.py +0 -0
  95. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_info.py +0 -0
  96. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_item.py +0 -0
  97. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_map.py +0 -0
  98. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_marker.py +0 -0
  99. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_team_info.py +0 -0
  100. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/rust_time.py +0 -0
  101. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/serialization.py +0 -0
  102. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/structs/util.py +0 -0
  103. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/deprecated.py +0 -0
  104. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/emojis.py +0 -0
  105. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/fonts/PermanentMarker.ttf +0 -0
  106. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/fonts/__init__.py +0 -0
  107. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/grab_items.py +0 -0
  108. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus/utils/yielding_event.py +0 -0
  109. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus.egg-info/dependency_links.txt +0 -0
  110. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus.egg-info/requires.txt +0 -0
  111. {rustplus-6.0.2 → rustplus-6.0.4}/rustplus.egg-info/top_level.txt +0 -0
  112. {rustplus-6.0.2 → rustplus-6.0.4}/setup.cfg +0 -0
  113. {rustplus-6.0.2 → rustplus-6.0.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: rustplus
3
- Version: 6.0.2
3
+ Version: 6.0.4
4
4
  Summary: A python wrapper for the Rust Plus API
5
5
  Home-page: https://github.com/olijeffers0n/rustplus
6
6
  Author: olijeffers0n
@@ -18,6 +18,15 @@ Requires-Dist: requests
18
18
  Requires-Dist: numpy
19
19
  Requires-Dist: scipy
20
20
  Requires-Dist: betterproto==2.0.0b6
21
+ Dynamic: author
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: license
26
+ Dynamic: project-url
27
+ Dynamic: requires-dist
28
+ Dynamic: requires-python
29
+ Dynamic: summary
21
30
 
22
31
  ![Rust+.py](https://raw.githubusercontent.com/olijeffers0n/rustplus/master/icon.png)
23
32
  <div align = "center">
@@ -8,9 +8,10 @@ from .annotations import Command, ChatEvent, ProtobufEvent, TeamEvent, EntityEve
8
8
  from .remote.fcm import FCMListener
9
9
  from .commands import CommandOptions, ChatCommand
10
10
  from .events import ChatEventPayload, TeamEventPayload, EntityEventPayload
11
- from .utils import convert_event_type_to_name, Emoji
11
+ from .utils import convert_event_type_to_name, Emoji, convert_coordinates
12
+ from .structs import RustError, RustMarker
12
13
 
13
14
  __name__ = "rustplus"
14
15
  __author__ = "olijeffers0n"
15
- __version__ = "6.0.2"
16
+ __version__ = "6.0.4"
16
17
  __support__ = "Discord: https://discord.gg/nQqJe8qvP8"
@@ -11,7 +11,7 @@ import asyncio
11
11
 
12
12
  from ..camera import CameraManager
13
13
  from ..proxy import ProxyValueGrabber
14
- from ..rustplus_proto import AppMessage, AppRequest
14
+ from ..rustplus_proto import AppMessage, AppRequest, AppError
15
15
  from ...commands import CommandOptions, ChatCommand, ChatCommandTime
16
16
  from ...events import (
17
17
  ProtobufEventPayload,
@@ -19,10 +19,11 @@ from ...events import (
19
19
  TeamEventPayload,
20
20
  ChatEventPayload,
21
21
  )
22
- from ...exceptions import ClientNotConnectedError, RequestError
22
+ from ...exceptions import RequestError
23
23
  from ...identification import ServerDetails, RegisteredListener
24
24
  from ...structs import RustChatMessage, RustTeamInfo
25
25
  from ...utils import YieldingEvent, convert_time
26
+ from ...utils.utils import error_present
26
27
 
27
28
 
28
29
  class RustWebsocket:
@@ -133,14 +134,21 @@ class RustWebsocket:
133
134
  )
134
135
 
135
136
  async def send_and_get(self, request: AppRequest) -> AppMessage:
136
- await self.send_message(request)
137
+ if not await self.send_message(request):
138
+ message = AppMessage()
139
+ error = AppError()
140
+ error.error = "Message Failed to send"
141
+ message.response.seq = request.seq
142
+ message.response.error = error
143
+ return message
137
144
  return await self.get_response(request.seq)
138
145
 
139
146
  async def send_message(
140
147
  self, request: AppRequest, ignore_response: bool = False
141
- ) -> None:
148
+ ) -> bool:
142
149
  if self.connection is None:
143
- raise ClientNotConnectedError("No Current Websocket Connection")
150
+ self.logger.warning("No Current Websocket Connection")
151
+ return False
144
152
 
145
153
  if self.debug:
146
154
  self.logger.info(f"Sending Message with seq {request.seq}: {request}")
@@ -157,6 +165,9 @@ class RustWebsocket:
157
165
  await self.connection.send(bytes(request))
158
166
  except Exception as err:
159
167
  self.logger.warning("WebSocket connection error: %s", err)
168
+ return False
169
+
170
+ return True
160
171
 
161
172
  async def get_response(self, seq: int) -> Union[AppMessage, None]:
162
173
 
@@ -171,8 +182,18 @@ class RustWebsocket:
171
182
  f"Received Message with seq {app_message.response.seq}: {app_message}"
172
183
  )
173
184
 
174
- if self.error_present(app_message.response.error.error):
175
- raise RequestError(app_message.response.error.error)
185
+ if error_present(app_message):
186
+
187
+ event: YieldingEvent = self.responses.get(app_message.response.seq, None)
188
+ if event is not None:
189
+ if self.debug:
190
+ self.logger.info(
191
+ f"Running Response Event With Error: {app_message}"
192
+ )
193
+
194
+ event.set_with_value(app_message)
195
+ else:
196
+ raise RequestError(app_message.response.error.error)
176
197
 
177
198
  prefix = self.get_prefix(
178
199
  str(app_message.broadcast.team_message.message.message)
@@ -335,13 +356,6 @@ class RustWebsocket:
335
356
 
336
357
  raise ValueError()
337
358
 
338
- @staticmethod
339
- def error_present(message) -> bool:
340
- """
341
- Checks message for error
342
- """
343
- return message != ""
344
-
345
359
  @staticmethod
346
360
  async def run_coroutine_non_blocking(coroutine: Coroutine) -> Task:
347
361
  loop: AbstractEventLoop = asyncio.get_event_loop_policy().get_event_loop()
@@ -32,6 +32,7 @@ from .structs import (
32
32
  RustContents,
33
33
  RustItem,
34
34
  )
35
+ from .structs.rust_error import RustError
35
36
  from .utils import (
36
37
  convert_time,
37
38
  translate_id_to_stack,
@@ -42,6 +43,7 @@ from .utils import (
42
43
  convert_monument,
43
44
  )
44
45
  from .remote.ratelimiter import RateLimiter
46
+ from .utils.utils import error_present
45
47
 
46
48
 
47
49
  class RustSocket:
@@ -127,13 +129,13 @@ class RustSocket:
127
129
  This Will permanently put your script into a state of 'hanging' Cannot be Undone. Only do this in scripts
128
130
  using commands
129
131
 
130
- :returns Nothing, This will never return
132
+ returns Nothing, This will never return
131
133
  """
132
134
 
133
135
  while True:
134
136
  await asyncio.sleep(1)
135
137
 
136
- async def get_time(self) -> Union[RustTime, None]:
138
+ async def get_time(self) -> Union[RustTime, RustError]:
137
139
  """
138
140
  Gets the current in-game time from the server.
139
141
 
@@ -142,18 +144,21 @@ class RustSocket:
142
144
 
143
145
  packet = await self._generate_request()
144
146
  packet.get_time = AppEmpty()
145
- packet = await self.ws.send_and_get(packet)
147
+ response = await self.ws.send_and_get(packet)
148
+
149
+ if response is None:
150
+ return RustError("get_time", "No response received")
146
151
 
147
- if packet is None:
148
- return None
152
+ if error_present(response):
153
+ return RustError("get_time", response.response.error.error)
149
154
 
150
155
  return RustTime(
151
- packet.response.time.day_length_minutes,
152
- convert_time(packet.response.time.sunrise),
153
- convert_time(packet.response.time.sunset),
154
- convert_time(packet.response.time.time),
155
- packet.response.time.time,
156
- packet.response.time.time_scale,
156
+ response.response.time.day_length_minutes,
157
+ convert_time(response.response.time.sunrise),
158
+ convert_time(response.response.time.sunset),
159
+ convert_time(response.response.time.time),
160
+ response.response.time.time,
161
+ response.response.time.time_scale,
157
162
  )
158
163
 
159
164
  async def send_team_message(self, message: str) -> None:
@@ -170,21 +175,24 @@ class RustSocket:
170
175
 
171
176
  await self.ws.send_message(packet, True)
172
177
 
173
- async def get_info(self) -> Union[RustInfo, None]:
178
+ async def get_info(self) -> Union[RustInfo, RustError]:
174
179
  """
175
180
  Gets information on the Rust Server
176
181
  :return: RustInfo - The info of the server
177
182
  """
178
183
  packet = await self._generate_request()
179
184
  packet.get_info = AppEmpty()
180
-
181
185
  response = await self.ws.send_and_get(packet)
186
+
182
187
  if response is None:
183
- return None
188
+ return RustError("get_info", "No response received")
189
+
190
+ if error_present(response):
191
+ return RustError("get_info", response.response.error.error)
184
192
 
185
193
  return RustInfo(response.response.info)
186
194
 
187
- async def get_team_chat(self) -> Union[List[RustChatMessage], None]:
195
+ async def get_team_chat(self) -> Union[List[RustChatMessage], RustError]:
188
196
  """
189
197
  Gets the team chat from the server
190
198
 
@@ -192,16 +200,19 @@ class RustSocket:
192
200
  """
193
201
  packet = await self._generate_request()
194
202
  packet.get_team_chat = AppEmpty()
195
-
196
203
  response = await self.ws.send_and_get(packet)
204
+
197
205
  if response is None:
198
- return None
206
+ return RustError("get_team_chat", "No response received")
207
+
208
+ if error_present(response):
209
+ return RustError("get_team_chat", response.response.error.error)
199
210
 
200
211
  return [
201
212
  RustChatMessage(message) for message in response.response.team_chat.messages
202
213
  ]
203
214
 
204
- async def get_team_info(self) -> Union[RustTeamInfo, None]:
215
+ async def get_team_info(self) -> Union[RustTeamInfo, RustError]:
205
216
  """
206
217
  Gets Information on the members of your team
207
218
 
@@ -209,14 +220,17 @@ class RustSocket:
209
220
  """
210
221
  packet = await self._generate_request()
211
222
  packet.get_team_info = AppEmpty()
212
-
213
223
  response = await self.ws.send_and_get(packet)
224
+
214
225
  if response is None:
215
- return None
226
+ return RustError("get_team_info", "No response received")
227
+
228
+ if error_present(response):
229
+ return RustError("get_team_info", response.response.error.error)
216
230
 
217
231
  return RustTeamInfo(response.response.team_info)
218
232
 
219
- async def get_markers(self) -> Union[List[RustMarker], None]:
233
+ async def get_markers(self) -> Union[List[RustMarker], RustError]:
220
234
  """
221
235
  Gets all the map markers from the server
222
236
 
@@ -224,10 +238,13 @@ class RustSocket:
224
238
  """
225
239
  packet = await self._generate_request()
226
240
  packet.get_map_markers = AppEmpty()
227
-
228
241
  response = await self.ws.send_and_get(packet)
242
+
229
243
  if response is None:
230
- return None
244
+ return RustError("get_markers", "No response received")
245
+
246
+ if error_present(response):
247
+ return RustError("get_markers", response.response.error.error)
231
248
 
232
249
  return [RustMarker(marker) for marker in response.response.map_markers.markers]
233
250
 
@@ -239,7 +256,7 @@ class RustSocket:
239
256
  add_team_positions: bool = False,
240
257
  override_images: dict = None,
241
258
  add_grid: bool = False,
242
- ) -> Union[Image.Image, None]:
259
+ ) -> Union[Image.Image, RustError]:
243
260
  """
244
261
  Gets an image of the map from the server with the specified additions
245
262
 
@@ -256,16 +273,20 @@ class RustSocket:
256
273
  override_images = {}
257
274
 
258
275
  server_info = await self.get_info()
259
- if server_info is None:
260
- return None
276
+ if isinstance(server_info, RustError):
277
+ return server_info
261
278
 
262
279
  map_size = server_info.size
263
280
 
264
281
  packet = await self._generate_request(5)
265
282
  packet.get_map = AppEmpty()
266
283
  response = await self.ws.send_and_get(packet)
284
+
267
285
  if response is None:
268
- return None
286
+ return RustError("get_map", "No response received")
287
+
288
+ if error_present(response):
289
+ return RustError("get_map", response.response.error.error)
269
290
 
270
291
  map_packet = response.response.map
271
292
  monuments: List[AppMapMonument] = map_packet.monuments
@@ -274,7 +295,7 @@ class RustSocket:
274
295
  output = Image.open(BytesIO(map_packet.jpg_image))
275
296
  except Exception as e:
276
297
  self.logger.error(f"Error opening image: {e}")
277
- return None
298
+ return RustError("get_map", str(e))
278
299
 
279
300
  output = output.crop(
280
301
  (500, 500, map_packet.height - 500, map_packet.width - 500)
@@ -349,7 +370,7 @@ class RustSocket:
349
370
 
350
371
  return output
351
372
 
352
- async def get_map_info(self) -> Union[RustMap, None]:
373
+ async def get_map_info(self) -> Union[RustMap, RustError]:
353
374
  """
354
375
  Gets the raw map data from the server
355
376
 
@@ -357,14 +378,19 @@ class RustSocket:
357
378
  """
358
379
  packet = await self._generate_request(tokens=5)
359
380
  packet.get_map = AppEmpty()
360
-
361
381
  response = await self.ws.send_and_get(packet)
382
+
362
383
  if response is None:
363
- return None
384
+ return RustError("get_map_info", "No response received")
385
+
386
+ if error_present(response):
387
+ return RustError("get_map_info", response.response.error.error)
364
388
 
365
389
  return RustMap(response.response.map)
366
390
 
367
- async def get_entity_info(self, eid: int = None) -> Union[RustEntityInfo, None]:
391
+ async def get_entity_info(
392
+ self, eid: int = None
393
+ ) -> Union[RustEntityInfo, RustError]:
368
394
  """
369
395
  Gets entity info from the server
370
396
 
@@ -374,10 +400,13 @@ class RustSocket:
374
400
  packet = await self._generate_request()
375
401
  packet.get_entity_info = AppEmpty()
376
402
  packet.entity_id = eid
377
-
378
403
  response = await self.ws.send_and_get(packet)
404
+
379
405
  if response is None:
380
- return None
406
+ return RustError("get_entity_info", "No response received")
407
+
408
+ if error_present(response):
409
+ return RustError("get_entity_info", response.response.error.error)
381
410
 
382
411
  return RustEntityInfo(response.response.entity_info)
383
412
 
@@ -413,7 +442,7 @@ class RustSocket:
413
442
 
414
443
  await self.ws.send_message(packet, True)
415
444
 
416
- async def check_subscription_to_entity(self, eid: int) -> Union[bool, None]:
445
+ async def check_subscription_to_entity(self, eid: int) -> Union[bool, RustError]:
417
446
  """
418
447
  Checks if you are subscribed to an entity
419
448
 
@@ -423,10 +452,15 @@ class RustSocket:
423
452
  packet = await self._generate_request()
424
453
  packet.check_subscription = AppEmpty()
425
454
  packet.entity_id = eid
426
-
427
455
  response = await self.ws.send_and_get(packet)
456
+
428
457
  if response is None:
429
- return None
458
+ return RustError("check_subscription_to_entity", "No response received")
459
+
460
+ if error_present(response):
461
+ return RustError(
462
+ "check_subscription_to_entity", response.response.error.error
463
+ )
430
464
 
431
465
  return response.response.flag.value
432
466
 
@@ -446,7 +480,7 @@ class RustSocket:
446
480
 
447
481
  async def get_contents(
448
482
  self, eid: int = None, combine_stacks: bool = False
449
- ) -> Union[RustContents, None]:
483
+ ) -> Union[RustContents, RustError]:
450
484
  """
451
485
  Gets the contents of a storage monitor-attached container
452
486
 
@@ -456,8 +490,8 @@ class RustSocket:
456
490
  """
457
491
  returned_data = await self.get_entity_info(eid)
458
492
 
459
- if returned_data is None:
460
- return None
493
+ if isinstance(returned_data, RustError):
494
+ return returned_data
461
495
 
462
496
  target_time = datetime.utcfromtimestamp(int(returned_data.protection_expiry))
463
497
  difference = target_time - datetime.utcnow()
@@ -501,7 +535,7 @@ class RustSocket:
501
535
 
502
536
  return RustContents(difference, bool(returned_data.has_protection), items)
503
537
 
504
- async def get_camera_manager(self, cam_id: str) -> Union[CameraManager, None]:
538
+ async def get_camera_manager(self, cam_id: str) -> Union[CameraManager, RustError]:
505
539
  """
506
540
  Gets a camera manager for a given camera ID
507
541
 
@@ -515,10 +549,12 @@ class RustSocket:
515
549
  subscribe = AppCameraSubscribe()
516
550
  subscribe.camera_id = cam_id
517
551
  packet.camera_subscribe = subscribe
518
-
519
552
  response = await self.ws.send_and_get(packet)
520
553
 
521
554
  if response is None:
522
- return None
555
+ return RustError("get_camera_manager", "No response received")
556
+
557
+ if error_present(response):
558
+ return RustError("get_camera_manager", response.response.error.error)
523
559
 
524
560
  return CameraManager(self, cam_id, response.response.camera_subscribe_info)
@@ -8,3 +8,4 @@ from .rust_entity_info import RustEntityInfo
8
8
  from .rust_contents import RustContents
9
9
  from .rust_item import RustItem
10
10
  from .util import Vector
11
+ from .rust_error import RustError
@@ -0,0 +1,33 @@
1
+ import logging
2
+ from typing import Any
3
+
4
+ from .serialization import Serializable
5
+
6
+
7
+ class RustError(Serializable):
8
+
9
+ LOGGER = logging.getLogger("rustplus.py")
10
+
11
+ def __init__(self, method: str, reason: str) -> None:
12
+ self._method = method
13
+ self._reason = reason
14
+
15
+ @property
16
+ def method(self) -> str:
17
+ return self._method
18
+
19
+ @property
20
+ def reason(self) -> str:
21
+ return self._reason
22
+
23
+ def __str__(self) -> str:
24
+ return f"Error Propagating from {self._method}: {self._reason}"
25
+
26
+ def __getattr__(self, attr_name: str) -> Any:
27
+ if attr_name in self.__dict__:
28
+ return self.__dict__[attr_name]
29
+
30
+ # This means we are gonna chuck the error in the user's face
31
+ self.LOGGER.error(
32
+ f"An Unhandled Error has occurred over the {self._method} method, reason: {self.reason}"
33
+ )
@@ -7,6 +7,7 @@ from .utils import (
7
7
  convert_marker,
8
8
  convert_monument,
9
9
  convert_event_type_to_name,
10
+ convert_coordinates
10
11
  )
11
12
  from .grab_items import translate_stack_to_id, translate_id_to_stack
12
13
  from .yielding_event import YieldingEvent
@@ -13,6 +13,13 @@ PLAYER_MARKER_ONLINE_COLOR = (201, 242, 155, 255)
13
13
  PLAYER_MARKER_OFFLINE_COLOR = (128, 128, 128, 255)
14
14
 
15
15
 
16
+ def error_present(app_message) -> bool:
17
+ """
18
+ Checks message for error
19
+ """
20
+ return app_message.response.error.error != ""
21
+
22
+
16
23
  def convert_time(time) -> str:
17
24
  hours, minutes = divmod(time * 60, 60)
18
25
 
@@ -74,6 +81,15 @@ def generate_grid(
74
81
  return img
75
82
 
76
83
 
84
+ def convert_coordinates(coords: Tuple[int, int], map_size: int) -> Tuple[str, int]:
85
+ grids = list(string.ascii_uppercase)
86
+ grids.extend(
87
+ a + b for a in string.ascii_uppercase for b in string.ascii_uppercase
88
+ )
89
+
90
+ return grids[int(coords[0] // GRID_DIAMETER)], int((map_size - coords[1]) // GRID_DIAMETER)
91
+
92
+
77
93
  def format_coord(x: int, y: int, map_size: int) -> Tuple[int, int]:
78
94
  # Adjust y and x coordinates with offsets
79
95
  y = max(0, min(map_size - y - 75, map_size - 150))
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: rustplus
3
- Version: 6.0.2
3
+ Version: 6.0.4
4
4
  Summary: A python wrapper for the Rust Plus API
5
5
  Home-page: https://github.com/olijeffers0n/rustplus
6
6
  Author: olijeffers0n
@@ -18,6 +18,15 @@ Requires-Dist: requests
18
18
  Requires-Dist: numpy
19
19
  Requires-Dist: scipy
20
20
  Requires-Dist: betterproto==2.0.0b6
21
+ Dynamic: author
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: license
26
+ Dynamic: project-url
27
+ Dynamic: requires-dist
28
+ Dynamic: requires-python
29
+ Dynamic: summary
21
30
 
22
31
  ![Rust+.py](https://raw.githubusercontent.com/olijeffers0n/rustplus/master/icon.png)
23
32
  <div align = "center">
@@ -93,6 +93,7 @@ rustplus/structs/__init__.py
93
93
  rustplus/structs/rust_chat_message.py
94
94
  rustplus/structs/rust_contents.py
95
95
  rustplus/structs/rust_entity_info.py
96
+ rustplus/structs/rust_error.py
96
97
  rustplus/structs/rust_info.py
97
98
  rustplus/structs/rust_item.py
98
99
  rustplus/structs/rust_map.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes