merge upstream

get_content_type_no_sub
media plugin forces type to upload
This commit is contained in:
Akamaru 2015-04-26 21:19:31 +02:00
parent fe78a49367
commit fa55b0b14a
2 changed files with 70 additions and 34 deletions

View File

@ -3,6 +3,7 @@ do
local mimetype = {} local mimetype = {}
-- TODO: Add more?
local types = { local types = {
["text/html"] = "html", ["text/html"] = "html",
["text/css"] = "css", ["text/css"] = "css",
@ -31,6 +32,7 @@ local types = {
["application/pdf"] = "pdf", ["application/pdf"] = "pdf",
["application/postscript"] = "ps", ["application/postscript"] = "ps",
["application/rtf"] = "rtf", ["application/rtf"] = "rtf",
["application/vnd.android.package-archive"] = "apk",
["application/vnd.ms-excel"] = "xls", ["application/vnd.ms-excel"] = "xls",
["application/vnd.ms-powerpoint"] = "ppt", ["application/vnd.ms-powerpoint"] = "ppt",
["application/vnd.wap.wmlc"] = "wmlc", ["application/vnd.wap.wmlc"] = "wmlc",
@ -72,10 +74,12 @@ local types = {
["video/x-msvideo"] = "avi" ["video/x-msvideo"] = "avi"
} }
-- Returns the common file extension from a content-type
function mimetype.get_mime_extension(content_type) function mimetype.get_mime_extension(content_type)
return types[content_type] return types[content_type]
end end
-- Returns the mimetype and subtype
function mimetype.get_content_type(extension) function mimetype.get_content_type(extension)
for k,v in pairs(types) do for k,v in pairs(types) do
if v == extension then if v == extension then
@ -84,5 +88,15 @@ function mimetype.get_content_type(extension)
end end
end end
-- Returns the mimetype without the subtype
function mimetype.get_content_type_no_sub(extension)
for k,v in pairs(types) do
if v == extension then
-- Before /
return k:match('([%w-]+)/')
end
end
end
return mimetype return mimetype
end end

View File

@ -1,41 +1,63 @@
do do
function run(msg, matches) local function run(msg, matches)
local receiver = get_receiver(msg) local receiver = get_receiver(msg)
local file = download_to_file(matches[1]) local url = matches[1]
send_document(get_receiver(msg), file, ok_cb, false) local ext = matches[2]
local file = download_to_file(url)
local cb_extra = {file_path=file}
local mime_type = mimetype.get_content_type_no_sub(ext)
if ext == 'gif' then
print('send_file')
send_document(receiver, file, rmtmp_cb, cb_extra)
elseif mime_type == 'text' then
print('send_document')
send_document(receiver, file, rmtmp_cb, cb_extra)
elseif mime_type == 'image' then
print('send_photo')
send_photo(receiver, file, rmtmp_cb, cb_extra)
elseif mime_type == 'audio' then
print('send_audio')
send_audio(receiver, file, rmtmp_cb, cb_extra)
elseif mime_type == 'video' then
print('send_video')
send_video(receiver, file, rmtmp_cb, cb_extra)
else
print('send_file')
send_document(receiver, file, rmtmp_cb, cb_extra)
end
end end
return { return {
description = "Wenn ein Link zu einer Datei gesendet wird, läd und sendet der Bot die Datei.", description = "Wenn ein User eine Medien-Datei sendet (gif, mp4, pdf, etc.), wird es gedownloadet und gesendet.",
usage = "Link zur Datei", usage = "",
patterns = { patterns = {
"(https?://[%w-_%.%?%.:/%+=&]+%.gif)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(gif))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.mp4)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(mp4))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.pdf)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(pdf))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.ogg)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(ogg))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.ogv)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(zip))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.oga)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(tar.gz))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.ogx)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(7z))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.zip)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(mp3))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.mp3)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(rar))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.rar)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(wmv))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.wmv)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(doc))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.wma)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(avi))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.doc)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(wav))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.tar.gz)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(apk))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.dlc)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(webm))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.txt)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(ogv))$",
"(https?://[%w-_%.%?%.:/%+=&]+%.deb)$", "(https?://[%w-_%.%?%.:/%+=&]+%.(webp))$"
"(https?://[%w-_%.%?%.:/%+=&]+%.webm)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.avi)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.wav)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.exe)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.rpm)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.dmg)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.apk)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.ipa)$",
"(https?://[%w-_%.%?%.:/%+=&]+%.webp)$"
}, },
run = run run = run
} }