get and set

This commit is contained in:
yago 2014-11-03 11:32:26 +01:00
parent 04b8312e76
commit 5f65d0bfdb
2 changed files with 43 additions and 9 deletions

View File

@ -189,6 +189,18 @@ function do_action(msg)
return return
end end
if string.starts(msg.text, '!save') then
local text = save_value(msg.text:sub(6,-1))
send_msg(receiver, text, ok_cb, false)
return
end
if string.starts(msg.text, '!get') then
local text = get_value(msg.text:sub(6,-1))
send_msg(receiver, text, ok_cb, false)
return
end
if string.starts(msg.text, '!version') then if string.starts(msg.text, '!version') then
text = 'James Bot '.. VERSION .. [[ text = 'James Bot '.. VERSION .. [[
Licencia GNU v2, código disponible en http://git.io/6jdjGg Licencia GNU v2, código disponible en http://git.io/6jdjGg
@ -229,7 +241,7 @@ function load_config()
local f = assert(io.open('./bot/config.json', "r")) local f = assert(io.open('./bot/config.json', "r"))
local c = f:read "*a" local c = f:read "*a"
local config = json:decode(c) local config = json:decode(c)
if config.torrent_path then if config.sh_enabled then
print ("!sh command is enabled") print ("!sh command is enabled")
for v,user in pairs(config.sudo_users) do for v,user in pairs(config.sudo_users) do
print("Allowed user: " .. user) print("Allowed user: " .. user)
@ -240,6 +252,27 @@ function load_config()
return config return config
end end
function save_value( text )
local vars = split_by_space(text)
if (#vars < 2) then
return "Usage: !save var_name value"
end
config.values[vars[1]] = vars[2]
local json_text = json:encode_pretty(config)
file = io.open ("./bot/config.json", "w+")
file:write(json_text)
file:close()
return "Saved "..vars[1].."="..vars[2]
end
function get_value( value_name )
local value = config.values[value_name]
if ( value == nil) then
return "Cant find "..value_name
end
return value_name.." = "..value
end
function is_sudo(msg) function is_sudo(msg)
local var = false local var = false
-- Check users id in config -- Check users id in config

View File

@ -1,5 +1,6 @@
{ {
"sudo_users":[0, 1], "log_file": "/var/www/html/log.txt",
"sh_enabled":false, "sh_enabled": false,
"log_file":"/var/www/html/log.txt" "sudo_users": [ 0, 1 ],
"values": { }
} }