This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/btc.lua
2014-11-28 22:25:38 +01:00

37 lines
869 B
Lua

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
}