Better error handling in total command
This commit is contained in:
parent
9991813209
commit
e2099b1c82
|
@ -104,12 +104,12 @@ class IRCBot(irc.IRCClient):
|
||||||
try:
|
try:
|
||||||
int(spl[2])
|
int(spl[2])
|
||||||
except ValueError:
|
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])
|
rtrn = self.tx.find_tx(spl[1], spl[2])
|
||||||
if rtrn == "AMOUNT_INVALID":
|
if rtrn == "AMOUNT_INVALID":
|
||||||
self.msg(channel, "Reference found but amount invalid")
|
self.msg(channel, "Reference found but amount invalid.")
|
||||||
elif not rtrn:
|
elif not rtrn:
|
||||||
self.msg(channel, "Reference not found")
|
self.msg(channel, "Reference not found.")
|
||||||
else:
|
else:
|
||||||
return dumps(rtrn)
|
return dumps(rtrn)
|
||||||
|
|
||||||
|
@ -121,6 +121,8 @@ class IRCBot(irc.IRCClient):
|
||||||
|
|
||||||
elif cmd == "total" and host in self.admins:
|
elif cmd == "total" and host in self.admins:
|
||||||
total_usd = self.revolut.get_total_usd()
|
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")
|
self.msg(channel, f"Total: {round(total_usd, 2)}USD")
|
||||||
|
|
||||||
def signedOn(self):
|
def signedOn(self):
|
||||||
|
|
|
@ -189,6 +189,8 @@ class Revolut(object):
|
||||||
def get_total_usd(self):
|
def get_total_usd(self):
|
||||||
rates = self.agora.get_rates_all()
|
rates = self.agora.get_rates_all()
|
||||||
accounts = self.accounts()
|
accounts = self.accounts()
|
||||||
|
if not accounts:
|
||||||
|
return False
|
||||||
total_usd = 0
|
total_usd = 0
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
if account["currency"] == "USD":
|
if account["currency"] == "USD":
|
||||||
|
|
Loading…
Reference in New Issue