From 1f2f793aacd28a5ee04e1bdd018ac34c29759ee3 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 28 Aug 2016 18:12:18 +0200 Subject: [PATCH 1/3] Verarbeite Pre-Processoren nicht mehr, wenn Bot in der Gruppe deaktiviert ist oder Plugin im Chat aus ist --- otouto/bot.lua | 24 ++++++++++++++++++------ otouto/plugins/channels.lua | 19 +------------------ otouto/utilities.lua | 12 ++++++++++++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/otouto/bot.lua b/otouto/bot.lua index 1b6c08c..f347b7c 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -82,6 +82,14 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec msg.text = string.gsub(msg.text, config.cmd_pat..'([A-Za-z0-9-_-]+)@'..self.info.username, "/%1") msg.text_lower = msg.text:lower() end + + if is_channel_disabled(msg)then + if not is_sudo(msg, config) or msg.text ~= "/channel enable" then + print('Channel wurde deaktiviert') + return + end + end + msg = pre_process_msg(self, msg, config) if not msg then return end -- deleted by banning @@ -243,10 +251,12 @@ end function pre_process_msg(self, msg, config) for n=1, #self.plugins do local plugin = self.plugins[n] - if plugin.pre_process and msg then - -- print('Preprocess '..plugin.name) -- remove comment to restore old behaviour - new_msg = plugin:pre_process(msg, config) - if not new_msg then return end -- Message was deleted + if plugin.pre_process and msg then + if not is_plugin_disabled_on_chat(plugin.name, msg, true) then + -- print('Preprocess '..plugin.name) -- remove comment to restore old behaviour + new_msg = plugin:pre_process(msg, config) + if not new_msg then return end -- Message was deleted + end end end return new_msg @@ -297,13 +307,15 @@ function match_plugins(self, msg, config, plugin) end end -function is_plugin_disabled_on_chat(plugin_name, msg) +function is_plugin_disabled_on_chat(plugin_name, msg, silent) local hash = get_redis_hash(msg, 'disabled_plugins') local disabled = redis:hget(hash, plugin_name) -- Plugin is disabled if disabled == 'true' then - print('Plugin '..plugin_name..' ist in diesem Chat deaktiviert') + if not silent then + print('Plugin '..plugin_name..' ist in diesem Chat deaktiviert') + end return true else return false diff --git a/otouto/plugins/channels.lua b/otouto/plugins/channels.lua index 568f083..e16e041 100644 --- a/otouto/plugins/channels.lua +++ b/otouto/plugins/channels.lua @@ -11,18 +11,6 @@ function channels:init(config) ]]..config.cmd_pat..[[channel* __/__: Aktiviert/deaktiviert den Bot im Chat]] end --- Checks if bot was disabled on specific chat -function channels:is_channel_disabled(msg) - local hash = 'chat:'..msg.chat.id..':disabled' - local disabled = redis:get(hash) - - if not disabled or disabled == "false" then - return false - end - - return disabled -end - function channels:enable_channel(msg) local hash = 'chat:'..msg.chat.id..':disabled' local disabled = redis:get(hash) @@ -55,12 +43,7 @@ function channels:pre_process(msg, config) end end - if channels:is_channel_disabled(msg) then - print('Channel wurde deaktiviert') - return - end - - return msg + return msg end function channels:action(msg, config, matches) diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 24d4651..a496d62 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -1085,4 +1085,16 @@ function table.contains(table, element) return false end +-- Checks if bot was disabled on specific chat +function is_channel_disabled(msg) + local hash = 'chat:'..msg.chat.id..':disabled' + local disabled = redis:get(hash) + + if not disabled or disabled == "false" then + return false + end + + return disabled +end + return utilities \ No newline at end of file From 3441780708db665e80e55f3356f20c7906f83d83 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 28 Aug 2016 18:16:35 +0200 Subject: [PATCH 2/3] =?UTF-8?q?HTML=20f=C3=BCr=20Reddit=5FPost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/reddit_post.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/otouto/plugins/reddit_post.lua b/otouto/plugins/reddit_post.lua index fdc0ba1..84441dc 100644 --- a/otouto/plugins/reddit_post.lua +++ b/otouto/plugins/reddit_post.lua @@ -15,9 +15,9 @@ function reddit_post:get_reddit_data(subreddit, reddit_code) end function reddit_post:send_reddit_data(data) - local title = utilities.md_escape(data[1].data.children[1].data.title) - local author = utilities.md_escape(data[1].data.children[1].data.author) - local subreddit = utilities.md_escape(data[1].data.children[1].data.subreddit) + local title = data[1].data.children[1].data.title + local author = data[1].data.children[1].data.author + local subreddit = data[1].data.children[1].data.subreddit if string.len(data[1].data.children[1].data.selftext) > 300 then selftext = string.sub(unescape(data[1].data.children[1].data.selftext:gsub("%b<>", "")), 1, 300) .. '...' else @@ -30,7 +30,7 @@ function reddit_post:send_reddit_data(data) end local score = comma_value(data[1].data.children[1].data.score) local comments = comma_value(data[1].data.children[1].data.num_comments) - local text = '*'..author..'* in */r/'..subreddit..'* _('..score..' Upvotes - '..comments..' Kommentare)_:\n'..title..'\n'..selftext..url + local text = ''..author..' in /r/'..subreddit..' ('..score..' Upvotes - '..comments..' Kommentare):\n'..title..'\n'..selftext..url return text end @@ -44,7 +44,7 @@ function reddit_post:action(msg, config, matches) local text = reddit_post:send_reddit_data(data) if not text then utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(msg, text, true) + utilities.send_reply(msg, text, 'HTML') end -return reddit_post +return reddit_post \ No newline at end of file From 0804d44bb84021cf97d3116c9f73bb4cdc6980ac Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 28 Aug 2016 18:18:16 +0200 Subject: [PATCH 3/3] Keine "Channel deaktiviert" Meldung, da sonst zu nervig --- otouto/bot.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/otouto/bot.lua b/otouto/bot.lua index f347b7c..2b16481 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -85,7 +85,6 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec if is_channel_disabled(msg)then if not is_sudo(msg, config) or msg.text ~= "/channel enable" then - print('Channel wurde deaktiviert') return end end