Integriere Telegram-Funktionen, wie sendPhoto, sendVideo, sendDocument, etc. in utilites.lua und update alle Plugins, damit sie diese Funktion nutzen

This commit is contained in:
Andreas Bielawski 2016-06-12 20:53:20 +02:00
parent df96462d03
commit 306782496e
6 changed files with 109 additions and 16 deletions

View File

@ -26,6 +26,7 @@ function ninegag:get_9GAG()
end end
function ninegag:action(msg, config) function ninegag:action(msg, config)
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local url, title = ninegag:get_9GAG() local url, title = ninegag:get_9GAG()
if not url then if not url then
utilities.send_reply(self, msg, config.errors.connection) utilities.send_reply(self, msg, config.errors.connection)
@ -33,9 +34,7 @@ function ninegag:action(msg, config)
end end
local file = download_to_file(url) local file = download_to_file(url)
bindings.sendPhoto(self, {chat_id = msg.chat.id, caption = title}, {photo = file} ) utilities.send_photo(self, msg.chat.id, file, title)
os.remove(file)
print("Deleted: "..file)
end end
return ninegag return ninegag

View File

@ -47,6 +47,7 @@ function gImages:action(msg, config)
return return
end end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local apikey = cred_data.google_apikey local apikey = cred_data.google_apikey
local cseid = cred_data.google_cse_id local cseid = cred_data.google_cse_id
local BASE_URL = 'https://www.googleapis.com/customsearch/v1' local BASE_URL = 'https://www.googleapis.com/customsearch/v1'
@ -68,9 +69,7 @@ function gImages:action(msg, config)
local img_url = jdat.items[i].link local img_url = jdat.items[i].link
local file = download_to_file(img_url) local file = download_to_file(img_url)
bindings.sendPhoto(self, {chat_id = msg.chat.id, caption = img_url}, {photo = file} ) utilities.send_photo(self, msg.chat.id, file, img_url)
os.remove(file)
print("Deleted: "..file)
end end
return gImages return gImages

View File

@ -51,7 +51,7 @@ function imdb:action(msg, config)
if jdat.Poster ~= "N/A" then if jdat.Poster ~= "N/A" then
local file = download_to_file(jdat.Poster) local file = download_to_file(jdat.Poster)
bindings.sendPhoto(self, {chat_id = msg.chat.id}, {photo = file} ) utilities.send_photo(self, msg.chat.id, file)
end end
end end

View File

@ -140,15 +140,11 @@ function twitter:action(msg)
utilities.send_reply(self, msg, header .. "\n" .. text.."\n"..footer) utilities.send_reply(self, msg, header .. "\n" .. text.."\n"..footer)
for k, v in pairs(images) do for k, v in pairs(images) do
local file = download_to_file(v) local file = download_to_file(v)
bindings.sendPhoto(self, {chat_id = msg.chat.id}, {photo = file} ) utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
os.remove(file)
print("Deleted: "..file)
end end
for k, v in pairs(videos) do for k, v in pairs(videos) do
local file = download_to_file(v) local file = download_to_file(v)
bindings.sendVideo(self, {chat_id = msg.chat.id}, {video = file} ) utilities.send_video(self, msg.chat.id, file, nil, msg.message_id)
os.remove(file)
print("Deleted: "..file)
end end
end end

View File

@ -142,9 +142,7 @@ function send_youtube_data(data, msg, self, link, sendpic)
text = text..'\nACHTUNG, In Deutschland gesperrt!' text = text..'\nACHTUNG, In Deutschland gesperrt!'
end end
local file = download_to_file(image_url) local file = download_to_file(image_url)
bindings.sendPhoto(self, {chat_id = msg.chat.id, reply_to_message_id = msg.message_id, caption = text }, {photo = file} ) utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
os.remove(file)
print("Deleted: "..file)
else else
utilities.send_reply(self, msg, text, true) utilities.send_reply(self, msg, text, true)
end end

View File

@ -34,6 +34,107 @@ function utilities:send_reply(old_msg, text, use_markdown)
parse_mode = use_markdown and 'Markdown' or nil parse_mode = use_markdown and 'Markdown' or nil
} ) } )
end end
-- NOTE: Telegram currently only allows file uploads up to 50 MB
-- https://core.telegram.org/bots/api#sendphoto
function utilities:send_photo(chat_id, file, text, reply_to_message_id)
local output = bindings.request(self, 'sendPhoto', {
chat_id = chat_id,
caption = text or nil,
reply_to_message_id = reply_to_message_id
}, {photo = file} )
os.remove(file)
print("Deleted: "..file)
return output
end
-- https://core.telegram.org/bots/api#sendaudio
function utilities:send_audio(chat_id, file, text, reply_to_message_id, duration, performer, title)
local output = bindings.request(self, 'sendAudio', {
chat_id = chat_id,
caption = text or nil,
duration = duration or nil,
performer = performer or nil,
title = title or nil,
reply_to_message_id = reply_to_message_id
}, {audio = file} )
os.remove(file)
print("Deleted: "..file)
return output
end
-- https://core.telegram.org/bots/api#senddocument
function utilities:send_document(chat_id, file, text, reply_to_message_id)
local output = bindings.request(self, 'sendDocument', {
chat_id = chat_id,
caption = text or nil,
reply_to_message_id = reply_to_message_id
}, {document = file} )
os.remove(file)
print("Deleted: "..file)
return output
end
-- https://core.telegram.org/bots/api#sendvideo
function utilities:send_video(chat_id, file, text, reply_to_message_id, duration, width, height)
local output = bindings.request(self, 'sendVideo', {
chat_id = chat_id,
caption = text or nil,
duration = duration or nil,
width = width or nil,
height = height or nil,
reply_to_message_id = reply_to_message_id
}, {video = file} )
os.remove(file)
print("Deleted: "..file)
return output
end
-- NOTE: Voice messages are .ogg files encoded with OPUS
-- https://core.telegram.org/bots/api#sendvoice
function utilities:send_voice(chat_id, file, text, reply_to_message_id, duration)
local output = bindings.request(self, 'sendVoice', {
chat_id = chat_id,
duration = duration or nil,
reply_to_message_id = reply_to_message_id
}, {voice = file} )
os.remove(file)
print("Deleted: "..file)
return output
end
-- https://core.telegram.org/bots/api#sendlocation
function utilities:send_location(chat_id, latitude, longitude, reply_to_message_id)
return bindings.request(self, 'sendLocation', {
chat_id = chat_id,
latitude = latitude,
longitude = longitude,
reply_to_message_id = reply_to_message_id
} )
end
-- NOTE: Venue is different from location: it shows information, such as the street adress or
-- title of the location with it.
-- https://core.telegram.org/bots/api#sendvenue
function utilities:send_venue(chat_id, latitude, longitude, reply_to_message_id, title, address)
return bindings.request(self, 'sendVenue', {
chat_id = chat_id,
latitude = latitude,
longitude = longitude,
title = title,
address = address,
reply_to_message_id = reply_to_message_id
} )
end
-- https://core.telegram.org/bots/api#sendchataction
function utilities:send_typing(chat_id, action)
return bindings.request(self, 'sendChatAction', {
chat_id = chat_id,
action = action
} )
end
-- get the indexed word in a string -- get the indexed word in a string
function utilities.get_word(s, i) function utilities.get_word(s, i)
s = s or '' s = s or ''