Added error messages to coins plugin
This commit is contained in:
parent
87a0111e74
commit
b970f38344
|
@ -26,7 +26,7 @@ class Coins(Plugin):
|
|||
|
||||
%%btc [<currency>]
|
||||
"""
|
||||
return self.cryptowat_summary('btc', args.get('<currency>', 'usd'))
|
||||
return self.cryptowat_summary('btc', args)
|
||||
|
||||
@command
|
||||
def eth(self, mask: IrcString, target: IrcString, args: DocOptDict):
|
||||
|
@ -34,16 +34,18 @@ class Coins(Plugin):
|
|||
|
||||
%%eth [<currency>]
|
||||
"""
|
||||
return self.cryptowat_summary('eth', args.get('<currency>', 'usd'))
|
||||
return self.cryptowat_summary('eth', args)
|
||||
|
||||
def cryptowat_summary(self, crypto: str, args: DocOptDict):
|
||||
currency = args.get('<currency>', 'usd')
|
||||
|
||||
def cryptowat_summary(self, crypto: str, currency: str = 'usd'):
|
||||
# Check if valid currency + crypto2currency
|
||||
if currency not in self.CURRENCIES or crypto == currency:
|
||||
return
|
||||
return '\x02[{}]\x02 Can\'t convert or invalid currency: {}'.format(crypto.upper(), currency)
|
||||
|
||||
# Send request to api
|
||||
data = requests.get(self.API_URL.format(crypto=crypto, currency=currency))
|
||||
if data:
|
||||
if not data:
|
||||
return '\x02[{}]\x02 No data received'.format(crypto)
|
||||
|
||||
result = data.json()['result']
|
||||
return '\x02[{crypto}]\x02 ' \
|
||||
'Current: \x02\x0307{currency}{last:,.2f}\x0F - ' \
|
||||
|
|
Loading…
Reference in New Issue
Block a user