few changes on bot.lua and utils.lua

TIMEOUT set to 10s
Uglify on serialize_to_file
Random name if previous patterns fails
This commit is contained in:
Akamaru 2015-04-16 20:16:37 +02:00
parent 5bf2b6bf17
commit b2b41f2311
2 changed files with 19 additions and 8 deletions

View File

@ -74,7 +74,6 @@ local function is_plugin_disabled_on_chat(plugin_name, receiver)
if disabled_chats and disabled_chats[receiver] then
-- Checks if plugin is disabled on this chat
for disabled_plugin,disabled in pairs(disabled_chats[receiver]) do
print(disabled_plugin)
if disabled_plugin == plugin_name and disabled then
local warning = ''
print(warning)

View File

@ -6,6 +6,8 @@ json = (loadfile "./libs/JSON.lua")()
serpent = (loadfile "./libs/serpent.lua")()
mimetype = (loadfile "./libs/mimetype.lua")()
http.TIMEOUT = 10
function get_receiver(msg)
if msg.to.type == 'user' then
return 'user#id'..msg.from.id
@ -53,8 +55,12 @@ function string:trim()
end
function get_http_file_name(url, headers)
-- Everything after the last /
local file_name = url:match("([^/]+)$")
-- Eg: fooo.var
local file_name = url:match("[^%w]+([%.%w]+)$")
-- Any delimited aphanumeric on the url
file_name = file_name or url:match("[^%w]+(%w+)[^%w]+$")
-- Random name, hope content-type works
file_name = file_name or str:random(5)
-- Possible headers names
local content_type = headers["content-type"]
@ -210,12 +216,18 @@ function file_exists(name)
end
-- Save into file the data serialized for lua.
function serialize_to_file(data, file)
-- Set uglify true to minify the file.
function serialize_to_file(data, file, uglify)
file = io.open(file, 'w+')
local serialized = serpent.block(data, {
comment = false,
name = "_"
})
local serialized
if not uglify then
serialized = serpent.block(data, {
comment = false,
name = '_'
})
else
serialized = serpent.dump(data)
end
file:write(serialized)
file:close()
end