From 2053f0b3a57e5e0ba6623d414cea0571c6beace1 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Sun, 3 Jul 2016 01:20:04 +0200 Subject: [PATCH] Bot kann jetzt mit File-IDs umgehen (https://core.telegram.org/bots/api#resending-files-without-reuploading) --- otouto/bindings.lua | 19 ++++++++++++------- otouto/utilities.lua | 30 ++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/otouto/bindings.lua b/otouto/bindings.lua index 5d57f7e..1f753ce 100644 --- a/otouto/bindings.lua +++ b/otouto/bindings.lua @@ -27,14 +27,19 @@ function bindings:request(method, parameters, file) parameters[k] = tostring(v) end if file and next(file) ~= nil then - local file_type, file_name = next(file) - local file_file = io.open(file_name, 'r') - local file_data = { - filename = file_name, + local file_type, file_name = next(file) + if string.match(file_name, '/tmp/') then + local file_file = io.open(file_name, 'r') + local file_data = { + filename = file_name, data = file_file:read('*a') - } - file_file:close() - parameters[file_type] = file_data + } + file_file:close() + parameters[file_type] = file_data + else + local file_type, file_name = next(file) + parameters[file_type] = file_name + end end if next(parameters) == nil then parameters = {''} diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 05d40ed..460a00e 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -59,8 +59,10 @@ function utilities:send_photo(chat_id, file, text, reply_to_message_id, reply_ma reply_to_message_id = reply_to_message_id, reply_markup = reply_markup }, {photo = file} ) - os.remove(file) - print("Deleted: "..file) + if string.match(file, '/tmp/') then + os.remove(file) + print("Deleted: "..file) + end return output end @@ -73,8 +75,10 @@ function utilities:send_audio(chat_id, file, reply_to_message_id, duration, perf title = title or nil, reply_to_message_id = reply_to_message_id }, {audio = file} ) - os.remove(file) - print("Deleted: "..file) + if string.match(file, '/tmp/') then + os.remove(file) + print("Deleted: "..file) + end return output end @@ -86,8 +90,10 @@ function utilities:send_document(chat_id, file, text, reply_to_message_id, reply reply_to_message_id = reply_to_message_id, reply_markup = reply_markup }, {document = file} ) - os.remove(file) - print("Deleted: "..file) + if string.match(file, '/tmp/') then + os.remove(file) + print("Deleted: "..file) + end return output end @@ -101,8 +107,10 @@ function utilities:send_video(chat_id, file, text, reply_to_message_id, duration height = height or nil, reply_to_message_id = reply_to_message_id }, {video = file} ) - os.remove(file) - print("Deleted: "..file) + if string.match(file, '/tmp/') then + os.remove(file) + print("Deleted: "..file) + end return output end @@ -114,8 +122,10 @@ function utilities:send_voice(chat_id, file, text, reply_to_message_id, duration duration = duration or nil, reply_to_message_id = reply_to_message_id }, {voice = file} ) - os.remove(file) - print("Deleted: "..file) + if string.match(file, '/tmp/') then + os.remove(file) + print("Deleted: "..file) + end return output end