comiteando desde telegram

This commit is contained in:
yagop 2014-07-03 21:18:07 +02:00
parent 361b01afca
commit 66a41c7936

View File

@ -3,6 +3,7 @@ json = (loadfile "./bot/JSON.lua")()
our_id = 0
now = os.time()
VERSION = 'v0.0.5'
function on_msg_receive (msg)
-- vardump(msg)
@ -29,10 +30,31 @@ end
-- Where magic happens
function do_action(msg)
receiver = get_receiver(msg)
local name = msg.from.first_name
if name == nil then
name = 'Noob '
end
if string.starts(msg.text, 'sh') then
bash = msg.text:sub(4,-1)
if is_sudo(msg) then
text = run_bash(bash)
else
text = name .. ' you have no power here!'
end
send_msg(receiver, text)
end
if string.starts(msg.text, 'uc3m') then
text = get_fortunes_uc3m()
send_msg(receiver, text)
end
if string.starts(msg.text, '9gag') then
text = get_infiniGAG()
send_msg(receiver, text)
end
if string.starts(msg.text, 'fortune') then
text = run_bash('fortune')
send_msg(receiver, text)
end
end
if string.starts(msg.text, 'forni') then
text = msg.text:sub(7,-1)
send_msg('Fornicio_2.0', text)
@ -58,7 +80,7 @@ function do_action(msg)
send_msg(receiver, echo)
end
if string.starts(msg.text, 'version') then
text = 'Version v0.0.4\n'
text = 'James Bot '.. VERSION
send_msg(receiver, text)
end
if string.starts(msg.text, 'help') then
@ -70,7 +92,8 @@ function do_action(msg)
!fwd : forward msg
!forni : send text to group Fornicio
!fortune : print a random adage
!weather : weather in Madrid]]
!weather : weather in Madrid
!9gag : send random url image from 9gag]]
send_msg(receiver, text)
end
end
@ -108,6 +131,17 @@ function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
function is_sudo(msg)
print('from: '.. msg.from.id)
if msg.from.id == 11696011 then
print('is sudo')
return true
else
print('is a noob')
return false
end
end
function run_bash(str)
local cmd = io.popen(str)
local result = cmd:read('*all')
@ -122,6 +156,28 @@ function readAll(file)
return content
end
function get_fortunes_uc3m()
i = math.random(0,178) -- max 178
b, c, h = http.request("http://www.gul.es/fortunes/f"..i)
return b
end
function get_infiniGAG()
b, c, h = http.request("http://infinigag-us.aws.af.cm")
local gag = json:decode(b)
-- for key,value in pairs(gag.data) do print(key,value) end
i = math.random(table.getn(gag.data)) -- random
local link_image = gag.data[i].images.normal
return link_image
end
function download_to_file(source, filePath)
local oFile = io.open(filePath, "w")
local save = ltn12.sink.file(oFile)
http.request{url = addr, sink = save }
end
function get_weather(location)
b, c, h = http.request("http://api.openweathermap.org/data/2.5/weather?q=" .. location .. "&units=metric")
weather = json:decode(b)
@ -130,7 +186,11 @@ function get_weather(location)
if weather.weather[1].main == 'Clear' then
conditions = conditions .. ''
elseif weather.weather[1].main == 'Clouds' then
conditions = conditions .. ''
conditions = conditions .. ' ☁☁'
elseif weather.weather[1].main == 'Rain' then
conditions = conditions .. ''
elseif weather.weather[1].main == 'Thunderstorm' then
conditions = conditions .. ' ☔☔☔☔'
end
return temp .. '\n' .. conditions
end