2016-06-14 15:25:53 +02:00
|
|
|
local media = {}
|
|
|
|
|
2016-08-01 16:18:02 +02:00
|
|
|
mimetype = (loadfile "./otouto/mimetype.lua")()
|
|
|
|
|
2016-06-14 15:25:53 +02:00
|
|
|
media.triggers = {
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(gif))$",
|
|
|
|
"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp4))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(pdf))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogg))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(zip))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(tar.gz))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(7z))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp3))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(rar))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wmv))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(doc))$",
|
|
|
|
"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(avi))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wav))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(apk))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webm))$",
|
|
|
|
"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogv))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webp))$"
|
|
|
|
}
|
|
|
|
|
|
|
|
function media:action(msg)
|
|
|
|
local url = matches[1]
|
|
|
|
local ext = matches[2]
|
2016-07-23 13:58:15 +02:00
|
|
|
local mime_type = mimetype.get_content_type_no_sub(ext)
|
2016-06-14 15:25:53 +02:00
|
|
|
local receiver = msg.chat.id
|
2016-07-23 13:58:15 +02:00
|
|
|
|
|
|
|
if mime_type == 'audio' then
|
|
|
|
chat_action = 'upload_audio'
|
|
|
|
elseif mime_type == 'video' then
|
|
|
|
chat_action = 'upload_video'
|
|
|
|
else
|
|
|
|
chat_action = 'upload_document'
|
|
|
|
end
|
2016-07-03 13:02:54 +02:00
|
|
|
|
2016-07-23 13:58:15 +02:00
|
|
|
local file, last_modified, nocache = get_cached_file(url, nil, msg.chat.id, chat_action, self)
|
|
|
|
if not file then return end
|
2016-06-14 15:25:53 +02:00
|
|
|
|
|
|
|
if ext == 'gif' then
|
|
|
|
print('send gif')
|
2016-07-03 13:02:54 +02:00
|
|
|
result = utilities.send_document(self, receiver, file, nil, msg.message_id)
|
2016-08-01 16:38:52 +02:00
|
|
|
elseif ext == 'ogg' then
|
|
|
|
print('send ogg')
|
|
|
|
result = utilities.send_voice(self, receiver, file, nil, msg.message_id)
|
2016-06-14 15:25:53 +02:00
|
|
|
elseif mime_type == 'audio' then
|
|
|
|
print('send_audio')
|
2016-07-03 13:02:54 +02:00
|
|
|
result = utilities.send_audio(self, receiver, file, nil, msg.message_id)
|
2016-06-14 15:25:53 +02:00
|
|
|
elseif mime_type == 'video' then
|
|
|
|
print('send_video')
|
2016-07-03 13:02:54 +02:00
|
|
|
result = utilities.send_video(self, receiver, file, nil, msg.message_id)
|
2016-06-14 15:25:53 +02:00
|
|
|
else
|
|
|
|
print('send_file')
|
2016-07-03 13:02:54 +02:00
|
|
|
result = utilities.send_document(self, receiver, file, nil, msg.message_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
if nocache then return end
|
|
|
|
if not result then return end
|
|
|
|
|
|
|
|
-- Cache File-ID und Last-Modified-Header in Redis
|
2016-07-05 19:21:37 +02:00
|
|
|
cache_file(result, url, last_modified)
|
2016-06-14 15:25:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return media
|