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

View File

@ -1,38 +1,30 @@
do
local BASE_URL = "https://bugzilla.mozilla.org/rest/"
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)
local res,code = https.request( url )
data = json:decode(res)
return data
end
function bugzilla_check(id)
-- data = bugzilla_login()
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)
local res,code = https.request( url )
data = json:decode(res)
return data
end
function bugzilla_listopened(email)
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 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
local res,code = https.request( url )
print(res)
data = json:decode(res)
local data = json:decode(res)
return data
end
@ -42,9 +34,7 @@ function run(msg, matches)
if matches[1] == "status" then
data = bugzilla_check(matches[2])
vardump(data)
if data.error == true then
return "Sorry, API failed with message: " .. data.message
else
@ -59,7 +49,6 @@ function run(msg, matches)
data = bugzilla_listopened(matches[2])
vardump(data)
if data.error == true then
return "Sorry, API failed with message: " .. data.message
else
@ -72,7 +61,6 @@ function run(msg, matches)
local total = table.map_length(data.bugs)
print("total bugs: " .. total)
response = "There are " .. total .. " number of bug(s) assigned/reported by " .. matches[2]
if total > 0 then
@ -88,7 +76,6 @@ function run(msg, matches)
end
end
return response
end
@ -115,3 +102,5 @@ return {
},
run = run
}
end

View File

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

View File

@ -1,6 +1,7 @@
do
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 symbol = rates[1]
local timestamp = rates[2]
@ -31,3 +32,4 @@ return {
run = run
}
end

View File

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

View File

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

View File

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

View File

@ -7,21 +7,22 @@
-- Globals
-- 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)
local api = base_api .. "/staticmap?"
-- 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
elseif scale=="country" then zoom=4
else zoom=13 end
else zoom = 13 end
local parameters =
"size=600x300" ..
@ -57,3 +58,4 @@ return {
run = run
}
end

View File

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

View File

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

View File

@ -1,25 +1,41 @@
do
function getDulcinea( text )
-- Powered by https://github.com/javierhonduco/dulcinea
local api = "http://dulcinea.herokuapp.com/api/?query="
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)
if dulcinea.status == "error" then
return "Error: " .. dulcinea.message
end
while dulcinea.type == "multiple" do
text = dulcinea.response[1].id
b = http.request(api..text)
dulcinea = json:decode(b)
end
local text = ""
local responses = #dulcinea.response
if responses == 0 then
return "Error: 404 word not found"
end
if (responses > 5) then
responses = 5
end
for i = 1, responses, 1 do
text = text .. dulcinea.response[i].word .. "\n"
local meanings = #dulcinea.response[i].meanings
@ -31,7 +47,7 @@ function getDulcinea( text )
text = text .. meaning .. "\n\n"
end
end
print (text)
return text
end
@ -41,8 +57,9 @@ end
return {
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 (.*)$"},
run = run
}
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,10 @@ function send_youtube_data(data, receiver)
local uploader = data.uploader
local text = title..' ('..uploader..')\n'..description
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)
end