From fcdb2a3542930b1bf1daacd0a8264dd41d0f7b1b Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 12 Oct 2014 12:32:13 +0200 Subject: [PATCH] \!eur [number] USD to EUR --- bot/bot.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 65b6807..d775537 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -184,7 +184,7 @@ function do_action(msg) end if string.starts(msg.text, '!eur') then - local eur = getEURUSD( ) + local eur = getEURUSD(msg.text) send_msg(receiver, eur, ok_cb, false) return end @@ -367,14 +367,20 @@ function get_9GAG() return link_image, title end -function getEURUSD( ) +function getEURUSD(text) b = http.request("http://webrates.truefx.com/rates/connect.html?c=EUR/USD&f=csv&s=n") local rates = b:split(", ") local symbol = rates[1] local timestamp = rates[2] local sell = rates[3]..rates[4] - local buy = rates[5]..rates[6] - return symbol..'\n'..'Buy: '..buy..'\n'..'Sell: '..sell + local buy = rates[5]..rates[6] + local usd = string.match(text, "!eur (%d+[%d%.]*)") + text = symbol..'\n'..'Buy: '..buy..'\n'..'Sell: '..sell + if usd then + eur = tonumber(usd) / tonumber(buy) + text = text.."\n "..usd.."USD = "..eur.."EUR" + end + return text end