set Values arent "shared" any more. I hope nobody will miss that "feature"

This commit is contained in:
yago 2014-12-14 21:44:19 +01:00
parent 5bbf754d73
commit e475659978
2 changed files with 17 additions and 8 deletions

View File

@ -10,16 +10,22 @@ else
_values = json:decode(c)
end
function get_value( value_name )
function get_value(chat, value_name)
-- If chat values is empty
if (_values[chat] == nil) then
return "There isn't any data"
end
-- If there is not value name, return all the values.
if (value_name == nil ) then
local text = ""
for key,value in pairs(_values) do
for key,value in pairs(_values[chat]) do
text = text..key.." = "..value.."\n"
end
return text
end
local value = _values[value_name]
local value = _values[chat][value_name]
if ( value == nil) then
return "Can't find "..value_name
end
@ -28,9 +34,9 @@ end
function run(msg, matches)
if matches[1] == "!get" then
return get_value(nil)
return get_value(msg.to.id, nil)
end
return get_value(matches[1])
return get_value(msg.to.id, matches[1])
end
return {

View File

@ -1,9 +1,12 @@
function save_value( text )
function save_value(chat, text )
var_name, var_value = string.match(text, "!set (%a+) (.+)")
if (var_name == nil or var_value == nil) then
return "Usage: !set var_name value"
end
_values[var_name] = var_value
if _values[chat] == nil then
_values[chat] = {}
end
_values[chat][var_name] = var_value
local json_text = json:encode_pretty(_values)
file = io.open ("./res/values.json", "w+")
@ -14,7 +17,7 @@ function save_value( text )
end
function run(msg, matches)
local text = save_value(msg.text)
local text = save_value(msg.to.id, msg.text)
return text
end