Merge Upstream
This commit is contained in:
commit
59537c6574
@ -25,6 +25,10 @@ Sende /hilfe, um zu starten
|
|||||||
-- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted!
|
-- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted!
|
||||||
enable_inline_for_everyone = true,
|
enable_inline_for_everyone = true,
|
||||||
|
|
||||||
|
-- Path, where getFile.lua should store the files WITHOUT an ending slash!
|
||||||
|
-- Create the following folders in this folder: photo, document, video, voice
|
||||||
|
getfile_path = '/tmp/telegram_files',
|
||||||
|
|
||||||
-- Redis settings. Only edit if you know what you're doing.
|
-- Redis settings. Only edit if you know what you're doing.
|
||||||
redis = {
|
redis = {
|
||||||
host = '127.0.0.1',
|
host = '127.0.0.1',
|
||||||
|
@ -7,7 +7,7 @@ media_download.triggers = {
|
|||||||
'/nil'
|
'/nil'
|
||||||
}
|
}
|
||||||
|
|
||||||
function media_download:download_to_file_permanently(url, file_name)
|
function media_download:download_to_file_permanently(url, save_dir, file_name)
|
||||||
local respbody = {}
|
local respbody = {}
|
||||||
local options = {
|
local options = {
|
||||||
url = url,
|
url = url,
|
||||||
@ -23,9 +23,7 @@ function media_download:download_to_file_permanently(url, file_name)
|
|||||||
|
|
||||||
if code ~= 200 then return false end
|
if code ~= 200 then return false end
|
||||||
|
|
||||||
-- TODO: Save, when folder doesn't exist
|
local file_path = save_dir..'/'..file_name
|
||||||
-- Create necessary folders in this folder!
|
|
||||||
local file_path = "tmp/"..file_name
|
|
||||||
file = io.open(file_path, "w+")
|
file = io.open(file_path, "w+")
|
||||||
file:write(table.concat(respbody))
|
file:write(table.concat(respbody))
|
||||||
file:close()
|
file:close()
|
||||||
@ -54,19 +52,25 @@ function media_download:pre_process(msg, self, config)
|
|||||||
file_id = msg.document.file_id
|
file_id = msg.document.file_id
|
||||||
file_size = msg.document.file_size
|
file_size = msg.document.file_size
|
||||||
else
|
else
|
||||||
return
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
if file_size > 19922944 then
|
if file_size > 19922944 then
|
||||||
print('Datei ist größer als 20 MB - Nicht downloadbar!')
|
print('Datei ist größer als 20 MB - Nicht downloadbar!')
|
||||||
return
|
return msg
|
||||||
|
end
|
||||||
|
|
||||||
|
local save_dir = config.getfile_path
|
||||||
|
if not save_dir then
|
||||||
|
print('getfile_path wurde nicht in der Config gesetzt, breche ab...')
|
||||||
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if file has already been downloaded
|
-- Check if file has already been downloaded
|
||||||
local already_downloaded = redis:sismember('telegram:file_id', file_id)
|
local already_downloaded = redis:sismember('telegram:file_id', file_id)
|
||||||
if already_downloaded == true then
|
if already_downloaded == true then
|
||||||
print('Datei wurde bereits gedownloadet')
|
print('Datei wurde bereits gedownloadet')
|
||||||
return
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Saving file to the Telegram Cloud
|
-- Saving file to the Telegram Cloud
|
||||||
@ -77,7 +81,7 @@ function media_download:pre_process(msg, self, config)
|
|||||||
-- Getting file from the Telegram Cloud
|
-- Getting file from the Telegram Cloud
|
||||||
if not request then
|
if not request then
|
||||||
print('Download fehlgeschlagen!')
|
print('Download fehlgeschlagen!')
|
||||||
return
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use original filename for documents
|
-- Use original filename for documents
|
||||||
@ -89,10 +93,11 @@ function media_download:pre_process(msg, self, config)
|
|||||||
|
|
||||||
-- Construct what we want
|
-- Construct what we want
|
||||||
local download_url = 'https://api.telegram.org/file/bot'..config.bot_api_key..'/'..request.result.file_path
|
local download_url = 'https://api.telegram.org/file/bot'..config.bot_api_key..'/'..request.result.file_path
|
||||||
local ok = media_download:download_to_file_permanently(download_url, file_path)
|
|
||||||
|
local ok = media_download:download_to_file_permanently(download_url, save_dir, file_path)
|
||||||
if not ok then
|
if not ok then
|
||||||
print('Download fehlgeschlagen!')
|
print('Download fehlgeschlagen!')
|
||||||
return
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save file_id to redis to prevent downloading the same file over and over when forwarding
|
-- Save file_id to redis to prevent downloading the same file over and over when forwarding
|
||||||
|
Reference in New Issue
Block a user