From 34a06290568402ee9d805cf5ec0363d3afe941f5 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Tue, 16 Aug 2016 17:27:51 +0200 Subject: [PATCH] =?UTF-8?q?-=20/kick,=20/ban,=20/whitelist=20und=20/block?= =?UTF-8?q?=20funktionieren=20jetzt=20auch=20von=20Service-Nachrichten=20a?= =?UTF-8?q?us=20-=20Geblockte=20User=20konnten=20trotzdem=20Kommandos=20au?= =?UTF-8?q?sf=C3=BChren.=20Dies=20wurde=20gefixt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/bot.lua | 1 + otouto/plugins/banhammer.lua | 47 ++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/otouto/bot.lua b/otouto/bot.lua index 89d7879..f97cd3a 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -233,6 +233,7 @@ function pre_process_msg(self, msg, config) if plugin.pre_process and msg then -- print('Preprocess '..plugin.name) -- remove comment to restore old behaviour new_msg = plugin:pre_process(msg, self, config) + if not new_msg then return end end end return new_msg diff --git a/otouto/plugins/banhammer.lua b/otouto/plugins/banhammer.lua index d93abe6..59423eb 100644 --- a/otouto/plugins/banhammer.lua +++ b/otouto/plugins/banhammer.lua @@ -174,8 +174,7 @@ end function banhammer:action(msg, config, matches) if not is_sudo(msg, config) then - utilities.send_reply(self, msg, config.errors.sudo) - return + return -- Silent ignore end if matches[1] == 'leave' then @@ -194,7 +193,13 @@ function banhammer:action(msg, config, matches) if not msg.reply_to_message then return end - user_id = msg.reply_to_message.from.id + if msg.reply_to_message.new_chat_member then + user_id = msg.reply_to_message.new_chat_member.id + elseif msg.reply_to_message.left_chat_member then + user_id = msg.reply_to_message.left_chat_member.id + else + user_id = msg.reply_to_message.from.id + end end if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then @@ -221,7 +226,11 @@ function banhammer:action(msg, config, matches) if not msg.reply_to_message then return end - user_id = msg.reply_to_message.from.id + if msg.reply_to_message.new_chat_member then + user_id = msg.reply_to_message.new_chat_member.id + else + user_id = msg.reply_to_message.from.id + end end banhammer:kick_user(user_id, msg.chat.id, self, true) return @@ -250,7 +259,11 @@ function banhammer:action(msg, config, matches) if not msg.reply_to_message then return end - local user_id = msg.reply_to_message.from.id + if msg.reply_to_message.new_chat_member then + user_id = msg.reply_to_message.new_chat_member.id + else + user_id = msg.reply_to_message.from.id + end local hash = 'whitelist:user#id'..user_id redis:set(hash, true) utilities.send_reply(self, msg, 'User '..user_id..' whitelisted') @@ -261,7 +274,13 @@ function banhammer:action(msg, config, matches) if not msg.reply_to_message then return end - local user_id = msg.reply_to_message.from.id + if msg.reply_to_message.new_chat_member then + user_id = msg.reply_to_message.new_chat_member.id + elseif msg.reply_to_message.left_chat_member then + user_id = msg.reply_to_message.left_chat_member.id + else + user_id = msg.reply_to_message.from.id + end local hash = 'whitelist:user#id'..user_id redis:del(hash) utilities.send_reply(self, msg, 'User '..user_id..' von der Whitelist entfernt!') @@ -327,7 +346,13 @@ function banhammer:action(msg, config, matches) if not msg.reply_to_message then return end - local user_id = msg.reply_to_message.from.id + if msg.reply_to_message.new_chat_member then + user_id = msg.reply_to_message.new_chat_member.id + elseif msg.reply_to_message.left_chat_member then + user_id = msg.reply_to_message.left_chat_member.id + else + user_id = msg.reply_to_message.from.id + end local hash = 'blocked:'..user_id redis:set(hash, true) utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot nun nicht mehr nutzen.') @@ -338,7 +363,13 @@ function banhammer:action(msg, config, matches) if not msg.reply_to_message then return end - local user_id = msg.reply_to_message.from.id + if msg.reply_to_message.new_chat_member then + user_id = msg.reply_to_message.new_chat_member.id + elseif msg.reply_to_message.left_chat_member then + user_id = msg.reply_to_message.left_chat_member.id + else + user_id = msg.reply_to_message.from.id + end local hash = 'blocked:'..user_id redis:del(hash) utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot wieder nutzen.')