Cleaned up startup and made `?selling` prettier

master
Joey Hines 2019-09-25 18:48:30 -05:00
parent cc03b0f0e6
commit 5146f2cb80
2 changed files with 18 additions and 6 deletions

View File

@ -16,11 +16,13 @@ def setup_logging():
def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url):
setup_logging()
bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token)
loop = asyncio.get_event_loop()
loop = None
bot = None
try:
bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token)
loop = asyncio.get_event_loop()
loop.run_until_complete(bot.start(discord_token))
except KeyboardInterrupt:
@ -29,5 +31,6 @@ def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url):
print(e)
logger.info('Bot encountered the following unhandled exception %s', e)
finally:
loop.run_until_complete(bot.logout())
if loop and bot:
loop.run_until_complete(bot.logout())
logger.info("Bot shutting down...")

View File

@ -20,8 +20,17 @@ def format_message(msg_format, *args):
def formatted_item_listing(item):
return format_message("{} {} for {}D, restocked {} day(s) ago", item["amount"], item["item_name"],
item["price"], item["days_since_restock"])
days = int(item["days_since_restock"])
if days == 0:
days_stocked = "today"
elif days == 1:
days_stocked = "yesterday"
else:
days_stocked = "{} days ago".format(days)
return format_message("{} {} for {}D, restocked {}", item["amount"], item["item_name"],
item["price"], days_stocked)
def formatted_location(location):