81 lines
1.9 KiB
Lua
81 lines
1.9 KiB
Lua
do
|
|
|
|
-- Checks if bot was disabled on specific chat
|
|
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
|
|
return false
|
|
end
|
|
|
|
return disabled
|
|
end
|
|
|
|
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)
|
|
return 'Channel aktiviert!'
|
|
else
|
|
return 'Channel ist nicht deaktiviert!'
|
|
end
|
|
end
|
|
|
|
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)
|
|
return 'Channel deaktiviert!'
|
|
else
|
|
return 'Channel ist bereits deaktiviert!'
|
|
end
|
|
end
|
|
|
|
local function pre_process(msg)
|
|
|
|
-- If is sudo can reeanble the channel
|
|
if is_sudo(msg) then
|
|
if msg.text == "#[Cc][Hh][Aa][Nn][Nn][Ee][Ll] [Ee][Nn][Aa][Bb][Ll][Ee]" then
|
|
enable_channel(msg)
|
|
end
|
|
end
|
|
|
|
if is_channel_disabled(msg) then
|
|
print('Channel wurde deaktiviert')
|
|
msg.text = ""
|
|
end
|
|
|
|
return msg
|
|
end
|
|
|
|
local function run(msg, matches)
|
|
-- Enable a channel
|
|
if matches[1] == '[Ee][Nn][Aa][Bb][Ll][Ee]' then
|
|
return enable_channel(msg)
|
|
end
|
|
-- Disable a channel
|
|
if matches[1] == '[Dd][Ii][Ss][Aa][Bb][Ll][Ee]' then
|
|
return disable_channel(msg)
|
|
end
|
|
end
|
|
|
|
return {
|
|
description = "(De)aktiviert den Bot im Chat (nur Superuser).",
|
|
usage = {
|
|
"#channel enable: Aktiviert den Bot im Chat",
|
|
"#channel disable: Deaktiviert den Bot im Chat"
|
|
},
|
|
patterns = {
|
|
"^#[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])"
|
|
},
|
|
run = run,
|
|
privileged = true,
|
|
pre_process = pre_process,
|
|
notyping = true
|
|
} |