Pfad für getfile.lua nicht mehr hardcodiert (config.lua aktualisieren!)
This commit is contained in:
parent
2c6ece93b5
commit
b28ae66707
@ -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 = "/home/YOURPATH/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,7 +52,7 @@ 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
|
||||||
@ -62,11 +60,17 @@ function media_download:pre_process(msg, self, config)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local save_dir = config.getfile_path
|
||||||
|
if not save_dir then
|
||||||
|
print('getfile_path not set in config, aborting...')
|
||||||
|
return msg
|
||||||
|
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('File has already been downloaded in the past, skipping...')
|
print('File has already been downloaded in the past, skipping...')
|
||||||
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 failed!')
|
print('Download failed!')
|
||||||
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 failed!')
|
print('Download failed!')
|
||||||
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