save values with spaces

This commit is contained in:
yago 2014-11-03 22:36:15 +01:00
parent bc6df5d683
commit c6ab143a7e

View File

@ -2,8 +2,7 @@
URL = require("socket.url") URL = require("socket.url")
json = (loadfile "./bot/JSON.lua")() json = (loadfile "./bot/JSON.lua")()
VERSION = 'v0.5' VERSION = 'v0.6'
function on_msg_receive (msg) function on_msg_receive (msg)
@ -226,7 +225,9 @@
!rae (word): Spanish dictionary !rae (word): Spanish dictionary
!eur : EURUSD market value !eur : EURUSD market value
!img (text) : search image with Google API and sends it !img (text) : search image with Google API and sends it
!uc3m : fortunes from Universidad Carlos III]] !uc3m : fortunes from Universidad Carlos III
!set [variable_name] [value] store for !get
!get (variable_name) retrieves variables saved with !set]]
send_msg(receiver, text, ok_cb, false) send_msg(receiver, text, ok_cb, false)
return return
end end
@ -253,16 +254,16 @@
end end
function save_value( text ) function save_value( text )
local vars = split_by_space(text) var_name, var_value = string.match(text, "(%a+) (.+)")
if (#vars < 2) then if (a == nil or b == nil) then
return "Usage: !set var_name value" return "Usage: !set var_name value"
end end
config.values[vars[1]] = vars[2] config.values[var_name] = var_value
local json_text = json:encode_pretty(config) local json_text = json:encode_pretty(config)
file = io.open ("./bot/config.json", "w+") file = io.open ("./bot/config.json", "w+")
file:write(json_text) file:write(json_text)
file:close() file:close()
return "Saved "..vars[1].."="..vars[2] return "Saved "..var_name.." = "..var_value
end end
function get_value( value_name ) function get_value( value_name )
@ -270,7 +271,7 @@
if (value_name == "" ) then if (value_name == "" ) then
local text = "" local text = ""
for key,value in pairs(config.values) do for key,value in pairs(config.values) do
text = text..key.."="..value.."\n" text = text..key.." = "..value.."\n"
end end
return text return text
end end