Indentation an little little little changes
This commit is contained in:
parent
edbb7e3441
commit
8f00b554a2
@ -1,15 +1,15 @@
|
|||||||
|
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
|
link_image = msg.text:sub(3,-1)
|
||||||
link_image = msg.text:sub(3,-1)
|
end
|
||||||
end
|
return link_image, title
|
||||||
return link_image, title
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function send_title(cb_extra, success, result)
|
function send_title(cb_extra, success, result)
|
||||||
@ -27,9 +27,10 @@ function run(msg, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "9GAG for telegram",
|
description = "9GAG for telegram",
|
||||||
usage = "!9gag: Send random image from 9gag",
|
usage = "!9gag: Send random image from 9gag",
|
||||||
patterns = {"^!9gag$"},
|
patterns = {"^!9gag$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -1,95 +1,82 @@
|
|||||||
|
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 )
|
||||||
|
data = json:decode(res)
|
||||||
local res,code = https.request( url )
|
return data
|
||||||
|
|
||||||
data = json:decode(res)
|
|
||||||
|
|
||||||
return data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function bugzilla_check(id)
|
function bugzilla_check(id)
|
||||||
-- data = bugzilla_login()
|
-- data = bugzilla_login()
|
||||||
|
vardump(data)
|
||||||
vardump(data)
|
local url = BASE_URL.."bug/" .. id .. "?api_key=" .. _config.bugzilla.apikey
|
||||||
url = "https://bugzilla.mozilla.org/rest/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)
|
||||||
|
return data
|
||||||
data = json:decode(res)
|
|
||||||
|
|
||||||
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 )
|
||||||
|
print(res)
|
||||||
local res,code = https.request( url )
|
local data = json:decode(res)
|
||||||
|
return data
|
||||||
print(res)
|
|
||||||
|
|
||||||
data = json:decode(res)
|
|
||||||
|
|
||||||
return data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
|
|
||||||
local response = ""
|
local response = ""
|
||||||
|
|
||||||
if matches[1] == "status" then
|
if matches[1] == "status" then
|
||||||
data = bugzilla_check(matches[2])
|
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)
|
vardump(data)
|
||||||
|
if data.error == true then
|
||||||
|
return "Sorry, API failed with message: " .. data.message
|
||||||
|
else
|
||||||
|
|
||||||
if data.error == true then
|
-- response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
|
||||||
return "Sorry, API failed with message: " .. data.message
|
-- response = response .. "\n Last update: "..data.bugs[1].last_change_time
|
||||||
else
|
-- response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
|
||||||
response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
|
-- response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
|
||||||
response = response .. "\n Last update: "..data.bugs[1].last_change_time
|
-- response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
|
||||||
response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
|
local total = table.map_length(data.bugs)
|
||||||
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)
|
print("total bugs: " .. total)
|
||||||
|
response = "There are " .. total .. " number of bug(s) assigned/reported by " .. matches[2]
|
||||||
|
|
||||||
if data.error == true then
|
if total > 0 then
|
||||||
return "Sorry, API failed with message: " .. data.message
|
response = response .. ": "
|
||||||
else
|
|
||||||
|
|
||||||
-- response = "Bug #"..matches[1]..":\nReporter: "..data.bugs[1].creator
|
for tableKey, bug in pairs(data.bugs) do
|
||||||
-- response = response .. "\n Last update: "..data.bugs[1].last_change_time
|
response = response .. "\n #" .. bug.id
|
||||||
-- response = response .. "\n Status: "..data.bugs[1].status.." "..data.bugs[1].resolution
|
response = response .. "\n Status: " .. bug.status .. " " .. bug.resolution
|
||||||
-- response = response .. "\n Whiteboard: "..data.bugs[1].whiteboard
|
response = response .. "\n Whiteboard: " .. bug.whiteboard
|
||||||
-- response = response .. "\n Access: https://bugzilla.mozilla.org/show_bug.cgi?id=" .. matches[1]
|
response = response .. "\n Summary: " .. bug.summary
|
||||||
local total = table.map_length(data.bugs)
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
print("total bugs: " .. total)
|
end
|
||||||
|
return response
|
||||||
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
|
end
|
||||||
|
|
||||||
-- (table)
|
-- (table)
|
||||||
@ -107,11 +94,13 @@ end
|
|||||||
-- total bugs: 2
|
-- total bugs: 2
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Lookup bugzilla status update",
|
description = "Lookup bugzilla status update",
|
||||||
usage = "/bot bugzilla [bug number]",
|
usage = "/bot bugzilla [bug number]",
|
||||||
patterns = {
|
patterns = {
|
||||||
"^/bugzilla (status) (.*)$",
|
"^/bugzilla (status) (.*)$",
|
||||||
"^/bugzilla (list) (.*)$"
|
"^/bugzilla (list) (.*)$"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -4,9 +4,10 @@ function run(msg, matches)
|
|||||||
end
|
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 = {
|
||||||
run = run
|
"^!echo (.*)$"
|
||||||
|
},
|
||||||
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
@ -1,10 +1,10 @@
|
|||||||
|
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
|
local b, c, h = http.request(web)
|
||||||
b, c, h = http.request(web)
|
return b
|
||||||
return b
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -13,9 +13,12 @@ function run(msg, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Fortunes from Universidad Carlos III",
|
description = "Fortunes from Universidad Carlos III",
|
||||||
usage = "!uc3m",
|
usage = "!uc3m",
|
||||||
patterns = {"^!uc3m$"},
|
patterns = {
|
||||||
run = run
|
"^!uc3m$"
|
||||||
|
},
|
||||||
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -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]
|
||||||
@ -17,8 +19,10 @@ function run(msg, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "generates a map showing the given GPS coordinates",
|
description = "generates a map showing the given GPS coordinates",
|
||||||
usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates",
|
usage = "!gps latitude,longitude: generates a map showing the given GPS coordinates",
|
||||||
patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"},
|
patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -1,33 +1,36 @@
|
|||||||
|
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
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
return imdb(matches[1])
|
return imdb(matches[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Imdb plugin for telegram",
|
description = "Imdb plugin for telegram",
|
||||||
usage = "!imdb [movie]",
|
usage = "!imdb [movie]",
|
||||||
patterns = {"^!imdb (.+)"},
|
patterns = {"^!imdb (.+)"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -5,40 +5,40 @@
|
|||||||
do
|
do
|
||||||
|
|
||||||
local function run(msg, matches)
|
local function run(msg, matches)
|
||||||
-- User submitted a user name
|
-- User submitted a user name
|
||||||
if matches[1] == "name" then
|
if matches[1] == "name" then
|
||||||
user = matches[2]
|
user = matches[2]
|
||||||
user = string.gsub(user," ","_")
|
user = string.gsub(user," ","_")
|
||||||
end
|
end
|
||||||
-- User submitted an id
|
-- User submitted an id
|
||||||
if matches[1] == "id" then
|
if matches[1] == "id" then
|
||||||
user = matches[2]
|
user = matches[2]
|
||||||
user = 'user#id'..user
|
user = 'user#id'..user
|
||||||
end
|
end
|
||||||
-- The message must come from a chat group
|
-- The message must come from a chat group
|
||||||
if msg.to.type == 'chat' then
|
if msg.to.type == 'chat' then
|
||||||
chat = 'chat#id'..msg.to.id
|
chat = 'chat#id'..msg.to.id
|
||||||
else
|
else
|
||||||
return 'This isnt a chat group!'
|
return 'This isnt a chat group!'
|
||||||
end
|
end
|
||||||
print ("Trying to add: "..user.." to "..chat)
|
print ("Trying to add: "..user.." to "..chat)
|
||||||
status = chat_add_user (chat, user, ok_cb, false)
|
status = chat_add_user (chat, user, ok_cb, false)
|
||||||
if not status then
|
if not status then
|
||||||
return "An error happened"
|
return "An error happened"
|
||||||
end
|
end
|
||||||
return "Added user: "..user.." to "..chat
|
return "Added user: "..user.." to "..chat
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Invite other user to the chat group",
|
description = "Invite other user to the chat group",
|
||||||
usage = {
|
usage = {
|
||||||
"!invite name [user_name]",
|
"!invite name [user_name]",
|
||||||
"!invite id [user_id]" },
|
"!invite id [user_id]" },
|
||||||
patterns = {
|
patterns = {
|
||||||
"^!invite (name) (.*)$",
|
"^!invite (name) (.*)$",
|
||||||
"^!invite (id) (%d+)$"
|
"^!invite (id) (%d+)$"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
@ -7,53 +7,55 @@
|
|||||||
|
|
||||||
-- 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" ..
|
||||||
"&zoom=" .. zoom ..
|
"&zoom=" .. zoom ..
|
||||||
"¢er=" .. URL.escape(area) ..
|
"¢er=" .. URL.escape(area) ..
|
||||||
"&markers=color:red"..URL.escape("|"..area)
|
"&markers=color:red"..URL.escape("|"..area)
|
||||||
|
|
||||||
if api_key ~=nil and api_key ~= "" then
|
if api_key ~=nil and api_key ~= "" then
|
||||||
parameters = parameters .. "&key="..api_key
|
parameters = parameters .. "&key="..api_key
|
||||||
end
|
end
|
||||||
return lat, lng, api..parameters
|
return lat, lng, api..parameters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
local receiver = get_receiver(msg)
|
local receiver = get_receiver(msg)
|
||||||
local lat,lng,url = get_staticmap(matches[1])
|
local lat,lng,url = get_staticmap(matches[1])
|
||||||
|
|
||||||
-- Send the actual location, is a google maps link
|
-- Send the actual location, is a google maps link
|
||||||
send_location(receiver, lat, lng, ok_cb, false)
|
send_location(receiver, lat, lng, ok_cb, false)
|
||||||
|
|
||||||
-- Send a picture of the map, which takes scale into account
|
-- Send a picture of the map, which takes scale into account
|
||||||
send_photo_from_url(receiver, url)
|
send_photo_from_url(receiver, url)
|
||||||
|
|
||||||
-- Return a link to the google maps stuff is now not needed anymore
|
-- Return a link to the google maps stuff is now not needed anymore
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Gets information about a location, maplink and overview",
|
description = "Gets information about a location, maplink and overview",
|
||||||
usage = "!loc (location): Gets information about a location, maplink and overview",
|
usage = "!loc (location): Gets information about a location, maplink and overview",
|
||||||
patterns = {"^!loc (.*)$"},
|
patterns = {"^!loc (.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -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 {
|
||||||
|
@ -1,24 +1,28 @@
|
|||||||
socket = require("socket")
|
do
|
||||||
|
|
||||||
|
local socket = require("socket")
|
||||||
|
|
||||||
function cron()
|
function cron()
|
||||||
-- Use yours desired web and id
|
-- Use yours desired web and id
|
||||||
local addr = "www.google.com"
|
local addr = "www.google.com"
|
||||||
local dest = "user#id"..our_id
|
local dest = "user#id"..our_id
|
||||||
-- Checks a TCP connexion
|
-- Checks a TCP connexion
|
||||||
local connexion = socket.connect(addr, 80)
|
local connexion = socket.connect(addr, 80)
|
||||||
if not connexion then
|
if not connexion then
|
||||||
local text = "ALERT: "..addr.." is offline"
|
local text = "ALERT: "..addr.." is offline"
|
||||||
print (text)
|
print (text)
|
||||||
send_msg(dest, text, ok_cb, false)
|
send_msg(dest, text, ok_cb, false)
|
||||||
else
|
else
|
||||||
connexion:close()
|
connexion:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "If domain is offline, send msg to peer",
|
description = "If domain is offline, send msg to peer",
|
||||||
usage = "",
|
usage = "",
|
||||||
patterns = {},
|
patterns = {},
|
||||||
run = nil,
|
run = nil,
|
||||||
cron = cron
|
cron = cron
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -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
|
122
plugins/time.lua
122
plugins/time.lua
@ -1,7 +1,7 @@
|
|||||||
-- Implement a command !time [area] which uses
|
-- Implement a command !time [area] which uses
|
||||||
-- 2 Google APIs to get the desired result:
|
-- 2 Google APIs to get the desired result:
|
||||||
-- 1. Geocoding to get from area to a lat/long pair
|
-- 1. Geocoding to get from area to a lat/long pair
|
||||||
-- 2. Timezone to get the local time in that lat/long location
|
-- 2. Timezone to get the local time in that lat/long location
|
||||||
|
|
||||||
-- 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
|
||||||
@ -12,89 +12,89 @@ dateFormat = "%A %d %B - %H:%M:%S"
|
|||||||
|
|
||||||
-- Need the utc time for the google api
|
-- Need the utc time for the google api
|
||||||
function utctime()
|
function utctime()
|
||||||
return os.time(os.date("!*t"))
|
return os.time(os.date("!*t"))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use the geocoding api to get the lattitude and longitude with accuracy specifier
|
-- Use the geocoding api to get the lattitude and longitude with accuracy specifier
|
||||||
-- CHECKME: this seems to work without a key??
|
-- CHECKME: this seems to work without a key??
|
||||||
function get_latlong(area)
|
function get_latlong(area)
|
||||||
local api = base_api .. "/geocode/json?"
|
local api = base_api .. "/geocode/json?"
|
||||||
local parameters = "address=".. (URL.escape(area) or "")
|
local parameters = "address=".. (URL.escape(area) or "")
|
||||||
if api_key ~= nil then
|
if api_key ~= nil then
|
||||||
parameters = parameters .. "&key="..api_key
|
parameters = parameters .. "&key="..api_key
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Do the request
|
-- Do the request
|
||||||
local res, code = https.request(api..parameters)
|
local res, code = https.request(api..parameters)
|
||||||
if code ~=200 then return nil end
|
if code ~=200 then return nil end
|
||||||
local data = json:decode(res)
|
local data = json:decode(res)
|
||||||
|
|
||||||
if (data.status == "ZERO_RESULTS") then
|
if (data.status == "ZERO_RESULTS") then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if (data.status == "OK") then
|
if (data.status == "OK") then
|
||||||
-- Get the data
|
-- Get the data
|
||||||
lat = data.results[1].geometry.location.lat
|
lat = data.results[1].geometry.location.lat
|
||||||
lng = data.results[1].geometry.location.lng
|
lng = data.results[1].geometry.location.lng
|
||||||
acc = data.results[1].geometry.location_type
|
acc = data.results[1].geometry.location_type
|
||||||
types= data.results[1].types
|
types= data.results[1].types
|
||||||
return lat,lng,acc,types
|
return lat,lng,acc,types
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use timezone api to get the time in the lat,
|
-- Use timezone api to get the time in the lat,
|
||||||
-- Note: this needs an API key
|
-- Note: this needs an API key
|
||||||
function get_time(lat,lng)
|
function get_time(lat,lng)
|
||||||
local api = base_api .. "/timezone/json?"
|
local api = base_api .. "/timezone/json?"
|
||||||
|
|
||||||
-- Get a timestamp (server time is relevant here)
|
-- Get a timestamp (server time is relevant here)
|
||||||
local timestamp = utctime()
|
local timestamp = utctime()
|
||||||
local parameters = "location=" ..
|
local parameters = "location=" ..
|
||||||
URL.escape(lat) .. "," ..
|
URL.escape(lat) .. "," ..
|
||||||
URL.escape(lng) ..
|
URL.escape(lng) ..
|
||||||
"×tamp="..URL.escape(timestamp)
|
"×tamp="..URL.escape(timestamp)
|
||||||
if api_key ~=nil then
|
if api_key ~=nil then
|
||||||
parameters = parameters .. "&key="..api_key
|
parameters = parameters .. "&key="..api_key
|
||||||
end
|
end
|
||||||
|
|
||||||
local res,code = https.request(api..parameters)
|
local res,code = https.request(api..parameters)
|
||||||
if code ~= 200 then return nil end
|
if code ~= 200 then return nil end
|
||||||
local data = json:decode(res)
|
local data = json:decode(res)
|
||||||
|
|
||||||
if (data.status == "ZERO_RESULTS") then
|
if (data.status == "ZERO_RESULTS") then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if (data.status == "OK") then
|
if (data.status == "OK") then
|
||||||
-- Construct what we want
|
-- Construct what we want
|
||||||
-- The local time in the location is:
|
-- The local time in the location is:
|
||||||
-- timestamp + rawOffset + dstOffset
|
-- timestamp + rawOffset + dstOffset
|
||||||
local localTime = timestamp + data.rawOffset + data.dstOffset
|
local localTime = timestamp + data.rawOffset + data.dstOffset
|
||||||
return localTime, data.timeZoneId
|
return localTime, data.timeZoneId
|
||||||
end
|
end
|
||||||
return localTime
|
return localTime
|
||||||
end
|
end
|
||||||
|
|
||||||
function getformattedLocalTime(area)
|
function getformattedLocalTime(area)
|
||||||
if area == nil then
|
if area == nil then
|
||||||
return "The time in nowhere is never"
|
return "The time in nowhere is never"
|
||||||
end
|
end
|
||||||
|
|
||||||
lat,lng,acc = get_latlong(area)
|
lat,lng,acc = get_latlong(area)
|
||||||
if lat == nil and lng == nil then
|
if lat == nil and lng == nil then
|
||||||
return 'It seems that in "'..area..'" they do not have a concept of time.'
|
return 'It seems that in "'..area..'" they do not have a concept of time.'
|
||||||
end
|
end
|
||||||
local localTime, timeZoneId = get_time(lat,lng)
|
local localTime, timeZoneId = get_time(lat,lng)
|
||||||
|
|
||||||
return "The local time in "..timeZoneId.." is: ".. os.date(dateFormat,localTime)
|
return "The local time in "..timeZoneId.." is: ".. os.date(dateFormat,localTime)
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
return getformattedLocalTime(matches[1])
|
return getformattedLocalTime(matches[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Displays the local time in an area",
|
description = "Displays the local time in an area",
|
||||||
usage = "!time [area]: Displays the local time in that area",
|
usage = "!time [area]: Displays the local time in that area",
|
||||||
patterns = {"^!time (.*)$"},
|
patterns = {"^!time (.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,9 @@ function run(msg, matches)
|
|||||||
-- replace short URLs
|
-- replace short URLs
|
||||||
if response.entities.url then
|
if response.entities.url then
|
||||||
for k, v in pairs(response.entities.urls) do
|
for k, v in pairs(response.entities.urls) do
|
||||||
local short = v.url
|
local short = v.url
|
||||||
local long = v.expanded_url
|
local long = v.expanded_url
|
||||||
text = text:gsub(short, long)
|
text = text:gsub(short, long)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -49,10 +49,10 @@ function run(msg, matches)
|
|||||||
local images = {}
|
local images = {}
|
||||||
if response.extended_entities and response.extended_entities.media then
|
if response.extended_entities and response.extended_entities.media then
|
||||||
for k, v in pairs(response.extended_entities.media) do
|
for k, v in pairs(response.extended_entities.media) do
|
||||||
local url = v.url
|
local url = v.url
|
||||||
local pic = v.media_url
|
local pic = v.media_url
|
||||||
text = text:gsub(url, "")
|
text = text:gsub(url, "")
|
||||||
table.insert(images, pic)
|
table.insert(images, pic)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,8 +65,10 @@ 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 = {
|
||||||
run = run
|
"https://twitter.com/[^/]+/status/([0-9]+)"
|
||||||
|
},
|
||||||
|
run = run
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
do
|
||||||
|
|
||||||
local OAuth = require "OAuth"
|
local OAuth = require "OAuth"
|
||||||
|
|
||||||
local consumer_key = ""
|
local consumer_key = ""
|
||||||
@ -6,45 +8,47 @@ local access_token = ""
|
|||||||
local access_token_secret = ""
|
local access_token_secret = ""
|
||||||
|
|
||||||
local client = OAuth.new(consumer_key, consumer_secret, {
|
local client = OAuth.new(consumer_key, consumer_secret, {
|
||||||
RequestToken = "https://api.twitter.com/oauth/request_token",
|
RequestToken = "https://api.twitter.com/oauth/request_token",
|
||||||
AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"},
|
AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"},
|
||||||
AccessToken = "https://api.twitter.com/oauth/access_token"
|
AccessToken = "https://api.twitter.com/oauth/access_token"
|
||||||
}, {
|
}, {
|
||||||
OAuthToken = access_token,
|
OAuthToken = access_token,
|
||||||
OAuthTokenSecret = access_token_secret
|
OAuthTokenSecret = access_token_secret
|
||||||
})
|
})
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
if consumer_key:isempty() then
|
if consumer_key:isempty() then
|
||||||
return "Twitter Consumer Key is empty, write it in plugins/twitter_send.lua"
|
return "Twitter Consumer Key is empty, write it in plugins/twitter_send.lua"
|
||||||
end
|
end
|
||||||
if consumer_secret:isempty() then
|
if consumer_secret:isempty() then
|
||||||
return "Twitter Consumer Secret is empty, write it in plugins/twitter_send.lua"
|
return "Twitter Consumer Secret is empty, write it in plugins/twitter_send.lua"
|
||||||
end
|
end
|
||||||
if access_token:isempty() then
|
if access_token:isempty() then
|
||||||
return "Twitter Access Token is empty, write it in plugins/twitter_send.lua"
|
return "Twitter Access Token is empty, write it in plugins/twitter_send.lua"
|
||||||
end
|
end
|
||||||
if access_token_secret:isempty() then
|
if access_token_secret:isempty() then
|
||||||
return "Twitter Access Token Secret is empty, write it in plugins/twitter_send.lua"
|
return "Twitter Access Token Secret is empty, write it in plugins/twitter_send.lua"
|
||||||
end
|
end
|
||||||
|
|
||||||
if not is_sudo(msg) then
|
if not is_sudo(msg) then
|
||||||
return "You aren't allowed to send tweets"
|
return "You aren't allowed to send tweets"
|
||||||
end
|
end
|
||||||
|
|
||||||
local response_code, response_headers, response_status_line, response_body =
|
local response_code, response_headers, response_status_line, response_body =
|
||||||
client:PerformRequest("POST", "https://api.twitter.com/1.1/statuses/update.json", {
|
client:PerformRequest("POST", "https://api.twitter.com/1.1/statuses/update.json", {
|
||||||
status = matches[1]
|
status = matches[1]
|
||||||
})
|
})
|
||||||
if response_code ~= 200 then
|
if response_code ~= 200 then
|
||||||
return "Error: "..response_code
|
return "Error: "..response_code
|
||||||
end
|
end
|
||||||
return "Tweet sended"
|
return "Tweet sended"
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Sends a tweet",
|
description = "Sends a tweet",
|
||||||
usage = "!tw [text]: Sends the Tweet with the configured accout.",
|
usage = "!tw [text]: Sends the Tweet with the configured accout.",
|
||||||
patterns = {"^!tw (.+)"},
|
patterns = {"^!tw (.+)"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -1,3 +1,4 @@
|
|||||||
|
do
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
return 'Telegram Bot '.. VERSION .. [[
|
return 'Telegram Bot '.. VERSION .. [[
|
||||||
@ -6,11 +7,12 @@ function run(msg, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Shows bot version",
|
description = "Shows bot version",
|
||||||
usage = "!version: Shows bot version",
|
usage = "!version: Shows bot version",
|
||||||
patterns = {
|
patterns = {
|
||||||
"^!version$"
|
"^!version$"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
127
plugins/vote.lua
127
plugins/vote.lua
@ -1,85 +1,88 @@
|
|||||||
|
do
|
||||||
|
|
||||||
local _file_votes = './data/votes.lua'
|
local _file_votes = './data/votes.lua'
|
||||||
|
|
||||||
function read_file_votes ()
|
function read_file_votes ()
|
||||||
local f = io.open(_file_votes, "r+")
|
local f = io.open(_file_votes, "r+")
|
||||||
if f == nil then
|
if f == nil then
|
||||||
print ('Created voting file '.._file_votes)
|
print ('Created voting file '.._file_votes)
|
||||||
serialize_to_file({}, _file_votes)
|
serialize_to_file({}, _file_votes)
|
||||||
else
|
else
|
||||||
print ('Values loaded: '.._file_votes)
|
print ('Values loaded: '.._file_votes)
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
return loadfile (_file_votes)()
|
return loadfile (_file_votes)()
|
||||||
end
|
end
|
||||||
|
|
||||||
function clear_votes (chat)
|
function clear_votes (chat)
|
||||||
local _votes = read_file_votes ()
|
local _votes = read_file_votes ()
|
||||||
_votes [chat] = {}
|
_votes [chat] = {}
|
||||||
serialize_to_file(_votes, _file_votes)
|
serialize_to_file(_votes, _file_votes)
|
||||||
end
|
end
|
||||||
|
|
||||||
function votes_result (chat)
|
function votes_result (chat)
|
||||||
local _votes = read_file_votes ()
|
local _votes = read_file_votes ()
|
||||||
local results = {}
|
local results = {}
|
||||||
local result_string = ""
|
local result_string = ""
|
||||||
if _votes [chat] == nil then
|
if _votes [chat] == nil then
|
||||||
_votes[chat] = {}
|
_votes[chat] = {}
|
||||||
end
|
end
|
||||||
for user,vote in pairs (_votes[chat]) do
|
for user,vote in pairs (_votes[chat]) do
|
||||||
if (results [vote] == nil) then
|
if (results [vote] == nil) then
|
||||||
results [vote] = user
|
results [vote] = user
|
||||||
else
|
else
|
||||||
results [vote] = results [vote] .. ", " .. user
|
results [vote] = results [vote] .. ", " .. user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for vote,users in pairs (results) do
|
for vote,users in pairs (results) do
|
||||||
result_string = result_string .. vote .. " : " .. users .. "\n"
|
result_string = result_string .. vote .. " : " .. users .. "\n"
|
||||||
end
|
end
|
||||||
return result_string
|
return result_string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function save_vote(chat, user, vote)
|
function save_vote(chat, user, vote)
|
||||||
local _votes = read_file_votes ()
|
local _votes = read_file_votes ()
|
||||||
if _votes[chat] == nil then
|
if _votes[chat] == nil then
|
||||||
_votes[chat] = {}
|
_votes[chat] = {}
|
||||||
end
|
end
|
||||||
_votes[chat][user] = vote
|
_votes[chat][user] = vote
|
||||||
|
|
||||||
serialize_to_file(_votes, _file_votes)
|
serialize_to_file(_votes, _file_votes)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
if (matches[1] == "ing") then
|
if (matches[1] == "ing") then
|
||||||
if (matches [2] == "reset") then
|
if (matches [2] == "reset") then
|
||||||
clear_votes (tostring(msg.to.id))
|
clear_votes (tostring(msg.to.id))
|
||||||
return "Voting statistics reset.."
|
return "Voting statistics reset.."
|
||||||
elseif (matches [2] == "stats") then
|
elseif (matches [2] == "stats") then
|
||||||
local votes_result = votes_result (tostring(msg.to.id))
|
local votes_result = votes_result (tostring(msg.to.id))
|
||||||
if (votes_result == "") then
|
if (votes_result == "") then
|
||||||
votes_result = "[No votes registered]\n"
|
votes_result = "[No votes registered]\n"
|
||||||
end
|
end
|
||||||
return "Voting statistics :\n" .. votes_result
|
return "Voting statistics :\n" .. votes_result
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
save_vote(tostring(msg.to.id), msg.from.print_name, tostring(tonumber(matches[2])))
|
save_vote(tostring(msg.to.id), msg.from.print_name, tostring(tonumber(matches[2])))
|
||||||
return "Vote registered : " .. msg.from.print_name .. " " .. tostring(tonumber(matches [2]))
|
return "Vote registered : " .. msg.from.print_name .. " " .. tostring(tonumber(matches [2]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Plugin for voting in groups.",
|
description = "Plugin for voting in groups.",
|
||||||
usage = {
|
usage = {
|
||||||
"!voting reset: Reset all the votes.",
|
"!voting reset: Reset all the votes.",
|
||||||
"!vote [number]: Cast the vote.",
|
"!vote [number]: Cast the vote.",
|
||||||
"!voting stats: Shows the statistics of voting."
|
"!voting stats: Shows the statistics of voting."
|
||||||
},
|
},
|
||||||
patterns = {
|
patterns = {
|
||||||
"^!vot(ing) (reset)",
|
"^!vot(ing) (reset)",
|
||||||
"^!vot(ing) (stats)",
|
"^!vot(ing) (stats)",
|
||||||
"^!vot(e) ([0-9]+)$"
|
"^!vot(e) ([0-9]+)$"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -1,39 +1,45 @@
|
|||||||
|
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
|
|
||||||
conditions = conditions .. ' ☀'
|
if weather.weather[1].main == 'Clear' then
|
||||||
elseif weather.weather[1].main == 'Clouds' then
|
conditions = conditions .. ' ☀'
|
||||||
conditions = conditions .. ' ☁☁'
|
elseif weather.weather[1].main == 'Clouds' then
|
||||||
elseif weather.weather[1].main == 'Rain' then
|
conditions = conditions .. ' ☁☁'
|
||||||
conditions = conditions .. ' ☔'
|
elseif weather.weather[1].main == 'Rain' then
|
||||||
elseif weather.weather[1].main == 'Thunderstorm' then
|
conditions = conditions .. ' ☔'
|
||||||
conditions = conditions .. ' ☔☔☔☔'
|
elseif weather.weather[1].main == 'Thunderstorm' then
|
||||||
end
|
conditions = conditions .. ' ☔☔☔☔'
|
||||||
return temp .. '\n' .. conditions
|
end
|
||||||
|
|
||||||
|
return temp .. '\n' .. conditions
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
if string.len(matches[1]) > 2 then
|
if string.len(matches[1]) > 2 then
|
||||||
city = matches[1]
|
city = matches[1]
|
||||||
else
|
else
|
||||||
city = "Madrid,ES"
|
city = "Madrid,ES"
|
||||||
end
|
end
|
||||||
return get_weather(city)
|
return get_weather(city)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "weather in that city (Madrid is default)",
|
description = "weather in that city (Madrid is default)",
|
||||||
usage = "!weather (city)",
|
usage = "!weather (city)",
|
||||||
patterns = {"^!weather(.*)$"},
|
patterns = {"^!weather(.*)$"},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -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
|
||||||
|
|
||||||
@ -43,12 +44,14 @@ function run(msg, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Send comic images from xkcd",
|
description = "Send comic images from xkcd",
|
||||||
usage = {"!xkcd (id): Send an xkcd image and title. If not id, send a random one"},
|
usage = {"!xkcd (id): Send an xkcd image and title. If not id, send a random one"},
|
||||||
patterns = {
|
patterns = {
|
||||||
"^!xkcd$",
|
"^!xkcd$",
|
||||||
"^!xkcd (%d+)",
|
"^!xkcd (%d+)",
|
||||||
"xkcd.com/(%d+)"
|
"xkcd.com/(%d+)"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user