From caba3c835dafe6dcdd92665375dd1cb95927d91a Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sun, 28 Aug 2016 13:35:27 +0200 Subject: [PATCH] =?UTF-8?q?Zeige=20Nachrichten=20im=20Terminal=20(wie=20fr?= =?UTF-8?q?=C3=BCher)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- miku/bot.lua | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5892ac9..29e0f9d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ config.lua tg tmp/* miku/plugins/licht.lua -Bot-Kommandoliste.txt \ No newline at end of file +Bot-Kommandoliste.txt +msg.txt \ No newline at end of file diff --git a/miku/bot.lua b/miku/bot.lua index 6512e8d..c20739d 100644 --- a/miku/bot.lua +++ b/miku/bot.lua @@ -49,7 +49,7 @@ function bot:init(config) -- The function run when the bot is started or reloade if p.init then p.init(self, config) end end - print('Bot wurde erfolgreich gestartet!\n@' .. self.info.username .. ', AKA ' .. self.info.first_name ..' ('..self.info.id..')') + print('Mikubot wurde erfolgreich gestartet!\n@' .. self.info.username .. ', AKA ' .. self.info.first_name ..' ('..self.info.id..')') -- Set loop variables self.last_update = self.last_update or 0 -- Update offset. @@ -63,6 +63,41 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec -- vardump(msg) -- Cache user info for those involved. + -- print messages + msg_time = convert_timestamp(msg.date, '[%H:%M:%S] ') + + if msg.chat.title then + from_chat = ' \27[36m'..msg.chat.title..':\27[0m ' + else + from_chat = '' + end + + if msg.from.first_name then + name1 = '\27[1m\27[31m'..msg.from.first_name..'\27[0m' + else + name1 = '' + end + if msg.from.last_name then + name2 = '\27[1m\27[31m'..msg.from.last_name..'\27[0m' + else + name2 = '' + end + if msg.from.username then + name3 = ' (@'..msg.from.username..'\27[0m)' + else + name3 = '' + end + full_name = name1..' '..name2..name3 + + if msg.text then + user_msg = msg.text..'\27[0m' + else + user_msg = '' + end + + full_message = msg_time..from_chat..full_name..' >>> '..user_msg + print(full_message) + if msg.date < os.time() - 5 then return end -- Do not process old messages. msg = utilities.enrich_message(msg)