diff --git a/miku/plugins/gdrive.lua b/miku/plugins/gdrive.lua index a9158d9..00bc78b 100644 --- a/miku/plugins/gdrive.lua +++ b/miku/plugins/gdrive.lua @@ -22,13 +22,13 @@ end 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) - local apikey = cred_data.google_apikey - local url = BASE_URL..'/files/'..docid..'?key='..apikey..'&fields=id,title,mimeType,ownerNames,exportLinks,fileExtension' - local res,code = https.request(url) - local res = string.gsub(res, 'image/', '') + local url = BASE_URL..'/files/'..docid..'?key='..apikey..'&fields=id,name,mimeType,owners,fullFileExtension' + local res, code = https.request(url) + local res = string.gsub(res, 'image/', '') -- snip mimetype local res = string.gsub(res, 'application/', '') if code ~= 200 then return nil end local data = json.decode(res) @@ -36,28 +36,29 @@ function gdrive:get_drive_document_data (docid) end function gdrive:send_drive_document_data(data, self, msg) - local title = data.title + local title = data.name local mimetype = data.mimeType local id = data.id - local owner = data.ownerNames[1] + local owner = data.owners[1].displayName local text = '"'..title..'", freigegeben von '..owner - if data.exportLinks then - if data.exportLinks.png then - local image_url = data.exportLinks.png + if mimetype:match('google') then -- if document is Google document (like a Spreadsheet) + if mimetype:match('drawing') then -- Drawing + local image_url = BASE_URL..'/files/'..id..'/export?key='..apikey..'&mimeType=image/png' utilities.send_typing(self, msg.chat.id, 'upload_photo') - local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + local file = download_to_file(image_url, 'export.png') + utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) return 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') - local file = download_to_file(pdf_url) - utilities.send_document(self, msg.chat.id, file, text, msg.message_id) + local file = download_to_file(pdf_url, 'document.pdf') + utilities.send_document(self, msg.chat.id, file, text, msg.message_id) return end else - local get_file_url = 'https://drive.google.com/uc?id='..id - local ext = data.fileExtension + local get_file_url = 'https://drive.google.com/uc?id='..id + 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 local respbody = {} local options = { @@ -71,18 +72,18 @@ function gdrive:send_drive_document_data(data, self, msg) local file_url = headers.location if ext == "jpg" or ext == "jpeg" or ext == "png" then utilities.send_typing(self, msg.chat.id, 'upload_photo') - local file = download_to_file(file_url) - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + local file = download_to_file(file_url, 'photo.'..ext) + utilities.send_photo(self, msg.chat.id, file, text, msg.message_id, keyboard) return else utilities.send_typing(self, msg.chat.id, 'upload_document') - local file = download_to_file(file_url) - utilities.send_document(self, msg.chat.id, file, text, msg.message_id) + local file = download_to_file(file_url, 'document.'..ext) + utilities.send_document(self, msg.chat.id, file, text, msg.message_id, keyboard) return end else - local text = '*'..title..'*, freigegeben von _'..owner..'_\n[Direktlink]('..get_file_url..')' - utilities.send_reply(self, msg, text, true) + local text = '*'..title..'*, freigegeben von _'..owner..'_' + utilities.send_reply(self, msg, text, true, keyboard) return end end diff --git a/miku/plugins/respond.lua b/miku/plugins/respond.lua index 7b5f636..8cd49ba 100644 --- a/miku/plugins/respond.lua +++ b/miku/plugins/respond.lua @@ -22,10 +22,32 @@ function respond:init(config) "^%(([Ii][Nn][Ll][Oo][Vv][Ee])%)$", "^/[Ww][Aa][Tt]$" } + + respond.inline_triggers = { + "^([Ll][Oo][Dd])$", + "^([Ll][Ff])$", + "^([Kk][Aa])$", + "^([Ii][Dd][Kk])$", + "^([Nn][Bb][Cc])$", + "^([Ii][Dd][Cc])$", + } end 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) local user_name = get_name(msg) local receiver = msg.chat.id diff --git a/miku/plugins/set.lua b/miku/plugins/set.lua index b3c20a3..63870ba 100644 --- a/miku/plugins/set.lua +++ b/miku/plugins/set.lua @@ -10,7 +10,7 @@ function set:init(config) set.doc = [[* ]]..config.cmd_pat..[[set* __ __: Speichert eine Variable mit einem Wert *]]..config.cmd_pat..[[set* __ _nil_: Löscht Variable -Nutze `!get ` zum Abrufen]] +Nutze `/get ` zum Abrufen]] end function set:save_value(msg, name, value)