Initial implemenation of btc command

This commit is contained in:
Marcel van der Boom 2014-11-28 22:25:38 +01:00
parent 1c96903cc0
commit 5cda6ad9e6

36
plugins/btc.lua Normal file
View File

@ -0,0 +1,36 @@
function getBTCEUR(eur)
-- Do request on bitcoinaverage, the final / is critical!
local res,code = https.request("https://api.bitcoinaverage.com/ticker/global/EUR/")
if code~= 200 then return nil end
local data = json:decode(res)
-- Easy, it's right there
text = "BTC/EUR"..'\n'..'Buy: '..data.ask..'\n'..'Sell: '..data.bid
-- If we have a number as second parameter, calculate the bitcoin amount
if eur~=nil then
btc = tonumber(eur) / tonumber(data.ask)
text = text.."\n EUR "..eur.." = BTC "..btc
end
return text
end
function run(msg, matches)
if matches[1] == "!btc" then
return getBTCEUR(nil)
end
return getBTCEUR(matches[1])
end
return {
description = "BTCEUR market value",
usage = "!btc [EUR]",
patterns = {
"^!btc$",
"^!btc (%d+[%d%.]*)$",
},
run = run
}