alias .btc to '.coin btc'

This commit is contained in:
iou1name 2025-05-25 18:34:23 -04:00
parent 1e4e919910
commit 6256a2dc78
2 changed files with 34 additions and 22 deletions

View File

@ -53,3 +53,12 @@ def crypto(bot, trigger):
msg += f"\x0310Total Market Cap\x03: \x0308" msg += f"\x0310Total Market Cap\x03: \x0308"
msg += re.sub(r'(^.+\.\d\d).*', r'\1', data['total_market_cap']) + "\x03" msg += re.sub(r'(^.+\.\d\d).*', r'\1', data['total_market_cap']) + "\x03"
bot.msg(msg) bot.msg(msg)
@commands('btc', 'bitcoin')
def bitcoin(bot, trigger):
"""
An alias for ".coin btc".
"""
trigger.args = ".coin btc".split()
crypto(bot, trigger)

View File

@ -49,26 +49,29 @@ def exchange(bot, trigger):
bot.msg(msg) bot.msg(msg)
@commands('btc', 'bitcoin') # coindesk changed their api and now i don't understand it, so this function
@example('.btc EUR') # is deprecated.
def bitcoin(bot, trigger):
"""
Show the current bitcoin value in USD. Optional parameter allows non-USD
conversion.
"""
if len(trigger.args) < 2:
cur_to = "USD"
else:
cur_to = trigger.args[1]
cur_to = cur_to.upper()
url = BTC_URI.format(**{"CUR_TO": cur_to}) #@commands('btc', 'bitcoin')
res = requests.get(url, verify=True) #@example('.btc EUR')
#def bitcoin(bot, trigger):
if res.text.startswith("Sorry"): # """
return bot.reply("Invalid currency type. Must be ISO 4217 compliant.") # Show the current bitcoin value in USD. Optional parameter allows non-USD
data = res.json() # conversion.
# """
rate = data["bpi"][cur_to]["rate_float"] # if len(trigger.args) < 2:
msg = f"\x03101 BTC\x03 = \x0312{rate} {cur_to}" # cur_to = "USD"
bot.msg(msg) # else:
# cur_to = trigger.args[1]
# cur_to = cur_to.upper()
#
# url = BTC_URI.format(**{"CUR_TO": cur_to})
# res = requests.get(url, verify=True)
#
# if res.text.startswith("Sorry"):
# return bot.reply("Invalid currency type. Must be ISO 4217 compliant.")
# data = res.json()
#
# rate = data["bpi"][cur_to]["rate_float"]
# msg = f"\x03101 BTC\x03 = \x0312{rate} {cur_to}"
# bot.msg(msg)