Merge branch 'soend-master'

This commit is contained in:
yago 2015-04-12 23:22:51 +02:00
commit 4e4dc7ed11
3 changed files with 88 additions and 2 deletions

View File

@ -34,14 +34,18 @@ function msg_valid(msg)
print("Not valid, msg from us") print("Not valid, msg from us")
return false return false
end end
-- Before bot was started
if msg.date < now then if msg.date < now then
print("Not valid, old msg") print("Not valid, old msg")
return false return false
end end
if msg.unread == 0 then if msg.unread == 0 then
print("Not valid, readed") print("Not valid, readed")
return false return false
end end
return true return true
end end
@ -158,6 +162,7 @@ function create_config( )
"location", "location",
"media", "media",
"plugins", "plugins",
"channels",
"set", "set",
"stats", "stats",
"time", "time",
@ -165,7 +170,8 @@ function create_config( )
"weather", "weather",
"xkcd", "xkcd",
"youtube" }, "youtube" },
sudo_users = {our_id} sudo_users = {our_id},
disabled_channels = {}
} }
serialize_to_file(config, './data/config.lua') serialize_to_file(config, './data/config.lua')
print ('saved config into ./data/config.lua') print ('saved config into ./data/config.lua')

View File

@ -446,4 +446,4 @@ function match_pattern(pattern, text)
return matches return matches
end end
-- nil -- nil
end end

80
plugins/channels.lua Normal file
View File

@ -0,0 +1,80 @@
-- 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()
return "Channel reenabled"
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 disabled"
end
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
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 = "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,
privileged = true,
pre_process = pre_process
}