night commit

This commit is contained in:
yagop 2014-07-07 10:30:27 +02:00
parent 2dce79e1c6
commit e6848e3251
2 changed files with 24 additions and 14 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# Config file
bot/config.json
# Object files # Object files
*.o *.o
*.ko *.ko

View File

@ -1,7 +1,7 @@
http = require("socket.http") http = require("socket.http")
json = (loadfile "./bot/JSON.lua")() json = (loadfile "./bot/JSON.lua")()
VERSION = 'v0.0.6' VERSION = 'v0.0.7'
function on_msg_receive (msg) function on_msg_receive (msg)
-- vardump(msg) -- vardump(msg)
@ -54,6 +54,10 @@ function do_action(msg)
if string.starts(msg.text, 'forni') then if string.starts(msg.text, 'forni') then
text = msg.text:sub(7,-1) text = msg.text:sub(7,-1)
send_msg('Fornicio_2.0', text) send_msg('Fornicio_2.0', text)
end
if string.starts(msg.text, 'hackers') then
text = msg.text:sub(9,-1)
send_msg('Juankers._Dios_existe_y_es_<span_class=', text)
end end
if string.starts(msg.text, 'fwd') then if string.starts(msg.text, 'fwd') then
fwd_msg (receiver, msg.id) fwd_msg (receiver, msg.id)
@ -67,7 +71,12 @@ function do_action(msg)
send_msg(receiver, "pong") send_msg(receiver, "pong")
end end
if string.starts(msg.text, 'weather') then if string.starts(msg.text, 'weather') then
text = get_weather('Madrid,ES') if string.len(msg.text) <= 9 then
city = 'Madrid,ES'
else
city = msg.text:sub(9,-1)
end
text = get_weather(city)
send_msg(receiver, text) send_msg(receiver, text)
end end
if string.starts(msg.text, 'echo') then if string.starts(msg.text, 'echo') then
@ -89,9 +98,10 @@ function do_action(msg)
!fwd : forward msg !fwd : forward msg
!forni : send text to group Fornicio !forni : send text to group Fornicio
!fortune : print a random adage !fortune : print a random adage
!weather : weather in Madrid !weather [city] : weather in that city (Madrid if not city)
!9gag : send random url image from 9gag !9gag : send random url image from 9gag
!uc3m : fortunes from Universidad Carlos III]] !uc3m : fortunes from Universidad Carlos III
!hackers : send text to group Juankers]]
send_msg(receiver, text) send_msg(receiver, text)
end end
end end
@ -139,12 +149,12 @@ function load_config()
print("Allowed user: " .. user) print("Allowed user: " .. user)
end end
end end
print("Torrent path: " .. config.torrent_path) -- print("Torrent path: " .. config.torrent_path)
f:close() f:close()
return config return config
end end
function save_torrent(msg) --[[ function save_torrent(msg)
if is_sudo(msg) == false then if is_sudo(msg) == false then
local name = msg.from.first_name local name = msg.from.first_name
if name == nil then if name == nil then
@ -162,7 +172,7 @@ function save_torrent(msg)
print ("Download ".. path .." to "..filePath) print ("Download ".. path .." to "..filePath)
download_to_file(path, filePath) download_to_file(path, filePath)
return "Downloaded ".. path .." to "..filePath return "Downloaded ".. path .." to "..filePath
end end ]]--
function is_sudo(msg) function is_sudo(msg)
local var = false local var = false
@ -223,16 +233,13 @@ function get_infiniGAG()
return link_image return link_image
end 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) function get_weather(location)
b, c, h = http.request("http://api.openweathermap.org/data/2.5/weather?q=" .. location .. "&units=metric") b, c, h = http.request("http://api.openweathermap.org/data/2.5/weather?q=" .. location .. "&units=metric")
weather = json:decode(b) weather = json:decode(b)
temp = 'The temperature in ' .. weather.name .. ' is ' .. weather.main.temp .. '°C' local city = weather.name
local country = weather.sys.country
temp = 'The temperature in ' .. city .. ' (' .. country .. ')'
temp = temp .. ' is ' .. weather.main.temp .. '°C'
conditions = 'Current conditions are: ' .. weather.weather[1].description conditions = 'Current conditions are: ' .. weather.weather[1].description
if weather.weather[1].main == 'Clear' then if weather.weather[1].main == 'Clear' then
conditions = conditions .. '' conditions = conditions .. ''