From b2b41f231166bd9792543642bc8627b228fd2c8b Mon Sep 17 00:00:00 2001 From: Akamaru Date: Thu, 16 Apr 2015 20:16:37 +0200 Subject: [PATCH] few changes on bot.lua and utils.lua TIMEOUT set to 10s Uglify on serialize_to_file Random name if previous patterns fails --- bot/bot.lua | 1 - bot/utils.lua | 26 +++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 7cfc8d7..a9d8ac9 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -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) diff --git a/bot/utils.lua b/bot/utils.lua index 39ef535..10a1c7c 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -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