2016-06-14 15:25:53 +02:00
|
|
|
local media = {}
|
|
|
|
|
2016-09-11 14:07:55 +02:00
|
|
|
local mime = (loadfile "./miku/mimetype.lua")()
|
2016-09-08 15:15:19 +02:00
|
|
|
|
2016-06-14 15:25:53 +02:00
|
|
|
media.triggers = {
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(gif))$",
|
2016-08-01 21:07:27 +02:00
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp4))$",
|
2016-06-14 15:25:53 +02:00
|
|
|
"(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))$",
|
2016-08-01 21:07:27 +02:00
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(avi))$",
|
2016-06-14 15:25:53 +02:00
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wav))$",
|
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(apk))$",
|
2016-07-18 18:37:29 +02:00
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ipa))$",
|
2016-06-14 15:25:53 +02:00
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webm))$",
|
2016-08-01 21:07:27 +02:00
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogv))$",
|
2016-06-14 15:25:53 +02:00
|
|
|
"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webp))$"
|
|
|
|
}
|
|
|
|
|
2016-08-15 23:14:28 +02:00
|
|
|
function media:action(msg, config, matches)
|
2016-06-14 15:25:53 +02:00
|
|
|
local url = matches[1]
|
|
|
|
local ext = matches[2]
|
2016-08-15 23:14:28 +02:00
|
|
|
local mime_type = mime.get_content_type_no_sub(ext)
|
2016-06-14 15:25:53 +02:00
|
|
|
local receiver = msg.chat.id
|
2016-07-23 20:04:22 +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-06-14 15:25:53 +02:00
|
|
|
|
2016-08-24 15:38:29 +02:00
|
|
|
local file, last_modified, nocache = get_cached_file(url, nil, msg.chat.id, chat_action)
|
2016-07-23 20:04:22 +02:00
|
|
|
if not file then return end
|
2016-06-14 15:25:53 +02:00
|
|
|
|
|
|
|
if ext == 'gif' then
|
2016-08-24 15:38:29 +02:00
|
|
|
result = utilities.send_document(receiver, file, nil, msg.message_id)
|
2016-08-01 21:07:27 +02:00
|
|
|
elseif ext == 'ogg' then
|
2016-10-03 21:56:32 +02:00
|
|
|
result = utilities.send_voice(receiver, file, nil, msg.message_id)
|
2016-06-14 15:25:53 +02:00
|
|
|
elseif mime_type == 'audio' then
|
2016-10-03 21:56:32 +02:00
|
|
|
result = utilities.send_audio(receiver, file, nil, msg.message_id)
|
2016-06-14 15:25:53 +02:00
|
|
|
elseif mime_type == 'video' then
|
2016-08-24 15:38:29 +02:00
|
|
|
result = utilities.send_video(receiver, file, nil, msg.message_id)
|
2016-06-14 15:25:53 +02:00
|
|
|
else
|
2016-08-24 15:38:29 +02:00
|
|
|
result = utilities.send_document(receiver, file, nil, msg.message_id)
|
2016-06-14 15:25:53 +02:00
|
|
|
end
|
2016-07-17 13:22:27 +02:00
|
|
|
|
|
|
|
if nocache then return end
|
|
|
|
if not result then return end
|
|
|
|
|
|
|
|
-- Cache File-ID und Last-Modified-Header in Redis
|
|
|
|
cache_file(result, url, last_modified)
|
2016-06-14 15:25:53 +02:00
|
|
|
end
|
|
|
|
|
2016-07-23 20:04:22 +02:00
|
|
|
return media
|