values.json and users.json are created if not exists

This commit is contained in:
yago 2014-11-23 12:25:33 +01:00
parent 019fdd06ba
commit 48b17bd5d0
6 changed files with 26 additions and 14 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
res/

View File

@ -3,7 +3,7 @@
URL = require("socket.url")
json = (loadfile "./bot/JSON.lua")()
VERSION = 'v0.7.3'
VERSION = 'v0.7.4'
-- taken from http://stackoverflow.com/a/11130774/3163199
function scandir(directory)
@ -16,7 +16,7 @@
end
function on_msg_receive (msg)
--vardump(msg)
vardump(msg)
if msg_valid(msg) == false then
return
@ -240,9 +240,18 @@
end
function load_user_stats()
local f = assert(io.open('./res/users.json', "r"))
local c = f:read "*a"
return json:decode(c)
local f = io.open('res/users.json', "r+")
-- If file doesn't exists
if f == nil then
f = io.open('res/users.json', "w+")
f:write("{}") -- Write empty table
f:close()
return {}
else
local c = f:read "*a"
f:close()
return json:decode(c)
end
end
function get_receiver(msg)

View File

@ -1,6 +1,14 @@
local f = assert(io.open('./res/values.json', "r+"))
local c = f:read "*a"
_values = json:decode(c)
local f = io.open('./res/values.json', "r+")
if f == nil then
f = io.open('./res/values.json', "w+")
f:write("{}") -- Write empty table
f:close()
_values = {}
else
local c = f:read "*a"
f:close()
_values = json:decode(c)
end
function get_value( value_name )
-- If there is not value name, return all the values.

0
res/.gitkeep Normal file
View File

View File

@ -1,3 +0,0 @@
{
}

View File

@ -1,3 +0,0 @@
{
}