Verarbeite Pre-Processoren nicht mehr, wenn Bot in der Gruppe deaktiviert ist oder Plugin im Chat aus ist

This commit is contained in:
Andreas Bielawski 2016-08-28 18:12:18 +02:00
parent b172aa5b16
commit 1f2f793aac
3 changed files with 31 additions and 24 deletions

View File

@ -82,6 +82,14 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
msg.text = string.gsub(msg.text, config.cmd_pat..'([A-Za-z0-9-_-]+)@'..self.info.username, "/%1")
msg.text_lower = msg.text:lower()
end
if is_channel_disabled(msg)then
if not is_sudo(msg, config) or msg.text ~= "/channel enable" then
print('Channel wurde deaktiviert')
return
end
end
msg = pre_process_msg(self, msg, config)
if not msg then return end -- deleted by banning
@ -244,11 +252,13 @@ function pre_process_msg(self, msg, config)
for n=1, #self.plugins do
local plugin = self.plugins[n]
if plugin.pre_process and msg then
if not is_plugin_disabled_on_chat(plugin.name, msg, true) then
-- print('Preprocess '..plugin.name) -- remove comment to restore old behaviour
new_msg = plugin:pre_process(msg, config)
if not new_msg then return end -- Message was deleted
end
end
end
return new_msg
end
@ -297,13 +307,15 @@ function match_plugins(self, msg, config, plugin)
end
end
function is_plugin_disabled_on_chat(plugin_name, msg)
function is_plugin_disabled_on_chat(plugin_name, msg, silent)
local hash = get_redis_hash(msg, 'disabled_plugins')
local disabled = redis:hget(hash, plugin_name)
-- Plugin is disabled
if disabled == 'true' then
if not silent then
print('Plugin '..plugin_name..' ist in diesem Chat deaktiviert')
end
return true
else
return false

View File

@ -11,18 +11,6 @@ function channels:init(config)
]]..config.cmd_pat..[[channel* _<enable>_/_<disable>_: Aktiviert/deaktiviert den Bot im Chat]]
end
-- Checks if bot was disabled on specific chat
function channels:is_channel_disabled(msg)
local hash = 'chat:'..msg.chat.id..':disabled'
local disabled = redis:get(hash)
if not disabled or disabled == "false" then
return false
end
return disabled
end
function channels:enable_channel(msg)
local hash = 'chat:'..msg.chat.id..':disabled'
local disabled = redis:get(hash)
@ -55,11 +43,6 @@ function channels:pre_process(msg, config)
end
end
if channels:is_channel_disabled(msg) then
print('Channel wurde deaktiviert')
return
end
return msg
end

View File

@ -1085,4 +1085,16 @@ function table.contains(table, element)
return false
end
-- Checks if bot was disabled on specific chat
function is_channel_disabled(msg)
local hash = 'chat:'..msg.chat.id..':disabled'
local disabled = redis:get(hash)
if not disabled or disabled == "false" then
return false
end
return disabled
end
return utilities