From a19c444db9d5625a9281684ba01961526533d535 Mon Sep 17 00:00:00 2001 From: yago Date: Thu, 9 Oct 2014 15:09:06 +0200 Subject: [PATCH] EURUSD :money_with_wings: --- bot/bot.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bot/bot.lua b/bot/bot.lua index eccd4d6..5317ec2 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -157,6 +157,12 @@ function do_action(msg) return end + if string.starts(msg.text, '!eur') then + local eur = getEURUSD( ) + send_msg(receiver, eur, ok_cb, false) + return + end + if string.starts(msg.text, '!version') then text = 'James Bot '.. VERSION .. [[ Licencia GNU v2, código disponible en http://git.io/6jdjGg @@ -294,6 +300,16 @@ function get_9GAG() return link_image, title end +function getEURUSD( ) + 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 +end + function download_to_file( url ) print("url a descargar: "..url) @@ -371,6 +387,13 @@ function split_by_space ( text ) return words end +function string:split(sep) + local sep, fields = sep or ":", {} + local pattern = string.format("([^%s]+)", sep) + self:gsub(pattern, function(c) fields[#fields+1] = c end) + return fields +end + function vardump(value, depth, key) local linePrefix = "" local spaces = ""