Reply in-game with inventory
This commit is contained in:
parent
396c1e2e33
commit
5184d4a173
|
@ -88,7 +88,7 @@ These can be ran by anyone, all bots will reply.
|
|||
|
||||
`!error` - raises an error
|
||||
|
||||
`!inv` - prints current inventory
|
||||
`!inv` - replies and prints current inventory
|
||||
|
||||
`!time` - replies with Minecraft world time
|
||||
|
||||
|
|
|
@ -106,15 +106,37 @@ class Commands:
|
|||
reply = 'ok'
|
||||
raise
|
||||
|
||||
## !inv - prints current inventory
|
||||
if command == 'inv':
|
||||
## !inv - replies and prints current inventory
|
||||
if command == 'inv' or command == 'inventory':
|
||||
inv_list = []
|
||||
uniq_item_counts = {}
|
||||
for i in self.g.inv.values():
|
||||
if i.present:
|
||||
inv_list.append('{}:{} x {}'.format(items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count))
|
||||
inv_list.append((items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count))
|
||||
|
||||
if i.item_id not in uniq_item_counts:
|
||||
uniq_item_counts[i.item_id] = 0
|
||||
uniq_item_counts[i.item_id] += i.item_count
|
||||
|
||||
inv_list.sort()
|
||||
result = '\n'.join(inv_list)
|
||||
print(result or 'Empty')
|
||||
console_result = '\n'.join(['{}:{} x {}'.format(*x) for x in inv_list])
|
||||
|
||||
if not console_result:
|
||||
print('Empty')
|
||||
reply = 'empty'
|
||||
else:
|
||||
print(console_result)
|
||||
|
||||
reply_result_1 = ', '.join(['{}:{} x {}'.format(*x) for x in inv_list])
|
||||
reply_result_2 = ', '.join(['{}:{} x {}'.format(items.ITEM_NAMES[k], str(k), v) for k,v in uniq_item_counts.items()])
|
||||
reply_result_3 = ', '.join(['{}:{}x{}'.format(items.ITEM_NAMES[k], str(k), v) for k,v in uniq_item_counts.items()])
|
||||
reply_result_4 = ', '.join(['{}:{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES[k]), str(k), v) for k,v in uniq_item_counts.items()])
|
||||
reply_result_5 = ' '.join(['{}{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES[k]), str(k), v) for k,v in uniq_item_counts.items()])
|
||||
|
||||
for r in [reply_result_1, reply_result_2, reply_result_3, reply_result_4, reply_result_5]:
|
||||
reply = r
|
||||
if len(reply) < 256:
|
||||
break
|
||||
|
||||
## !time - replies with Minecraft world time
|
||||
if command == 'time':
|
||||
|
|
Loading…
Reference in New Issue
Block a user