From 09b09b3f96f85b13d4b622dbbef59b58b8c31395 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 7 May 2021 04:02:51 +0000 Subject: [PATCH] Improve !info command --- mosfet/commands.py | 72 +++++++++++++++++++++++++++++++++++++--------- mosfet/game.py | 3 +- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/mosfet/commands.py b/mosfet/commands.py index 83de7ef..1d3844d 100644 --- a/mosfet/commands.py +++ b/mosfet/commands.py @@ -23,7 +23,7 @@ class Commands: def handle_chat(self, message): source, sender, text = message - reply = None + reply = '' private = False for_me = False authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0' @@ -244,23 +244,67 @@ class Commands: tree = next(self.g.world.find_trees(pos, 50)) reply = str(tree)[1:-1] - ## !block x y z - replies what block is at (x, y, z) - if command == 'block': - try: - data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ') - x1, y1, z1 = [int(x) for x in data.split()] - except (AttributeError, ValueError): - reply = 'usage: !block x1 y1 z1' + ## !info [query] - replies with info on a coordinate, block, item, or player + if command == 'info': + if not reply: + try: + check = data.replace('(', ' ').replace(')', ' ').replace(',', ' ') + x1, y1, z1 = [int(x) for x in check.split()] + coord = (x1, y1, z1) + block = self.g.world.block_at(*coord) + + if not reply and block is None: + reply = 'coord out of range' + + if not reply: + reply = 'Block: ' + blocks.BLOCKS[block] + ':' + str(block) + if blocks.PROPS[block]: + reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()]) + except (AttributeError, ValueError): + pass if not reply: - coord = (x1, y1, z1) - block = self.g.world.block_at(*coord) + try: + check = int(data) - if not reply and block is None: - reply = 'first coord out of range' + if check in blocks.BLOCKS: + block = check + reply += 'Block: ' + blocks.BLOCKS[block] + ':' + str(block) + if blocks.PROPS[block]: + reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()]) - if not reply: - reply = blocks.BLOCKS[block] + ':' + str(block) + if check in blocks.BLOCKS and check in items.ITEM_NAMES: + reply += ' / ' + + if check in items.ITEM_NAMES: + item = check + reply += 'Item: ' + items.ITEM_NAMES[item] + ':' + str(item) + + except ValueError: + pass + + check = data.lower() + if not reply and check in self.g.player_names: + uuid = self.g.player_names[check] + + for p in self.g.players.values(): + if p.player_uuid == uuid: + player = p + break + else: # for + reply = 'player out of range' + + if not reply: + reply += 'Player: ' + + results = [] + for k, v in player.items(): + try: + results.append('{}:{}'.format(k, int(v))) + except ValueError: + results.append('{}:{}'.format(k, str(v))) + + reply += ', '.join(results) ################# Specific commands ########################## diff --git a/mosfet/game.py b/mosfet/game.py index 43f34d1..8be3e5e 100644 --- a/mosfet/game.py +++ b/mosfet/game.py @@ -493,7 +493,8 @@ class Game: for action in packet.actions: if isinstance(action, packet.AddPlayerAction): self.g.player_names[action.uuid] = action.name - self.g.player_names[action.name] = action.uuid # porque no los dos? + self.g.player_names[action.name] = action.uuid + self.g.player_names[action.name.lower()] = action.uuid # porque no los dos? def handle_update_health(self, packet): print(packet)