serialize config with function
This commit is contained in:
parent
7ce798b21b
commit
a889d410f1
16
bot/bot.lua
16
bot/bot.lua
@ -121,13 +121,7 @@ end
|
|||||||
|
|
||||||
-- Save the content of _config to config.lua
|
-- Save the content of _config to config.lua
|
||||||
function save_config( )
|
function save_config( )
|
||||||
file = io.open('./bot/config.lua', 'w+')
|
serialize_to_file(_config, './bot/config.lua')
|
||||||
local serialized = serpent.block(_config, {
|
|
||||||
comment = false,
|
|
||||||
name = "config"
|
|
||||||
})
|
|
||||||
file:write(serialized)
|
|
||||||
file:close()
|
|
||||||
print ('saved config into ./bot/config.lua')
|
print ('saved config into ./bot/config.lua')
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,13 +161,7 @@ function create_config( )
|
|||||||
"youtube" },
|
"youtube" },
|
||||||
sudo_users = {our_id}
|
sudo_users = {our_id}
|
||||||
}
|
}
|
||||||
file = io.open('./bot/config.lua', 'w+')
|
serialize_to_file(config, './bot/config.lua')
|
||||||
local serialized = serpent.block(config, {
|
|
||||||
comment = false,
|
|
||||||
name = "config"
|
|
||||||
})
|
|
||||||
file:write(serialized)
|
|
||||||
file:close()
|
|
||||||
print ('saved config into ./bot/config.lua')
|
print ('saved config into ./bot/config.lua')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -170,3 +170,14 @@ function file_exists(name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Save into file the data serialized for lua.
|
||||||
|
function serialize_to_file(data, file)
|
||||||
|
file = io.open(file, 'w+')
|
||||||
|
local serialized = serpent.block(data, {
|
||||||
|
comment = false,
|
||||||
|
name = "_"
|
||||||
|
})
|
||||||
|
file:write(serialized)
|
||||||
|
file:close()
|
||||||
|
end
|
Reference in New Issue
Block a user