Skip to content

Commit

Permalink
Indentation an little little little changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yagop committed Mar 31, 2015
1 parent edbb7e3 commit 8f00b55
Show file tree
Hide file tree
Showing 20 changed files with 498 additions and 449 deletions.
29 changes: 15 additions & 14 deletions plugins/9gag.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
do

function get_9GAG()
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 link_image = gag[i].src
local title = gag[i].title
if link_image:sub(0,2) == '//' then
link_image = msg.text:sub(3,-1)
end
return link_image, title
local b = http.request("http://api-9gag.herokuapp.com/")
local gag = json:decode(b)
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
link_image = msg.text:sub(3,-1)
end
return link_image, title
end

function send_title(cb_extra, success, result)
Expand All @@ -27,9 +27,10 @@ function run(msg, matches)
end

return {
description = "9GAG for telegram",
usage = "!9gag: Send random image from 9gag",
patterns = {"^!9gag$"},
run = run
description = "9GAG for telegram",
usage = "!9gag: Send random image from 9gag",
patterns = {"^!9gag$"},
run = run
}

end
167 changes: 78 additions & 89 deletions plugins/bugzilla.lua
Original file line number Diff line number Diff line change
@@ -1,95 +1,82 @@
function bugzilla_login()
url = "https://bugzilla.mozilla.org/rest/login?login=" .. _config.bugzilla.username .. "&password=" .. _config.bugzilla.password

print("accessing " .. url)
do

local res,code = https.request( url )
local BASE_URL = "https://bugzilla.mozilla.org/rest/"

data = json:decode(res)

return data
function bugzilla_login()
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
-- print(url)
local res,code = https.request( url )

data = json:decode(res)

return data

function bugzilla_check(id)
-- data = bugzilla_login()
vardump(data)
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 res,code = https.request( url )

print(res)

data = json:decode(res)

return data
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)
local data = json:decode(res)
return data
end

function run(msg, matches)

local response = ""

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
response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
response = response .. "\n Last update: "..data.bugs[1].last_change_time
response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
print(response)
end
elseif matches[1] == "list" then
data = bugzilla_listopened(matches[2])

vardump(data)

if data.error == true then
return "Sorry, API failed with message: " .. data.message
else

-- response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
-- response = response .. "\n Last update: "..data.bugs[1].last_change_time
-- response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
-- response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
-- response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
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
response = response .. ": "

for tableKey, bug in pairs(data.bugs) do
response = response .. "\n #" .. bug.id
response = response .. "\n Status: " .. bug.status .. " " .. bug.resolution
response = response .. "\n Whiteboard: " .. bug.whiteboard
response = response .. "\n Summary: " .. bug.summary
end
end
end

end

return response
local response = ""

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
response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
response = response .. "\n Last update: "..data.bugs[1].last_change_time
response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
print(response)
end
elseif matches[1] == "list" then
data = bugzilla_listopened(matches[2])

vardump(data)
if data.error == true then
return "Sorry, API failed with message: " .. data.message
else

-- response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
-- response = response .. "\n Last update: "..data.bugs[1].last_change_time
-- response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
-- response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
-- response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
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
response = response .. ": "

for tableKey, bug in pairs(data.bugs) do
response = response .. "\n #" .. bug.id
response = response .. "\n Status: " .. bug.status .. " " .. bug.resolution
response = response .. "\n Whiteboard: " .. bug.whiteboard
response = response .. "\n Summary: " .. bug.summary
end
end
end

end
return response
end

-- (table)
Expand All @@ -107,11 +94,13 @@ end
-- total bugs: 2

return {
description = "Lookup bugzilla status update",
usage = "/bot bugzilla [bug number]",
patterns = {
"^/bugzilla (status) (.*)$",
"^/bugzilla (list) (.*)$"
},
run = run
}
description = "Lookup bugzilla status update",
usage = "/bot bugzilla [bug number]",
patterns = {
"^/bugzilla (status) (.*)$",
"^/bugzilla (list) (.*)$"
},
run = run
}

end
11 changes: 6 additions & 5 deletions plugins/echo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ function run(msg, matches)
end

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

4 changes: 3 additions & 1 deletion plugins/eur.lua
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -31,3 +32,4 @@ return {
run = run
}

end
21 changes: 12 additions & 9 deletions plugins/fortunes_uc3m.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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)
return b
local i = math.random(0,178) -- max 178
local web = "http://www.gul.es/fortunes/f"..i
local b, c, h = http.request(web)
return b
end


Expand All @@ -13,9 +13,12 @@ function run(msg, matches)
end

return {
description = "Fortunes from Universidad Carlos III",
usage = "!uc3m",
patterns = {"^!uc3m$"},
run = run
description = "Fortunes from Universidad Carlos III",
usage = "!uc3m",
patterns = {
"^!uc3m$"
},
run = run
}

end
14 changes: 9 additions & 5 deletions plugins/gps.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
do

function run(msg, matches)
local lat = matches[1]
local lon = matches[2]
Expand All @@ -17,8 +19,10 @@ function run(msg, matches)
end

return {
description = "generates a map showing the given GPS coordinates",
usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates",
patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"},
run = run
}
description = "generates a map showing the given GPS coordinates",
usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates",
patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"},
run = run
}

end
45 changes: 24 additions & 21 deletions plugins/imdb.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
do

function imdb(movie)
local http = require("socket.http")
http.TIMEOUT = 5
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 code ~= 200 then
return "Error: " .. code
end

if #response > 0 then
r = json:decode(response)
r['Url'] = "http://imdb.com/title/" .. r.imdbID
t = ""
for k, v in pairs(r) do t = t .. k .. ": " .. v .. ", " end
return t:sub(1, -3)
end
return nil
if #response > 0 then
local r = json:decode(response)
r['Url'] = "http://imdb.com/title/" .. r.imdbID
local t = ""
for k, v in pairs(r) do t = t .. k .. ": " .. v .. ", " end
return t:sub(1, -3)
end
return nil
end

function run(msg, matches)
return imdb(matches[1])
return imdb(matches[1])
end

return {
description = "Imdb plugin for telegram",
usage = "!imdb [movie]",
patterns = {"^!imdb (.+)"},
run = run
description = "Imdb plugin for telegram",
usage = "!imdb [movie]",
patterns = {"^!imdb (.+)"},
run = run
}

end
Loading

0 comments on commit 8f00b55

Please sign in to comment.