]>
jfr.im git - erebus.git/blob - modules/coins.py
1 # Erebus IRC bot - Author: Erebus Team
3 # This file is released into the public domain; see http://unlicense.org/
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
15 lib
= modlib
.modlib(__name__
)
16 modstart
= lib
.modstart
25 re
.compile(r
'([0-9.,\s]+)\s(btc|bitcoin|doge|dogecoin|ltc|litecoin)'),
29 re
.compile(r
'([0-9.,\s]+)\s([a-zA-Z]{3})\sin\s([a-zA-Z]{3})'),
32 url
= 'http://www.cryptocoincharts.info/v2/api/tradingPairs'
34 def get_coin_price(pairs
):
35 response
= requests
.post(url
, data
= {'pairs': pairs}
)
36 return json
.loads(response
.text
)
39 def cmd_gtest(bot
, user
, chan
, realtarget
, *args
):
42 response
= get_coin_price('btc_eur')
43 price
= str(float(response
[0]['price']) * float(args
[0]))
44 bot
.msg(chan
, "%s BTC = %s EUR" % (args
[0], price
))
46 bot
.msg(chan
, "Invalid amount.")
48 response
= get_coin_price('btc_eur')
49 price
= str(float(response
[0]['price']))
50 bot
.msg(chan
, "1 BTC = %s EUR" % price
)
53 def cmd_gtest(bot
, user
, chan
, realtarget
, *args
):
56 doge_btc
= get_coin_price('doge_btc')
57 btc_eur
= get_coin_price('btc_eur')
58 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(args
[0]))
59 bot
.msg(chan
, "%s DOGE = %s EUR" % (args
[0], price
))
61 bot
.msg(chan
, "Invalid amount.")
63 doge_btc
= get_coin_price('doge_btc')
64 btc_eur
= get_coin_price('btc_eur')
65 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']))
66 bot
.msg(chan
, "1 DOGE = %s EUR" % price
)
69 def cmd_gtest(bot
, user
, chan
, realtarget
, *args
):
72 ltc_btc
= get_coin_price('ltc_btc')
73 btc_eur
= get_coin_price('btc_eur')
74 price
= str(float(ltc_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(args
[0]))
75 bot
.msg(chan
, "%s LTC = %s EUR" % (args
[0], price
))
77 bot
.msg(chan
, "Invalid amount.")
79 ltc_btc
= get_coin_price('ltc_btc')
80 btc_eur
= get_coin_price('btc_eur')
81 price
= str(float(ltc_btc
[0]['price']) * float(btc_eur
[0]['price']))
82 bot
.msg(chan
, "1 LTC = %s EUR" % price
)
84 @lib.hooknum("PRIVMSG")
85 def privmsg_hook(bot
, line
):
88 linetx
= line
.split(None, 3)[3][1:]
92 chan
= line
.split()[2]
96 for a
, f
, t
in r
.findall(linetx
):
98 # https://www.google.com/finance/converter?a=1.2&from=USD&to=EUR
100 a
= a
.replace(",", ".")
101 a
= a
.replace(" ", "")
103 if 'btc' in line
or 'bitcoin' in line
or 'doge' in line
or 'dogecoin' in line
:
105 for amount
, coin
in r
.findall(linetx
):
106 amount
= amount
.replace(",", ".")
107 amount
= amount
.replace(" ", "")
108 if 'btc' in coin
or 'bitcoin' in coin
:
110 response
= get_coin_price('btc_eur')
111 price
= str(float(response
[0]['price']) * float(amount
))
112 bot
.msg(chan
, "%s BTC = %s EUR" % (amount
, price
))
116 if 'ltc' in coin
or 'litecoin' in coin
:
119 if 'doge' in coin
or 'dogecoin' in coin
:
121 doge_btc
= get_coin_price('doge_btc')
122 btc_eur
= get_coin_price('btc_eur')
123 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(amount
))
124 bot
.msg(chan
, "%s DOGE = %s EUR" % (amount
, price
))
126 bot
.msg(chan
, "Invalid amount.")