\!eur [number] USD to EUR
This commit is contained in:
parent
a285e45b07
commit
fcdb2a3542
12
bot/bot.lua
12
bot/bot.lua
@ -184,7 +184,7 @@ function do_action(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if string.starts(msg.text, '!eur') then
|
if string.starts(msg.text, '!eur') then
|
||||||
local eur = getEURUSD( )
|
local eur = getEURUSD(msg.text)
|
||||||
send_msg(receiver, eur, ok_cb, false)
|
send_msg(receiver, eur, ok_cb, false)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -367,14 +367,20 @@ function get_9GAG()
|
|||||||
return link_image, title
|
return link_image, title
|
||||||
end
|
end
|
||||||
|
|
||||||
function getEURUSD( )
|
function getEURUSD(text)
|
||||||
b = http.request("http://webrates.truefx.com/rates/connect.html?c=EUR/USD&f=csv&s=n")
|
b = http.request("http://webrates.truefx.com/rates/connect.html?c=EUR/USD&f=csv&s=n")
|
||||||
local rates = b:split(", ")
|
local rates = b:split(", ")
|
||||||
local symbol = rates[1]
|
local symbol = rates[1]
|
||||||
local timestamp = rates[2]
|
local timestamp = rates[2]
|
||||||
local sell = rates[3]..rates[4]
|
local sell = rates[3]..rates[4]
|
||||||
local buy = rates[5]..rates[6]
|
local buy = rates[5]..rates[6]
|
||||||
return symbol..'\n'..'Buy: '..buy..'\n'..'Sell: '..sell
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user