Better error handling in total command

This commit is contained in:
Mark Veidemanis 2021-12-28 11:57:18 +00:00
parent 9991813209
commit e2099b1c82
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 7 additions and 3 deletions

View File

@ -104,12 +104,12 @@ class IRCBot(irc.IRCClient):
try:
int(spl[2])
except ValueError:
self.msg(channel, "Amount is not an integer")
self.msg(channel, "Amount is not an integer.")
rtrn = self.tx.find_tx(spl[1], spl[2])
if rtrn == "AMOUNT_INVALID":
self.msg(channel, "Reference found but amount invalid")
self.msg(channel, "Reference found but amount invalid.")
elif not rtrn:
self.msg(channel, "Reference not found")
self.msg(channel, "Reference not found.")
else:
return dumps(rtrn)
@ -121,6 +121,8 @@ class IRCBot(irc.IRCClient):
elif cmd == "total" and host in self.admins:
total_usd = self.revolut.get_total_usd()
if not total_usd:
self.msg(channel, "Error getting total balance.")
self.msg(channel, f"Total: {round(total_usd, 2)}USD")
def signedOn(self):

View File

@ -189,6 +189,8 @@ class Revolut(object):
def get_total_usd(self):
rates = self.agora.get_rates_all()
accounts = self.accounts()
if not accounts:
return False
total_usd = 0
for account in accounts:
if account["currency"] == "USD":