]>
jfr.im git - erebus.git/blob - modules/coins.py
34bbb545a7ffc94fa54405dada45edd67466d175
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., ]+[0-9]+) (BTC|bitcoin|doge|dogecoin|ltc|litecoin)'), # Fix regex
26 re
.compile(r
'([0-9.\s]+)\s(btc|bitcoin|doge|dogecoin|ltc|litecoin)'),
29 url
= 'http://www.cryptocoincharts.info/v2/api/tradingPairs'
31 def get_coin_price(pairs
):
32 response
= requests
.post(url
, data
= {'pairs': pairs}
)
33 return json
.loads(response
.text
)
36 def cmd_gtest(bot
, user
, chan
, realtarget
, *args
):
39 response
= get_coin_price('btc_eur')
40 price
= str(float(response
[0]['price']) * float(args
[0]))
41 bot
.msg(chan
, "%s BTC = %s EUR" % (args
[0], price
))
43 bot
.msg(chan
, "Invalid amount.")
45 response
= get_coin_price('btc_eur')
46 price
= str(float(response
[0]['price']))
47 bot
.msg(chan
, "1 BTC = %s EUR" % price
)
50 def cmd_gtest(bot
, user
, chan
, realtarget
, *args
):
53 doge_btc
= get_coin_price('doge_btc')
54 btc_eur
= get_coin_price('btc_eur')
55 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(args
[0]))
56 bot
.msg(chan
, "%s DOGE = %s EUR" % (args
[0], price
))
58 bot
.msg(chan
, "Invalid amount.")
60 doge_btc
= get_coin_price('doge_btc')
61 btc_eur
= get_coin_price('btc_eur')
62 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']))
63 bot
.msg(chan
, "1 DOGE = %s EUR" % price
)
66 def cmd_gtest(bot
, user
, chan
, realtarget
, *args
):
69 ltc_btc
= get_coin_price('ltc_btc')
70 btc_eur
= get_coin_price('btc_eur')
71 price
= str(float(ltc_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(args
[0]))
72 bot
.msg(chan
, "%s LTC = %s EUR" % (args
[0], price
))
74 bot
.msg(chan
, "Invalid amount.")
76 ltc_btc
= get_coin_price('ltc_btc')
77 btc_eur
= get_coin_price('btc_eur')
78 price
= str(float(ltc_btc
[0]['price']) * float(btc_eur
[0]['price']))
79 bot
.msg(chan
, "1 LTC = %s EUR" % price
)
81 @lib.hooknum("PRIVMSG")
82 def privmsg_hook(bot
, line
):
85 linetx
= line
.split(None, 3)[3][1:]
89 chan
= line
.split()[2]
91 if 'btc' in line
or 'bitcoin' in line
or 'doge' in line
or 'dogecoin' in line
:
93 for amount
, coin
in r
.findall(linetx
):
94 amount
= amount
.replace(" ", "")
95 if 'btc' in coin
or 'bitcoin' in coin
:
97 response
= get_coin_price('btc_eur')
98 price
= str(float(response
[0]['price']) * float(amount
))
99 bot
.msg(chan
, "%s BTC = %s EUR" % (amount
, price
))
103 if 'ltc' in coin
or 'litecoin' in coin
:
106 if 'doge' in coin
or 'dogecoin' in coin
:
108 doge_btc
= get_coin_price('doge_btc')
109 btc_eur
= get_coin_price('btc_eur')
110 price
= str(float(doge_btc
[0]['price']) * float(btc_eur
[0]['price']) * float(amount
))
111 bot
.msg(chan
, "%s DOGE = %s EUR" % (amount
, price
))
113 bot
.msg(chan
, "Invalid amount.")