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

80 lines
1.6 KiB
Lua
Raw Normal View History

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
return 'Channel isn\'t disabled'
end
_config.disabled_channels[receiver] = false
save_config()
2015-04-12 23:08:42 +02:00
return "Channel reenabled"
end
2015-04-12 23:08:42 +02:00
local function disable_channel( receiver )
if not _config.disabled_channels then
_config.disabled_channels = {}
end
_config.disabled_channels[receiver] = false
save_config()
return "Channel disabled"
end
2015-04-12 23:08:42 +02:00
local function pre_process(msg)
local receiver = get_receiver(msg)
-- If is sudo can reeanble the channel
if is_sudo(msg) then
if msg.text == "!channel enable" then
enable_channel(receiver)
end
end
2015-04-12 23:08:42 +02:00
if is_channel_disabled(receiver) then
msg.text = ""
end
return msg
end
2015-04-12 23:08:42 +02:00
local function run(msg, matches)
local receiver = get_receiver(msg)
-- Enable a channel
if matches[1] == 'enable' then
2015-04-12 23:08:42 +02:00
return enable_channel(receiver)
end
-- Disable a channel
if matches[1] == 'disable' then
2015-04-12 23:08:42 +02:00
return disable_channel(receiver)
end
end
return {
description = "Plugin to manage channels. Enable or disable channel.",
usage = {
"!channel enable: enable current channel",
"!channel disable: disable current channel" },
patterns = {
"^!channel? (enable)",
"^!channel? (disable)" },
run = run,
2015-04-12 23:08:42 +02:00
privileged = true,
pre_process = pre_process
}