X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/d85eeb9b35ff63e45109a0a1677ff20835254ad6..fb20be7c5c80f13474786337d69005f3497d21c6:/modules/coins.py diff --git a/modules/coins.py b/modules/coins.py index 34bbb54..8548d60 100644 --- a/modules/coins.py +++ b/modules/coins.py @@ -22,8 +22,11 @@ import json import requests coin_regex = ( -# re.compile(r'([0-9., ]+[0-9]+) (BTC|bitcoin|doge|dogecoin|ltc|litecoin)'), # Fix regex - re.compile(r'([0-9.\s]+)\s(btc|bitcoin|doge|dogecoin|ltc|litecoin)'), + re.compile(r'([0-9.,\s]+)\s(btc|bitcoin|doge|dogecoin|ltc|litecoin)'), +) + +cur_regex = ( + re.compile(r'([0-9.,\s]+)\s([a-zA-Z]{3})\sin\s([a-zA-Z]{3})'), ) url = 'http://www.cryptocoincharts.info/v2/api/tradingPairs' @@ -32,8 +35,8 @@ def get_coin_price(pairs): response = requests.post(url, data = {'pairs': pairs}) return json.loads(response.text) -@lib.hook('btc') -def cmd_gtest(bot, user, chan, realtarget, *args): +@lib.hook() +def btc(bot, user, chan, realtarget, *args): if len(args) > 0: try: response = get_coin_price('btc_eur') @@ -46,8 +49,8 @@ def cmd_gtest(bot, user, chan, realtarget, *args): price = str(float(response[0]['price'])) bot.msg(chan, "1 BTC = %s EUR" % price) -@lib.hook('doge') -def cmd_gtest(bot, user, chan, realtarget, *args): +@lib.hook() +def doge(bot, user, chan, realtarget, *args): if len(args) > 0: try: doge_btc = get_coin_price('doge_btc') @@ -62,8 +65,8 @@ def cmd_gtest(bot, user, chan, realtarget, *args): price = str(float(doge_btc[0]['price']) * float(btc_eur[0]['price'])) bot.msg(chan, "1 DOGE = %s EUR" % price) -@lib.hook('ltc') -def cmd_gtest(bot, user, chan, realtarget, *args): +@lib.hook() +def ltc(bot, user, chan, realtarget, *args): if len(args) > 0: try: ltc_btc = get_coin_price('ltc_btc') @@ -88,9 +91,19 @@ def privmsg_hook(bot, line): chan = line.split()[2] + if 'in' in line: + for r in cur_regex: + for a, f, t in r.findall(linetx): + + # https://www.google.com/finance/converter?a=1.2&from=USD&to=EUR + + a = a.replace(",", ".") + a = a.replace(" ", "") + if 'btc' in line or 'bitcoin' in line or 'doge' in line or 'dogecoin' in line: for r in coin_regex: for amount, coin in r.findall(linetx): + amount = amount.replace(",", ".") amount = amount.replace(" ", "") if 'btc' in coin or 'bitcoin' in coin: try: @@ -111,7 +124,3 @@ def privmsg_hook(bot, line): bot.msg(chan, "%s DOGE = %s EUR" % (amount, price)) except: bot.msg(chan, "Invalid amount.") - - - print amount - print coin