diff --git a/.gitignore b/.gitignore index e69de29..d6d2cd0 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +res/ \ No newline at end of file diff --git a/bot/bot.lua b/bot/bot.lua index dce382f..3126f44 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -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) diff --git a/plugins/get.lua b/plugins/get.lua index d42c4da..18c2765 100644 --- a/plugins/get.lua +++ b/plugins/get.lua @@ -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. diff --git a/res/.gitkeep b/res/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/res/users.json b/res/users.json deleted file mode 100644 index 0e0dcd2..0000000 --- a/res/users.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} \ No newline at end of file diff --git a/res/values.json b/res/values.json deleted file mode 100644 index 0e0dcd2..0000000 --- a/res/values.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} \ No newline at end of file