From 535f8905549533898fd90d4bb78a0c5bc34e7756 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 28 Dec 2021 14:10:05 +0000 Subject: [PATCH] Add error handling in commands --- handler/commands.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/handler/commands.py b/handler/commands.py index 722ea28..dee12b3 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -13,8 +13,12 @@ class IRCCommands(object): Get details of open trades and post on IRC. """ trades = agora.dashboard(send_irc=False) + if trades is False: + msg("Error getting trades.") + return if not trades: msg("No open trades.") + return for trade_id in trades: msg(trade_id) @@ -44,8 +48,12 @@ class IRCCommands(object): """ if length == 1: messages = agora.get_all_messages(send_irc=False) + if messages is False: + msg("Error getting messages.") + return if not messages: msg("No messages.") + return for message_id in messages: for message in messages[message_id]: msg(f"{message_id}: {message}") @@ -96,9 +104,15 @@ class IRCCommands(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, revolut, tx): accounts = revolut.accounts() + accounts_posted = 0 + if accounts is None: + msg("Error getting accounts.") for account in accounts: if account["balance"] > 0: msg(f"{account['name']} {account['currency']}: {account['balance']}") + accounts_posted += 1 + if accounts_posted == 0: + msg("No accounts with balances.") class total(object): name = "total"