data is the new res folder
This commit is contained in:
parent
859fb485fa
commit
6c9efc902c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
res/
|
||||
data/
|
||||
bot/config.lua
|
@ -5,7 +5,7 @@ json = (loadfile "./libs/JSON.lua")()
|
||||
serpent = (loadfile "./libs/serpent.lua")()
|
||||
require("./bot/utils")
|
||||
|
||||
VERSION = '0.8.1'
|
||||
VERSION = '0.8.2'
|
||||
|
||||
function on_msg_receive (msg)
|
||||
vardump(msg)
|
||||
|
@ -1,14 +1,20 @@
|
||||
local f = io.open('./res/values.json', "r+")
|
||||
local _file_values = './data/values.lua'
|
||||
|
||||
function read_file_values( )
|
||||
local f = io.open(_file_values, "r+")
|
||||
-- If file doesn't exists
|
||||
if f == nil then
|
||||
f = io.open('./res/values.json', "w+")
|
||||
f:write("{}") -- Write empty table
|
||||
f:close()
|
||||
_values = {}
|
||||
-- Create a new empty table
|
||||
print ('Created value file '.._file_values)
|
||||
serialize_to_file({}, _file_values)
|
||||
else
|
||||
local c = f:read "*a"
|
||||
print ('Stats loaded: '.._file_values)
|
||||
f:close()
|
||||
_values = json:decode(c)
|
||||
end
|
||||
return loadfile (_file_values)()
|
||||
end
|
||||
|
||||
_values = read_file_values()
|
||||
|
||||
function fetch_value(chat, value_name)
|
||||
if (_values[chat] == nil) then
|
||||
|
@ -1,3 +1,5 @@
|
||||
local _file_values = './data/values.lua'
|
||||
|
||||
function save_value(chat, text )
|
||||
var_name, var_value = string.match(text, "!set (%a+) (.+)")
|
||||
if (var_name == nil or var_value == nil) then
|
||||
@ -8,10 +10,8 @@ function save_value(chat, text )
|
||||
end
|
||||
_values[chat][var_name] = var_value
|
||||
|
||||
local json_text = json:encode_pretty(_values)
|
||||
file = io.open ("./res/values.json", "w+")
|
||||
file:write(json_text)
|
||||
file:close()
|
||||
-- Save values to file
|
||||
serialize_to_file(_values, _file_values)
|
||||
|
||||
return "Saved "..var_name.." = "..var_value
|
||||
end
|
||||
|
@ -4,7 +4,7 @@
|
||||
do
|
||||
|
||||
local socket = require('socket')
|
||||
local _file_stats = './res/stats.lua'
|
||||
local _file_stats = './data/stats.lua'
|
||||
local _stats
|
||||
|
||||
function update_user_stats(msg)
|
||||
|
Reference in New Issue
Block a user