From 5184d4a173c23e3f96991f515cbe8d97bea482e7 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 6 May 2021 09:29:26 +0000 Subject: [PATCH] Reply in-game with inventory --- README.md | 2 +- mosfet/commands.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4de223a..2390e22 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/mosfet/commands.py b/mosfet/commands.py index fc26f13..b4dd138 100644 --- a/mosfet/commands.py +++ b/mosfet/commands.py @@ -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':