- NEU: post_photo: Downloadet Foto, wenn es als Dokument gesendet wird und sendet es als Foto erneut
- getfile nimmt jetzt den API-Key aus der Config - Venue: Bugfix - Facebook: Bugfix
This commit is contained in:
parent
6eb401d586
commit
83e5f4a85e
@ -43,6 +43,7 @@ function facebook:fb_post (id, story_id)
|
||||
|
||||
local from = data.from.name
|
||||
local message = data.message
|
||||
if not message then return nil end
|
||||
local name = data.name
|
||||
if data.link then
|
||||
link = '\n<a href="'..data.link..'">'..data.name..'</a>'
|
||||
|
@ -1,6 +1,5 @@
|
||||
-- YOU NEED THE FOLLOWING FOLDERS: photo, document, video, voice
|
||||
-- PLEASE ADJUST YOUR PATH BELOW
|
||||
-- Save your bot api key in redis set telegram:credentials!
|
||||
|
||||
local media_download = {}
|
||||
|
||||
@ -34,7 +33,7 @@ function media_download:download_to_file_permanently(url, file_name)
|
||||
return true
|
||||
end
|
||||
|
||||
function media_download:pre_process(msg, self)
|
||||
function media_download:pre_process(msg, self, config)
|
||||
if msg.photo then
|
||||
local lv = #msg.photo -- find biggest photo, always the last value
|
||||
file_id = msg.photo[lv].file_id
|
||||
@ -89,7 +88,7 @@ function media_download:pre_process(msg, self)
|
||||
end
|
||||
|
||||
-- Construct what we want
|
||||
local download_url = 'https://api.telegram.org/file/bot'..cred_data.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)
|
||||
if not ok then
|
||||
print('Download failed!')
|
||||
|
37
otouto/plugins/post_photo.lua
Normal file
37
otouto/plugins/post_photo.lua
Normal file
@ -0,0 +1,37 @@
|
||||
-- This plugin goes through every message with a document and if the document is an image,
|
||||
-- it downloads the file and resends it as image
|
||||
|
||||
local post_photo = {}
|
||||
|
||||
post_photo.triggers = {
|
||||
'/nil'
|
||||
}
|
||||
|
||||
function post_photo:pre_process(msg, self, config)
|
||||
if not msg.document then return msg end -- Ignore
|
||||
local mime_type = msg.document.mime_type
|
||||
if mime_type ~= 'image/jpeg' and mime_type ~= 'image/png' and mime_type ~= 'image/bmp' then return msg end
|
||||
|
||||
local file_id = msg.document.file_id
|
||||
local file_size = msg.document.file_size
|
||||
if file_size > 19922944 then
|
||||
print('File is over 20 MB - can\'t download :(')
|
||||
return
|
||||
end
|
||||
|
||||
-- Saving file to the Telegram Cloud
|
||||
local request = bindings.request(self, 'getFile', {
|
||||
file_id = file_id
|
||||
} )
|
||||
|
||||
local download_url = 'https://api.telegram.org/file/bot'..config.bot_api_key..'/'..request.result.file_path
|
||||
local file = download_to_file(download_url, msg.file_name)
|
||||
utilities.send_photo(self, msg.chat.id, file, msg.caption, msg.message_id)
|
||||
|
||||
return msg
|
||||
end
|
||||
|
||||
function post_photo:action(msg)
|
||||
end
|
||||
|
||||
return post_photo
|
@ -7,7 +7,7 @@ venue.triggers = {
|
||||
local apikey = cred_data.google_apikey
|
||||
|
||||
function venue:pre_process(msg, self)
|
||||
if not msg.venue then return end -- Ignore
|
||||
if not msg.venue then return msg end -- Ignore
|
||||
|
||||
local lat = msg.venue.location.latitude
|
||||
local lng = msg.venue.location.longitude
|
||||
|
Reference in New Issue
Block a user