removed spaghetti code

updated version number
This commit is contained in:
topkecleon 2015-09-24 19:44:43 -04:00
parent a4b0a7ebed
commit 9a7f166fd4
3 changed files with 8 additions and 27 deletions

28
bot.lua
View File

@ -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()

View File

@ -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.

View File

@ -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