Skip to content

Commit

Permalink
data is the new res folder
Browse files Browse the repository at this point in the history
  • Loading branch information
yagop committed Jan 6, 2015
1 parent 859fb48 commit 6c9efc9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
res/
data/
bot/config.lua
2 changes: 1 addition & 1 deletion bot/bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
26 changes: 16 additions & 10 deletions plugins/get.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
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)
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
-- Create a new empty table
print ('Created value file '.._file_values)
serialize_to_file({}, _file_values)
else
print ('Stats loaded: '.._file_values)
f:close()
end
return loadfile (_file_values)()
end

_values = read_file_values()

function fetch_value(chat, value_name)
if (_values[chat] == nil) then
return nil
Expand Down
8 changes: 4 additions & 4 deletions plugins/set.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugins/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6c9efc9

Please sign in to comment.