diff --git a/requirements.txt b/requirements.txt index 083b1f0..dc5cc2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ http-ece requests numpy scipy -betterproto \ No newline at end of file +betterproto==2.0.0b6 \ No newline at end of file diff --git a/rustplus/api/base_rust_api.py b/rustplus/api/base_rust_api.py index 9f6d89a..57444c9 100644 --- a/rustplus/api/base_rust_api.py +++ b/rustplus/api/base_rust_api.py @@ -182,7 +182,6 @@ async def send_wakeup_request(self) -> None: app_request = self._generate_protobuf() app_request.get_time = AppEmpty() - app_request.get_time._serialized_on_wire = True await self.remote.add_ignored_response(app_request.seq) @@ -445,6 +444,7 @@ async def hang() -> None: while True: await asyncio.sleep(1) + @deprecated("Implement this yourself. This will be removed in thed future") def get_conversation_factory(self) -> ConversationFactory: """ Gets the current ConversationFactory object diff --git a/rustplus/api/remote/camera/camera_manager.py b/rustplus/api/remote/camera/camera_manager.py index bc70ffb..53f58e0 100644 --- a/rustplus/api/remote/camera/camera_manager.py +++ b/rustplus/api/remote/camera/camera_manager.py @@ -1,5 +1,5 @@ import time -from typing import Iterable, Union, List, Coroutine, TypeVar, Set, Callable +from typing import Iterable, Union, List, Coroutine, Set, Callable from PIL import Image @@ -14,14 +14,12 @@ from ...structures import Vector from .structures import CameraInfo, Entity, LimitedQueue -RS = TypeVar("RS", bound="RustSocket") - class CameraManager: def __init__( - self, rust_socket: RS, cam_id: str, cam_info_message: AppCameraInfo + self, rust_socket, cam_id: str, cam_info_message: AppCameraInfo ) -> None: - self.rust_socket: RS = rust_socket + self.rust_socket = rust_socket self._cam_id: str = cam_id self._last_packets: LimitedQueue = LimitedQueue(6) self._cam_info_message: CameraInfo = CameraInfo(cam_info_message) @@ -140,7 +138,6 @@ async def exit_camera(self) -> None: await self.rust_socket._handle_ratelimit() app_request: AppRequest = self.rust_socket._generate_protobuf() app_request.camera_unsubscribe = AppEmpty() - app_request.camera_unsubscribe._serialized_on_wire = True await self.rust_socket.remote.send_message(app_request) await self.rust_socket.remote.add_ignored_response(app_request.seq) diff --git a/rustplus/api/remote/events/event_handler.py b/rustplus/api/remote/events/event_handler.py index 7d65fe7..41a1aba 100644 --- a/rustplus/api/remote/events/event_handler.py +++ b/rustplus/api/remote/events/event_handler.py @@ -19,25 +19,19 @@ async def run_entity_event( return for handler in handlers.copy(): - coro, event_type = handler.data - - await coro(EntityEvent(app_message, event_type)) + await handler.get_coro()(EntityEvent(app_message, handler.get_entity_type())) @staticmethod async def run_team_event(app_message: AppMessage, server_id: ServerID) -> None: handlers: Set[RegisteredListener] = TeamEvent.handlers.get_handlers(server_id) for handler in handlers.copy(): - coro = handler.data - - await coro(TeamEvent(app_message)) + await handler.get_coro()(TeamEvent(app_message)) @staticmethod async def run_chat_event(app_message: AppMessage, server_id: ServerID) -> None: handlers: Set[RegisteredListener] = ChatEvent.handlers.get_handlers(server_id) for handler in handlers.copy(): - coro = handler.data - - await coro(ChatEvent(app_message)) + await handler.get_coro()(ChatEvent(app_message)) @staticmethod async def run_proto_event(byte_data: bytes, server_id: ServerID) -> None: @@ -45,6 +39,4 @@ async def run_proto_event(byte_data: bytes, server_id: ServerID) -> None: server_id ) for handler in handlers.copy(): - coro = handler.data - - await coro(ProtobufEvent(byte_data)) + await handler.get_coro()(ProtobufEvent(byte_data)) diff --git a/rustplus/api/remote/events/handler_list.py b/rustplus/api/remote/events/handler_list.py index eb5235d..353d4f3 100644 --- a/rustplus/api/remote/events/handler_list.py +++ b/rustplus/api/remote/events/handler_list.py @@ -28,6 +28,7 @@ def get_handlers( class EntityHandlerList(HandlerList): def __init__(self) -> None: + super().__init__() self._handlers: Dict[ ServerID, Dict[str, Set[RegisteredListener]] ] = defaultdict(dict) diff --git a/rustplus/api/remote/events/registered_listener.py b/rustplus/api/remote/events/registered_listener.py index c3682b0..f0eff68 100644 --- a/rustplus/api/remote/events/registered_listener.py +++ b/rustplus/api/remote/events/registered_listener.py @@ -1,27 +1,25 @@ -from typing import Union +from typing import Union, Coroutine class RegisteredListener: - def __init__(self, listener_id: Union[str, int], data) -> None: + def __init__(self, listener_id: Union[str, int], coroutine: Coroutine, entity_type: int = None) -> None: self.listener_id = str(listener_id) - self.data = data + self._coroutine = coroutine + self._entity_type = entity_type def get_coro(self): - if isinstance(self.data, tuple): - return self.data[0] - return self.data + return self._coroutine + + def get_entity_type(self): + return self._entity_type def __eq__(self, other) -> bool: - if isinstance(other, RegisteredListener): - coro = self.data - if isinstance(self.data, tuple): - coro = self.data[0] + if not isinstance(other, RegisteredListener): + return False - return self.listener_id == other.listener_id and coro == coro - return False + return self.listener_id == other.listener_id and \ + self._coroutine == other.get_coro() and \ + self._entity_type == other.get_entity_type() def __hash__(self): - coro = self.data - if isinstance(self.data, tuple): - coro = self.data[0] - return hash((self.listener_id, coro)) + return hash((self.listener_id, self._coroutine, self._entity_type)) diff --git a/rustplus/api/remote/rust_remote_interface.py b/rustplus/api/remote/rust_remote_interface.py index 79c885e..522ac23 100644 --- a/rustplus/api/remote/rust_remote_interface.py +++ b/rustplus/api/remote/rust_remote_interface.py @@ -180,7 +180,6 @@ async def get_entity_info(remote: RustRemote, eid): app_request: AppRequest = remote.api._generate_protobuf() app_request.entity_id = eid app_request.get_entity_info = AppEmpty() - app_request.get_entity_info._serialized_on_wire = True await remote.send_message(app_request) @@ -196,7 +195,7 @@ def entity_event_callback(future_inner: Future) -> None: EntityEvent.handlers.register( RegisteredListener( - entity_id, (coroutine, entity_info.response.entity_info.type) + entity_id, coroutine, entity_info.response.entity_info.type ), self.server_id, ) diff --git a/rustplus/api/rust_api.py b/rustplus/api/rust_api.py index a409661..687f3c2 100644 --- a/rustplus/api/rust_api.py +++ b/rustplus/api/rust_api.py @@ -76,7 +76,6 @@ async def get_time(self) -> RustTime: app_request = self._generate_protobuf() app_request.get_time = AppEmpty() - app_request.get_time._serialized_on_wire = True await self.remote.send_message(app_request) @@ -102,7 +101,6 @@ async def get_info(self) -> RustInfo: app_request = self._generate_protobuf() app_request.get_info = AppEmpty() - app_request.get_info._serialized_on_wire = True await self.remote.send_message(app_request) @@ -115,7 +113,6 @@ async def get_team_chat(self) -> List[RustChatMessage]: app_request = self._generate_protobuf() app_request.get_team_chat = AppEmpty() - app_request.get_team_chat._serialized_on_wire = True await self.remote.send_message(app_request) @@ -130,7 +127,6 @@ async def get_team_info(self) -> RustTeamInfo: app_request = self._generate_protobuf() app_request.get_team_info = AppEmpty() - app_request.get_team_info._serialized_on_wire = True await self.remote.send_message(app_request) @@ -143,7 +139,6 @@ async def get_markers(self) -> List[RustMarker]: app_request = self._generate_protobuf() app_request.get_map_markers = AppEmpty() - app_request.get_map_markers._serialized_on_wire = True await self.remote.send_message(app_request) @@ -158,7 +153,6 @@ async def get_raw_map_data(self) -> RustMap: app_request = self._generate_protobuf() app_request.get_map = AppEmpty() - app_request.get_map._serialized_on_wire = True await self.remote.send_message(app_request) @@ -190,7 +184,6 @@ async def get_map( app_request = self._generate_protobuf() app_request.get_map = AppEmpty() - app_request.get_map._serialized_on_wire = True await self.remote.send_message(app_request) @@ -295,7 +288,6 @@ async def get_entity_info(self, eid: int = None) -> RustEntityInfo: app_request = self._generate_protobuf() app_request.entity_id = eid app_request.get_entity_info = AppEmpty() - app_request.get_entity_info._serialized_on_wire = True await self.remote.send_message(app_request) diff --git a/rustplus/utils/rust_utils.py b/rustplus/utils/rust_utils.py index 59d9959..3c56474 100644 --- a/rustplus/utils/rust_utils.py +++ b/rustplus/utils/rust_utils.py @@ -159,8 +159,8 @@ def entity_type_to_string(id) -> str: def convert_xy_to_grid( coords: tuple, map_size: float, catch_out_of_bounds: bool = True -) -> Tuple[int, int]: - grid_size = 146.3 +) -> Tuple[str, int]: + grid_size = 146.28571428571428 grids = list(string.ascii_uppercase) + [ f"A{letter}" for letter in list(string.ascii_uppercase) ]