import asyncio import discord from discord.ext import commands from urllib import request import json, requests class Cryptocoin(object): """Voor al uw crypto currency advies.""" def __init__(self, bot): self.bot = bot self.voice_states = {} def __check(self, ctx): #Todo: Is dit het geld-verdienen kanaal? return True def getCoinPrice(self, coinId, currencyId="USD", time="now"): url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=" + currencyId + "&fsym=" + coinId if (time != "now"): url += "&ts=" + str(time) response = requests.get(url) try: priceData = json.loads(response.content.decode('utf-8')) return priceData[coinId][currencyId] except: return -1 @commands.command(pass_context=True) @asyncio.coroutine def coinprice(self, ctx, coinId: str, currencyId: str="USD"): """Geeft de huidige prijs van de desbetreffende crypto currency Bijv: !coinprice BTC Of voor de echte (Erik) Hollanders: !coinprice NLG EUR """ allowedCurrencies = ["USD", "EUR", "JPY", "GBP", "CNY", "CAD", "BTC"] if (currencyId not in allowedCurrencies): yield from ctx.channel.send("Valuta " + currencyId + " ken ik niet. :disappointed: ") return price = self.getCoinPrice(coinId, currencyId) if (price == -1): yield from ctx.channel.send("Die cryptocoin ken ik niet... :frowning2: ") return yield from ctx.channel.send(coinId + " is nu " + str(price) + " " + currencyId + " waard.")