diff --git a/bot/bot.lua b/bot/bot.lua index 7cdefc7..36171fc 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -121,13 +121,7 @@ end -- Save the content of _config to config.lua function save_config( ) - file = io.open('./bot/config.lua', 'w+') - local serialized = serpent.block(_config, { - comment = false, - name = "config" - }) - file:write(serialized) - file:close() + serialize_to_file(_config, './bot/config.lua') print ('saved config into ./bot/config.lua') end @@ -167,13 +161,7 @@ function create_config( ) "youtube" }, sudo_users = {our_id} } - file = io.open('./bot/config.lua', 'w+') - local serialized = serpent.block(config, { - comment = false, - name = "config" - }) - file:write(serialized) - file:close() + serialize_to_file(config, './bot/config.lua') print ('saved config into ./bot/config.lua') end diff --git a/bot/utils.lua b/bot/utils.lua index 81079e4..bce3c4a 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -169,4 +169,15 @@ function file_exists(name) else return false 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 \ No newline at end of file diff --git a/launch.sh b/launch.sh index 56ce55d..09399ab 100755 --- a/launch.sh +++ b/launch.sh @@ -14,4 +14,4 @@ if [ ! -f ./tg/bin/telegram-cli ]; then exit fi -./tg/bin/telegram-cli -k tg/tg-server.pub -s ./bot/bot.lua -W +./tg/bin/telegram-cli -k tg/tg-server.pub -s ./bot/bot.lua -W -l 1