This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/channels.lua
Akamaru bd5ae0d642 big update
too much changed ._.
2015-05-28 16:47:30 +02:00

76 lines
1.5 KiB
Lua

-- 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
return 'Channel ist nicht deaktiviert!'
end
_config.disabled_channels[receiver] = false
save_config()
return "Channel wieder aktiviert!"
end
local function disable_channel( receiver )
if not _config.disabled_channels then
_config.disabled_channels = {}
end
_config.disabled_channels[receiver] = true
save_config()
return "Channel deaktiviert!"
end
local function pre_process(msg)
local receiver = get_receiver(msg)
-- If sender is sudo then re-enable the channel
if is_sudo(msg) then
if msg.text == "/channel enable" then
enable_channel(receiver)
end
end
if is_channel_disabled(receiver) then
msg.text = ""
end
return msg
end
local function run(msg, matches)
local receiver = get_receiver(msg)
-- Enable a channel
if matches[1] == 'enable' then
return enable_channel(receiver)
end
-- Disable a channel
if matches[1] == 'disable' then
return disable_channel(receiver)
end
end
return {
description = "",
usage = {"/channel kann nur Akamaru"},
patterns = {"^/channel? (enable)","^/channel? (disable)" },
run = run,
privileged = true,
pre_process = pre_process
}