values.json and users.json are created if not exists
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
res/
 | 
			
		||||
							
								
								
									
										19
									
								
								bot/bot.lua
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
									
								
							
							
						
						
									
										0
									
								
								res/.gitkeep
									
									
									
									
									
										Normal file
									
								
							@@ -1,3 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,3 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user