get, set, and stats persistence
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
local f = assert(io.open('./res/values.json', "r+"))
|
||||
local c = f:read "*a"
|
||||
_values = json:decode(c)
|
||||
|
||||
function get_value( value_name )
|
||||
-- If there is not value name, return all the values.
|
||||
if (value_name == nil ) then
|
||||
local text = ""
|
||||
for key,value in pairs(config.values) do
|
||||
for key,value in pairs(_values) do
|
||||
text = text..key.." = "..value.."\n"
|
||||
end
|
||||
return text
|
||||
end
|
||||
local value = config.values[value_name]
|
||||
local value = _values[value_name]
|
||||
if ( value == nil) then
|
||||
return "Can't find "..value_name
|
||||
end
|
||||
|
||||
@@ -3,11 +3,13 @@ function save_value( text )
|
||||
if (var_name == nil or var_value == nil) then
|
||||
return "Usage: !set var_name value"
|
||||
end
|
||||
config.values[var_name] = var_value
|
||||
local json_text = json:encode_pretty(config)
|
||||
file = io.open ("./bot/config.json", "w+")
|
||||
_values[var_name] = var_value
|
||||
|
||||
local json_text = json:encode_pretty(_values)
|
||||
file = io.open ("./res/values.json", "w+")
|
||||
file:write(json_text)
|
||||
file:close()
|
||||
|
||||
return "Saved "..var_name.." = "..var_value
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
function run(msg, matches)
|
||||
vardump(_users)
|
||||
-- Save stats to file
|
||||
local json_users = json:encode_pretty(_users)
|
||||
vardump(json_users)
|
||||
file_users = io.open ("./res/users.json", "w")
|
||||
file_users:write(json_users)
|
||||
file_users:close()
|
||||
|
||||
local text = ""
|
||||
for id, user in pairs(_users) do
|
||||
text = text..user.name..": "..user.msg_num.."\n"
|
||||
|
||||
Reference in New Issue
Block a user