From b207af820da5d4df4f2a2f35a68b942c36b09a14 Mon Sep 17 00:00:00 2001 From: Emily <35015090+EmilyV99@users.noreply.github.com> Date: Wed, 24 Jan 2024 15:14:44 -0500 Subject: [PATCH] Improve CommonClient commands '/missing' now properly can take multi-word filter text, and is case-insensitive. '/missing' now only shows missing locations, not checked locations. New command '/checked' shows checked locations, opposite to '/missing' '/received', '/items', and '/locations' now also take optional filter text. --- CommonClient.py | 95 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/CommonClient.py b/CommonClient.py index c75ca3fd806e..5401be29e185 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -19,7 +19,7 @@ if __name__ == "__main__": Utils.init_logging("TextClient", exception_logger="Client") -from MultiServer import CommandProcessor +from MultiServer import CommandProcessor, mark_raw from NetUtils import Endpoint, decode, NetworkItem, encode, JSONtoTextParser, \ ClientStatus, Permission, NetworkSlot, RawJSONtoTextParser from Utils import Version, stream_input, async_start @@ -70,23 +70,41 @@ def _cmd_disconnect(self) -> bool: async_start(self.ctx.disconnect(), name="disconnecting") return True - def _cmd_received(self) -> bool: - """List all received items""" - self.output(f'{len(self.ctx.items_received)} received items:') - for index, item in enumerate(self.ctx.items_received, 1): - self.output(f"{self.ctx.item_names[item.item]} from {self.ctx.player_names[item.player]}") + @mark_raw + def _cmd_received(self, filter_text = "") -> bool: + """List all received items + Can be given text, which will be used as filter.""" + count = 0 + if filter_text: + self.output(f"Received items matching '{filter_text}':") + else: + self.output("Received items:") + for item in self.ctx.items_received: + item_name = self.ctx.item_names[item.item] + if not filter_text or filter_text.lower() in item_name.lower(): + count += 1 + self.output(f"{item_name} from {self.ctx.player_names[item.player]}") + if count == 0: + self.output("No received items found") + else: + self.output(f"Found {count} {'matching ' if filter_text else ''}received items") return True - + + @mark_raw def _cmd_missing(self, filter_text = "") -> bool: - """List all missing location checks, from your local game state. + """List all missing location checks from your local game state. Can be given text, which will be used as filter.""" if not self.ctx.game: self.output("No game set, cannot determine missing checks.") return False + if filter_text: + self.output(f"Missing checks matching '{filter_text}':") + else: + self.output("Missing checks:") count = 0 - checked_count = 0 + total_count = 0 for location, location_id in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id.items(): - if filter_text and filter_text not in location: + if filter_text and filter_text.lower() not in location.lower(): continue if location_id < 0: continue @@ -94,35 +112,70 @@ def _cmd_missing(self, filter_text = "") -> bool: if location_id in self.ctx.missing_locations: self.output('Missing: ' + location) count += 1 + total_count += 1 + elif location_id in self.ctx.checked_locations: + total_count += 1 + + if count: + self.output(f"Found {count}/{total_count} {'matching ' if filter_text else ''}missing checks") + else: + self.output("No missing checks found.") + return True + @mark_raw + def _cmd_checked(self, filter_text = "") -> bool: + """List all checked location checks from your local game state. + Can be given text, which will be used as filter.""" + if not self.ctx.game: + self.output("No game set, cannot determine checked checks.") + return False + if filter_text: + self.output(f"Checked locations matching '{filter_text}':") + else: + self.output("Checked locations:") + count = 0 + total_count = 0 + for location, location_id in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id.items(): + if filter_text and filter_text.lower() not in location.lower(): + continue + if location_id < 0: + continue + if location_id not in self.ctx.locations_checked: + if location_id in self.ctx.missing_locations: + total_count += 1 elif location_id in self.ctx.checked_locations: self.output('Checked: ' + location) count += 1 - checked_count += 1 - + total_count += 1 + if count: - self.output( - f"Found {count} missing location checks{f'. {checked_count} location checks previously visited.' if checked_count else ''}") + self.output(f"Found {count}/{total_count} {'matching ' if filter_text else ''}checked locations") else: - self.output("No missing location checks found.") + self.output("No checked locations found.") return True - def _cmd_items(self): - """List all item names for the currently running game.""" + @mark_raw + def _cmd_items(self, filter_text = ""): + """List all item names for the currently running game. + Can be given text, which will be used as filter.""" if not self.ctx.game: self.output("No game set, cannot determine existing items.") return False self.output(f"Item Names for {self.ctx.game}") for item_name in AutoWorldRegister.world_types[self.ctx.game].item_name_to_id: - self.output(item_name) + if not filter_text or filter_text.lower() in item_name.lower(): + self.output(item_name) - def _cmd_locations(self): - """List all location names for the currently running game.""" + @mark_raw + def _cmd_locations(self, filter_text = ""): + """List all location names for the currently running game. + Can be given text, which will be used as filter.""" if not self.ctx.game: self.output("No game set, cannot determine existing locations.") return False self.output(f"Location Names for {self.ctx.game}") for location_name in AutoWorldRegister.world_types[self.ctx.game].location_name_to_id: - self.output(location_name) + if not filter_text or filter_text.lower() in location_name.lower(): + self.output(location_name) def _cmd_ready(self): """Send ready status to server."""