2016-07-07 21:34:32 +02:00
|
|
|
do
|
|
|
|
|
2015-04-12 23:08:42 +02:00
|
|
|
-- Checks if bot was disabled on specific chat
|
2015-11-12 17:42:03 +01:00
|
|
|
local function is_channel_disabled(msg)
|
|
|
|
local hash = 'chat:'..msg.to.id..':disabled'
|
|
|
|
local disabled = redis:get(hash)
|
|
|
|
|
|
|
|
if not disabled or disabled == "false" then
|
2015-04-12 23:08:42 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
return disabled
|
2015-04-12 23:08:42 +02:00
|
|
|
end
|
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
local function enable_channel(msg)
|
|
|
|
local hash = 'chat:'..msg.to.id..':disabled'
|
|
|
|
local disabled = redis:get(hash)
|
|
|
|
if disabled then
|
|
|
|
print('Setze Redis Variable "'..hash..'" auf false')
|
|
|
|
redis:set(hash, false)
|
2016-07-07 21:34:32 +02:00
|
|
|
return 'Channel aktiviert!'
|
2015-11-12 17:42:03 +01:00
|
|
|
else
|
|
|
|
return 'Channel ist nicht deaktiviert!'
|
|
|
|
end
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
local function disable_channel(msg)
|
|
|
|
local hash = 'chat:'..msg.to.id..':disabled'
|
|
|
|
local disabled = redis:get(hash)
|
|
|
|
if disabled ~= "true" then
|
|
|
|
print('Setze Redis Variable "'..hash..'" auf true')
|
|
|
|
redis:set(hash, true)
|
2016-07-07 21:34:32 +02:00
|
|
|
return 'Channel deaktiviert!'
|
2015-11-12 17:42:03 +01:00
|
|
|
else
|
|
|
|
return 'Channel ist bereits deaktiviert!'
|
|
|
|
end
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
|
2015-04-12 23:08:42 +02:00
|
|
|
local function pre_process(msg)
|
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
-- If is sudo can reeanble the channel
|
2015-04-12 23:08:42 +02:00
|
|
|
if is_sudo(msg) then
|
2016-07-07 21:34:32 +02:00
|
|
|
if msg.text == "#[Cc][Hh][Aa][Nn][Nn][Ee][Ll] [Ee][Nn][Aa][Bb][Ll][Ee]" then
|
2015-11-12 17:42:03 +01:00
|
|
|
enable_channel(msg)
|
2015-04-12 23:08:42 +02:00
|
|
|
end
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
2015-04-12 23:08:42 +02:00
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
if is_channel_disabled(msg) then
|
|
|
|
print('Channel wurde deaktiviert')
|
2015-04-12 23:08:42 +02:00
|
|
|
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)
|
2015-02-27 14:06:12 +01:00
|
|
|
-- Enable a channel
|
2016-07-07 21:34:32 +02:00
|
|
|
if matches[1] == '[Ee][Nn][Aa][Bb][Ll][Ee]' then
|
2015-11-12 17:42:03 +01:00
|
|
|
return enable_channel(msg)
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
-- Disable a channel
|
2016-07-07 21:34:32 +02:00
|
|
|
if matches[1] == '[Dd][Ii][Ss][Aa][Bb][Ll][Ee]' then
|
2015-11-12 17:42:03 +01:00
|
|
|
return disable_channel(msg)
|
2015-02-27 14:06:12 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-11-12 17:42:03 +01:00
|
|
|
description = "(De)aktiviert den Bot im Chat (nur Superuser).",
|
|
|
|
usage = {
|
2016-06-22 13:59:06 +02:00
|
|
|
"#channel enable: Aktiviert den Bot im Chat",
|
|
|
|
"#channel disable: Deaktiviert den Bot im Chat"
|
2015-11-12 17:42:03 +01:00
|
|
|
},
|
|
|
|
patterns = {
|
2016-07-07 21:34:32 +02:00
|
|
|
"^#[Cc][Hh][Aa][Nn][Nn][Ee][Ll] ([Ee][Nn][Aa][Bb][Ll][Ee])",
|
|
|
|
"^#[Cc][Hh][Aa][Nn][Nn][Ee][Ll] ([Dd][Ii][Ss][Aa][Bb][Ll][Ee])"
|
2015-11-12 17:42:03 +01:00
|
|
|
},
|
|
|
|
run = run,
|
|
|
|
privileged = true,
|
|
|
|
pre_process = pre_process,
|
|
|
|
notyping = true
|
2015-02-27 14:06:12 +01:00
|
|
|
}
|