From 9a7f166fd40d90691a7b688e1249caddf5eec0e9 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Thu, 24 Sep 2015 19:44:43 -0400 Subject: [PATCH] removed spaghetti code updated version number --- bot.lua | 28 ++++------------------------ plugins/about.lua | 2 +- plugins/youtube.lua | 5 +++-- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/bot.lua b/bot.lua index 3d81f4a..aa2aebd 100755 --- a/bot.lua +++ b/bot.lua @@ -3,7 +3,7 @@ HTTPS= require('ssl.https') URL = require('socket.url') JSON = require('dkjson') -VERSION = '2.10' +VERSION = '2.11' function on_msg_receive(msg) @@ -13,7 +13,9 @@ function on_msg_receive(msg) msg.chat.id = msg.from.id end - msg = process_msg(msg) + if msg.new_chat_participant and msg.new_chat_participant.id == bot.id then + msg.text = '/about' + end -- If bot is added to a group, send the about message. if msg.date < os.time() - 10 then return end -- don't react to old messages if not msg.text then return end -- don't react to media messages @@ -80,28 +82,6 @@ function bot_init() end -function process_msg(msg) - - if msg.new_chat_participant then - if msg.new_chat_participant.id ~= bot.id then - if msg.from.id == 100547061 then return msg end - msg.text = 'hi '..bot.first_name - msg.from = msg.new_chat_participant - else - msg.text = '/about' - end - end - - if msg.left_chat_participant and msg.left_chat_participant.id ~= bot.id then - if msg.from.id == 100547061 then return msg end - msg.text = 'bye '..bot.first_name - msg.from = msg.left_chat_participant - end - - return msg - -end - bot_init() last_update = 0 last_cron = os.time() diff --git a/plugins/about.lua b/plugins/about.lua index a074d72..84c1ab3 100755 --- a/plugins/about.lua +++ b/plugins/about.lua @@ -14,7 +14,7 @@ function PLUGIN.action(msg) local message = [[ I am ]] .. bot.first_name .. [[: a plugin-wielding, multi-purpose Telegram bot. - Use /help for a list of commands. + Send /help for a list of commands. Based on otouto v]] .. VERSION .. [[ by @topkecleon. otouto v2 is licensed under the GPLv2. diff --git a/plugins/youtube.lua b/plugins/youtube.lua index 3f9d402..c09414a 100755 --- a/plugins/youtube.lua +++ b/plugins/youtube.lua @@ -8,7 +8,8 @@ PLUGIN.doc = [[ ]] PLUGIN.triggers = { - '^/youtube' + '^/youtube', + '^/yt' } function PLUGIN.action(msg) @@ -28,7 +29,7 @@ function PLUGIN.action(msg) -- Print Items local text = "" for k,item in pairs(data_JSON.items) do - text = text..'http://youtu.be/'..item.id.videoId..' '..item.snippet.title..'\n\n' + text = text .. item.snippet.title .. '\n' .. 'http://youtu.be/' .. item.id.videoId .. '\n\n' end -- END - ERRO 404 local text_end = text