From 96c0328423d0785c93afa52f7780543e80face19 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sat, 25 Jun 2016 17:25:50 +0200 Subject: [PATCH] =?UTF-8?q?-=20NEU:=20leave=5Fgroup-Plugin=20-=20Bot=20ver?= =?UTF-8?q?l=C3=A4sst=20Gruppe,=20wenn=20der=20Administrator=20des=20Bots?= =?UTF-8?q?=20nicht=20Mitglied=20ist=20und=20meldet=20dies=20auch=20an=20d?= =?UTF-8?q?en=20Administrator=20-=20Facebook:=20Fotos=20wurden=20nicht=20g?= =?UTF-8?q?esendet,=20wenn=20Parameter=20angeh=C3=A4ngt=20wurde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/facebook.lua | 2 +- otouto/plugins/leave_group.lua | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 otouto/plugins/leave_group.lua diff --git a/otouto/plugins/facebook.lua b/otouto/plugins/facebook.lua index cadd012..61a098d 100644 --- a/otouto/plugins/facebook.lua +++ b/otouto/plugins/facebook.lua @@ -159,7 +159,7 @@ function facebook:action(msg, config, matches) local text, image_url = facebook:send_facebook_photo(photo_id, receiver) if not image_url then return end utilities.send_typing(self, msg.chat.id, 'upload_photo') - local file = download_to_file(image_url) + local file = download_to_file(image_url, 'photo.jpg') utilities.send_reply(self, msg, text, true) utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) return diff --git a/otouto/plugins/leave_group.lua b/otouto/plugins/leave_group.lua new file mode 100644 index 0000000..657b636 --- /dev/null +++ b/otouto/plugins/leave_group.lua @@ -0,0 +1,52 @@ +local leave_group = {} + +local utilities = require('otouto.utilities') +local bindings = require('otouto.bindings') + +leave_group.triggers = { + '/nil' +} + +local report_to_admin = true -- set to false to not be notified, when Bot leaves groups without you + +function leave_group:check_for_admin(msg, self, config) + local result = bindings.request(self, 'getChatMember', { + chat_id = msg.chat.id, + user_id = config.admin + } ) + if not result.ok then + print('Konnte nicht prüfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber...') + return false + end + if result.result.status ~= "member" then + return false + else + return true + end +end + +function leave_group:pre_process(msg, self, config) + if msg.group_chat_created or msg.new_chat_member then + local admin_in_group = leave_group:check_for_admin(msg, self, config) + if not admin_in_group then + print('Admin ist nicht in der Gruppe, verlasse sie deshalb...') + utilities.send_reply(self, msg, 'Dieser Bot wurde in eine fremde Gruppe hinzugefügt. Dies wird gemeldet!\nThis bot was added to foreign group. This incident will be reported!') + local result = bindings.request(self, 'leaveChat', { + chat_id = msg.chat.id + } ) + local chat_name = msg.chat.title + local chat_id = msg.chat.id + local from = msg.from.name + local from_id = msg.from.id + if report_to_admin then + utilities.send_message(self, config.admin, '#WARNUNG: Bot wurde in fremde Gruppe hinzugefügt:\nGruppenname: '..chat_name..' ('..chat_id..')\nHinzugefügt von: '..from..' ('..from_id..')') + end + end + end + return msg +end + +function leave_group:action(msg) +end + +return leave_group