From 2e2b8e4f9f8b59bf3bdbf55d8d3666599260c6e4 Mon Sep 17 00:00:00 2001 From: Prince Mandor Date: Thu, 4 Jun 2015 13:56:36 +0300 Subject: [PATCH 1/3] added 'all' functionality to !plugins enable/disable chat command --- plugins/plugins.lua | 63 +++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/plugins/plugins.lua b/plugins/plugins.lua index 2612de71..c657bf3b 100644 --- a/plugins/plugins.lua +++ b/plugins/plugins.lua @@ -21,21 +21,27 @@ local function plugin_exists( name ) return false end +local chars = { + enabled = ' ✔', + disabled = ' ❌', + privileged = ' 🎓', + system = ' 💻', +}; + local function list_plugins(only_enabled) local text = '' for k, v in pairs( plugins_names( )) do - -- ✔ enabled, ❌ disabled - local status = '❌' + local status = chars.disabled; -- Check if is enabled for k2, v2 in pairs(_config.enabled_plugins) do if v == v2..'.lua' then - status = '✔' + status = chars.enabled; end end - if not only_enabled or status == '✔' then + if not only_enabled or status == chars.enabled then -- get the name v = string.match (v, "(.*)%.lua") - text = text..v..' '..status..'\n' + text = text..v..' '..status..(plugins[v] and plugins[v].privileged and chars.privileged or '')..(plugins[v] and plugins[v].system and chars.system or '')..'\n' end end return text @@ -47,7 +53,6 @@ local function reload_plugins( ) return list_plugins(true) end - local function enable_plugin( plugin_name ) print('checking if '..plugin_name..' exists') -- Check if plugin is enabled @@ -84,20 +89,29 @@ local function disable_plugin( name, chat ) end local function disable_plugin_on_chat(receiver, plugin) - if not plugin_exists(plugin) then - return "Plugin doesn't exists" - end - + if not _config.disabled_plugin_on_chat then _config.disabled_plugin_on_chat = {} end - + if not _config.disabled_plugin_on_chat[receiver] then _config.disabled_plugin_on_chat[receiver] = {} end - + + if plugin == 'all' then + for _, plugin_name in pairs(_config.enabled_plugins) do + if (not (plugins[plugin_name] and plugins[plugin_name].system)) then + _config.disabled_plugin_on_chat[receiver][plugin_name] = true + end + end + save_config() + return 'All non-system plugins was disabled on this chat' + end + if not plugin_exists(plugin) then + return "Plugin doesn't exists" + end _config.disabled_plugin_on_chat[receiver][plugin] = true - + save_config() return 'Plugin '..plugin..' disabled on this chat' end @@ -106,20 +120,25 @@ local function reenable_plugin_on_chat(receiver, plugin) if not _config.disabled_plugin_on_chat then return 'There aren\'t any disabled plugins' end - + if not _config.disabled_plugin_on_chat[receiver] then return 'There aren\'t any disabled plugins for this chat' end - + + if plugin == 'all' then + _config.disabled_plugin_on_chat[receiver] = {} + save_config() + return 'All plugins reenabled on this chat' + end if not _config.disabled_plugin_on_chat[receiver][plugin] then return 'This plugin is not disabled' end - + _config.disabled_plugin_on_chat[receiver][plugin] = false save_config() return 'Plugin '..plugin..' is enabled again' end - + local function run(msg, matches) -- Show the available plugins if matches[1] == '!plugins' then @@ -165,9 +184,12 @@ return { description = "Plugin to manage other plugins. Enable, disable or reload.", usage = { "!plugins: list all plugins.", - "!plugins enable [plugin]: enable plugin.", "!plugins disable [plugin]: disable plugin.", - "!plugins disable [plugin] chat: disable plugin only this chat.", + "!plugins enable [plugin]: enable plugin.", + "!plugins disable [plugin] chat: disable plugin on this chat only.", + "!plugins enable [plugin] chat: reenable disabled on this chat plugin.", + "!plugins disable all chat: disable all non-system plugins on this chat only.", + "!plugins enable all chat: reenable all disabled plugins on this chat.", "!plugins reload: reloads all plugins." }, patterns = { "^!plugins$", @@ -177,7 +199,8 @@ return { "^!plugins? (disable) ([%w_%.%-]+) (chat)", "^!plugins? (reload)$" }, run = run, - privileged = true + privileged = true, + system = true, } end \ No newline at end of file From e304cd4aa3fb9afc28cd1b8aa893ff9daf6b2be9 Mon Sep 17 00:00:00 2001 From: Prince Mandor Date: Fri, 5 Jun 2015 01:25:39 +0300 Subject: [PATCH 2/3] refactored LUA way --- libs/mimetype.lua | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libs/mimetype.lua b/libs/mimetype.lua index 4ff6c293..f3d67666 100644 --- a/libs/mimetype.lua +++ b/libs/mimetype.lua @@ -70,9 +70,14 @@ local types = { ["video/x-mng"] = "mng", ["video/x-ms-asf"] = "asf", ["video/x-ms-wmv"] = "wmv", - ["video/x-msvideo"] = "avi" + ["video/x-msvideo"] = "avi", } +local reverse_types = {} +for k, v in pairs(types) do + reverse_types[v] = k +end + -- Returns the common file extension from a content-type function mimetype.get_mime_extension(content_type) return types[content_type] @@ -80,21 +85,13 @@ end -- Returns the mimetype and subtype function mimetype.get_content_type(extension) - for k,v in pairs(types) do - if v == extension then - return k - end - end + return reverse_types[extension] end -- Returns the mimetype without the subtype function mimetype.get_content_type_no_sub(extension) - for k,v in pairs(types) do - if v == extension then - -- Before / - return k:match('([%w-]+)/') - end - end + -- Before / + return reverse_types[extension]:match('([%w-]+)/') end return mimetype From 8e1cfb69cb0acdae9e62d63b38f90ccaa519935f Mon Sep 17 00:00:00 2001 From: Prince Mandor Date: Fri, 5 Jun 2015 03:13:05 +0300 Subject: [PATCH 3/3] Localization -- just begining --- bot/bot.lua | 1 + bot/l10n.lua | 11 +++++++++++ plugins/plugins.lua | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 bot/l10n.lua diff --git a/bot/bot.lua b/bot/bot.lua index 96d3a2cc..09736eac 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -3,6 +3,7 @@ package.path = package.path .. ';.luarocks/share/lua/5.2/?.lua' package.cpath = package.cpath .. ';.luarocks/lib/lua/5.2/?.so' require("./bot/utils") +require("./bot/l10n") VERSION = '0.13.0' diff --git a/bot/l10n.lua b/bot/l10n.lua new file mode 100644 index 00000000..ec4ff219 --- /dev/null +++ b/bot/l10n.lua @@ -0,0 +1,11 @@ +do + l10n = setmetatable({ + curLocalization={}, + setLocale = function() end, + }, + {__call = function (tbl, src) + if type(src) == 'string' then + return (tbl.curLocalization[src] or src); + end; + end}); +end \ No newline at end of file diff --git a/plugins/plugins.lua b/plugins/plugins.lua index c657bf3b..84947d31 100644 --- a/plugins/plugins.lua +++ b/plugins/plugins.lua @@ -181,9 +181,9 @@ local function run(msg, matches) end return { - description = "Plugin to manage other plugins. Enable, disable or reload.", + description = l10n("Plugin to manage other plugins. Enable, disable or reload."), usage = { - "!plugins: list all plugins.", + l10n("!plugins: list all plugins."), "!plugins disable [plugin]: disable plugin.", "!plugins enable [plugin]: enable plugin.", "!plugins disable [plugin] chat: disable plugin on this chat only.",