Skip to content
This repository has been archived by the owner on Oct 14, 2018. It is now read-only.

added 'all' functionality to '!plugins enable/disable chat' command #226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bot/bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
11 changes: 11 additions & 0 deletions bot/l10n.lua
Original file line number Diff line number Diff line change
@@ -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
21 changes: 9 additions & 12 deletions libs/mimetype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,28 @@ 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]
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
Expand Down
67 changes: 45 additions & 22 deletions plugins/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -162,12 +181,15 @@ 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.",
"!plugins enable [plugin]: enable plugin.",
l10n("!plugins: list all plugins."),
"!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$",
Expand All @@ -177,7 +199,8 @@ return {
"^!plugins? (disable) ([%w_%.%-]+) (chat)",
"^!plugins? (reload)$" },
run = run,
privileged = true
privileged = true,
system = true,
}

end