From 8b7c55088af687314c077b723952ff46eefdfdda Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Thu, 8 Sep 2016 01:35:10 +0200 Subject: [PATCH] =?UTF-8?q?Code-Cleanup=20f=C3=BCr=20Utilities,=20fix=20#1?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/app_store.lua | 2 +- otouto/plugins/bitly_create.lua | 4 +- otouto/plugins/channels.lua | 2 +- otouto/plugins/control.lua | 2 +- otouto/plugins/creds.lua | 2 +- otouto/plugins/dhl.lua | 4 +- otouto/plugins/gImages.lua | 15 +++- otouto/plugins/games.lua | 2 +- otouto/plugins/github_feed.lua | 10 +-- otouto/plugins/id.lua | 30 ++++---- otouto/plugins/imgblacklist.lua | 2 +- otouto/plugins/luarun.lua | 2 +- otouto/plugins/lyrics.lua | 2 +- otouto/plugins/plugins.lua | 18 ++++- otouto/plugins/quotes.lua | 8 -- otouto/plugins/rss.lua | 10 +-- otouto/plugins/site_header.lua | 2 +- otouto/plugins/stats.lua | 2 +- otouto/plugins/tagesschau_eil.lua | 2 +- otouto/plugins/twitter_send.lua | 10 +-- otouto/utilities.lua | 124 +++--------------------------- 21 files changed, 85 insertions(+), 170 deletions(-) diff --git a/otouto/plugins/app_store.lua b/otouto/plugins/app_store.lua index a3b0980..3b9fb6f 100644 --- a/otouto/plugins/app_store.lua +++ b/otouto/plugins/app_store.lua @@ -43,7 +43,7 @@ function app_store:send_appstore_data(data) else game_center = '' end - local category_count = tablelength(data.genres) + local category_count = #data.genres if category_count == 1 then category = '\nKategorie: '..data.genres[1] else diff --git a/otouto/plugins/bitly_create.lua b/otouto/plugins/bitly_create.lua index 9ae823d..9d2c7df 100644 --- a/otouto/plugins/bitly_create.lua +++ b/otouto/plugins/bitly_create.lua @@ -124,10 +124,10 @@ function bitly_create:action(msg, config, matches) end if matches[2] == nil then - long_url = url_encode(matches[1]) + long_url = URL.encode(matches[1]) domain = 'bit.ly' else - long_url = url_encode(matches[2]) + long_url = URL.encode(matches[2]) domain = matches[1] end utilities.send_reply(msg, bitly_create:create_bitlink(long_url, domain, bitly_access_token)) diff --git a/otouto/plugins/channels.lua b/otouto/plugins/channels.lua index e16e041..bb62de6 100644 --- a/otouto/plugins/channels.lua +++ b/otouto/plugins/channels.lua @@ -47,7 +47,7 @@ function channels:pre_process(msg, config) end function channels:action(msg, config, matches) - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/plugins/control.lua b/otouto/plugins/control.lua index abf1ca9..616d120 100644 --- a/otouto/plugins/control.lua +++ b/otouto/plugins/control.lua @@ -11,7 +11,7 @@ end function control:action(msg, config) - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then return end diff --git a/otouto/plugins/creds.lua b/otouto/plugins/creds.lua index 5da43cc..9c19a39 100644 --- a/otouto/plugins/creds.lua +++ b/otouto/plugins/creds.lua @@ -89,7 +89,7 @@ end function creds_manager:action(msg, config, matches) local receiver = msg.from.id - if receiver ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/plugins/dhl.lua b/otouto/plugins/dhl.lua index b7cabc6..4852fe8 100644 --- a/otouto/plugins/dhl.lua +++ b/otouto/plugins/dhl.lua @@ -16,9 +16,9 @@ function dhl:sendungsstatus(id) local res,code = https.request(url) if code ~= 200 then return "Fehler beim Abrufen von mobil.dhl.de" end local status = string.match(res, "
(.-)
") - local status = all_trim(status) + local status = utilities.trim(status) local zeit = string.match(res, "
(.-)
") - local zeit = all_trim(zeit) + local zeit = utilities.trim(zeit) if not zeit or zeit == '
' then return status end diff --git a/otouto/plugins/gImages.lua b/otouto/plugins/gImages.lua index 1fd8260..78af76a 100644 --- a/otouto/plugins/gImages.lua +++ b/otouto/plugins/gImages.lua @@ -23,6 +23,19 @@ end gImages.command = 'img ' +function gImages:is_blacklisted(msg) + _blacklist = redis:smembers("telegram:img_blacklist") + local var = false + for v,word in pairs(_blacklist) do + if string.find(string.lower(msg), string.lower(word)) then + print("Wort steht auf der Blacklist!") + var = true + break + end + end + return var +end + -- Yes, the callback is copied from below, but I can't think of another method :\ function gImages:callback(callback, msg, self, config, input) if not msg then return end @@ -150,7 +163,7 @@ function gImages:action(msg, config, matches) end print ('Checking if search contains blacklisted word: '..input) - if is_blacklisted(input) then + if gImages:is_blacklisted(input) then utilities.send_reply(msg, 'Vergiss es! ._.') return end diff --git a/otouto/plugins/games.lua b/otouto/plugins/games.lua index 0e34912..ddbe85f 100644 --- a/otouto/plugins/games.lua +++ b/otouto/plugins/games.lua @@ -79,7 +79,7 @@ function games:send_game_data(game_id, self, msg) if xml.find(result, 'Genres') then local genres = xml.find(result, 'Genres') - local genre_count = tablelength(genres)-1 + local genre_count = #genres-1 if genre_count == 1 then genre = '\nGenre: '..genres[1][1] else diff --git a/otouto/plugins/github_feed.lua b/otouto/plugins/github_feed.lua index 1c5f2c5..78a2d98 100644 --- a/otouto/plugins/github_feed.lua +++ b/otouto/plugins/github_feed.lua @@ -180,7 +180,7 @@ function gh_feed:action(msg, config, matches) -- For channels if matches[1] == 'sub' and matches[2] and matches[3] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -194,7 +194,7 @@ function gh_feed:action(msg, config, matches) utilities.send_reply(msg, output, true) return elseif matches[1] == 'del' and matches[2] and matches[3] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -227,7 +227,7 @@ function gh_feed:action(msg, config, matches) end if matches[1] == 'sub' and matches[2] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -235,7 +235,7 @@ function gh_feed:action(msg, config, matches) utilities.send_reply(msg, output, true) return elseif matches[1] == 'del' and matches[2] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -247,7 +247,7 @@ function gh_feed:action(msg, config, matches) utilities.send_reply(msg, list_subs, true, keyboard) return elseif matches[1] == 'sync' then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/plugins/id.lua b/otouto/plugins/id.lua index f88b4e9..0becc6d 100644 --- a/otouto/plugins/id.lua +++ b/otouto/plugins/id.lua @@ -66,27 +66,27 @@ function id:action(msg, config, matches) end local chat_id = msg.chat.id - local user = 'Du bist @%s, auch bekannt als *%s* `[%s]`' + local user = 'Du bist @%s, auch bekannt als %s [%s]' if msg.from.username then - user = user:format(utilities.markdown_escape(msg.from.username), msg.from.name, msg.from.id) + user = user:format(utilities.html_escape(msg.from.username), msg.from.name, msg.from.id) else - user = 'Du bist *%s* `[%s]`,' + user = 'Du bist %s [%s],' user = user:format(msg.from.name, msg.from.id) end - local group = '@%s, auch bekannt als *%s* `[%s]`.' + local group = '@%s, auch bekannt als %s [%s].' if msg.chat.type == 'private' then - group = group:format(utilities.markdown_escape(self.info.username), self.info.first_name, self.info.id) + group = group:format(utilities.html_escape(self.info.username), self.info.first_name, self.info.id) elseif msg.chat.username then - group = group:format(utilities.markdown_escape(msg.chat.username), msg.chat.title, chat_id) + group = group:format(utilities.html_escape(msg.chat.username), msg.chat.title, chat_id) else - group = '*%s* `[%s]`.' + group = '%s [%s].' group = group:format(msg.chat.title, chat_id) end local output = user .. ', und du bist in der Gruppe ' .. group - utilities.send_message(msg.chat.id, output, true, msg.message_id, true) + utilities.send_message(msg.chat.id, output, true, msg.message_id, 'HTML') elseif matches[1] == "chat" then if msg.chat.type ~= 'group' and msg.chat.type ~= 'supergroup' then utilities.send_reply(msg, 'Das hier ist keine Gruppe!') @@ -118,21 +118,21 @@ function id:action(msg, config, matches) local result = id:get_member_count(msg, chat_id) local member_count = result.result if member_count == 1 then - member_count = 'ist *1 Mitglied' + member_count = 'ist 1 Mitglied' else - member_count = 'sind *'..member_count..' Mitglieder' + member_count = 'sind '..member_count..' Mitglieder' end - local text = 'IDs für *'..chat_name..'* `['..chat_id..']`\nHier '..member_count..':*\n---------\n' + local text = 'IDs für '..chat_name..' ['..chat_id..']\nHier '..member_count..':\n---------\n' for k,user in pairs(users_info) do if table.contains(admins, tostring(user.id)) then - text = text..'*'..user.name..'* `['..user.id..']` _Administrator_\n' + text = text..''..user.name..' ['..user.id..'] Administrator\n' elseif tostring(creator_id) == user.id then - text = text..'*'..user.name..'* `['..user.id..']` _Gründer_\n' + text = text..''..user.name..' ['..user.id..'] Gründer\n' else - text = text..'*'..user.name..'* `['..user.id..']`\n' + text = text..''..user.name..' ['..user.id..']\n' end end - utilities.send_reply(msg, text..'_(Bots sind nicht gelistet)_', true) + utilities.send_reply(msg, text..'(Bots sind nicht gelistet)', 'HTML') end end diff --git a/otouto/plugins/imgblacklist.lua b/otouto/plugins/imgblacklist.lua index f94393f..1f94a83 100644 --- a/otouto/plugins/imgblacklist.lua +++ b/otouto/plugins/imgblacklist.lua @@ -49,7 +49,7 @@ function imgblacklist:remove_blacklist(word) end function imgblacklist:action(msg, config, matches) - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/plugins/luarun.lua b/otouto/plugins/luarun.lua index a15c750..75bcd12 100644 --- a/otouto/plugins/luarun.lua +++ b/otouto/plugins/luarun.lua @@ -27,7 +27,7 @@ end function luarun:action(msg, config) - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then return true end diff --git a/otouto/plugins/lyrics.lua b/otouto/plugins/lyrics.lua index 88584a8..b69e7ee 100644 --- a/otouto/plugins/lyrics.lua +++ b/otouto/plugins/lyrics.lua @@ -16,7 +16,7 @@ lyrics.command = 'lyrics ' function lyrics:getLyrics(text) local apikey = cred_data.lyricsnmusic_apikey - local q = url_encode(text) + local q = URL.encode(text) local b = http.request("http://api.lyricsnmusic.com/songs?api_key="..apikey.."&q=" .. q) response = json.decode(b) local reply = "" diff --git a/otouto/plugins/plugins.lua b/otouto/plugins/plugins.lua index 77dd3f0..e231eb7 100644 --- a/otouto/plugins/plugins.lua +++ b/otouto/plugins/plugins.lua @@ -24,6 +24,18 @@ end plugin_manager.command = 'plugins ' +-- Returns at table of lua files inside plugins +function plugin_manager:plugins_names() + local files = {} + for k, v in pairs(scandir("otouto/plugins")) do + -- Ends with .lua + if (v:match(".lua$")) then + files[#files+1] = v + end + end + return files +end + -- Returns the key (index) in the config.enabled_plugins table function plugin_manager:plugin_enabled(name, chat) for k,v in pairs(enabled_plugins) do @@ -37,7 +49,7 @@ end -- Returns true if file exists in plugins folder function plugin_manager:plugin_exists(name) - for k,v in pairs(plugins_names()) do + for k,v in pairs(plugin_manager:plugins_names()) do if name..'.lua' == v then return true end @@ -47,7 +59,7 @@ end function plugin_manager:list_plugins() local text = '' - for k, v in pairs(plugins_names()) do + for k, v in pairs(plugin_manager:plugins_names()) do -- ✔ enabled, ❌ disabled local status = '❌' -- Check if is enabled @@ -161,7 +173,7 @@ function plugin_manager:reenable_plugin_on_chat(msg, plugin) end function plugin_manager:action(msg, config, matches) - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/plugins/quotes.lua b/otouto/plugins/quotes.lua index 35e8c31..d56c75d 100644 --- a/otouto/plugins/quotes.lua +++ b/otouto/plugins/quotes.lua @@ -21,10 +21,6 @@ end quotes.command = 'quote' function quotes:save_quote(msg) - if msg.text:sub(11):isempty() then - return "Benutzung: /addquote [Zitat]" - end - local quote = msg.text:sub(11) local hash = get_redis_hash(msg, 'quotes') print('Saving quote to redis set '..hash) @@ -33,10 +29,6 @@ function quotes:save_quote(msg) end function quotes:delete_quote(msg) - if msg.text:sub(11):isempty() then - return "Benutzung: /delquote [Zitat]" - end - local quote = msg.text:sub(11) local hash = get_redis_hash(msg, 'quotes') print('Deleting quote from redis set '..hash) diff --git a/otouto/plugins/rss.lua b/otouto/plugins/rss.lua index e9c2fb9..5c44a5b 100644 --- a/otouto/plugins/rss.lua +++ b/otouto/plugins/rss.lua @@ -211,7 +211,7 @@ function rss:action(msg, config, matches) -- For channels if matches[1] == 'sub' and matches[2] and matches[3] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -225,7 +225,7 @@ function rss:action(msg, config, matches) utilities.send_reply(msg, output, 'HTML') return elseif matches[1] == 'del' and matches[2] and matches[3] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -258,7 +258,7 @@ function rss:action(msg, config, matches) end if matches[1] == 'sub' and matches[2] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -266,7 +266,7 @@ function rss:action(msg, config, matches) utilities.send_reply(msg, output, 'HTML') return elseif matches[1] == 'del' and matches[2] then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -278,7 +278,7 @@ function rss:action(msg, config, matches) utilities.send_reply(msg, list_subs, 'HTML', keyboard) return elseif matches[1] == 'sync' then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/plugins/site_header.lua b/otouto/plugins/site_header.lua index eeca8e1..2670273 100644 --- a/otouto/plugins/site_header.lua +++ b/otouto/plugins/site_header.lua @@ -8,7 +8,7 @@ function site_header:init(config) end function site_header:action(msg, config, matches) - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) end diff --git a/otouto/plugins/stats.lua b/otouto/plugins/stats.lua index 3e24137..baa5b1d 100644 --- a/otouto/plugins/stats.lua +++ b/otouto/plugins/stats.lua @@ -136,7 +136,7 @@ function stats:action(msg, config, matches) end if matches[2] == "chat" then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return else diff --git a/otouto/plugins/tagesschau_eil.lua b/otouto/plugins/tagesschau_eil.lua index 6859280..ce4a62f 100644 --- a/otouto/plugins/tagesschau_eil.lua +++ b/otouto/plugins/tagesschau_eil.lua @@ -64,7 +64,7 @@ function tagesschau_eil:action(msg, config) local output = tagesschau_eil:deabonnieren(id) utilities.send_reply(msg, output, true) elseif input:match('(sync)$') then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/plugins/twitter_send.lua b/otouto/plugins/twitter_send.lua index 6ceb3f1..325d35e 100644 --- a/otouto/plugins/twitter_send.lua +++ b/otouto/plugins/twitter_send.lua @@ -248,7 +248,7 @@ end function twitter_send:action(msg, config, matches) if matches[1] == "twwhitelist add" then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return else @@ -265,7 +265,7 @@ function twitter_send:action(msg, config, matches) end if matches[1] == "twwhitelist del" then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return else @@ -288,7 +288,7 @@ function twitter_send:action(msg, config, matches) -- Thanks to the great doc at https://github.com/ignacio/LuaOAuth#a-more-involved-example if not oauth_token and not oauth_token_secret then if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return else @@ -312,7 +312,7 @@ function twitter_send:action(msg, config, matches) if matches[1] == 'auth' and matches[2] then if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end @@ -327,7 +327,7 @@ function twitter_send:action(msg, config, matches) if matches[1] == 'unauth' then if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then - if msg.from.id ~= config.admin then + if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end diff --git a/otouto/utilities.lua b/otouto/utilities.lua index a46b418..2bc3b88 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -342,38 +342,21 @@ function utilities.input_from_msg(msg) return utilities.input(msg.text) or (msg.reply_to_message and #msg.reply_to_message.text > 0 and msg.reply_to_message.text) or false end --- Calculates the length of the given string as UTF-8 characters -function utilities.utf8_len(s) - local chars = 0 - for i = 1, string.len(s) do - local b = string.byte(s, i) - if b < 128 or b >= 192 then - chars = chars + 1 - end - end - return chars -end - -- Trims whitespace from a string. function utilities.trim(str) local s = str:gsub('^%s*(.-)%s*$', '%1') return s end --- Returns true if the string is empty +-- Returns true if the string is blank/empty function string:isempty() - return self == nil or self == '' -end - --- Returns true if the string is blank -function string:isblank() self = self:trim() - return self:isempty() + return self == nil or self == '' end function get_name(msg) local name = msg.from.first_name - if name == nil then + if not name then name = msg.from.id end return name @@ -391,10 +374,6 @@ function convert_timestamp(timestamp, date_format) return os.date(date_format, timestamp) end -function string.starts(String, Start) - return Start == string.sub(String,1,string.len(Start)) -end - -- Saves file to $HOME/tmp/. If file_name isn't provided, -- will get the text after the last "/" for filename -- and content-type for extension @@ -497,19 +476,6 @@ function utilities.build_name(first, last) end end -function utilities:resolve_username(input) - input = input:gsub('^@', '') - for _, user in pairs(self.database.users) do - if user.username and user.username:lower() == input:lower() then - local t = {} - for key, val in pairs(user) do - t[key] = val - end - return t - end - end -end - function utilities:handle_exception(err, message, log_chat) local output = string.format( '[%s]\n%s: %s\n%s\n', @@ -527,19 +493,12 @@ function utilities:handle_exception(err, message, log_chat) end --- MOVED TO DOWNLOAD_TO_FILE -function utilities.download_file(url, filename) - return download_to_file(url, filename) -end - function utilities.md_escape(text) return text:gsub('_', '\\_') :gsub('%[', '\\['):gsub('%]', '\\]') :gsub('%*', '\\*'):gsub('`', '\\`') end -utilities.markdown_escape = utilities.md_escape - function utilities.html_escape(text) return text:gsub('&', '&'):gsub('<', '<'):gsub('>', '>') end @@ -565,13 +524,6 @@ function utilities.triggers(username, cmd_pat, trigger_table) return self end -function utilities.with_http_timeout(timeout, fun) - local original = http.TIMEOUT - http.TIMEOUT = timeout - fun() - http.TIMEOUT = original -end - function utilities.enrich_user(user) user.id_str = tostring(user.id) user.name = utilities.build_name(user.first_name, user.last_name) @@ -594,11 +546,11 @@ function utilities.enrich_message(msg) if msg.forward_from then msg.forward_from = utilities.enrich_user(msg.forward_from) end - if msg.new_chat_participant then - msg.new_chat_participant = utilities.enrich_user(msg.new_chat_participant) + if msg.new_chat_member then + msg.new_chat_member = utilities.enrich_user(msg.new_chat_member) end - if msg.left_chat_participant then - msg.left_chat_participant = utilities.enrich_user(msg.left_chat_participant) + if msg.left_chat_member then + msg.left_chat_member = utilities.enrich_user(msg.left_chat_member) end return msg end @@ -632,29 +584,6 @@ function scandir(directory) return t end --- Returns at table of lua files inside plugins -function plugins_names() - local files = {} - for k, v in pairs(scandir("otouto/plugins")) do - -- Ends with .lua - if (v:match(".lua$")) then - files[#files+1] = v - end - end - return files -end - --- Function name explains what it does. -function file_exists(name) - local f = io.open(name,"r") - if f ~= nil then - io.close(f) - return true - else - return false - end -end - -- Returns a table with matches or nil function match_pattern(pattern, text) if text then @@ -793,17 +722,6 @@ function get_redis_hash(msg, var) end end --- remove whitespace -function all_trim(s) - return s:match( "^%s*(.-)%s*$" ) -end - -function tablelength(T) - local count = 0 - for _ in pairs(T) do count = count + 1 end - return count -end - function round(num, idp) if idp and idp>0 then local mult = 10^idp @@ -823,6 +741,9 @@ function comma_value(amount) return formatted end +function string.starts(String,Start) + return string.sub(String,1,string.len(Start))==Start +end function string.ends(str, fin) return fin=='' or string.sub(str,-string.len(fin)) == fin @@ -1034,19 +955,6 @@ function makeHumanTime(totalseconds) end end -function is_blacklisted(msg) - _blacklist = redis:smembers("telegram:img_blacklist") - local var = false - for v,word in pairs(_blacklist) do - if string.find(string.lower(msg), string.lower(word)) then - print("Wort steht auf der Blacklist!") - var = true - break - end - end - return var -end - function unescape(str) str = string.gsub( str, '<', '<' ) str = string.gsub( str, '>', '>' ) @@ -1065,16 +973,6 @@ function unescape(str) return str end -function url_encode(str) - if (str) then - str = string.gsub (str, "\n", "\r\n") - str = string.gsub (str, "([^%w %-%_%.%~])", - function (c) return string.format ("%%%02X", string.byte(c)) end) - str = string.gsub (str, " ", "+") - end - return str -end - function table.contains(table, element) for _, value in pairs(table) do if value == element then @@ -1103,4 +1001,4 @@ function utilities.fix_utf8(str) end -return utilities +return utilities \ No newline at end of file