2015-04-12 23:08:42 +02:00
|
|
|
-- Checks if bot was disabled on specific chat
|
|
|
|
local function is_channel_disabled( receiver )
|
|
|
|
if not _config.disabled_channels then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if _config.disabled_channels[receiver] == nil then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
return _config.disabled_channels[receiver]
|
|
|
|
end
|
|
|
|
|
|
|
|
local function enable_channel(receiver)
|
|
|
|
if not _config.disabled_channels then
|
|
|
|
_config.disabled_channels = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
if _config.disabled_channels[receiver] == nil then
|
2015-04-14 20:21:23 +02:00
|
|
|
return 'Channel ist nicht deaktiviert!'
|
2015-04-12 23:08:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
_config.disabled_channels[receiver] = false
|
|
|
|
|
2015-02-27 14:06:12 +01:00
|
|
|
save_config()
|
2015-04-14 20:21:23 +02:00
|
|
|
return "Channel wieder aktiviert!"
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
|
2015-04-12 23:08:42 +02:00
|
|
|
local function disable_channel( receiver )
|
|
|
|
if not _config.disabled_channels then
|
|
|
|
_config.disabled_channels = {}
|
|
|
|
end
|
|
|
|
|
2015-04-12 23:21:37 +02:00
|
|
|
_config.disabled_channels[receiver] = true
|
2015-04-12 23:08:42 +02:00
|
|
|
|
|
|
|
save_config()
|
2015-04-14 20:21:23 +02:00
|
|
|
return "Channel deaktiviert!"
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
|
2015-04-12 23:08:42 +02:00
|
|
|
local function pre_process(msg)
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
|
2015-05-28 16:47:30 +02:00
|
|
|
-- If sender is sudo then re-enable the channel
|
2015-04-12 23:08:42 +02:00
|
|
|
if is_sudo(msg) then
|
2015-04-14 20:21:23 +02:00
|
|
|
if msg.text == "/channel enable" then
|
2015-04-12 23:08:42 +02:00
|
|
|
enable_channel(receiver)
|
|
|
|
end
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
2015-04-12 23:08:42 +02:00
|
|
|
|
|
|
|
if is_channel_disabled(receiver) then
|
|
|
|
msg.text = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
return msg
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
|
2015-04-12 23:08:42 +02:00
|
|
|
local function run(msg, matches)
|
|
|
|
local receiver = get_receiver(msg)
|
2015-02-27 14:06:12 +01:00
|
|
|
-- Enable a channel
|
|
|
|
if matches[1] == 'enable' then
|
2015-04-12 23:08:42 +02:00
|
|
|
return enable_channel(receiver)
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
-- Disable a channel
|
|
|
|
if matches[1] == 'disable' then
|
2015-04-12 23:08:42 +02:00
|
|
|
return disable_channel(receiver)
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-04-14 20:21:23 +02:00
|
|
|
description = "",
|
2015-05-12 20:15:15 +02:00
|
|
|
usage = {"/channel kann nur Akamaru"},
|
2015-04-28 17:49:11 +02:00
|
|
|
patterns = {"^/channel? (enable)","^/channel? (disable)" },
|
2015-02-27 14:06:12 +01:00
|
|
|
run = run,
|
2015-04-12 23:08:42 +02:00
|
|
|
privileged = true,
|
|
|
|
pre_process = pre_process
|
2015-02-27 14:06:12 +01:00
|
|
|
}
|