Gif as file

This commit is contained in:
yago 2014-09-24 15:31:25 +02:00
parent 5e2a329f01
commit 8fd79a94e3

View File

@ -15,6 +15,10 @@ function on_msg_receive (msg)
else else
if is_image_url(msg.text) then if is_image_url(msg.text) then
send_image_from_url (msg) send_image_from_url (msg)
else
if is_file_url(msg.text) then
send_file_from_url (msg)
end
end end
end end
@ -42,6 +46,18 @@ function msg_valid(msg)
end end
end end
function send_file_from_url (msg)
last = string.get_last_word(msg.text)
last = last:match("[%w_:/.%%&-]+") -- Lets sanitize!
extension = string.get_extension_from_filename(last)
file_name = string.random(5)
file = "/tmp/"..file_name.."."..extension
sh = "curl --insecure -o '"..file.."' "..last
run_bash(sh)
send_document(get_receiver(msg), file, ok_cb, false)
end
function send_image_from_url (msg) function send_image_from_url (msg)
last = string.get_last_word(msg.text) last = string.get_last_word(msg.text)
last = last:match("[%w_:/.%%&-]+") -- Lets sanitize! last = last:match("[%w_:/.%%&-]+") -- Lets sanitize!
@ -58,7 +74,16 @@ function is_image_url(text)
print ('IS image ' .. text ..'?') print ('IS image ' .. text ..'?')
last = string.get_last_word(text) last = string.get_last_word(text)
extension = string.get_extension_from_filename(last) extension = string.get_extension_from_filename(last)
if extension == 'jpg' or extension == 'png' or extension == 'gif' then if extension == 'jpg' or extension == 'png' then
return true
end
return false
end
function is_file_url(text)
last = string.get_last_word(text)
extension = string.get_extension_from_filename(last)
if extension == 'gif' then
return true return true
end end
return false return false