]>
jfr.im git - erebus.git/blob - modules/coins.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
4 # This file is released into the public domain; see http://unlicense.org/
8 'author': 'Erebus Team',
9 'license': 'public domain',
17 lib
= modlib
.modlib(__name__
)
18 modstart
= lib
.modstart
27 re
.compile(r
'([0-9.,\s]+)\s(btc|bitcoin|doge|dogecoin|ltc|litecoin)'),
31 re
.compile(r
'([0-9.,\s]+)\s([a-zA-Z]{3})\sin\s([a-zA-Z]{3})'),
34 url
= 'http://www.cryptocoincharts.info/v2/api/tradingPairs'
36 def get_coin_price(pairs
):
37 response
= requests
.post(url
, data
= {'pairs': pairs}
)
38 return json
.loads(response
.text
)
41 def btc(bot
, user
, chan
, realtarget
, *args
):
44 response
= get_coin_price('btc_eur')
45 price
= str(float(response
[0]['price']) * float(args
[0]))
46 bot
.msg(chan
, "%s BTC = %s EUR" % (args
[0], price
))
48 bot
.msg(chan
, "Invalid amount.")
50 response
= get_coin_price('btc_eur')
51 price
= str(float(response
[0]['price']))
52 bot
.msg(chan
, "1 BTC = %s EUR" % price
)
55 def doge(bot
, user
, chan
, realtarget
, *args
):
58 doge_btc
= get_coin_price('doge_btc')
59 btc_eur
= get_coin_price('btc_eur')
60 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(args
[0]))
61 bot
.msg(chan
, "%s DOGE = %s EUR" % (args
[0], price
))
63 bot
.msg(chan
, "Invalid amount.")
65 doge_btc
= get_coin_price('doge_btc')
66 btc_eur
= get_coin_price('btc_eur')
67 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']))
68 bot
.msg(chan
, "1 DOGE = %s EUR" % price
)
71 def ltc(bot
, user
, chan
, realtarget
, *args
):
74 ltc_btc
= get_coin_price('ltc_btc')
75 btc_eur
= get_coin_price('btc_eur')
76 price
= str(float(ltc_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(args
[0]))
77 bot
.msg(chan
, "%s LTC = %s EUR" % (args
[0], price
))
79 bot
.msg(chan
, "Invalid amount.")
81 ltc_btc
= get_coin_price('ltc_btc')
82 btc_eur
= get_coin_price('btc_eur')
83 price
= str(float(ltc_btc
[0]['price']) * float(btc_eur
[0]['price']))
84 bot
.msg(chan
, "1 LTC = %s EUR" % price
)
86 @lib.hooknum("PRIVMSG")
87 def privmsg_hook(bot
, line
):
90 linetx
= line
.split(None, 3)[3][1:]
94 chan
= line
.split()[2]
98 for a
, f
, t
in r
.findall(linetx
):
100 # https://www.google.com/finance/converter?a=1.2&from=USD&to=EUR
102 a
= a
.replace(",", ".")
103 a
= a
.replace(" ", "")
105 if 'btc' in line
or 'bitcoin' in line
or 'doge' in line
or 'dogecoin' in line
:
107 for amount
, coin
in r
.findall(linetx
):
108 amount
= amount
.replace(",", ".")
109 amount
= amount
.replace(" ", "")
110 if 'btc' in coin
or 'bitcoin' in coin
:
112 response
= get_coin_price('btc_eur')
113 price
= str(float(response
[0]['price']) * float(amount
))
114 bot
.msg(chan
, "%s BTC = %s EUR" % (amount
, price
))
118 if 'ltc' in coin
or 'litecoin' in coin
:
121 if 'doge' in coin
or 'dogecoin' in coin
:
123 doge_btc
= get_coin_price('doge_btc')
124 btc_eur
= get_coin_price('btc_eur')
125 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(amount
))
126 bot
.msg(chan
, "%s DOGE = %s EUR" % (amount
, price
))
128 bot
.msg(chan
, "Invalid amount.")