From edd8a506290e9abe713650a298b9fe51c4397427 Mon Sep 17 00:00:00 2001 From: Priit Heinsaar Date: Fri, 27 Feb 2015 15:06:12 +0200 Subject: [PATCH 1/3] Added functionality to disable bot responding in disable channels --- bot/bot.lua | 4 ++++ bot/utils.lua | 14 +++++++++++++ plugins/channels.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 plugins/channels.lua diff --git a/bot/bot.lua b/bot/bot.lua index cd69354..dafac13 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -47,6 +47,10 @@ function msg_valid(msg) print("Not valid, readed") return false end + if is_disabled(msg) then + print("Disabled channel") + return false + end end function do_lex(msg, text) diff --git a/bot/utils.lua b/bot/utils.lua index f5ef26c..74d2da4 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -146,6 +146,20 @@ function is_sudo(msg) return var end +function is_disabled(msg) + local var = false + if msg.text == "!channel enable" then + return var + end + -- Check users id in config + for v,channel in pairs(_config.disabled_channels) do + if channel == msg.to.id then + var = true + end + end + return var +end + -- Returns the name of the sender function get_name(msg) local name = msg.from.first_name diff --git a/plugins/channels.lua b/plugins/channels.lua new file mode 100644 index 0000000..eb622ef --- /dev/null +++ b/plugins/channels.lua @@ -0,0 +1,48 @@ +function enable_channel( channel_id, channel_name ) + -- Add to the config table + table.remove(_config.disabled_channels, get_index(channel_id)) + save_config() + return "Channel "..channel_name.." enabled" +end + +function disable_channel( channel_id, channel_name ) + -- Disable + table.insert(_config.disabled_channels, channel_id) + save_config( ) + return "Channel "..channel_name.." disabled" +end + +function get_index( channel_id ) + for k,v in pairs(_config.disabled_channels) do + if channel_id == v then + return k + end + end + -- If not found + return false +end + +function run(msg, matches) + -- Enable a channel + if matches[1] == 'enable' then + print("enable: "..msg.to.id) + return enable_channel(msg.to.id, msg.to.title) + end + -- Disable a channel + if matches[1] == 'disable' then + print("disable: "..msg.to.id) + return disable_channel(msg.to.id, msg.to.title) + 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 +} \ No newline at end of file From 114c47382f38b2f5d214f78078bd726a0f356509 Mon Sep 17 00:00:00 2001 From: Priit Heinsaar Date: Fri, 27 Feb 2015 15:08:05 +0200 Subject: [PATCH 2/3] Added functionality to disable bot responding in disable channels --- bot/bot.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/bot.lua b/bot/bot.lua index dafac13..4c42485 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -177,7 +177,8 @@ function create_config( ) "weather", "xkcd", "youtube" }, - sudo_users = {our_id} + sudo_users = {our_id}, + disabled_channels = {} } serialize_to_file(config, './data/config.lua') print ('saved config into ./data/config.lua') From 8fc40063b610879d43e58369395290987fdc0cb4 Mon Sep 17 00:00:00 2001 From: Priit Heinsaar Date: Fri, 27 Feb 2015 15:40:48 +0200 Subject: [PATCH 3/3] Added functionality to disable bot responding in disable channels --- bot/bot.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/bot.lua b/bot/bot.lua index 4c42485..b162ffa 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -170,6 +170,7 @@ function create_config( ) "location", "media", "plugins", + "channels", "set", "stats", "time",