Übernehme Änderungen von Brawl345/Brawlbot-v2

This commit is contained in:
Akamaru 2016-07-20 21:19:06 +02:00
parent dff2efba46
commit ed4026fd32
3 changed files with 47 additions and 24 deletions

View File

@ -22,13 +22,13 @@ end
local apikey = cred_data.google_apikey local apikey = cred_data.google_apikey
local BASE_URL = 'https://www.googleapis.com/drive/v2' local BASE_URL = 'https://www.googleapis.com/drive/v3'
local apikey = cred_data.google_apikey
function gdrive:get_drive_document_data (docid) function gdrive:get_drive_document_data (docid)
local apikey = cred_data.google_apikey local url = BASE_URL..'/files/'..docid..'?key='..apikey..'&fields=id,name,mimeType,owners,fullFileExtension'
local url = BASE_URL..'/files/'..docid..'?key='..apikey..'&fields=id,title,mimeType,ownerNames,exportLinks,fileExtension' local res, code = https.request(url)
local res,code = https.request(url) local res = string.gsub(res, 'image/', '') -- snip mimetype
local res = string.gsub(res, 'image/', '')
local res = string.gsub(res, 'application/', '') local res = string.gsub(res, 'application/', '')
if code ~= 200 then return nil end if code ~= 200 then return nil end
local data = json.decode(res) local data = json.decode(res)
@ -36,28 +36,29 @@ function gdrive:get_drive_document_data (docid)
end end
function gdrive:send_drive_document_data(data, self, msg) function gdrive:send_drive_document_data(data, self, msg)
local title = data.title local title = data.name
local mimetype = data.mimeType local mimetype = data.mimeType
local id = data.id local id = data.id
local owner = data.ownerNames[1] local owner = data.owners[1].displayName
local text = '"'..title..'", freigegeben von '..owner local text = '"'..title..'", freigegeben von '..owner
if data.exportLinks then if mimetype:match('google') then -- if document is Google document (like a Spreadsheet)
if data.exportLinks.png then if mimetype:match('drawing') then -- Drawing
local image_url = data.exportLinks.png local image_url = BASE_URL..'/files/'..id..'/export?key='..apikey..'&mimeType=image/png'
utilities.send_typing(self, msg.chat.id, 'upload_photo') utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(image_url) local file = download_to_file(image_url, 'export.png')
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
return return
else else
local pdf_url = data.exportLinks.pdf local pdf_url = BASE_URL..'/files/'..id..'/export?key='..apikey..'&mimeType=application/pdf'
utilities.send_typing(self, msg.chat.id, 'upload_document') utilities.send_typing(self, msg.chat.id, 'upload_document')
local file = download_to_file(pdf_url) local file = download_to_file(pdf_url, 'document.pdf')
utilities.send_document(self, msg.chat.id, file, text, msg.message_id) utilities.send_document(self, msg.chat.id, file, text, msg.message_id)
return return
end end
else else
local get_file_url = 'https://drive.google.com/uc?id='..id local get_file_url = 'https://drive.google.com/uc?id='..id
local ext = data.fileExtension local keyboard = '{"inline_keyboard":[[{"text":"Direktlink","url":"'..get_file_url..'"}]]}'
local ext = data.fullFileExtension
if mimetype == "png" or mimetype == "jpg" or mimetype == "jpeg" or mimetype == "gif" or mimetype == "webp" then if mimetype == "png" or mimetype == "jpg" or mimetype == "jpeg" or mimetype == "gif" or mimetype == "webp" then
local respbody = {} local respbody = {}
local options = { local options = {
@ -71,18 +72,18 @@ function gdrive:send_drive_document_data(data, self, msg)
local file_url = headers.location local file_url = headers.location
if ext == "jpg" or ext == "jpeg" or ext == "png" then if ext == "jpg" or ext == "jpeg" or ext == "png" then
utilities.send_typing(self, msg.chat.id, 'upload_photo') utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(file_url) local file = download_to_file(file_url, 'photo.'..ext)
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) utilities.send_photo(self, msg.chat.id, file, text, msg.message_id, keyboard)
return return
else else
utilities.send_typing(self, msg.chat.id, 'upload_document') utilities.send_typing(self, msg.chat.id, 'upload_document')
local file = download_to_file(file_url) local file = download_to_file(file_url, 'document.'..ext)
utilities.send_document(self, msg.chat.id, file, text, msg.message_id) utilities.send_document(self, msg.chat.id, file, text, msg.message_id, keyboard)
return return
end end
else else
local text = '*'..title..'*, freigegeben von _'..owner..'_\n[Direktlink]('..get_file_url..')' local text = '*'..title..'*, freigegeben von _'..owner..'_'
utilities.send_reply(self, msg, text, true) utilities.send_reply(self, msg, text, true, keyboard)
return return
end end
end end

View File

@ -22,10 +22,32 @@ function respond:init(config)
"^%(([Ii][Nn][Ll][Oo][Vv][Ee])%)$", "^%(([Ii][Nn][Ll][Oo][Vv][Ee])%)$",
"^/[Ww][Aa][Tt]$" "^/[Ww][Aa][Tt]$"
} }
respond.inline_triggers = {
"^([Ll][Oo][Dd])$",
"^([Ll][Ff])$",
"^([Kk][Aa])$",
"^([Ii][Dd][Kk])$",
"^([Nn][Bb][Cc])$",
"^([Ii][Dd][Cc])$",
}
end end
respond.command = 'lod, /lf, /nbc, /wat' respond.command = 'lod, /lf, /nbc, /wat'
function respond:inline_callback(inline_query, config, matches)
local text = matches[1]
if string.match(text, "[Ll][Oo][Dd]") then
face = 'ಠ_ಠ'
elseif string.match(text, "[Ll][Ff]") then
face = '( ͡° ͜ʖ ͡°)'
elseif string.match(text, "[Nn][Bb][Cc]") or string.match(text, "[Ii][Dd][Cc]") or string.match(text, "[Kk][Aa]") or string.match(text, "[Ii][Dd][Kk]") then
face = '¯\\\\\\_(ツ)_/¯'
end
results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..face..'","input_message_content":{"message_text":"'..face..'"}}]'
utilities.answer_inline_query(self, inline_query, results, 9999)
end
function respond:action(msg, config, matches) function respond:action(msg, config, matches)
local user_name = get_name(msg) local user_name = get_name(msg)
local receiver = msg.chat.id local receiver = msg.chat.id

View File

@ -10,7 +10,7 @@ function set:init(config)
set.doc = [[* set.doc = [[*
]]..config.cmd_pat..[[set* _<Variable>_ _<Wert>_: Speichert eine Variable mit einem Wert ]]..config.cmd_pat..[[set* _<Variable>_ _<Wert>_: Speichert eine Variable mit einem Wert
*]]..config.cmd_pat..[[set* _<Variable>_ _nil_: Löscht Variable *]]..config.cmd_pat..[[set* _<Variable>_ _nil_: Löscht Variable
Nutze `!get <Variable>` zum Abrufen]] Nutze `/get <Variable>` zum Abrufen]]
end end
function set:save_value(msg, name, value) function set:save_value(msg, name, value)