Improve !info command

This commit is contained in:
Tanner Collin 2021-05-07 04:02:51 +00:00
parent 4d2d358175
commit 09b09b3f96
2 changed files with 60 additions and 15 deletions

View File

@ -23,7 +23,7 @@ class Commands:
def handle_chat(self, message): def handle_chat(self, message):
source, sender, text = message source, sender, text = message
reply = None reply = ''
private = False private = False
for_me = False for_me = False
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0' authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
@ -244,23 +244,67 @@ class Commands:
tree = next(self.g.world.find_trees(pos, 50)) tree = next(self.g.world.find_trees(pos, 50))
reply = str(tree)[1:-1] reply = str(tree)[1:-1]
## !block x y z - replies what block is at (x, y, z) ## !info [query] - replies with info on a coordinate, block, item, or player
if command == 'block': if command == 'info':
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'
if not reply: if not reply:
try:
check = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
x1, y1, z1 = [int(x) for x in check.split()]
coord = (x1, y1, z1) coord = (x1, y1, z1)
block = self.g.world.block_at(*coord) block = self.g.world.block_at(*coord)
if not reply and block is None: if not reply and block is None:
reply = 'first coord out of range' reply = 'coord out of range'
if not reply: if not reply:
reply = blocks.BLOCKS[block] + ':' + str(block) 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:
try:
check = int(data)
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 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 ########################## ################# Specific commands ##########################

View File

@ -493,7 +493,8 @@ class Game:
for action in packet.actions: for action in packet.actions:
if isinstance(action, packet.AddPlayerAction): if isinstance(action, packet.AddPlayerAction):
self.g.player_names[action.uuid] = action.name 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): def handle_update_health(self, packet):
print(packet) print(packet)