Indentation an little little little changes

This commit is contained in:
yago 2015-03-31 20:17:14 +02:00
parent edbb7e3441
commit 8f00b554a2
20 changed files with 492 additions and 443 deletions

View File

@ -1,9 +1,9 @@
do
function get_9GAG() function get_9GAG()
b = http.request("http://api-9gag.herokuapp.com/") local b = http.request("http://api-9gag.herokuapp.com/")
local gag = json:decode(b) local gag = json:decode(b)
math.randomseed(os.time()) local i = math.random(#gag) -- random max json table size (# is an operator o.O)
i = math.random(#gag) -- random max json table size (# is an operator o.O)
local link_image = gag[i].src local link_image = gag[i].src
local title = gag[i].title local title = gag[i].title
if link_image:sub(0,2) == '//' then if link_image:sub(0,2) == '//' then
@ -33,3 +33,4 @@ return {
run = run run = run
} }
end

View File

@ -1,38 +1,30 @@
do
local BASE_URL = "https://bugzilla.mozilla.org/rest/"
function bugzilla_login() function bugzilla_login()
url = "https://bugzilla.mozilla.org/rest/login?login=" .. _config.bugzilla.username .. "&password=" .. _config.bugzilla.password local url = BASE_URL.."login?login=" .. _config.bugzilla.username .. "&password=" .. _config.bugzilla.password
print("accessing " .. url) print("accessing " .. url)
local res,code = https.request( url ) local res,code = https.request( url )
data = json:decode(res) data = json:decode(res)
return data return data
end end
function bugzilla_check(id) function bugzilla_check(id)
-- data = bugzilla_login() -- data = bugzilla_login()
vardump(data) vardump(data)
url = "https://bugzilla.mozilla.org/rest/bug/" .. id .. "?api_key=" .. _config.bugzilla.apikey local url = BASE_URL.."bug/" .. id .. "?api_key=" .. _config.bugzilla.apikey
-- print(url) -- print(url)
local res,code = https.request( url ) local res,code = https.request( url )
data = json:decode(res) data = json:decode(res)
return data return data
end end
function bugzilla_listopened(email) function bugzilla_listopened(email)
local url = BASE_URL.."bug?include_fields=id,summary,status,whiteboard,resolution&email1=" .. email .. "&email2=" .. email .. "&emailassigned_to2=1&emailreporter1=1&emailtype1=substring&emailtype2=substring&f1=bug_status&f2=bug_status&n1=1&n2=1&o1=equals&o2=equals&resolution=---&v1=closed&v2=resolved&api_key=" .. _config.bugzilla.apikey
url = "https://bugzilla.mozilla.org/rest/bug?include_fields=id,summary,status,whiteboard,resolution&email1=" .. email .. "&email2=" .. email .. "&emailassigned_to2=1&emailreporter1=1&emailtype1=substring&emailtype2=substring&f1=bug_status&f2=bug_status&n1=1&n2=1&o1=equals&o2=equals&resolution=---&v1=closed&v2=resolved&api_key=" .. _config.bugzilla.apikey
local res,code = https.request( url ) local res,code = https.request( url )
print(res) print(res)
local data = json:decode(res)
data = json:decode(res)
return data return data
end end
@ -42,9 +34,7 @@ function run(msg, matches)
if matches[1] == "status" then if matches[1] == "status" then
data = bugzilla_check(matches[2]) data = bugzilla_check(matches[2])
vardump(data) vardump(data)
if data.error == true then if data.error == true then
return "Sorry, API failed with message: " .. data.message return "Sorry, API failed with message: " .. data.message
else else
@ -59,7 +49,6 @@ function run(msg, matches)
data = bugzilla_listopened(matches[2]) data = bugzilla_listopened(matches[2])
vardump(data) vardump(data)
if data.error == true then if data.error == true then
return "Sorry, API failed with message: " .. data.message return "Sorry, API failed with message: " .. data.message
else else
@ -72,7 +61,6 @@ function run(msg, matches)
local total = table.map_length(data.bugs) local total = table.map_length(data.bugs)
print("total bugs: " .. total) print("total bugs: " .. total)
response = "There are " .. total .. " number of bug(s) assigned/reported by " .. matches[2] response = "There are " .. total .. " number of bug(s) assigned/reported by " .. matches[2]
if total > 0 then if total > 0 then
@ -88,7 +76,6 @@ function run(msg, matches)
end end
end end
return response return response
end end
@ -115,3 +102,5 @@ return {
}, },
run = run run = run
} }
end

View File

@ -6,7 +6,8 @@ end
return { return {
description = "Simplest plugin ever!", description = "Simplest plugin ever!",
usage = "!echo [whatever]: echoes the msg", usage = "!echo [whatever]: echoes the msg",
patterns = {"^!echo (.*)$"}, patterns = {
"^!echo (.*)$"
},
run = run run = run
} }

View File

@ -1,6 +1,7 @@
do
function getEURUSD(usd) function getEURUSD(usd)
b = http.request("http://webrates.truefx.com/rates/connect.html?c=EUR/USD&f=csv&s=n") local b = http.request("http://webrates.truefx.com/rates/connect.html?c=EUR/USD&f=csv&s=n")
local rates = b:split(", ") local rates = b:split(", ")
local symbol = rates[1] local symbol = rates[1]
local timestamp = rates[2] local timestamp = rates[2]
@ -31,3 +32,4 @@ return {
run = run run = run
} }
end

View File

@ -1,9 +1,9 @@
do
function get_fortunes_uc3m() function get_fortunes_uc3m()
math.randomseed(os.time())
local i = math.random(0,178) -- max 178 local i = math.random(0,178) -- max 178
local web = "http://www.gul.es/fortunes/f"..i local web = "http://www.gul.es/fortunes/f"..i
b, c, h = http.request(web) local b, c, h = http.request(web)
return b return b
end end
@ -15,7 +15,10 @@ end
return { return {
description = "Fortunes from Universidad Carlos III", description = "Fortunes from Universidad Carlos III",
usage = "!uc3m", usage = "!uc3m",
patterns = {"^!uc3m$"}, patterns = {
"^!uc3m$"
},
run = run run = run
} }
end

View File

@ -1,3 +1,5 @@
do
function run(msg, matches) function run(msg, matches)
local lat = matches[1] local lat = matches[1]
local lon = matches[2] local lon = matches[2]
@ -22,3 +24,5 @@ return {
patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"}, patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"},
run = run run = run
} }
end

View File

@ -1,20 +1,21 @@
do
function imdb(movie) function imdb(movie)
local http = require("socket.http") local http = require("socket.http")
http.TIMEOUT = 5 http.TIMEOUT = 5
movie = movie:gsub(' ', '+') local movie = movie:gsub(' ', '+')
url = "http://www.imdbapi.com/?t=" .. movie local url = "http://www.imdbapi.com/?t=" .. movie
response, code, headers = http.request(url) local response, code, headers = http.request(url)
if code ~= 200 then if code ~= 200 then
return "Error: " .. code return "Error: " .. code
end end
if #response > 0 then if #response > 0 then
r = json:decode(response) local r = json:decode(response)
r['Url'] = "http://imdb.com/title/" .. r.imdbID r['Url'] = "http://imdb.com/title/" .. r.imdbID
t = "" local t = ""
for k, v in pairs(r) do t = t .. k .. ": " .. v .. ", " end for k, v in pairs(r) do t = t .. k .. ": " .. v .. ", " end
return t:sub(1, -3) return t:sub(1, -3)
end end
@ -31,3 +32,5 @@ return {
patterns = {"^!imdb (.+)"}, patterns = {"^!imdb (.+)"},
run = run run = run
} }
end

View File

@ -7,21 +7,22 @@
-- Globals -- Globals
-- If you have a google api key for the geocoding/timezone api -- If you have a google api key for the geocoding/timezone api
do
api_key = nil local api_key = nil
base_api = "https://maps.googleapis.com/maps/api" local base_api = "https://maps.googleapis.com/maps/api"
function get_staticmap(area) function get_staticmap(area)
local api = base_api .. "/staticmap?" local api = base_api .. "/staticmap?"
-- Get a sense of scale -- Get a sense of scale
lat,lng,acc,types = get_latlong(area) local lat,lng,acc,types = get_latlong(area)
local scale=types[1] local scale = types[1]
if scale=="locality" then zoom=8 if scale=="locality" then zoom=8
elseif scale=="country" then zoom=4 elseif scale=="country" then zoom=4
else zoom=13 end else zoom = 13 end
local parameters = local parameters =
"size=600x300" .. "size=600x300" ..
@ -57,3 +58,4 @@ return {
run = run run = run
} }
end

View File

@ -1,8 +1,8 @@
do do
function run(msg, matches) function run(msg, matches)
file = download_to_file(matches[1]) local file = download_to_file(matches[1])
send_document(get_receiver(msg), file, ok_cb, false) local send_document(get_receiver(msg), file, ok_cb, false)
end end
return { return {

View File

@ -1,4 +1,6 @@
socket = require("socket") do
local socket = require("socket")
function cron() function cron()
-- Use yours desired web and id -- Use yours desired web and id
@ -22,3 +24,5 @@ return {
run = nil, run = nil,
cron = cron cron = cron
} }
end

View File

@ -1,25 +1,41 @@
do
function getDulcinea( text ) function getDulcinea( text )
-- Powered by https://github.com/javierhonduco/dulcinea -- Powered by https://github.com/javierhonduco/dulcinea
local api = "http://dulcinea.herokuapp.com/api/?query=" local api = "http://dulcinea.herokuapp.com/api/?query="
local query_url = api..text local query_url = api..text
b = http.request(query_url)
local b, code = http.request(query_url)
if code ~= 200 then
return "Error: HTTP Connexion"
end
dulcinea = json:decode(b) dulcinea = json:decode(b)
if dulcinea.status == "error" then if dulcinea.status == "error" then
return "Error: " .. dulcinea.message return "Error: " .. dulcinea.message
end end
while dulcinea.type == "multiple" do while dulcinea.type == "multiple" do
text = dulcinea.response[1].id text = dulcinea.response[1].id
b = http.request(api..text) b = http.request(api..text)
dulcinea = json:decode(b) dulcinea = json:decode(b)
end end
local text = "" local text = ""
local responses = #dulcinea.response local responses = #dulcinea.response
if responses == 0 then if responses == 0 then
return "Error: 404 word not found" return "Error: 404 word not found"
end end
if (responses > 5) then if (responses > 5) then
responses = 5 responses = 5
end end
for i = 1, responses, 1 do for i = 1, responses, 1 do
text = text .. dulcinea.response[i].word .. "\n" text = text .. dulcinea.response[i].word .. "\n"
local meanings = #dulcinea.response[i].meanings local meanings = #dulcinea.response[i].meanings
@ -31,7 +47,7 @@ function getDulcinea( text )
text = text .. meaning .. "\n\n" text = text .. meaning .. "\n\n"
end end
end end
print (text)
return text return text
end end
@ -41,8 +57,9 @@ end
return { return {
description = "Spanish dictionary", description = "Spanish dictionary",
usage = "!rae [word]: Search that word in Spanish dictionary. Powered by https://github.com/javierhonduco/dulcinea", usage = "!rae [word]: Search that word in Spanish dictionary.",
patterns = {"^!rae (.*)$"}, patterns = {"^!rae (.*)$"},
run = run run = run
} }
end

View File

@ -67,6 +67,8 @@ end
return { return {
description = "When user sends twitter URL, send text and images to origin. Requieres OAuth Key.", description = "When user sends twitter URL, send text and images to origin. Requieres OAuth Key.",
usage = "", usage = "",
patterns = {"https://twitter.com/[^/]+/status/([0-9]+)"}, patterns = {
"https://twitter.com/[^/]+/status/([0-9]+)"
},
run = run run = run
} }

View File

@ -1,3 +1,5 @@
do
local OAuth = require "OAuth" local OAuth = require "OAuth"
local consumer_key = "" local consumer_key = ""
@ -48,3 +50,5 @@ return {
patterns = {"^!tw (.+)"}, patterns = {"^!tw (.+)"},
run = run run = run
} }
end

View File

@ -1,3 +1,4 @@
do
function run(msg, matches) function run(msg, matches)
return 'Telegram Bot '.. VERSION .. [[ return 'Telegram Bot '.. VERSION .. [[
@ -14,3 +15,4 @@ return {
run = run run = run
} }
end

View File

@ -1,3 +1,5 @@
do
local _file_votes = './data/votes.lua' local _file_votes = './data/votes.lua'
function read_file_votes () function read_file_votes ()
@ -83,3 +85,4 @@ return {
run = run run = run
} }
end

View File

@ -1,14 +1,18 @@
do
local BASE_URL = "http://api.openweathermap.org/data/2.5"
function get_weather(location) function get_weather(location)
print("Finding weather in ", location) print("Finding weather in ", location)
b, c, h = http.request("http://api.openweathermap.org/data/2.5/weather?q=" .. location .. "&units=metric") local b, c, h = http.request(BASE_URL.."/weather?q=" .. location .. "&units=metric")
weather = json:decode(b) local weather = json:decode(b)
print("Weather returns", weather) print("Weather returns", weather)
local city = weather.name local city = weather.name
local country = weather.sys.country local country = weather.sys.country
temp = 'The temperature in ' .. city .. ' (' .. country .. ')' local temp = 'The temperature in ' .. city .. ' (' .. country .. ')'
temp = temp .. ' is ' .. weather.main.temp .. '°C' 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 .. ''
elseif weather.weather[1].main == 'Clouds' then elseif weather.weather[1].main == 'Clouds' then
@ -18,6 +22,7 @@ function get_weather(location)
elseif weather.weather[1].main == 'Thunderstorm' then elseif weather.weather[1].main == 'Thunderstorm' then
conditions = conditions .. ' ☔☔☔☔' conditions = conditions .. ' ☔☔☔☔'
end end
return temp .. '\n' .. conditions return temp .. '\n' .. conditions
end end
@ -37,3 +42,4 @@ return {
run = run run = run
} }
end

View File

@ -1,3 +1,5 @@
do
function get_last_id() function get_last_id()
local res,code = https.request("http://xkcd.com/info.0.json") local res,code = https.request("http://xkcd.com/info.0.json")
if code ~= 200 then return "HTTP ERROR" end if code ~= 200 then return "HTTP ERROR" end
@ -19,8 +21,7 @@ end
function get_xkcd_random() function get_xkcd_random()
local last = get_last_id() local last = get_last_id()
math.randomseed(os.time()) local i = math.random(1, last)
i = math.random(1, last)
return get_xkcd(i) return get_xkcd(i)
end end
@ -52,3 +53,5 @@ return {
}, },
run = run run = run
} }
end

View File

@ -16,7 +16,10 @@ function send_youtube_data(data, receiver)
local uploader = data.uploader local uploader = data.uploader
local text = title..' ('..uploader..')\n'..description local text = title..' ('..uploader..')\n'..description
local image_url = data.thumbnail.hqDefault local image_url = data.thumbnail.hqDefault
local cb_extra = {receiver=receiver, url=image_url} local cb_extra = {
receiver = receiver,
url = image_url
}
send_msg(receiver, text, send_photo_from_url_callback, cb_extra) send_msg(receiver, text, send_photo_from_url_callback, cb_extra)
end end