Troubles sending images
This commit is contained in:
parent
e7bc20af3e
commit
6b49398098
@ -1,8 +1,9 @@
|
|||||||
|
do
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
file = download_to_file(matches[1])
|
local url = matches[1]
|
||||||
print("I will send the image " .. file)
|
local receiver = get_receiver(msg)
|
||||||
send_photo(get_receiver(msg), file, ok_cb, false)
|
send_photo_from_url(receiver, url)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -15,3 +16,5 @@ return {
|
|||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
@ -1,27 +1,28 @@
|
|||||||
|
do
|
||||||
|
|
||||||
function getGoogleImage(text)
|
function getGoogleImage(text)
|
||||||
text = URL.escape(text)
|
local text = URL.escape(text)
|
||||||
for i = 1, 5, 1 do -- Try 5 times
|
|
||||||
local api = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q="
|
local api = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q="
|
||||||
b = http.request(api..text)
|
local res, code = http.request(api..text)
|
||||||
local google = json:decode(b)
|
if code ~= 200 then return nil end
|
||||||
|
local google = json:decode(res)
|
||||||
|
|
||||||
if (google.responseStatus == 200) then -- OK
|
if google.responseStatus ~= 200 then
|
||||||
math.randomseed(os.time())
|
return nil
|
||||||
i = math.random(#google.responseData.results) -- Random image from results
|
end
|
||||||
|
|
||||||
|
-- Google response Ok
|
||||||
|
local i = math.random(#google.responseData.results) -- Random image from results
|
||||||
return google.responseData.results[i].url
|
return google.responseData.results[i].url
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
local receiver = get_receiver(msg)
|
local receiver = get_receiver(msg)
|
||||||
local text = msg.text:sub(6,-1)
|
local text = msg.text:sub(6,-1)
|
||||||
local url = getGoogleImage(text)
|
local url = getGoogleImage(text)
|
||||||
local file_path = download_to_file(url)
|
print("Image URL: ", url)
|
||||||
print(file_path)
|
send_photo_from_url(receiver, url)
|
||||||
send_photo(receiver, file_path, ok_cb, false)
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -31,3 +32,4 @@ return {
|
|||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end
|
Reference in New Issue
Block a user