From f89167257247d10b5f2648d40614df8bcc407c9f Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sat, 18 Jun 2016 13:42:30 +0200 Subject: [PATCH] - Bot-Username wird direkt aus den self-Infos genommen - Portiere service_entergroup --- config.lua.example | 2 -- otouto/bot.lua | 4 +-- otouto/plugins/entergroup.lua | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 otouto/plugins/entergroup.lua diff --git a/config.lua.example b/config.lua.example index 81fe21b..a4e4eb7 100644 --- a/config.lua.example +++ b/config.lua.example @@ -2,8 +2,6 @@ return { -- Your authorization token from the botfather. bot_api_key = '', - -- Bot's username without @ - bot_user_name = '', -- Your Telegram ID. admin = 1337, -- Two-letter language code. diff --git a/otouto/bot.lua b/otouto/bot.lua index af086da..243d6d4 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -74,8 +74,8 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec end -- gsub out user name if multiple bots are in the same group - msg.text = string.gsub(msg.text, '@'..config.bot_user_name, "") - msg.text_lower = string.gsub(msg.text, '@'..string.lower(config.bot_user_name), "") + msg.text = string.gsub(msg.text, '@'..self.info.username, "") + msg.text_lower = string.gsub(msg.text, '@'..string.lower(self.info.username), "") msg = pre_process_msg(self, msg, config) diff --git a/otouto/plugins/entergroup.lua b/otouto/plugins/entergroup.lua new file mode 100644 index 0000000..1762767 --- /dev/null +++ b/otouto/plugins/entergroup.lua @@ -0,0 +1,57 @@ +local entergroup = {} + +local utilities = require('otouto.utilities') +local bindings = require('otouto.bindings') + +entergroup.triggers = { + '/nil' +} + +function entergroup:chat_new_user(msg, self) + local user_name = msg.new_chat_member.first_name + local chat_title = msg.chat.title + if msg.from.username then + at_name = ' (@'..msg.from.username..')' + else + at_name = '' + end + if msg.from.id == msg.new_chat_member.id then -- entered through link + added_by = '' + else + added_by = '\n'..msg.from.name..at_name..' hat dich hinzugefĆ¼gt!' + end + if msg.new_chat_member.id == self.info.id then -- don't say hello to ourselves + return + end + local text = 'Hallo '..user_name..', willkommen bei *'..chat_title..'*!'..added_by + utilities.send_reply(self, msg, text, true) +end + +function entergroup:chat_del_user(msg, self) + if msg.left_chat_member.id == msg.from.id then -- silent ignore, if user wasn't kicked + return + end + local user_name = msg.left_chat_member.first_name + if msg.from.username then + at_name = ' (@'..msg.from.username..')' + else + at_name = '' + end + local text = user_name..' wurde von '..msg.from.first_name..at_name..' aus der Gruppe gekickt.' + utilities.send_reply(self, msg, text, true) +end + +function entergroup:pre_process(msg, self) + if msg.new_chat_member then + entergroup:chat_new_user(msg, self) + elseif msg.left_chat_member then + entergroup:chat_del_user(msg, self) + end + + return msg +end + +function entergroup:action(msg) +end + +return entergroup