]> jfr.im git - erebus.git/blob - modules/coins.py
Added coins module with btc/ltc/doge
[erebus.git] / modules / coins.py
1 # Erebus IRC bot - Author: Erebus Team
2 # simple coin module
3 # This file is released into the public domain; see http://unlicense.org/
4
5 # module info
6 modinfo = {
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
11 }
12
13 # preamble
14 import modlib
15 lib = modlib.modlib(__name__)
16 modstart = lib.modstart
17 modstop = lib.modstop
18
19 # module code
20 import json
21 import requests
22
23 url = 'http://www.cryptocoincharts.info/v2/api/tradingPairs'
24
25 def get_coin_price(pairs):
26 response = requests.post(url, data = {'pairs': pairs})
27 return json.loads(response.text)
28
29 @lib.hook('btc')
30 def cmd_gtest(bot, user, chan, realtarget, *args):
31 if len(args) > 0:
32 try:
33 response = get_coin_price('btc_eur')
34 price = str(float(response[0]['price']) * float(args[0]))
35 bot.msg(chan, "%s BTC = %s EUR" % (args[0], price))
36 except:
37 bot.msg(chan, "Invalid amount.")
38 else:
39 response = get_coin_price('btc_eur')
40 price = str(float(response[0]['price']))
41 bot.msg(chan, "1 BTC = %s EUR" % price)
42
43 @lib.hook('doge')
44 def cmd_gtest(bot, user, chan, realtarget, *args):
45 if len(args) > 0:
46 try:
47 doge_btc = get_coin_price('doge_btc')
48 btc_eur = get_coin_price('btc_eur')
49 price = str(float(doge_btc[0]['price']) * float(btc_eur[0]['price']) * float(args[0]))
50 bot.msg(chan, "%s DOGE = %s EUR" % (args[0], price))
51 except:
52 bot.msg(chan, "Invalid amount.")
53 else:
54 doge_btc = get_coin_price('doge_btc')
55 btc_eur = get_coin_price('btc_eur')
56 price = str(float(doge_btc[0]['price']) * float(btc_eur[0]['price']))
57 bot.msg(chan, "1 DOGE = %s EUR" % price)
58
59 @lib.hook('ltc')
60 def cmd_gtest(bot, user, chan, realtarget, *args):
61 if len(args) > 0:
62 try:
63 ltc_btc = get_coin_price('ltc_btc')
64 btc_eur = get_coin_price('btc_eur')
65 price = str(float(ltc_btc[0]['price']) * float(btc_eur[0]['price']) * float(args[0]))
66 bot.msg(chan, "%s LTC = %s EUR" % (args[0], price))
67 except:
68 bot.msg(chan, "Invalid amount.")
69 else:
70 ltc_btc = get_coin_price('ltc_btc')
71 btc_eur = get_coin_price('btc_eur')
72 price = str(float(ltc_btc[0]['price']) * float(btc_eur[0]['price']))
73 bot.msg(chan, "1 LTC = %s EUR" % price)