diff --git a/README.md b/README.md index be0c44e..4c8071d 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,8 @@ Einige Funktionen, die oft benötigt werden, sind in `utilites.lua` verfügbar. ## Bindings **Diese Sektion wurde noch nicht lokalisiert.** -Calls to the Telegram bot API are performed with the `bindings.lua` file through the multipart-post library. otouto's bindings file supports all standard API methods and all arguments. Its main function, `bindings.request`, accepts four arguments: `self`, `method`, `parameters`, `file`. (At the very least, `self` should be a table containing `BASE_URL`, which is bot's API endpoint, ending with a slash, eg `https://api.telegram.org/bot123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ987654321/`.) + +Calls to the Telegram bot API are performed with the `bindings.lua` file through the multipart-post library. otouto's bindings file supports all standard API methods and all arguments. Its main function, `bindings.request`, accepts three arguments: `method`, `parameters`, `file`. Before using it, initialize the bindings module with its `init` function, passing your bot token as the argument. `method` is the name of the API method. `parameters` (optional) is a table of key/value pairs of the method's parameters to be sent with the method. `file` (super-optional) is a table of a single key/value pair, where the key is the name of the parameter and the value is the filename (if these are included in `parameters` instead, otouto will attempt to send the filename as a file ID). @@ -114,45 +115,41 @@ Additionally, any method can be called as a key in the `bindings` table (for exa ``` bindings.request( - self, - 'sendMessage', - { - chat_id = 987654321, - text = 'Quick brown fox.', - reply_to_message_id = 54321, - disable_web_page_preview = false, - parse_method = 'Markdown' - } + 'sendMessage', + { + chat_id = 987654321, + text = 'Quick brown fox.', + reply_to_message_id = 54321, + disable_web_page_preview = false, + parse_method = 'Markdown' + } ) -bindings.sendMessage( - self, - { - chat_id = 987654321, - text = 'Quick brown fox.', - reply_to_message_id = 54321, - disable_web_page_preview = false, - parse_method = 'Markdown' - } -) +bindings.sendMessage{ + chat_id = 987654321, + text = 'Quick brown fox.', + reply_to_message_id = 54321, + disable_web_page_preview = false, + parse_method = 'Markdown' +} ``` Furthermore, `utilities.lua` provides two "shortcut" functions to mimic the behavior of otouto's old bindings: `send_message` and `send_reply`. `send_message` accepts these arguments: `self`, `chat_id`, `text`, `disable_web_page_preview`, `reply_to_message_id`, `use_markdown`. The following function call is equivalent to the two above: ``` -utilities.send_message(self, 987654321, 'Quick brown fox.', false, 54321, true) +utilities.send_message(987654321, 'Quick brown fox.', false, 54321, true) ``` Uploading a file for the `sendPhoto` method would look like this: ``` -bindings.sendPhoto(self, { chat_id = 987654321 }, { photo = 'rarepepe.jpg' } ) +bindings.sendPhoto({ chat_id = 987654321 }, { photo = 'dankmeme.jpg' } ) ``` and using `sendPhoto` with a file ID would look like this: ``` -bindings.sendPhoto(self, { chat_id = 987654321, photo = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789' } ) +bindings.sendPhoto{ chat_id = 987654321, photo = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789' } ``` Upon success, bindings will return the deserialized result from the API. Upon failure, it will return false and the result. In the case of a connection error, it will return two false values. If an invalid method name is given, bindings will throw an exception. This is to mimic the behavior of more conventional bindings as well as to prevent "silent errors". diff --git a/miku/bindings.lua b/miku/bindings.lua index 68739d2..982ea91 100644 --- a/miku/bindings.lua +++ b/miku/bindings.lua @@ -1,9 +1,23 @@ --[[ - bindings.lua (rev. 2016/05/28) - otouto's bindings for the Telegram bot API. - https://core.telegram.org/bots/api - Copyright 2016 topkecleon. Published under the AGPLv3. - See the "Bindings" section of README.md for usage information. + bindings.lua (rev. 2016/08/20) + otouto's bindings for the Telegram bot API. + https://core.telegram.org/bots/api + See the "Bindings" section of README.md for usage information. + + Copyright 2016 topkecleon + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License version 3 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ]]-- local bindings = {} @@ -14,6 +28,11 @@ local JSON = require('dkjson') local ltn12 = require('ltn12') local MP_ENCODE = require('multipart-post').encode +function bindings.init(token) + bindings.BASE_URL = 'https://api.telegram.org/bot' .. token .. '/' + return bindings +end + -- Build and send a request to the API. -- Expecting self, method, and parameters, where method is a string indicating -- the API method and parameters is a key/value table of parameters with their @@ -21,7 +40,7 @@ local MP_ENCODE = require('multipart-post').encode -- Returns the table response with success. Returns false and the table -- response with failure. Returns false and false with a connection error. -- To mimic old/normal behavior, it errs if used with an invalid method. -function bindings:request(method, parameters, file) +function bindings.request(method, parameters, file) parameters = parameters or {} for k,v in pairs(parameters) do parameters[k] = tostring(v) @@ -48,7 +67,7 @@ function bindings:request(method, parameters, file) local response = {} local body, boundary = MP_ENCODE(parameters) local success, code = HTTPS.request{ - url = self.BASE_URL .. method, + url = bindings.BASE_URL .. method, method = 'POST', headers = { ["Content-Type"] = "multipart/form-data; boundary=" .. boundary, @@ -75,8 +94,8 @@ function bindings:request(method, parameters, file) end function bindings.gen(_, key) - return function(self, params, file) - return bindings.request(self, key, params, file) + return function(params, file) + return bindings.request(key, params, file) end end setmetatable(bindings, { __index = bindings.gen }) diff --git a/miku/bot.lua b/miku/bot.lua index e6c69e5..ce095ab 100644 --- a/miku/bot.lua +++ b/miku/bot.lua @@ -1,23 +1,39 @@ +--[[ + bot.lua + The heart and sole of otouto, ie the init and main loop. + + Copyright 2016 topkecleon + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License version 3 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +]]-- + local bot = {} bindings = require('miku.bindings') utilities = require('miku.utilities') -bot.version = '160823' +bot.version = '160824' function bot:init(config) -- The function run when the bot is started or reloaded. + bindings = require('otouto.bindings').init(config.bot_api_key) + utilities = require('otouto.utilities') cred_data = load_cred() - assert( - config.bot_api_key, - 'You did not set your bot token in the config!' - ) - self.BASE_URL = 'https://api.telegram.org/bot' .. config.bot_api_key .. '/' - -- Fetch bot information. Try until it succeeds. repeat print('Sammel Bot-Informationen...') - self.info = bindings.getMe(self) + self.info = bindings.getMe() until self.info self.info = self.info.result @@ -87,7 +103,7 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba -- vardump(callback) if msg.date < os.time() - 1800 then -- Do not process old messages. - utilities.answer_callback_query(self, callback, 'Nachricht älter als eine halbe Stunde, bitte sende den Befehl selbst noch einmal.', true) + utilities.answer_callback_query(callback, 'Nachricht älter als eine halbe Stunde, bitte sende den Befehl selbst noch einmal.', true) return end @@ -99,14 +115,14 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba local user_id = callback.from.id local chat_id = msg.chat.id if redis:get('blocked:'..user_id) then - utilities.answer_callback_query(self, callback, 'Du darfst den Bot nicht nutzen!', true) + utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true) return end -- Check if user is banned local banned = redis:get('banned:'..chat_id..':'..user_id) if banned then - utilities.answer_callback_query(self, callback, 'Du darfst den Bot nicht nutzen!', true) + utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true) return end @@ -119,11 +135,11 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then local allowed = redis:get('whitelist:chat#id'.. chat_id) if not allowed then - utilities.answer_callback_query(self, callback, 'Du darfst den Bot nicht nutzen!', true) + utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true) return end else - utilities.answer_callback_query(self, callback, 'Du darfst den Bot nicht nutzen!', true) + utilities.answer_callback_query(callback, 'Du darfst den Bot nicht nutzen!', true) return end end @@ -156,13 +172,13 @@ function bot:process_inline_query(inline_query, config) -- When an inline query -- but he WON'T be able to make new requests. local user_id = inline_query.from.id if redis:get('blocked:'..user_id) then - utilities.answer_inline_query(self, inline_query, nil, 0, true) + abort_inline_query(inline_query) return end if not config.enable_inline_for_everyone then local is_whitelisted = redis:get('whitelist:user#id'..inline_query.from.id) - if not is_whitelisted then utilities.answer_inline_query(self, inline_query, nil, 0, true) return end + if not is_whitelisted then abort_inline_query(inline_query) return end end if inline_query.query:match('"') then @@ -175,7 +191,7 @@ function bot:process_inline_query(inline_query, config) -- When an inline query end -- Stop the spinning circle - utilities.answer_inline_query(self, inline_query, nil, 0, true) + abort_inline_query(inline_query) end function bot:run(config) @@ -183,7 +199,7 @@ function bot:run(config) while self.is_started do -- Update loop - local res = bindings.getUpdates(self, { timeout = 20, offset = self.last_update+1 } ) + local res = bindings.getUpdates{ timeout = 20, offset = self.last_update+1 } if res then -- Iterate over every new message. for n=1, #res.result do @@ -210,7 +226,7 @@ function bot:run(config) if v.cron then -- Call each plugin's cron function, if it has one. local result, err = pcall(function() v.cron(self, config) end) if not result then - utilities.handle_exception(self, err, 'CRON: ' .. n, config) + utilities.handle_exception(self, err, 'CRON: ' .. n, config.log_chat) end end end @@ -232,7 +248,8 @@ function pre_process_msg(self, msg, config) local plugin = self.plugins[n] if plugin.pre_process and msg then -- print('Preprocess '..plugin.name) -- remove comment to restore old behaviour - new_msg = plugin:pre_process(msg, self, config) + new_msg = plugin:pre_process(msg, config) + if not new_msg then return end -- Message was deleted end end return new_msg @@ -274,7 +291,7 @@ function match_plugins(self, msg, config, plugin) end end) if not success then - utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config) + utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config.log_chat) return end -- if one pattern matches, end @@ -310,11 +327,16 @@ function create_plugin_set() 'control', 'about', 'id', + 'post_photo', + 'images', + 'media', + 'service_migrate_to_supergroup', 'creds', 'echo', 'banhammer', 'channels', 'plugins', + 'settings', 'help' } print ('Aktiviere Plugins und speicher in telegram:enabled_plugins') diff --git a/miku/plugins/9gag.lua b/miku/plugins/9gag.lua index 45d0d66..66a3984 100644 --- a/miku/plugins/9gag.lua +++ b/miku/plugins/9gag.lua @@ -31,7 +31,7 @@ end function ninegag:inline_callback(inline_query, config) local res, code = http.request(url) - if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end + if code ~= 200 then abort_inline_query(inline_query) return end local gag = json.decode(res) local results = '[' @@ -45,19 +45,19 @@ function ninegag:inline_callback(inline_query, config) end end local results = results..']' - utilities.answer_inline_query(self, inline_query, results, 300) + utilities.answer_inline_query(inline_query, results, 300) end function ninegag:action(msg, config) - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local url, title, post_url = ninegag:get_9GAG() if not url then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}') + utilities.send_photo(msg.chat.id, file, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}') end return ninegag \ No newline at end of file diff --git a/miku/plugins/about.lua b/miku/plugins/about.lua index a20bf73..6385c50 100644 --- a/miku/plugins/about.lua +++ b/miku/plugins/about.lua @@ -14,7 +14,7 @@ function about:init(config) end function about:action(msg, config) - utilities.send_message(self, msg.chat.id, about.text, true, nil, true) + utilities.send_message(msg.chat.id, about.text, true, nil, true) end return about \ No newline at end of file diff --git a/miku/plugins/adfly.lua b/miku/plugins/adfly.lua index 49e3181..0901898 100644 --- a/miku/plugins/adfly.lua +++ b/miku/plugins/adfly.lua @@ -27,11 +27,11 @@ function adfly:inline_callback(inline_query, config, matches) url = redis:get(hash) end - if not url then utilities.answer_inline_query(self, inline_query) return end - if url == 'NOTFOUND' then utilities.answer_inline_query(self, inline_query) return end + if not url then abort_inline_query(inline_query) return end + if url == 'NOTFOUND' then abort_inline_query(inline_query) return end local results = '[{"type":"article","id":"1","title":"Verlängerte URL","description":"'..url..'","url":"'..url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..url..'"}}]' - utilities.answer_inline_query(self, inline_query, results, 3600, true) + utilities.answer_inline_query(inline_query, results, 3600, true) end function adfly:action(msg, config, matches) @@ -40,17 +40,17 @@ function adfly:action(msg, config, matches) if redis:exists(hash) == false then local expanded_url = adfly:expand_adfly_link(adfly_code) if not expanded_url then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end if expanded_url == 'NOTFOUND' then - utilities.send_reply(self, msg, 'Fehler: Keine Adf.ly-URL gefunden!') + utilities.send_reply(msg, 'Fehler: Keine Adf.ly-URL gefunden!') return end - utilities.send_reply(self, msg, expanded_url) + utilities.send_reply(msg, expanded_url) else local data = redis:get(hash) - utilities.send_reply(self, msg, data) + utilities.send_reply(msg, data) end end diff --git a/miku/plugins/afk.lua b/miku/plugins/afk.lua index 29463de..8af65e6 100644 --- a/miku/plugins/afk.lua +++ b/miku/plugins/afk.lua @@ -58,10 +58,10 @@ function afk:switch_afk(user_name, user_id, chat_id, timestamp, text) end end -function afk:pre_process(msg, self) +function afk:pre_process(msg) if msg.chat.type == "private" then -- Ignore - return + return msg end local user_name = get_name(msg) @@ -84,15 +84,15 @@ function afk:pre_process(msg, self) if afk_text then redis:hset(hash, 'afk_text', false) if show_afk_keyboard == 'true' then - utilities.send_reply(self, msg, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', 'HTML', '{"hide_keyboard":true,"selective":true}') + utilities.send_reply(msg, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', 'HTML', '{"hide_keyboard":true,"selective":true}') else - utilities.send_message(self, chat_id, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', true, nil, 'HTML') + utilities.send_message(chat_id, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', true, nil, 'HTML') end else if show_afk_keyboard == 'true' then - utilities.send_reply(self, msg, user_name..' ist wieder da! (war '..duration..' weg)', nil, '{"hide_keyboard":true,"selective":true}') + utilities.send_reply(msg, user_name..' ist wieder da! (war '..duration..' weg)', nil, '{"hide_keyboard":true,"selective":true}') else - utilities.send_message(self, chat_id, user_name..' ist wieder da! (war '..duration..' weg)') + utilities.send_message(chat_id, user_name..' ist wieder da! (war '..duration..' weg)') end end end @@ -102,7 +102,7 @@ end function afk:action(msg, config, matches) if msg.chat.type == "private" then - utilities.send_reply(self, msg, "Mir ist's egal, ob du AFK bist.") + utilities.send_reply(msg, "Mir ist's egal, ob du AFK bist.") return end @@ -118,7 +118,7 @@ function afk:action(msg, config, matches) keyboard = nil end - utilities.send_reply(self, msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard) + utilities.send_reply(msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard) end return afk \ No newline at end of file diff --git a/miku/plugins/app_store.lua b/miku/plugins/app_store.lua index 5ef13af..41ea4c5 100644 --- a/miku/plugins/app_store.lua +++ b/miku/plugins/app_store.lua @@ -96,15 +96,15 @@ function app_store:action(msg, config, matches) local data = app_store:get_appstore_data() if data == nil then print('Das Appstore-Plugin unterstützt nur Apps!') end if data == 'HTTP-FEHLER' or data == 'NOTFOUND' then - utilities.send_reply(self, msg, 'App nicht gefunden!', 'HTML') + utilities.send_reply(msg, 'App nicht gefunden!', 'HTML') return else local output, image_url = app_store:send_appstore_data(data) - utilities.send_reply(self, msg, output, 'HTML') + utilities.send_reply(msg, output, 'HTML') if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end end end diff --git a/miku/plugins/bImages.lua b/miku/plugins/bImages.lua index 8ddf60a..a4adcf9 100644 --- a/miku/plugins/bImages.lua +++ b/miku/plugins/bImages.lua @@ -59,8 +59,8 @@ function bImages:inline_callback(inline_query, config, matches) results = bImages:getImages(query) end - if not results then utilities.answer_inline_query(self, inline_query) return end - utilities.answer_inline_query(self, inline_query, results, 3600) + if not results then abort_inline_query(inline_query) return end + utilities.answer_inline_query(inline_query, results, 3600) end function bImages:action() diff --git a/miku/plugins/banhammer.lua b/miku/plugins/banhammer.lua index 8090cf0..f10f430 100644 --- a/miku/plugins/banhammer.lua +++ b/miku/plugins/banhammer.lua @@ -39,11 +39,11 @@ function banhammer:init(config) Alternativ kann auch auf die Nachricht des Users geantwortet werden, die Befehle sind dnn die obrigen ohne `user` bzw.`delete`.]] end -function banhammer:kick_user(user_id, chat_id, self, onlykick) +function banhammer:kick_user(user_id, chat_id, onlykick) if user_id == tostring(our_id) then return "Ich werde mich nicht selbst kicken!" else - local request = bindings.request(self, 'kickChatMember', { + local request = bindings.request('kickChatMember', { chat_id = chat_id, user_id = user_id } ) @@ -56,7 +56,7 @@ function banhammer:kick_user(user_id, chat_id, self, onlykick) end end -function banhammer:ban_user(user_id, chat_id, self) +function banhammer:ban_user(user_id, chat_id) if user_id == tostring(our_id) then return "Ich werde mich nicht selbst kicken!" else @@ -64,15 +64,15 @@ function banhammer:ban_user(user_id, chat_id, self) local hash = 'banned:'..chat_id..':'..user_id redis:set(hash, true) -- Kick from chat - return banhammer:kick_user(user_id, chat_id, self) + return banhammer:kick_user(user_id, chat_id) end end -function banhammer:unban_user(user_id, chat_id, self, chat_type) +function banhammer:unban_user(user_id, chat_id, chat_type) local hash = 'banned:'..chat_id..':'..user_id redis:del(hash) if chat_type == 'supergroup' then - bindings.request(self, 'unbanChatMember', { + bindings.request('unbanChatMember', { chat_id = chat_id, user_id = user_id } ) @@ -98,7 +98,7 @@ function banhammer:is_chat_whitelisted(id) return white end -function banhammer:pre_process(msg, self, config) +function banhammer:pre_process(msg, config) -- SERVICE MESSAGE if msg.new_chat_member then local user_id = msg.new_chat_member.id @@ -106,7 +106,7 @@ function banhammer:pre_process(msg, self, config) local banned = banhammer:is_banned(user_id, msg.chat.id) if banned then print('User is banned!') - banhammer:kick_user(user_id, msg.chat.id, self, true) + banhammer:kick_user(user_id, msg.chat.id, true) end -- No further checks return msg @@ -119,7 +119,7 @@ function banhammer:pre_process(msg, self, config) local banned = banhammer:is_banned(user_id, chat_id) if banned then print('Banned user talking!') - banhammer:ban_user(user_id, chat_id, self) + banhammer:ban_user(user_id, chat_id) return end end @@ -155,7 +155,7 @@ function banhammer:pre_process(msg, self, config) end else if not has_been_warned then - utilities.send_reply(self, msg, "Dies ist ein privater Bot, der erst nach einer Freischaltung benutzt werden kann.\nThis is a private bot, which can only be after an approval.") + utilities.send_reply(msg, "Dies ist ein privater Bot, der erst nach einer Freischaltung benutzt werden kann.\nThis is a private bot, which can only be after an approval.") redis:hset('user:'..user_id, 'has_been_warned', true) else print('User has already been warned!') @@ -181,7 +181,7 @@ function banhammer:action(msg, config, matches) if matches[1] == 'leave' then if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then - bindings.request(self, 'leaveChat', { + bindings.request('leaveChat', { chat_id = msg.chat.id } ) return @@ -206,17 +206,17 @@ function banhammer:action(msg, config, matches) if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then if matches[2] == 'user' or not matches[2] then - local text = banhammer:ban_user(user_id, chat_id, self) - utilities.send_reply(self, msg, text) + local text = banhammer:ban_user(user_id, chat_id) + utilities.send_reply(msg, text) return end if matches[2] == 'delete' then - local text = banhammer:unban_user(user_id, chat_id, self, msg.chat.type) - utilities.send_reply(self, msg, text) + local text = banhammer:unban_user(user_id, chat_id, msg.chat.type) + utilities.send_reply(msg, text) return end else - utilities.send_reply(self, msg, 'Das ist keine Chat-Gruppe') + utilities.send_reply(msg, 'Das ist keine Chat-Gruppe') return end end @@ -234,10 +234,10 @@ function banhammer:action(msg, config, matches) user_id = msg.reply_to_message.from.id end end - banhammer:kick_user(user_id, msg.chat.id, self, true) + banhammer:kick_user(user_id, msg.chat.id, true) return else - utilities.send_reply(self, msg, 'Das ist keine Chat-Gruppe') + utilities.send_reply(msg, 'Das ist keine Chat-Gruppe') return end end @@ -246,14 +246,14 @@ function banhammer:action(msg, config, matches) if matches[2] == 'enable' then local hash = 'whitelist:enabled' redis:set(hash, true) - utilities.send_reply(self, msg, 'Whitelist aktiviert') + utilities.send_reply(msg, 'Whitelist aktiviert') return end if matches[2] == 'disable' then local hash = 'whitelist:enabled' redis:del(hash) - utilities.send_reply(self, msg, 'Whitelist deaktiviert') + utilities.send_reply(msg, 'Whitelist deaktiviert') return end @@ -268,7 +268,7 @@ function banhammer:action(msg, config, matches) end local hash = 'whitelist:user#id'..user_id redis:set(hash, true) - utilities.send_reply(self, msg, 'User '..user_id..' whitelisted') + utilities.send_reply(msg, 'User '..user_id..' whitelisted') return end @@ -285,14 +285,14 @@ function banhammer:action(msg, config, matches) end local hash = 'whitelist:user#id'..user_id redis:del(hash) - utilities.send_reply(self, msg, 'User '..user_id..' von der Whitelist entfernt!') + utilities.send_reply(msg, 'User '..user_id..' von der Whitelist entfernt!') return end if matches[2] == 'user' then local hash = 'whitelist:user#id'..matches[3] redis:set(hash, true) - utilities.send_reply(self, msg, 'User '..matches[3]..' whitelisted') + utilities.send_reply(msg, 'User '..matches[3]..' whitelisted') return end @@ -300,10 +300,10 @@ function banhammer:action(msg, config, matches) if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then local hash = 'whitelist:chat#id'..msg.chat.id redis:set(hash, true) - utilities.send_reply(self, msg, 'Chat '..msg.chat.id..' whitelisted') + utilities.send_reply(msg, 'Chat '..msg.chat.id..' whitelisted') return else - utilities.send_reply(self, msg, 'Das ist keine Chat-Gruppe!') + utilities.send_reply(msg, 'Das ist keine Chat-Gruppe!') return end end @@ -311,7 +311,7 @@ function banhammer:action(msg, config, matches) if matches[2] == 'delete' and matches[3] == 'user' then local hash = 'whitelist:user#id'..matches[4] redis:del(hash) - utilities.send_reply(self, msg, 'User '..matches[4]..' von der Whitelist entfernt!') + utilities.send_reply(msg, 'User '..matches[4]..' von der Whitelist entfernt!') return end @@ -319,10 +319,10 @@ function banhammer:action(msg, config, matches) if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then local hash = 'whitelist:chat#id'..msg.chat.id redis:del(hash) - utilities.send_reply(self, msg, 'Chat '..msg.chat.id..' von der Whitelist entfernt') + utilities.send_reply(msg, 'Chat '..msg.chat.id..' von der Whitelist entfernt') return else - utilities.send_reply(self, msg, 'Das ist keine Chat-Gruppe!') + utilities.send_reply(msg, 'Das ist keine Chat-Gruppe!') return end end @@ -333,14 +333,14 @@ function banhammer:action(msg, config, matches) if matches[2] == 'user' and matches[3] then local hash = 'blocked:'..matches[3] redis:set(hash, true) - utilities.send_reply(self, msg, 'User '..matches[3]..' darf den Bot nun nicht mehr nutzen.') + utilities.send_reply(msg, 'User '..matches[3]..' darf den Bot nun nicht mehr nutzen.') return end if matches[2] == 'delete' and matches[3] then local hash = 'blocked:'..matches[3] redis:del(hash) - utilities.send_reply(self, msg, 'User '..matches[3]..' darf den Bot wieder nutzen.') + utilities.send_reply(msg, 'User '..matches[3]..' darf den Bot wieder nutzen.') return end @@ -357,7 +357,7 @@ function banhammer:action(msg, config, matches) end local hash = 'blocked:'..user_id redis:set(hash, true) - utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot nun nicht mehr nutzen.') + utilities.send_reply(msg, 'User '..user_id..' darf den Bot nun nicht mehr nutzen.') return end @@ -374,7 +374,7 @@ function banhammer:action(msg, config, matches) end local hash = 'blocked:'..user_id redis:del(hash) - utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot wieder nutzen.') + utilities.send_reply(msg, 'User '..user_id..' darf den Bot wieder nutzen.') return end diff --git a/miku/plugins/birthday.lua b/miku/plugins/birthday.lua index 754402f..fbd32eb 100644 --- a/miku/plugins/birthday.lua +++ b/miku/plugins/birthday.lua @@ -90,7 +90,7 @@ function birthday:action(msg, config, matches) end end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return birthday diff --git a/miku/plugins/bitly.lua b/miku/plugins/bitly.lua index deb63a4..f9afe4c 100644 --- a/miku/plugins/bitly.lua +++ b/miku/plugins/bitly.lua @@ -38,10 +38,10 @@ function bitly:inline_callback(inline_query, config, matches) url = data.long_url end - if not url then utilities.answer_inline_query(self, inline_query) return end + if not url then abort_inline_query(inline_query) return end local results = '[{"type":"article","id":"2","title":"Verlängerte URL","description":"'..url..'","url":"'..url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..url..'"}}]' - utilities.answer_inline_query(self, inline_query, results, 3600) + utilities.answer_inline_query(inline_query, results, 3600) end function bitly:action(msg, config, matches) @@ -50,14 +50,14 @@ function bitly:action(msg, config, matches) if redis:exists(hash) == false then local longurl = bitly:expand_bitly_link(shorturl) if not longurl then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply( msg, config.errors.connection) return end - utilities.send_reply(self, msg, longurl) + utilities.send_reply(msg, longurl) return else local data = redis:hgetall(hash) - utilities.send_reply(self, msg, data.long_url) + utilities.send_reply(msg, data.long_url) return end end diff --git a/miku/plugins/bitly_create.lua b/miku/plugins/bitly_create.lua index e17c4a1..70d1f4c 100644 --- a/miku/plugins/bitly_create.lua +++ b/miku/plugins/bitly_create.lua @@ -83,38 +83,38 @@ function bitly_create:action(msg, config, matches) bitly_access_token = redis:hget(hash, 'bitly') if matches[1] == 'auth' and matches[2] then - utilities.send_reply(self, msg, bitly_create:get_bitly_access_token(hash, matches[2]), true) + utilities.send_reply(msg, bitly_create:get_bitly_access_token(hash, matches[2]), true) local message_id = redis:hget(hash, 'bitly_login_msg') - utilities.edit_message(self, msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) + utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) redis:hdel(hash, 'bitly_login_msg') return end if matches[1] == 'auth' then - local result = utilities.send_reply(self, msg, '*Bitte logge dich ein und folge den Anweisungen.*', true, '{"inline_keyboard":[[{"text":"Bei Bitly anmelden","url":"https://bitly.com/oauth/authorize?client_id='..client_id..'&redirect_uri='..redirect_uri..'&state='..self.info.username..'"}]]}') + local result = utilities.send_reply(msg, '*Bitte logge dich ein und folge den Anweisungen.*', true, '{"inline_keyboard":[[{"text":"Bei Bitly anmelden","url":"https://bitly.com/oauth/authorize?client_id='..client_id..'&redirect_uri='..redirect_uri..'&state='..self.info.username..'"}]]}') redis:hset(hash, 'bitly_login_msg', result.result.message_id) return end if matches[1] == 'unauth' and bitly_access_token then redis:hdel(hash, 'bitly') - utilities.send_reply(self, msg, '*Erfolgreich ausgeloggt!* Du kannst den Zugriff [in deinen Kontoeinstellungen](https://bitly.com/a/settings/connected) endgültig entziehen.', true) + utilities.send_reply(msg, '*Erfolgreich ausgeloggt!* Du kannst den Zugriff [in deinen Kontoeinstellungen](https://bitly.com/a/settings/connected) endgültig entziehen.', true) return elseif matches[1] == 'unauth' and not bitly_access_token then - utilities.send_reply(self, msg, 'Wie willst du dich ausloggen, wenn du gar nicht eingeloggt bist?', true) + utilities.send_reply(msg, 'Wie willst du dich ausloggen, wenn du gar nicht eingeloggt bist?', true) return end if matches[1] == 'me' and bitly_access_token then local text = bitly_create:get_bitly_user_info(bitly_access_token) if text then - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) return else return end elseif matches[1] == 'me' and not bitly_access_token then - utilities.send_reply(self, msg, 'Du bist nicht eingeloggt! Logge dich ein mit\n/short auth', true) + utilities.send_reply(msg, 'Du bist nicht eingeloggt! Logge dich ein mit\n/short auth', true) return end @@ -130,7 +130,7 @@ function bitly_create:action(msg, config, matches) long_url = url_encode(matches[2]) domain = matches[1] end - utilities.send_reply(self, msg, bitly_create:create_bitlink(long_url, domain, bitly_access_token)) + utilities.send_reply(msg, bitly_create:create_bitlink(long_url, domain, bitly_access_token)) return end diff --git a/miku/plugins/boobs.lua b/miku/plugins/boobs.lua index cccf32b..da4cc00 100644 --- a/miku/plugins/boobs.lua +++ b/miku/plugins/boobs.lua @@ -57,10 +57,10 @@ function boobs:action(msg, config, matches) if url ~= nil then local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, url, msg.message_id) + utilities.send_photo(msg.chat.id, file, url, msg.message_id) return else - utilities.send_reply(self, msg, 'Nichts gefunden :(') + utilities.send_reply(msg, 'Nichts gefunden :(') return end end diff --git a/miku/plugins/br.lua b/miku/plugins/br.lua index d7e50f3..046a017 100644 --- a/miku/plugins/br.lua +++ b/miku/plugins/br.lua @@ -35,11 +35,11 @@ function br:action(msg, config, matches) local article = URL.escape(matches[1]) local text, image_url = br:get_br_article(article) if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url, 'br_teaser.jpg') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) end return br \ No newline at end of file diff --git a/miku/plugins/btc.lua b/miku/plugins/btc.lua index 483294c..068deb5 100644 --- a/miku/plugins/btc.lua +++ b/miku/plugins/btc.lua @@ -28,7 +28,7 @@ end function btc:action(msg, config, matches) - utilities.send_reply(self, msg, btc:getBTCX(cur), true) + utilities.send_reply(msg, btc:getBTCX(cur), true) end return btc \ No newline at end of file diff --git a/miku/plugins/calc.lua b/miku/plugins/calc.lua index cd645db..2a32b1c 100644 --- a/miku/plugins/calc.lua +++ b/miku/plugins/calc.lua @@ -29,7 +29,7 @@ function calc:mathjs(exp) end function calc:action(msg, config, matches) - utilities.send_reply(self, msg, calc:mathjs(matches[1])) + utilities.send_reply(msg, calc:mathjs(matches[1])) end return calc diff --git a/miku/plugins/cats.lua b/miku/plugins/cats.lua index 03cd743..5df8d17 100644 --- a/miku/plugins/cats.lua +++ b/miku/plugins/cats.lua @@ -56,18 +56,18 @@ function cats:inline_callback(inline_query, config, matches) end end local results = results..']' - utilities.answer_inline_query(self, inline_query, results, 30) + utilities.answer_inline_query(inline_query, results, 30) end function cats:action(msg, config) if matches[1] == 'gif' then local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey local file = download_to_file(url, 'miau.gif') - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) else local url = 'http://thecatapi.com/api/images/get?type=jpg,png&apikey='..apikey local file = download_to_file(url, 'miau.png') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end end diff --git a/miku/plugins/cf_image_hosting.lua b/miku/plugins/cf_image_hosting.lua index b6aedd6..5405ac8 100644 --- a/miku/plugins/cf_image_hosting.lua +++ b/miku/plugins/cf_image_hosting.lua @@ -22,7 +22,7 @@ function cf_img:inline_callback(inline_query, config, matches) local site = matches[1] local pic = matches[2] local full_url = cf_img:get_full_url(site, pic) - if not full_url then utilities.answer_inline_query(self, inline_query) return end + if not full_url then abort_inline_query(inline_query) return end local results @@ -31,7 +31,7 @@ function cf_img:inline_callback(inline_query, config, matches) else results = '[{"type":"photo","id":"7777","photo_url":"'..full_url..'","thumb_url":"'..full_url..'"}]' end - utilities.answer_inline_query(self, inline_query, results, 3600, true) + utilities.answer_inline_query(inline_query, results, 3600, true) end function cf_img:action(msg, config, matches) @@ -39,16 +39,16 @@ function cf_img:action(msg, config, matches) local pic = matches[2] local full_url = cf_img:get_full_url(site, pic) if not full_url then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(full_url) if string.ends(full_url, '.gif') then - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end end diff --git a/miku/plugins/channel.lua b/miku/plugins/channel.lua index d9b7779..089a46f 100644 --- a/miku/plugins/channel.lua +++ b/miku/plugins/channel.lua @@ -21,7 +21,7 @@ function channel:action(msg, config) local input = utilities.input(msg.text) local output local chat_id = '@'..matches[1] - local admin_list, gca_results = utilities.get_chat_administrators(self, chat_id) + local admin_list, gca_results = utilities.get_chat_administrators(chat_id) if admin_list then local is_admin = false @@ -38,17 +38,17 @@ function channel:action(msg, config) -- this plugin will also be ready :P -- Also, URL buttons work!? Maybe beta? if reply_markup:match('"callback_data":"') then - utilities.send_reply(self, msg, 'callback_data ist in Buttons nicht erlaubt.') + utilities.send_reply(msg, 'callback_data ist in Buttons nicht erlaubt.') return elseif reply_markup:match('"switch_inline_query":"') then - utilities.send_reply(self, msg, 'switch_inline_query ist in Buttons nicht erlaubt.') + utilities.send_reply(msg, 'switch_inline_query ist in Buttons nicht erlaubt.') return end else text = matches[2] reply_markup = nil end - local success, result = utilities.send_message(self, chat_id, text, true, nil, true, reply_markup) + local success, result = utilities.send_message(chat_id, text, true, nil, true, reply_markup) if success then output = 'Deine Nachricht wurde versendet!' else @@ -60,7 +60,7 @@ function channel:action(msg, config) else output = 'Sorry, ich konnte die Administratorenliste nicht abrufen!\n`'..gca_results.description..'`' end - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end return channel \ No newline at end of file diff --git a/miku/plugins/channels.lua b/miku/plugins/channels.lua index e831ebc..1519246 100644 --- a/miku/plugins/channels.lua +++ b/miku/plugins/channels.lua @@ -47,7 +47,7 @@ function channels:disable_channel(msg) end end -function channels:pre_process(msg, self, config) +function channels:pre_process(msg, config) -- If is sudo can reeanble the channel if is_sudo(msg, config) then if msg.text == "/channel enable" then @@ -57,9 +57,7 @@ function channels:pre_process(msg, self, config) if channels:is_channel_disabled(msg) then print('Channel wurde deaktiviert') - msg.text = '' - msg.text_lower = '' - msg.entities = '' + return end return msg @@ -67,18 +65,18 @@ end function channels:action(msg, config, matches) if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end -- Enable a channel if matches[1] == 'enable' then - utilities.send_reply(self, msg, channels:enable_channel(msg)) + utilities.send_reply(msg, channels:enable_channel(msg)) return end -- Disable a channel if matches[1] == 'disable' then - utilities.send_reply(self, msg, channels:disable_channel(msg)) + utilities.send_reply(msg, channels:disable_channel(msg)) return end end diff --git a/miku/plugins/chucknorris.lua b/miku/plugins/chucknorris.lua index 55ee4d1..45fea70 100644 --- a/miku/plugins/chucknorris.lua +++ b/miku/plugins/chucknorris.lua @@ -20,10 +20,10 @@ end function chucknorris:action(msg, config) local text = chucknorris:get_joke() if not text then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(self, msg, unescape(text)) + utilities.send_reply(msg, unescape(text)) end return chucknorris \ No newline at end of file diff --git a/miku/plugins/cleverbot.lua b/miku/plugins/cleverbot.lua index 1cf2672..15ed8c7 100644 --- a/miku/plugins/cleverbot.lua +++ b/miku/plugins/cleverbot.lua @@ -11,17 +11,17 @@ end cleverbot.command = 'cbot ' function cleverbot:action(msg, config, matches) - utilities.send_typing(self, msg.chat.id, 'typing') + utilities.send_typing(msg.chat.id, 'typing') local text = matches[1] local query, code = https.request(cleverbot.url..URL.escape(text)) if code ~= 200 then - utilities.send_reply(self, msg, 'Ich möchte jetzt nicht reden...') + utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...') return end local data = json.decode(query) if not data.clever then - utilities.send_reply(self, msg, 'Ich möchte jetzt nicht reden...') + utilities.send_reply(msg, 'Ich möchte jetzt nicht reden...') return end @@ -32,7 +32,7 @@ function cleverbot:action(msg, config, matches) local answer = string.gsub(answer, "Ü", "Ü") local answer = string.gsub(answer, "ü", "ü") local answer = string.gsub(answer, "ß", "ß") - utilities.send_reply(self, msg, answer) + utilities.send_reply(msg, answer) end return cleverbot \ No newline at end of file diff --git a/miku/plugins/clypit.lua b/miku/plugins/clypit.lua index 8a41aec..893ad62 100644 --- a/miku/plugins/clypit.lua +++ b/miku/plugins/clypit.lua @@ -19,10 +19,10 @@ function clypit:get_clypit_details(shortcode) end function clypit:action(msg, config, matches) - utilities.send_typing(self, msg.chat.id, 'upload_audio') + utilities.send_typing(msg.chat.id, 'upload_audio') local audio, title, duration = clypit:get_clypit_details(matches[1]) - if not audio then return utilities.send_reply(self, msg, config.errors.connection) end - utilities.send_audio(self, msg.chat.id, audio, nil, msg.message_id, duration, nil, title) + if not audio then return utilities.send_reply(msg, config.errors.connection) end + utilities.send_audio(msg.chat.id, audio, nil, msg.message_id, duration, nil, title) end return clypit diff --git a/miku/plugins/control.lua b/miku/plugins/control.lua index ddfa4b3..69309a0 100644 --- a/miku/plugins/control.lua +++ b/miku/plugins/control.lua @@ -32,22 +32,22 @@ function control:action(msg, config) config[k] = v end end - bot.init(self, config) - utilities.send_reply(self, msg, 'Bot neu gestartet!') + bot.init(config) + utilities.send_reply(msg, 'Bot neu gestartet!') elseif msg.text_lower:match('^'..cmd_pat..'halt') then self.is_started = false - utilities.send_reply(self, msg, 'Stoppe Bot!') + utilities.send_reply(msg, 'Stoppe Bot!') elseif msg.text_lower:match('^'..cmd_pat..'script') then local input = msg.text_lower:match('^'..cmd_pat..'script\n(.+)') if not input then - utilities.send_reply(self, msg, 'usage: ```\n'..cmd_pat..'script\n'..cmd_pat..'command \n...\n```', true) + utilities.send_reply(msg, 'usage: ```\n'..cmd_pat..'script\n'..cmd_pat..'command \n...\n```', true) return end input = input .. '\n' for command in input:gmatch('(.-)\n') do command = utilities.trim(command) msg.text = command - bot.on_msg_receive(self, msg, config) + bot.on_msg_receive(msg, config) end end diff --git a/miku/plugins/cowsay.lua b/miku/plugins/cowsay.lua index ac3c098..45b177d 100644 --- a/miku/plugins/cowsay.lua +++ b/miku/plugins/cowsay.lua @@ -13,18 +13,18 @@ cowsay.command = 'cowsay ' function cowsay:inline_callback(inline_query, config, matches) local input = matches[1] - if string.match(input, '"') then utilities.answer_inline_query(self, inline_query) return end + if string.match(input, '"') then abort_inline_query(inline_query) return end local text = '```'..run_command('cowsay "'..input..'"')..'```' local text = text:gsub('\\', '\\\\') local results = '[{"type":"article","id":"7912","title":"Muh!","input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}}]' - utilities.answer_inline_query(self, inline_query, results, 2) + utilities.answer_inline_query(inline_query, results, 2) end function cowsay:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, cowsay.doc, true) + utilities.send_reply(msg, cowsay.doc, true) return end @@ -34,7 +34,7 @@ function cowsay:action(msg, config) text = '```'..run_command('cowsay "'..input..'"')..'```' end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) end return cowsay \ No newline at end of file diff --git a/miku/plugins/creds.lua b/miku/plugins/creds.lua index 1c95ddf..5da43cc 100644 --- a/miku/plugins/creds.lua +++ b/miku/plugins/creds.lua @@ -90,31 +90,31 @@ end function creds_manager:action(msg, config, matches) local receiver = msg.from.id if receiver ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end if msg.chat.type ~= 'private' then - utilities.send_reply(self, msg, 'Dieses Plugin solltest du nur [privat](http://telegram.me/' .. self.info.username .. '?start=creds) verwenden!', true) + utilities.send_reply(msg, 'Dieses Plugin solltest du nur [privat](http://telegram.me/' .. self.info.username .. '?start=creds) verwenden!', true) return end if matches[1] == "/creds" then - utilities.send_reply(self, msg, creds_manager:list_creds()) + utilities.send_reply(msg, creds_manager:list_creds()) return elseif matches[1] == "/creds add" then local var = string.lower(string.sub(matches[2], 1, 50)) local key = string.sub(matches[3], 1, 1000) - utilities.send_reply(self, msg, creds_manager:add_creds(var, key)) + utilities.send_reply(msg, creds_manager:add_creds(var, key)) return elseif matches[1] == "/creds del" then local var = string.lower(matches[2]) - utilities.send_reply(self, msg, creds_manager:del_creds(var)) + utilities.send_reply(msg, creds_manager:del_creds(var)) return elseif matches[1] == "/creds rename" then local var = string.lower(string.sub(matches[2], 1, 50)) local newvar = string.lower(string.sub(matches[3], 1, 1000)) - utilities.send_reply(self, msg, creds_manager:rename_creds(var, newvar)) + utilities.send_reply(msg, creds_manager:rename_creds(var, newvar)) return end end diff --git a/miku/plugins/currency.lua b/miku/plugins/currency.lua index a9d4779..27665b8 100644 --- a/miku/plugins/currency.lua +++ b/miku/plugins/currency.lua @@ -39,7 +39,7 @@ function currency:inline_callback(inline_query, config, matches) end local value, iserr = currency:convert_money(base, to, amount) - if iserr then utilities.answer_inline_query(self, inline_query) return end + if iserr then abort_inline_query(inline_query) return end local output = amount..' '..base..' = *'..value..' '..to..'*' if tonumber(amount) == 1 then @@ -48,7 +48,7 @@ function currency:inline_callback(inline_query, config, matches) title = amount..' '..base..' entsprechen' end local results = '[{"type":"article","id":"20","title":"'..title..'","description":"'..value..' '..to..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/currency/cash.jpg","thumb_width":157,"thumb_height":140,"input_message_content":{"message_text":"'..output..'","parse_mode":"Markdown"}}]' - utilities.answer_inline_query(self, inline_query, results, 3600) + utilities.answer_inline_query(inline_query, results, 3600) end function currency:convert_money(base, to, amount) @@ -83,7 +83,7 @@ end function currency:action(msg, config, matches) if matches[1] == '/cash' then - utilities.send_reply(self, msg, currency.doc, true) + utilities.send_reply(msg, currency.doc, true) return elseif not matches[2] then -- first pattern base = 'EUR' @@ -100,24 +100,24 @@ function currency:action(msg, config, matches) end if from == to then - utilities.send_reply(self, msg, 'Jaja, sehr witzig...') + utilities.send_reply(msg, 'Jaja, sehr witzig...') return end local value = currency:convert_money(base, to, amount) if value == 'NOCONNECT' then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return elseif value == 'WRONGBASE' then - utilities.send_reply(self, msg, 'Keine gültige Basiswährung.') + utilities.send_reply(msg, 'Keine gültige Basiswährung.') return elseif value == 'WRONGCONVERTRATE' then - utilities.send_reply(self, msg, 'Keine gültige Umwandlungswährung.') + utilities.send_reply(msg, 'Keine gültige Umwandlungswährung.') return end local output = amount..' '..base..' = *'..value..' '..to..'*' - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end return currency \ No newline at end of file diff --git a/miku/plugins/dailymotion.lua b/miku/plugins/dailymotion.lua index 33f5fc3..3d61c08 100644 --- a/miku/plugins/dailymotion.lua +++ b/miku/plugins/dailymotion.lua @@ -20,8 +20,8 @@ end function dailymotion:action(msg, config, matches) local text = dailymotion:send_dailymotion_info(matches[1]) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_reply(self, msg, text, true) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text, true) end return dailymotion diff --git a/miku/plugins/danbooru.lua b/miku/plugins/danbooru.lua index efa4b6f..275ceb8 100644 --- a/miku/plugins/danbooru.lua +++ b/miku/plugins/danbooru.lua @@ -47,13 +47,13 @@ end function danbooru:action(msg, config, matches) if matches[1] == 'danbooru.donmai.us' and matches[2] then local url = danbooru:get_specific_post(matches[2]) - if not url then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + if not url then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) if string.ends(url, ".gif") or string.ends(url, ".zip") or string.ends(url, ".webm") then - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end return end @@ -81,12 +81,12 @@ function danbooru:action(msg, config, matches) if post then local download_url = BASE_URL..post.large_file_url - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local img = download_to_file(download_url) if string.ends(download_url, ".gif") or string.ends(download_url, ".zip") or string.ends(download_url, ".webm") then - utilities.send_document(self, msg.chat.id, img, nil, msg.message_id) + utilities.send_document(msg.chat.id, img, nil, msg.message_id) else - utilities.send_photo(self, msg.chat.id, img, nil, msg.message_id) + utilities.send_photo(msg.chat.id, img, nil, msg.message_id) end local txt = '' @@ -100,11 +100,11 @@ function danbooru:action(msg, config, matches) txt = txt .. '[' .. math.ceil(post.file_size/1000) .. 'kb] ' .. BASE_URL .. post.file_url end if txt ~= '' then - utilities.send_reply(self, msg, txt) + utilities.send_reply(msg, txt) end return else - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end end diff --git a/miku/plugins/derpibooru.lua b/miku/plugins/derpibooru.lua index d3a4880..d50c193 100644 --- a/miku/plugins/derpibooru.lua +++ b/miku/plugins/derpibooru.lua @@ -26,18 +26,18 @@ end function derpibooru:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, derpibooru.doc, true) + utilities.send_reply(msg, derpibooru.doc, true) return end local tag = string.gsub(input, " ", '+' ) local url, source = derpibooru:get_dp(tag) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, source, msg.message_id) + utilities.send_photo(msg.chat.id, file, source, msg.message_id) end return derpibooru \ No newline at end of file diff --git a/miku/plugins/derpibooru_nsfw.lua b/miku/plugins/derpibooru_nsfw.lua index c7fb785..8d19ea9 100644 --- a/miku/plugins/derpibooru_nsfw.lua +++ b/miku/plugins/derpibooru_nsfw.lua @@ -32,18 +32,18 @@ end function derpibooru_nsfw:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, derpibooru_nsfw.doc, true) + utilities.send_reply(msg, derpibooru_nsfw.doc, true) return end local tag = string.gsub(input, " ", '+' ) local url, source = derpibooru_nsfw:get_dp(tag) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, source, msg.message_id) + utilities.send_photo(msg.chat.id, file, source, msg.message_id) end return derpibooru_nsfw \ No newline at end of file diff --git a/miku/plugins/deviantart.lua b/miku/plugins/deviantart.lua index 9497877..2cc2fc7 100644 --- a/miku/plugins/deviantart.lua +++ b/miku/plugins/deviantart.lua @@ -34,13 +34,13 @@ end function deviantart:action(msg, config, matches) local data = deviantart:get_da_data('http://'..matches[1]..'.deviantart.com/art/'..matches[2]) - if not data then utilities.send_reply(self, msg, config.errors.connection) return end + if not data then utilities.send_reply(msg, config.errors.connection) return end local text, file = deviantart:send_da_data(data) if file then - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + utilities.send_photo(msg.chat.id, file, text, msg.message_id) else - utilities.send_reply(self, msg, text) + utilities.send_reply(msg, text) return end end diff --git a/miku/plugins/dhl.lua b/miku/plugins/dhl.lua index 8ac51db..0a15ca5 100644 --- a/miku/plugins/dhl.lua +++ b/miku/plugins/dhl.lua @@ -28,7 +28,7 @@ end function dhl:action(msg, config, matches) local sendungs_id = matches[1] if string.len(sendungs_id) < 8 then return end - utilities.send_reply(self, msg, dhl:sendungsstatus(sendungs_id), true) + utilities.send_reply(msg, dhl:sendungsstatus(sendungs_id), true) end return dhl diff --git a/miku/plugins/dogify.lua b/miku/plugins/dogify.lua index 127bab2..a263320 100644 --- a/miku/plugins/dogify.lua +++ b/miku/plugins/dogify.lua @@ -12,19 +12,19 @@ dogify.command = 'dogify text/den/du/willst' function dogify:action(msg, config, matches) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, dogify.doc, true) + utilities.send_reply(msg, dogify.doc, true) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local path = input:gsub(" ", "%%20") local photo_url = 'http://dogr.io/'..path..'.png?split=false&.png' local file = download_to_file(photo_url) if not file then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end return dogify \ No newline at end of file diff --git a/miku/plugins/dropbox.lua b/miku/plugins/dropbox.lua index d2f3eb3..c0cb31d 100644 --- a/miku/plugins/dropbox.lua +++ b/miku/plugins/dropbox.lua @@ -13,18 +13,18 @@ function dropbox:action(msg, config, matches) local v,code = https.request(link) if code == 200 then - if string.ends(link, '.png') or string.ends(link, '.jpe?g')then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + if string.ends(link, ".png") or string.ends(link, ".jpe?g")then + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(link) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) return elseif string.ends(link, '.webp') or string.ends(link, '.gif') then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(link) - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) return else - utilities.send_reply(self, msg, link) + utilities.send_reply(msg, link) end return else diff --git a/miku/plugins/e621.lua b/miku/plugins/e621.lua index a7f51fa..b278ef5 100644 --- a/miku/plugins/e621.lua +++ b/miku/plugins/e621.lua @@ -24,17 +24,17 @@ end function e621:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, e621.doc, true) + utilities.send_reply(msg, e621.doc, true) return end local url = e621:get_e621(input) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, url, msg.message_id) + utilities.send_photo(msg.chat.id, file, url, msg.message_id) end return e621 \ No newline at end of file diff --git a/miku/plugins/echo.lua b/miku/plugins/echo.lua index 525a3ad..eb1ea5a 100644 --- a/miku/plugins/echo.lua +++ b/miku/plugins/echo.lua @@ -22,18 +22,18 @@ function echo:inline_callback(inline_query, config, matches) end local results = results..'{"type":"article","id":"4","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fett.jpg","title":"Fett","description":"*'..text..'*","input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}},{"type":"article","id":"5","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/kursiv.jpg","title":"Kursiv","description":"_'..text..'_","input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}},{"type":"article","id":"6","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fixedsys.jpg","title":"Feste Breite","description":"`'..text..'`","input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}}]' - utilities.answer_inline_query(self, inline_query, results, 0) + utilities.answer_inline_query(inline_query, results, 0) end function echo:action(msg) local input = utilities.input_from_msg(msg) if not input then - utilities.send_message(self, msg.chat.id, echo.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, echo.doc, true, msg.message_id, true) else local output if msg.chat.type == 'supergroup' then output = '*Echo:*\n"' .. utilities.md_escape(input) .. '"' - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_message(msg.chat.id, output, true, nil, true) return elseif msg.chat.type == 'group' then local b = 1 @@ -42,7 +42,7 @@ function echo:action(msg) input,b = input:gsub('^/+','') end end - utilities.send_message(self, msg.chat.id, input, true, nil, true) + utilities.send_message(msg.chat.id, input, true, nil, true) end end diff --git a/miku/plugins/expand.lua b/miku/plugins/expand.lua index 1c951f6..67cc792 100644 --- a/miku/plugins/expand.lua +++ b/miku/plugins/expand.lua @@ -27,7 +27,7 @@ function expand:inline_callback(inline_query, config, matches) end local results = '[{"type":"article","id":"7","title":"'..title..'","description":"'..description..'","url":"'..url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..url..'"}}]' - utilities.answer_inline_query(self, inline_query, results, 3600) + utilities.answer_inline_query(inline_query, results, 3600) end function expand:url(long_url) @@ -47,10 +47,10 @@ end function expand:action(msg, config, matches) local ok, response_headers = expand:url(matches[1]) if ok and response_headers.location then - utilities.send_reply(self, msg, response_headers.location) + utilities.send_reply(msg, response_headers.location) return else - utilities.send_reply(self, msg, 'Fehler beim Erweitern der URL.') + utilities.send_reply(msg, "Fehler beim Erweitern der URL.") return end end diff --git a/miku/plugins/facebook.lua b/miku/plugins/facebook.lua index bb13fea..8a6af16 100644 --- a/miku/plugins/facebook.lua +++ b/miku/plugins/facebook.lua @@ -136,7 +136,7 @@ function facebook:action(msg, config, matches) else id = matches[4] end - utilities.send_reply(self, msg, facebook:fb_post(id, story_id), 'HTML') + utilities.send_reply(msg, facebook:fb_post(id, story_id), 'HTML') return elseif matches[1] == 'photo' or matches[2] == 'photos' then if not matches[4] then @@ -146,10 +146,10 @@ function facebook:action(msg, config, matches) end local text, image_url = facebook:send_facebook_photo(photo_id, receiver) if not image_url then return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url, 'photo.jpg') - utilities.send_reply(self, msg, text, 'HTML') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_reply(msg, text, 'HTML') + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) return elseif matches[1] == 'video' or matches[2] == 'videos' then if not matches[3] then @@ -164,10 +164,10 @@ function facebook:action(msg, config, matches) title = 'VIDEO: '..title end if not video_url then return end - utilities.send_reply(self, msg, output, 'HTML', '{"inline_keyboard":[[{"text":"'..utilities.md_escape(title)..'","url":"'..video_url..'"}]]}') + utilities.send_reply(msg, output, 'HTML', '{"inline_keyboard":[[{"text":"'..utilities.md_escape(title)..'","url":"'..video_url..'"}]]}') return else - utilities.send_reply(self, msg, facebook:facebook_info(matches[1]), 'HTML') + utilities.send_reply(msg, facebook:facebook_info(matches[1]), 'HTML') return end end diff --git a/miku/plugins/flickr.lua b/miku/plugins/flickr.lua index 4ee16c9..4de6f23 100644 --- a/miku/plugins/flickr.lua +++ b/miku/plugins/flickr.lua @@ -49,21 +49,21 @@ end function flickr:action(msg, config, matches) local data = flickr:get_flickr_photo_data(matches[2]) - if not data then utilities.send_reply(self, msg, config.errors.connection) return end + if not data then utilities.send_reply(msg, config.errors.connection) return end local text, image_url, isgif = flickr:send_flickr_photo_data(data) if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url) if isgif then - utilities.send_document(self, msg.chat.id, file, text, msg.message_id) + utilities.send_document(msg.chat.id, file, text, msg.message_id) return else - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + utilities.send_photo(msg.chat.id, file, text, msg.message_id) return end else - utilities.send_reply(self, msg, text) + utilities.send_reply(msg, text) return end end diff --git a/miku/plugins/flickr_search.lua b/miku/plugins/flickr_search.lua index e1b87e9..587c79f 100644 --- a/miku/plugins/flickr_search.lua +++ b/miku/plugins/flickr_search.lua @@ -32,15 +32,15 @@ end function flickr_search:action(msg, config, matches) local url = flickr_search:get_flickr(matches[1]) - if not url then utilities.send_reply(self, msg, config.errors.results) return end + if not url then utilities.send_reply(msg, config.errors.results) return end local file = download_to_file(url) - - if string.ends(url, '.gif') then - utilities.send_document(self, msg.chat.id, file, url) + + if string.ends(url, ".gif") then + utilities.send_document(msg.chat.id, file, url) return else - utilities.send_photo(self, msg.chat.id, file, url) + utilities.send_photo(msg.chat.id, file, url) return end end diff --git a/miku/plugins/flip_text.lua b/miku/plugins/flip_text.lua index ff5e0df..8a1b167 100644 --- a/miku/plugins/flip_text.lua +++ b/miku/plugins/flip_text.lua @@ -15,14 +15,14 @@ function flip:action(msg, config, matches) local command = matches[1] local text = matches[2] if text:match('"') then - utilities.send_reply(self, msg, 'Vergiss es!') + utilities.send_reply(msg, 'Vergiss es!') return elseif command == 'flip' then new_text = run_command('flip "'..text..'"') elseif command == 'rev' then new_text = run_command('echo "' .. text .. '" | rev') end - utilities.send_reply(self, msg, new_text) + utilities.send_reply(msg, new_text) end return flip \ No newline at end of file diff --git a/miku/plugins/forecast.lua b/miku/plugins/forecast.lua index cd31686..a668542 100644 --- a/miku/plugins/forecast.lua +++ b/miku/plugins/forecast.lua @@ -217,17 +217,17 @@ function forecast:inline_callback(inline_query, config, matches) end local lat, lng = get_city_coordinates(city, config) - if not lat and not lng then utilities.answer_inline_query(self, inline_query) return end + if not lat and not lng then abort_inline_query(inline_query) return end if matches[1] == 'f' then title, description, text, ttl = forecast:get_forecast(lat, lng, true) else title, description, text, ttl = forecast:get_forecast_hourly(lat, lng, true) end - if not title and not description and not text and not ttl then utilities.answer_inline_query(self, inline_query) return end + if not title and not description and not text and not ttl then abort_inline_query(inline_query) return end local text = text:gsub('\n', '\\n') local results = '[{"type":"article","id":"28062013","title":"'..title..'","description":"'..description..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/weather/cloudy.jpg","thumb_width":80,"thumb_height":80,"input_message_content":{"message_text":"'..text..'", "parse_mode":"Markdown"}}]' - utilities.answer_inline_query(self, inline_query, results, ttl, is_personal) + utilities.answer_inline_query(inline_query, results, ttl, is_personal) end function forecast:action(msg, config, matches) @@ -246,7 +246,7 @@ function forecast:action(msg, config, matches) local lat, lng = get_city_coordinates(city, config) if not lat and not lng then - utilities.send_reply(self, msg, '*Diesen Ort gibt es nicht!*', true) + utilities.send_reply(msg, '*Diesen Ort gibt es nicht!*', true) return end @@ -258,7 +258,7 @@ function forecast:action(msg, config, matches) if not text then text = '*Konnte die Wettervorhersage für diese Stadt nicht bekommen.*' end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) end return forecast \ No newline at end of file diff --git a/miku/plugins/gImages.lua b/miku/plugins/gImages.lua index e083d6f..ae444fd 100644 --- a/miku/plugins/gImages.lua +++ b/miku/plugins/gImages.lua @@ -29,8 +29,8 @@ gImages.command = 'img ' -- Yes, the callback is copied from below, but I can't think of another method :\ function gImages:callback(callback, msg, self, config, input) if not msg then return end - utilities.answer_callback_query(self, callback, 'Suche nochmal nach "'..URL.unescape(input)..'"') - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.answer_callback_query(callback, 'Suche nochmal nach "'..URL.unescape(input)..'"') + utilities.send_typing(msg.chat.id, 'upload_photo') local hash = 'telegram:cache:gImages' local results = redis:smembers(hash..':'..string.lower(URL.unescape(input))) @@ -38,10 +38,10 @@ function gImages:callback(callback, msg, self, config, input) print('doing web request') results = gImages:get_image(input) if results == 403 then - utilities.send_reply(self, msg, config.errors.quotaexceeded, true) + utilities.send_reply(msg, config.errors.quotaexceeded, true) return elseif not results then - utilities.send_reply(self, msg, config.errors.results, true) + utilities.send_reply(msg, config.errors.results, true) return end gImages:cache_result(results, input) @@ -89,18 +89,18 @@ function gImages:callback(callback, msg, self, config, input) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) + utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true) return end if mimetype == 'image/gif' then - result = utilities.send_document(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}') + result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}') else - result = utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}') + result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}') end if not result then - utilities.send_reply(self, msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}') + utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}') return end end @@ -147,18 +147,18 @@ function gImages:action(msg, config, matches) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, gImages.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, gImages.doc, true, msg.message_id, true) return end end print ('Überprüfe, ob das Wort auf der Blackliste steht: '..input) if is_blacklisted(input) then - utilities.send_reply(self, msg, 'Vergiss es!') + utilities.send_reply(msg, 'Vergiss es!') return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local hash = 'telegram:cache:gImages' local results = redis:smembers(hash..':'..string.lower(input)) @@ -167,10 +167,10 @@ function gImages:action(msg, config, matches) print('doing web request') results = gImages:get_image(URL.escape(input)) if results == 403 then - utilities.send_reply(self, msg, config.errors.quotaexceeded, true) + utilities.send_reply(msg, config.errors.quotaexceeded, true) return elseif not results or results == 'NORESULTS' then - utilities.send_reply(self, msg, config.errors.results, true) + utilities.send_reply(msg, config.errors.results, true) return end gImages:cache_result(results, input) @@ -218,18 +218,18 @@ function gImages:action(msg, config, matches) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) + utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true) return end if mimetype == 'image/gif' then - result = utilities.send_document(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}') + result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}') else - result = utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}') + result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}') end if not result then - utilities.send_reply(self, msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}') + utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}') return end end diff --git a/miku/plugins/gImages_nsfw.lua b/miku/plugins/gImages_nsfw.lua index 62d2a3f..8e9fc79 100644 --- a/miku/plugins/gImages_nsfw.lua +++ b/miku/plugins/gImages_nsfw.lua @@ -29,8 +29,8 @@ gImages_nsfw.command = 'img2 ' -- Yes, the callback is copied from below, but I can't think of another method :\ function gImages_nsfw:callback(callback, msg, self, config, input) if not msg then return end - utilities.answer_callback_query(self, callback, 'Suche nochmal nach "'..URL.unescape(input)..'"') - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.answer_callback_query(callback, 'Suche nochmal nach "'..URL.unescape(input)..'"') + utilities.send_typing(msg.chat.id, 'upload_photo') local hash = 'telegram:cache:gImages_nsfw' local results = redis:smembers(hash..':'..string.lower(URL.unescape(input))) @@ -38,10 +38,10 @@ function gImages_nsfw:callback(callback, msg, self, config, input) print('doing web request') results = gImages_nsfw:get_image(input) if results == 403 then - utilities.send_reply(self, msg, config.errors.quotaexceeded, true) + utilities.send_reply(msg, config.errors.quotaexceeded, true) return elseif not results then - utilities.send_reply(self, msg, config.errors.results, true) + utilities.send_reply(msg, config.errors.results, true) return end gImages_nsfw:cache_result(results, input) @@ -89,18 +89,18 @@ function gImages_nsfw:callback(callback, msg, self, config, input) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) + utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true) return end if mimetype == 'image/gif' then - result = utilities.send_document(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') + result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') else - result = utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') + result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') end if not result then - utilities.send_reply(self, msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') + utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') return end end @@ -147,18 +147,18 @@ function gImages_nsfw:action(msg, config, matches) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, gImages_nsfw.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, gImages_nsfw.doc, true, msg.message_id, true) return end end print ('Überprüfe, ob das Wort auf der Blackliste steht: '..input) if is_blacklisted(input) then - utilities.send_reply(self, msg, 'Vergiss es!') + utilities.send_reply(msg, 'Vergiss es!') return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local hash = 'telegram:cache:gImages_nsfw' local results = redis:smembers(hash..':'..string.lower(input)) @@ -167,10 +167,10 @@ function gImages_nsfw:action(msg, config, matches) print('doing web request') results = gImages_nsfw:get_image(URL.escape(input)) if results == 403 then - utilities.send_reply(self, msg, config.errors.quotaexceeded, true) + utilities.send_reply(msg, config.errors.quotaexceeded, true) return elseif not results or results == 'NORESULTS' then - utilities.send_reply(self, msg, config.errors.results, true) + utilities.send_reply(msg, config.errors.results, true) return end gImages_nsfw:cache_result(results, input) @@ -218,18 +218,18 @@ function gImages_nsfw:action(msg, config, matches) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) + utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true) return end if mimetype == 'image/gif' then - result = utilities.send_document(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') + result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') else - result = utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') + result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') end if not result then - utilities.send_reply(self, msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') + utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') return end end diff --git a/miku/plugins/gMaps.lua b/miku/plugins/gMaps.lua index adb0f4b..b9841d9 100644 --- a/miku/plugins/gMaps.lua +++ b/miku/plugins/gMaps.lua @@ -22,29 +22,29 @@ end function gMaps:inline_callback(inline_query, config, matches) local place = matches[1] local coords = utilities.get_coords(place, config) - if type(coords) == 'string' then utilities.answer_inline_query(self, inline_query) return end + if type(coords) == 'string' then abort_inline_query(inline_query) return end local results = '[{"type":"venue","id":"10","latitude":'..coords.lat..',"longitude":'..coords.lon..',"title":"Ort","address":"'..coords.addr..'"}]' - utilities.answer_inline_query(self, inline_query, results, 10000) + utilities.answer_inline_query(inline_query, results, 10000) end function gMaps:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, gMaps.doc, true) + utilities.send_reply(msg, gMaps.doc, true) return end - utilities.send_typing(self, msg.chat.id, 'find_location') + utilities.send_typing(msg.chat.id, 'find_location') local coords = utilities.get_coords(input, config) if type(coords) == 'string' then - utilities.send_reply(self, msg, coords) + utilities.send_reply(msg, coords) return end - utilities.send_location(self, msg.chat.id, coords.lat, coords.lon, msg.message_id) - utilities.send_photo(self, msg.chat.id, gMaps:get_staticmap(input, coords.lat, coords.lon), nil, msg.message_id) + utilities.send_location(msg.chat.id, coords.lat, coords.lon, msg.message_id) + utilities.send_photo(msg.chat.id, gMaps:get_staticmap(input, coords.lat, coords.lon), nil, msg.message_id) end return gMaps \ No newline at end of file diff --git a/miku/plugins/gSearch.lua b/miku/plugins/gSearch.lua index 3e5cf3a..1afe984 100644 --- a/miku/plugins/gSearch.lua +++ b/miku/plugins/gSearch.lua @@ -23,7 +23,7 @@ function gSearch:googlethat(query, config) return '403' end if code ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end local data = json.decode(res) @@ -53,22 +53,22 @@ end function gSearch:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, gSearch.doc, true) + utilities.send_reply(msg, gSearch.doc, true) return end local results, stats = gSearch:googlethat(input, onfig) if results == '403' then - utilities.send_reply(self, msg, config.errors.quotaexceeded) + utilities.send_reply(msg, config.errors.quotaexceeded) return end if not results then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_message(self, msg.chat.id, gSearch:stringlinks(results, stats), true, nil, true, '{"inline_keyboard":[[{"text":"Alle Ergebnisse anzeigen","url":"https://www.google.com/search?q='..URL.escape(input)..'"}]]}') + utilities.send_message(msg.chat.id, gSearch:stringlinks(results, stats), true, nil, true, '{"inline_keyboard":[[{"text":"Alle Ergebnisse anzeigen","url":"https://www.google.com/search?q='..URL.escape(input)..'"}]]}') end diff --git a/miku/plugins/games.lua b/miku/plugins/games.lua index c421773..987250a 100644 --- a/miku/plugins/games.lua +++ b/miku/plugins/games.lua @@ -48,7 +48,7 @@ function games:send_game_photo(result, self, msg) for k, v in pairs(images) do i = i+1 local file = download_to_file(v, 'game'..i..'.jpg') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end end @@ -113,10 +113,10 @@ function games:send_game_data(game_id, self, msg) end local text = '*'..title..'* für *'..platform..'*'..date..desc..genre..players..video..publisher - utilities.send_reply(self, msg, text, true) - + utilities.send_reply(msg, text, true) + if xml.find(result, 'boxart') then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') games:send_game_photo(result, self, msg) end return @@ -128,14 +128,14 @@ function games:action(msg, config) if msg.reply_to_message and msg.reply_to_message.text then game = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, fun.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, fun.doc, true, msg.message_id, true) return end end local game_id = games:get_game_id(game) if not game_id then - utilities.send_reply(self, msg, 'Spiel nicht gefunden!') + utilities.send_reply(msg, 'Spiel nicht gefunden!') return else games:send_game_data(game_id, self, msg) diff --git a/miku/plugins/gdrive.lua b/miku/plugins/gdrive.lua index 3622c89..936fdb2 100644 --- a/miku/plugins/gdrive.lua +++ b/miku/plugins/gdrive.lua @@ -38,15 +38,15 @@ function gdrive:send_drive_document_data(data, self, msg) 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') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url, 'export.png') - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + utilities.send_photo(msg.chat.id, file, text, msg.message_id) return else 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(msg.chat.id, 'upload_document') local file = download_to_file(pdf_url, 'document.pdf') - utilities.send_document(self, msg.chat.id, file, text, msg.message_id) + utilities.send_document(msg.chat.id, file, text, msg.message_id) return end else @@ -65,19 +65,19 @@ function gdrive:send_drive_document_data(data, self, msg) local headers = response[3] local file_url = headers.location if ext == "jpg" or ext == "jpeg" or ext == "png" then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(file_url, 'photo.'..ext) - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id, keyboard) + utilities.send_photo(msg.chat.id, file, text, msg.message_id, keyboard) return else - utilities.send_typing(self, msg.chat.id, 'upload_document') + utilities.send_typing(msg.chat.id, 'upload_document') local file = download_to_file(file_url, 'document.'..ext) - utilities.send_document(self, msg.chat.id, file, text, msg.message_id, keyboard) + utilities.send_document(msg.chat.id, file, text, msg.message_id, keyboard) return end else local text = '*'..title..'*, freigegeben von _'..owner..'_' - utilities.send_reply(self, msg, text, true, keyboard) + utilities.send_reply(msg, text, true, keyboard) return end end @@ -86,7 +86,7 @@ end function gdrive:action(msg, config, matches) local docid = matches[2] local data = gdrive:get_drive_document_data(docid) - if not data then utilities.send_reply(self, msg, config.errors.connection) return end + if not data then utilities.send_reply(msg, config.errors.connection) return end gdrive:send_drive_document_data(data, self, msg) return end diff --git a/miku/plugins/get.lua b/miku/plugins/get.lua index 7c40486..2f2333b 100644 --- a/miku/plugins/get.lua +++ b/miku/plugins/get.lua @@ -50,7 +50,7 @@ function get:action(msg) output = get:list_variables(msg) end - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_message(msg.chat.id, output, true, nil, true) end return get diff --git a/miku/plugins/get_data.lua b/miku/plugins/get_data.lua index d2c8f31..acd4cad 100644 --- a/miku/plugins/get_data.lua +++ b/miku/plugins/get_data.lua @@ -10,17 +10,17 @@ get_data.command = 'me' function get_data:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, get_data.doc, true) + utilities.send_reply(msg, get_data.doc, true) return end - utilities.send_typing(self, msg.chat.id, 'upload_document') + utilities.send_typing(msg.chat.id, 'upload_document') local file = download_to_file(input) if not file then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) end return get_data diff --git a/miku/plugins/get_txt.lua b/miku/plugins/get_txt.lua index 26624f3..2c8599e 100644 --- a/miku/plugins/get_txt.lua +++ b/miku/plugins/get_txt.lua @@ -12,10 +12,10 @@ function get_txt:action(msg, config, matches) end local res, code = doer.request(url) if code ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(self, msg, res) + utilities.send_reply(msg, res) end return get_txt \ No newline at end of file diff --git a/miku/plugins/getfile.lua b/miku/plugins/getfile.lua index 06b2897..1c1c94b 100644 --- a/miku/plugins/getfile.lua +++ b/miku/plugins/getfile.lua @@ -31,7 +31,7 @@ function media_download:download_to_file_permanently(url, save_dir, file_name) return true end -function media_download:pre_process(msg, self, config) +function media_download:pre_process(msg, config) if msg.photo then local lv = #msg.photo -- find biggest photo, always the last value file_id = msg.photo[lv].file_id @@ -74,7 +74,7 @@ function media_download:pre_process(msg, self, config) end -- Saving file to the Telegram Cloud - local request = bindings.request(self, 'getFile', { + local request = bindings.request('getFile', { file_id = file_id } ) diff --git a/miku/plugins/gfycat.lua b/miku/plugins/gfycat.lua index 18781bf..93c087e 100644 --- a/miku/plugins/gfycat.lua +++ b/miku/plugins/gfycat.lua @@ -6,26 +6,26 @@ gfycat.triggers = { "gfycat.com/([A-Za-z0-9-_-]+)" } -function gfycat:send_gfycat_video(name, self, msg) +function gfycat:send_gfycat_video(name, msg) local BASE_URL = "https://gfycat.com" local url = BASE_URL..'/cajax/get/'..name local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end local data = json.decode(res).gfyItem - utilities.send_typing(self, msg.chat.id, 'upload_video') + utilities.send_typing(msg.chat.id, 'upload_video') local file = download_to_file(data.webmUrl) if file == nil then - send_reply(self, msg, 'Fehler beim Herunterladen von '..name) + send_reply(msg, 'Fehler beim Herunterladen von '..name) return else - utilities.send_video(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_video(msg.chat.id, file, nil, msg.message_id) return end end function gfycat:action(msg, config, matches) local name = matches[1] - gfycat:send_gfycat_video(name, self, msg) + gfycat:send_gfycat_video(name, msg) return end diff --git a/miku/plugins/gifeye.lua b/miku/plugins/gifeye.lua index 71eabc9..dec1e69 100644 --- a/miku/plugins/gifeye.lua +++ b/miku/plugins/gifeye.lua @@ -14,10 +14,10 @@ gifeye.command = 'ge ' function gifeye:action(msg, config, matches) local url = 'http://i.gifeye.com/'..matches[1]..'.gif' - utilities.send_typing(self, msg.chat.id, 'upload_document') + utilities.send_typing(msg.chat.id, 'upload_document') local file = download_to_file(url) if not file then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end @@ -26,7 +26,7 @@ function gifeye:action(msg, config, matches) else source = nil end - utilities.send_document(self, msg.chat.id, file, source, msg.message_id) + utilities.send_document(msg.chat.id, file, source, msg.message_id) end return gifeye \ No newline at end of file diff --git a/miku/plugins/giphy.lua b/miku/plugins/giphy.lua index 29bf42d..755f11b 100644 --- a/miku/plugins/giphy.lua +++ b/miku/plugins/giphy.lua @@ -30,8 +30,8 @@ function giphy:inline_callback(inline_query, config, matches) else data = giphy:get_gifs(matches[2]) end - if not data then utilities.answer_inline_query(self, inline_query) return end - if not data[1] then utilities.answer_inline_query(self, inline_query) return end + if not data then abort_inline_query(inline_query) return end + if not data[1] then abort_inline_query(inline_query) return end local results = '[' local id = 450 @@ -43,7 +43,7 @@ function giphy:inline_callback(inline_query, config, matches) end end local results = results..']' - utilities.answer_inline_query(self, inline_query, results, 3600) + utilities.answer_inline_query(inline_query, results, 3600) end function giphy:action() diff --git a/miku/plugins/github.lua b/miku/plugins/github.lua index 62adc4d..80432d4 100644 --- a/miku/plugins/github.lua +++ b/miku/plugins/github.lua @@ -63,7 +63,7 @@ function github:action(msg, config, matches) else output = github:send_gh_commit_data(gh_code, gh_commit_sha, data) end - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end return github \ No newline at end of file diff --git a/miku/plugins/github_feed.lua b/miku/plugins/github_feed.lua index e8dcbf3..40e1b12 100644 --- a/miku/plugins/github_feed.lua +++ b/miku/plugins/github_feed.lua @@ -181,42 +181,42 @@ function gh_feed:action(msg, config, matches) -- For channels if matches[1] == 'sub' and matches[2] and matches[3] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local id = '@'..matches[3] - local result = utilities.get_chat_info(self, id) + local result = utilities.get_chat_info(id) if not result then - utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + utilities.send_reply(msg, 'Diesen Kanal gibt es nicht!') return end local output = gh_feed:subscribe(id, matches[2]) - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) return elseif matches[1] == 'del' and matches[2] and matches[3] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local id = '@'..matches[3] - local result = utilities.get_chat_info(self, id) + local result = utilities.get_chat_info(id) if not result then - utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + utilities.send_reply(msg, 'Diesen Kanal gibt es nicht!') return end local output = gh_feed:unsubscribe(id, matches[2]) - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) return elseif matches[1] == 'gh' and matches[2] then local id = '@'..matches[2] - local result = utilities.get_chat_info(self, id) + local result = utilities.get_chat_info(id) if not result then - utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + utilities.send_reply(msg, 'Diesen Kanal gibt es nicht!') return end local chat_name = result.result.title local output = gh_feed:print_subs(id, chat_name) - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) return end @@ -228,42 +228,39 @@ function gh_feed:action(msg, config, matches) if matches[1] == 'sub' and matches[2] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local output = gh_feed:subscribe(id, matches[2]) - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) return elseif matches[1] == 'del' and matches[2] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local output = gh_feed:unsubscribe(id, matches[2]) - utilities.send_reply(self, msg, output, true, '{"hide_keyboard":true}') + utilities.send_reply(msg, output, true, '{"hide_keyboard":true}') return elseif matches[1] == 'del' and not matches[2] then local list_subs, keyboard = gh_feed:print_subs(id, chat_name) - utilities.send_reply(self, msg, list_subs, true, keyboard) + utilities.send_reply(msg, list_subs, true, keyboard) return elseif matches[1] == 'sync' then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end - gh_feed:cron(self) + gh_feed:cron() return end local output = gh_feed:print_subs(id, chat_name) - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) return end -function gh_feed:cron(self_plz) - if not self.BASE_URL then - self = self_plz - end +function gh_feed:cron() local keys = redis:keys(gh_feed_get_base_redis("*", "subs")) for k,v in pairs(keys) do local repo = string.match(v, "github:(.+):subs") @@ -292,7 +289,7 @@ function gh_feed:cron(self_plz) redis:set(gh_feed_get_base_redis(repo, "etag"), last_etag) redis:set(gh_feed_get_base_redis(repo, "date"), last_date) for k2, receiver in pairs(redis:smembers(v)) do - utilities.send_message(self, receiver, text, true, nil, true) + utilities.send_message(receiver, text, true, nil, true) end end end diff --git a/miku/plugins/googl.lua b/miku/plugins/googl.lua index b7f9e82..0721282 100644 --- a/miku/plugins/googl.lua +++ b/miku/plugins/googl.lua @@ -25,10 +25,10 @@ end function googl:inline_callback(inline_query, config, matches) local shorturl = matches[1] local text, longUrl = googl:send_googl_info(shorturl) - if not longUrl then utilities.answer_inline_query(self, inline_query) return end + if not longUrl then abort_inline_query(inline_query) return end local results = '[{"type":"article","id":"9","title":"Verlängerte URL","description":"'..longUrl..'","url":"'..longUrl..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..text..'"}}]' - utilities.answer_inline_query(self, inline_query, results, 1) + utilities.answer_inline_query(inline_query, results, 1) end function googl:send_googl_info (shorturl) @@ -49,8 +49,8 @@ end function googl:action(msg, config, matches) local shorturl = matches[1] local text = googl:send_googl_info(shorturl) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_reply(self, msg, text) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text) end return googl \ No newline at end of file diff --git a/miku/plugins/gps.lua b/miku/plugins/gps.lua index c829cb8..583af18 100644 --- a/miku/plugins/gps.lua +++ b/miku/plugins/gps.lua @@ -27,11 +27,11 @@ function gps:inline_callback(inline_query, config, matches) local results = '[{"type":"location","id":"8","latitude":'..lat..',"longitude":'..lon..',"title":"Standort"}]' - utilities.answer_inline_query(self, inline_query, results, 10000) + utilities.answer_inline_query(inline_query, results, 10000) end function gps:action(msg, config, matches) - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local lat = matches[1] local lon = matches[2] @@ -42,10 +42,10 @@ function gps:action(msg, config, matches) local zoom = zooms[i] local url = "https://maps.googleapis.com/maps/api/staticmap?zoom=" .. zoom .. "&size=600x300&maptype=hybrid¢er=" .. lat .. "," .. lon .. "&markers=color:red%7Clabel:•%7C" .. lat .. "," .. lon local file = download_to_file(url, 'zoom_'..i..'.png') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_location(self, msg.chat.id, lat, lon, msg.message_id) + utilities.send_location(msg.chat.id, lat, lon, msg.message_id) end return gps \ No newline at end of file diff --git a/miku/plugins/hallo.lua b/miku/plugins/hallo.lua index 679e1b0..efb7f66 100644 --- a/miku/plugins/hallo.lua +++ b/miku/plugins/hallo.lua @@ -6,7 +6,7 @@ hallo.triggers = { function hallo:action(msg, config) local name = msg.from.first_name - utilities.send_reply(self, msg, 'Hallo '..name..'!') + utilities.send_reply(msg, 'Hallo '..name..'!') end return hallo diff --git a/miku/plugins/hdf.lua b/miku/plugins/hdf.lua index 888fbf8..b173f03 100644 --- a/miku/plugins/hdf.lua +++ b/miku/plugins/hdf.lua @@ -17,9 +17,9 @@ function hdf:action(msg, config) "/hdf5.jpg" } local random_pic = math.random(#hdf_pics) - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(HDF_URL..hdf_pics[random_pic]) - utilities.send_photo(self, msg.chat.id, file) + utilities.send_photo(msg.chat.id, file) end return hdf diff --git a/miku/plugins/help.lua b/miku/plugins/help.lua index 197e113..9ae74e2 100644 --- a/miku/plugins/help.lua +++ b/miku/plugins/help.lua @@ -28,10 +28,10 @@ function help:inline_callback(inline_query, config, matches) local doc = doc:gsub('\\n', '\\\n') local chosen_plugin = utilities.get_word(plugin.command, 1) local results = '[{"type":"article","id":"9","title":"Hilfe für '..chosen_plugin..'","description":"Hilfe für das Plugin \\"'..chosen_plugin..'\\" wird gepostet.","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/help/hilfe.jpg","input_message_content":{"message_text":"'..doc..'","parse_mode":"Markdown"}}]' - utilities.answer_inline_query(self, inline_query, results, 600, nil, nil, 'Hilfe anzeigen', 'hilfe_'..chosen_plugin) + utilities.answer_inline_query(inline_query, results, 600, nil, nil, 'Hilfe anzeigen', 'hilfe_'..chosen_plugin) end end - utilities.answer_inline_query(self, inline_query) + utilities.answer_inline_query(inline_query) end function help:action(msg, config, matches) @@ -61,11 +61,11 @@ function help:action(msg, config, matches) local help_text = help_text .. table.concat(commandlist, '\n• '..config.cmd_pat) .. '\nParameter: [optional]' local help_text = help_text:gsub('%[', '\\[') - local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true) + local res = utilities.send_message(msg.from.id, help_text, true, nil, true) if not res then - utilities.send_reply(self, msg, 'Bitte schreibe mir zuerst [privat](http://telegram.me/' .. self.info.username .. '?start=help) für eine Hilfe.', true) + utilities.send_reply(msg, 'Bitte schreibe mir zuerst [privat](http://telegram.me/' .. self.info.username .. '?start=help) für eine Hilfe.', true) elseif msg.chat.type ~= 'private' then - utilities.send_reply(self, msg, 'Ich habe dir die Hilfe privat gesendet!.') + utilities.send_reply(msg, 'Ich habe dir die Hilfe privat gesendet!.') end return end @@ -74,12 +74,12 @@ function help:action(msg, config, matches) local plugin = self.plugins[n] if plugin.command and utilities.get_word(plugin.command, 1) == input and plugin.doc then local output = '*Hilfe für* _' .. utilities.get_word(plugin.command, 1) .. '_ *:*' .. plugin.doc - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_message(msg.chat.id, output, true, nil, true) return end end - utilities.send_reply(self, msg, 'Für diesen Befehl gibt es keine Hilfe.') + utilities.send_reply(msg, 'Für diesen Befehl gibt es keine Hilfe.') end return help \ No newline at end of file diff --git a/miku/plugins/id.lua b/miku/plugins/id.lua index e723b3f..8a6262c 100644 --- a/miku/plugins/id.lua +++ b/miku/plugins/id.lua @@ -15,8 +15,8 @@ function id:init(config) id.doc = [[```Zeige dir deine ID und die IDs aller Gruppenmitglieder an.``]] end -function id:get_member_count(self, msg, chat_id) - return bindings.request(self, 'getChatMembersCount', { +function id:get_member_count(msg, chat_id) + return bindings.request('getChatMembersCount', { chat_id = chat_id } ) end @@ -51,7 +51,7 @@ function id:inline_callback(inline_query, config, matches) local name = utilities.build_name(inline_query.from.first_name, inline_query.from.last_name) local results = '[{"type":"article","id":"30","title":"Deine Telegram-ID ist:","description":"'..id..'","input_message_content":{"message_text":"'..name..': '..id..'","parse_mode":"HTML"}}]' - utilities.answer_inline_query(self, inline_query, results, 10000, true) + utilities.answer_inline_query(inline_query, results, 10000, true) end function id:action(msg, config, matches) @@ -83,10 +83,10 @@ function id:action(msg, config, matches) local output = user .. ', und du bist in der Gruppe ' .. group - utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true) + utilities.send_message(msg.chat.id, output, true, msg.message_id, true) elseif matches[1] == "chat" then if msg.chat.type ~= 'group' and msg.chat.type ~= 'supergroup' then - utilities.send_reply(self, msg, 'Das hier ist keine Gruppe!') + utilities.send_reply(msg, 'Das hier ist keine Gruppe!') return end local chat_name = msg.chat.title @@ -103,7 +103,7 @@ function id:action(msg, config, matches) end -- get all administrators and the creator - local administrators = utilities.get_chat_administrators(self, chat_id) + local administrators = utilities.get_chat_administrators(chat_id) local admins = {} for num in pairs(administrators.result) do if administrators.result[num].status ~= 'creator' then @@ -112,7 +112,7 @@ function id:action(msg, config, matches) creator_id = administrators.result[num].user.id end end - local result = id:get_member_count(self, msg, chat_id) + local result = id:get_member_count(msg, chat_id) local member_count = result.result if member_count == 1 then member_count = 'ist *1 Mitglied' @@ -129,7 +129,7 @@ function id:action(msg, config, matches) text = text..'*'..user.name..'* `['..user.id..']`\n' end end - utilities.send_reply(self, msg, text..'_(Bots sind nicht gelistet)_', true) + utilities.send_reply(msg, text..'_(Bots sind nicht gelistet)_', true) end end diff --git a/miku/plugins/images.lua b/miku/plugins/images.lua index 4862e41..67c51ff 100644 --- a/miku/plugins/images.lua +++ b/miku/plugins/images.lua @@ -7,8 +7,8 @@ images.triggers = { function images:action(msg, config, matches) local url = matches[1] - local file, last_modified, nocache = get_cached_file(url, nil, msg.chat.id, 'upload_photo', self) - local result = utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + local file, last_modified, nocache = get_cached_file(url, nil, msg.chat.id, 'upload_photo') + local result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id) if nocache then return end if not result then return end diff --git a/miku/plugins/imdb.lua b/miku/plugins/imdb.lua index 06a233a..c32e6a1 100644 --- a/miku/plugins/imdb.lua +++ b/miku/plugins/imdb.lua @@ -26,9 +26,9 @@ function imdb:inline_callback(inline_query, config, matches) local query = matches[1] local url = BASE_URL..'/?s='..URL.escape(query) local res, code = https.request(url) - if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end + if code ~= 200 then abort_inline_query(inline_query) return end local data = json.decode(res) - if data.Response ~= "True" then utilities.answer_inline_query(self, inline_query) return end + if data.Response ~= "True" then abort_inline_query(inline_query) return end local results = '[' local id = 500 @@ -63,26 +63,26 @@ function imdb:inline_callback(inline_query, config, matches) local results = results:sub(0, -2) local results = results..']' - utilities.answer_inline_query(self, inline_query, results, 10000) + utilities.answer_inline_query(inline_query, results, 10000) end function imdb:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, imdb.doc, true) + utilities.send_reply(msg, imdb.doc, true) return end local url = BASE_URL..'/?t='..URL.escape(input) local jstr, res = https.request(url) if res ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end local jdat = json.decode(jstr) if jdat.Response ~= 'True' then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end @@ -90,11 +90,11 @@ function imdb:action(msg, config) output = output..string.gsub(jdat.imdbRating, '%.', ',')..'/10 | '..jdat.Runtime..' | '.. jdat.Genre..'\n' output = output..'' .. jdat.Plot .. '' - utilities.send_reply(self, msg, output, 'HTML', '{"inline_keyboard":[[{"text":"IMDb-Seite aufrufen","url":"http://imdb.com/title/'.. jdat.imdbID..'"}]]}') + utilities.send_reply(msg, output, 'HTML', '{"inline_keyboard":[[{"text":"IMDb-Seite aufrufen","url":"http://imdb.com/title/'.. jdat.imdbID..'"}]]}') if jdat.Poster ~= "N/A" then local file = download_to_file(jdat.Poster) - utilities.send_photo(self, msg.chat.id, file) + utilities.send_photo(msg.chat.id, file) end end diff --git a/miku/plugins/imgblacklist.lua b/miku/plugins/imgblacklist.lua index 6f8cfd5..6434ac1 100644 --- a/miku/plugins/imgblacklist.lua +++ b/miku/plugins/imgblacklist.lua @@ -50,7 +50,7 @@ end function imgblacklist:action(msg, config, matches) if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end @@ -60,22 +60,22 @@ function imgblacklist:action(msg, config, matches) _blacklist = redis:smembers("telegram:img_blacklist") if action == 'add' and not word then - utilities.send_reply(self, msg, imgblacklist.doc, true) + utilities.send_reply(msg, imgblacklist.doc, true) return elseif action == "add" and word then - utilities.send_reply(self, msg, imgblacklist:add_blacklist(word), true) + utilities.send_reply(msg, imgblacklist:add_blacklist(word), true) return end if action == 'remove' and not word then - utilities.send_reply(self, msg, imgblacklist.doc, true) + utilities.send_reply(msg, imgblacklist.doc, true) return elseif action == "remove" and word then - utilities.send_reply(self, msg, imgblacklist:remove_blacklist(word), true) + utilities.send_reply(msg, imgblacklist:remove_blacklist(word), true) return end - utilities.send_reply(self, msg, imgblacklist:show_blacklist()) + utilities.send_reply(msg, imgblacklist:show_blacklist()) end return imgblacklist diff --git a/miku/plugins/imgur.lua b/miku/plugins/imgur.lua index 61554a6..2ff7eca 100644 --- a/miku/plugins/imgur.lua +++ b/miku/plugins/imgur.lua @@ -40,14 +40,14 @@ end function imgur:action(msg) local imgur_code = matches[1] if imgur_code == "login" then return nil end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local link = imgur:get_imgur_data(imgur_code) if link then local file = download_to_file(link) if string.ends(link, ".gif") then - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end end end diff --git a/miku/plugins/insider.lua b/miku/plugins/insider.lua index ca65b1b..a47565d 100644 --- a/miku/plugins/insider.lua +++ b/miku/plugins/insider.lua @@ -39,7 +39,7 @@ function insider:action(msg, config) 'Insider: MeeeeeeeM\nErschaffen/hauptsächlich verwendet von: Brawl, nino\nWo eingesetzt?: FiiiiiiiiiiiiiiiiiF\nBemerkung: SooooooooooooooooS', 'Insider: DJ mP\nErschaffen/hauptsächlich verwendet von: Brawl\nWo eingesetzt?: Telegram\nBemerkung: als Kurzname für masterP', 'Insider: Satya Nutella\nErschaffen/hauptsächlich verwendet von: Brawl\nWo eingesetzt?: Telegram\nBemerkung: Anstelle von "Satya Nadella"'} - utilities.send_reply(self, msg, insiders[math.random(#insiders)], 'HTML') + utilities.send_reply(msg, insiders[math.random(#insiders)], 'HTML') end return insider \ No newline at end of file diff --git a/miku/plugins/ip_info.lua b/miku/plugins/ip_info.lua index bee92f8..8c4f29e 100644 --- a/miku/plugins/ip_info.lua +++ b/miku/plugins/ip_info.lua @@ -73,14 +73,14 @@ end function ip_info:action(msg, config, matches) local host = matches[1] local text, image_url = ip_info:get_host_data(host) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end + if not text then utilities.send_reply(msg, config.errors.connection) return end if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url, 'map.png') - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + utilities.send_photo(msg.chat.id, file, text, msg.message_id) else - utilities.send_reply(self, msg, text) + utilities.send_reply(msg, text) end end diff --git a/miku/plugins/isup.lua b/miku/plugins/isup.lua index dacbb20..1d44f5b 100644 --- a/miku/plugins/isup.lua +++ b/miku/plugins/isup.lua @@ -68,10 +68,10 @@ end function isup:action(msg, config) if isup:isup(matches[1]) then - utilities.send_reply(self, msg, matches[1]..' ist UP! ✅') + utilities.send_reply(msg, matches[1]..' ist UP! ✅') return else - utilities.send_reply(self, msg, matches[1]..' ist DOWN! ❌') + utilities.send_reply(msg, matches[1]..' ist DOWN! ❌') return end end diff --git a/miku/plugins/justkitten.lua b/miku/plugins/justkitten.lua index 4c4a3f4..99290e9 100644 --- a/miku/plugins/justkitten.lua +++ b/miku/plugins/justkitten.lua @@ -18,9 +18,9 @@ function jk:action(msg, config) "/justkitten6.jpg" } local random_pic = math.random(#jk_pics) - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(JK_URL..jk_pics[random_pic]) - utilities.send_photo(self, msg.chat.id, file) + utilities.send_photo(msg.chat.id, file) end return jk \ No newline at end of file diff --git a/miku/plugins/kickstarter_search.lua b/miku/plugins/kickstarter_search.lua index e5c3c9d..1302db1 100644 --- a/miku/plugins/kickstarter_search.lua +++ b/miku/plugins/kickstarter_search.lua @@ -38,19 +38,19 @@ function kickstarter_search:action(msg, config, matches) local query = matches[1] local text, image_url = kickstarter_search:search_it(query, slug) if not text then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return elseif text == 'NOTFOUND' then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url, query..'.png') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return kickstarter_search \ No newline at end of file diff --git a/miku/plugins/konachan.lua b/miku/plugins/konachan.lua index 07636e7..4fdc6cc 100644 --- a/miku/plugins/konachan.lua +++ b/miku/plugins/konachan.lua @@ -23,19 +23,19 @@ end function konachan:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, konachan.doc, true) + utilities.send_reply(msg, konachan.doc, true) return end local tag = string.gsub(input, " ", '+' ) local url = konachan:get_kc(tag) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) - utilities.send_reply(self, msg, url) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + utilities.send_reply(msg, url) end return konachan \ No newline at end of file diff --git a/miku/plugins/konachan_nsfw.lua b/miku/plugins/konachan_nsfw.lua index b6fff71..103dee6 100644 --- a/miku/plugins/konachan_nsfw.lua +++ b/miku/plugins/konachan_nsfw.lua @@ -23,19 +23,19 @@ end function konachan_nsfw:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, konachan_nsfw.doc, true) + utilities.send_reply(msg, konachan_nsfw.doc, true) return end local tag = string.gsub(input, " ", '+' ) local url = konachan_nsfw:get_kc(tag) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) - utilities.send_reply(self, msg, url) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + utilities.send_reply(msg, url) end return konachan_nsfw \ No newline at end of file diff --git a/miku/plugins/location_manager.lua b/miku/plugins/location_manager.lua index f26615a..f6b5334 100644 --- a/miku/plugins/location_manager.lua +++ b/miku/plugins/location_manager.lua @@ -44,20 +44,20 @@ function loc_manager:action(msg, config, matches) local user_id = msg.from.id if matches[1] == 'set' then - utilities.send_reply(self, msg, loc_manager:set_location(user_id, matches[2]), true) + utilities.send_reply(msg, loc_manager:set_location(user_id, matches[2]), true) return elseif matches[1] == 'del' then - utilities.send_reply(self, msg, loc_manager:del_location(user_id), true) + utilities.send_reply(msg, loc_manager:del_location(user_id), true) return else local set_location = get_location(user_id) if not set_location then - utilities.send_reply(self, msg, '*Du hast keinen Ort gesetzt!*', true) + utilities.send_reply(msg, '*Du hast keinen Ort gesetzt!*', true) return else local coords = utilities.get_coords(set_location, config) - utilities.send_location(self, msg.chat.id, coords.lat, coords.lon, msg.message_id) - utilities.send_reply(self, msg, 'Gesetzter Wohnort: *'..set_location..'*', true) + utilities.send_location(msg.chat.id, coords.lat, coords.lon, msg.message_id) + utilities.send_reply(msg, 'Gesetzter Wohnort: *'..set_location..'*', true) return end end diff --git a/miku/plugins/lyrics.lua b/miku/plugins/lyrics.lua index b3c3d68..be3ccee 100644 --- a/miku/plugins/lyrics.lua +++ b/miku/plugins/lyrics.lua @@ -36,12 +36,12 @@ function lyrics:action(msg, config, matches) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, lyrics.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, lyrics.doc, true, msg.message_id, true) return end end - utilities.send_reply(self, msg, lyrics:getLyrics(input), true) + utilities.send_reply(msg, lyrics:getLyrics(input), true) end return lyrics diff --git a/miku/plugins/magische_miesmuschel.lua b/miku/plugins/magische_miesmuschel.lua index ff0e6c4..a31f115 100644 --- a/miku/plugins/magische_miesmuschel.lua +++ b/miku/plugins/magische_miesmuschel.lua @@ -15,7 +15,7 @@ function muschel:frag_die_muschel() end function muschel:action(msg, config, matches) - utilities.send_reply(self, msg, muschel:frag_die_muschel()) + utilities.send_reply(msg, muschel:frag_die_muschel()) end return muschel diff --git a/miku/plugins/mal_user.lua b/miku/plugins/mal_user.lua index fbd0671..73f0747 100644 --- a/miku/plugins/mal_user.lua +++ b/miku/plugins/mal_user.lua @@ -35,10 +35,10 @@ function mal_user:action(msg, config, matches) local user = matches[1] local text = mal_user:get_infos(user) if not text then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return mal_user \ No newline at end of file diff --git a/miku/plugins/me.lua b/miku/plugins/me.lua index 2671695..50c535c 100644 --- a/miku/plugins/me.lua +++ b/miku/plugins/me.lua @@ -13,7 +13,7 @@ function me:action(msg, config) return end - utilities.send_message(self, msg.chat.id, msg.from.first_name..' '..input) + utilities.send_message(msg.chat.id, msg.from.first_name..' '..input) end return me diff --git a/miku/plugins/media.lua b/miku/plugins/media.lua index 29b900f..025d01d 100644 --- a/miku/plugins/media.lua +++ b/miku/plugins/media.lua @@ -35,19 +35,19 @@ function media:action(msg, config, matches) chat_action = 'upload_document' end - local file, last_modified, nocache = get_cached_file(url, nil, msg.chat.id, chat_action, self) + local file, last_modified, nocache = get_cached_file(url, nil, msg.chat.id, chat_action) if not file then return end if ext == 'gif' then - result = utilities.send_document(self, receiver, file, nil, msg.message_id) + result = utilities.send_document(receiver, file, nil, msg.message_id) elseif ext == 'ogg' then - result = utilities.send_voice(self, receiver, file, nil, msg.message_id) + result = utilities.send_voice(receiver, file, nil, msg.message_id) elseif mime_type == 'audio' then - result = utilities.send_audio(self, receiver, file, nil, msg.message_id) + result = utilities.send_audio(receiver, file, nil, msg.message_id) elseif mime_type == 'video' then - result = utilities.send_video(self, receiver, file, nil, msg.message_id) + result = utilities.send_video(receiver, file, nil, msg.message_id) else - result = utilities.send_document(self, receiver, file, nil, msg.message_id) + result = utilities.send_document(receiver, file, nil, msg.message_id) end if nocache then return end diff --git a/miku/plugins/minecraft_server.lua b/miku/plugins/minecraft_server.lua index d235bea..717f35b 100644 --- a/miku/plugins/minecraft_server.lua +++ b/miku/plugins/minecraft_server.lua @@ -74,7 +74,7 @@ function mc_server:parseText(text, mc_server) end function mc_server:action(msg, config, matches) - utilities.send_reply(self, msg, mc_server:parseText(msg.text, mc_server), true) + utilities.send_reply(msg, mc_server:parseText(msg.text, mc_server), true) end return mc_server diff --git a/miku/plugins/minecraft_skin.lua b/miku/plugins/minecraft_skin.lua index 8c0d756..29cf67c 100644 --- a/miku/plugins/minecraft_skin.lua +++ b/miku/plugins/minecraft_skin.lua @@ -16,14 +16,14 @@ function mc_skin:action(msg, config, matches) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, mc_skin.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, mc_skin.doc, true, msg.message_id, true) return end end local url = 'http://www.minecraft-skin-viewer.net/3d.php?layers=true&aa=true&a=0&w=330&wt=10&abg=330&abd=40&ajg=340&ajd=20&ratio=13&format=png&login='..input..'&headOnly=false&displayHairs=true&randomness=341.png' local file = download_to_file(url, input..'.png') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end return mc_skin diff --git a/miku/plugins/moe.lua b/miku/plugins/moe.lua index 751eff6..ea1a134 100644 --- a/miku/plugins/moe.lua +++ b/miku/plugins/moe.lua @@ -28,14 +28,14 @@ function moe:action(msg, config, matches) site_url = 'http://yagyuu.moe' end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local photo_url = moe:get_url(site_url) if not photo_url then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end local file = download_to_file(photo_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end return moe \ No newline at end of file diff --git a/miku/plugins/myanimelist.lua b/miku/plugins/myanimelist.lua index a0fd012..99aae68 100644 --- a/miku/plugins/myanimelist.lua +++ b/miku/plugins/myanimelist.lua @@ -205,31 +205,31 @@ function mal:action(msg, config, matches) if matches[1] == 'anime' or matches[1] == 'mal' then local anime_info = mal:get_mal_info(query, 'anime') if anime_info == "HTTP-Fehler" then - utilities.send_reply(self, msg, 'Anime nicht gefunden!') + utilities.send_reply(msg, 'Anime nicht gefunden!') return else local text, image_url = mal:send_anime_data(anime_info) if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) return end elseif matches[1] == 'manga' then local manga_info = mal:get_mal_info(query, 'manga') if manga_info == "HTTP-Fehler" then - utilities.send_reply(self, msg, 'Manga nicht gefunden!') + utilities.send_reply(msg, 'Manga nicht gefunden!') return else local text, image_url = mal:send_manga_data(manga_info) if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) return end end diff --git a/miku/plugins/myfigurecollection.lua b/miku/plugins/myfigurecollection.lua index 085e7ef..8246bf8 100644 --- a/miku/plugins/myfigurecollection.lua +++ b/miku/plugins/myfigurecollection.lua @@ -48,10 +48,10 @@ function mfc:action(msg, config, matches) local user = matches[1] local text = mfc:get_infos(user) if not text then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return mfc \ No newline at end of file diff --git a/miku/plugins/nicovideo.lua b/miku/plugins/nicovideo.lua index e5c54c5..018d2ab 100644 --- a/miku/plugins/nicovideo.lua +++ b/miku/plugins/nicovideo.lua @@ -47,13 +47,13 @@ function nicovideo:action(msg, config, matches) local id = matches[1] local text, pic_url = nicovideo:get_video(id) if not text then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(pic_url, 'nicovideo_thumb.png') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + utilities.send_reply(msg, text, 'HTML') end return nicovideo \ No newline at end of file diff --git a/miku/plugins/notify.lua b/miku/plugins/notify.lua index 7ede65f..67520ab 100644 --- a/miku/plugins/notify.lua +++ b/miku/plugins/notify.lua @@ -23,7 +23,7 @@ function isWordFoundInString(word,input) select(2,input:gsub('%W+' .. word .. '%W+','')) > 0 end -function notify:pre_process(msg, self) +function notify:pre_process(msg) local notify_users = redis:smembers('notify:ls') -- I call this beautiful lady the "if soup" @@ -44,7 +44,7 @@ function notify:pre_process(msg, self) local from = string.gsub(msg.from.name, "%_", " ") local chat_name = string.gsub(msg.chat.title, "%_", " ") local text = from..' am '..send_date..' in "'..chat_name..'":\n\n'..msg.text - utilities.send_message(self, id, text, true) + utilities.send_message(id, text, true) end end end @@ -57,7 +57,7 @@ end function notify:action(msg, config, matches) if not msg.from.username then - utilities.send_reply(self, msg, 'Du hast keinen Usernamen und kannst daher dieses Feature nicht nutzen. Tut mir leid!' ) + utilities.send_reply(msg, 'Du hast keinen Usernamen und kannst daher dieses Feature nicht nutzen. Tut mir leid!' ) return end @@ -67,18 +67,18 @@ function notify:action(msg, config, matches) if matches[1] == "del" then if not redis:sismember('notify:ls', username) then - utilities.send_reply(self, msg, 'Du wirst noch gar nicht benachrichtigt!') + utilities.send_reply(msg, 'Du wirst noch gar nicht benachrichtigt!') return end print('Setze notify redis hash '..hash..' auf false') redis:hset(hash, 'notify', false) print('Lösche '..username..' von redis set notify:ls') redis:srem('notify:ls', username) - utilities.send_reply(self, msg, 'Du erhälst jetzt keine Benachrichtigungen mehr, wenn du angesprochen wirst.') + utilities.send_reply(msg, 'Du erhälst jetzt keine Benachrichtigungen mehr, wenn du angesprochen wirst.') return else if redis:sismember('notify:ls', username) then - utilities.send_reply(self, msg, 'Du wirst schon benachrichtigt!') + utilities.send_reply(msg, 'Du wirst schon benachrichtigt!') return end print('Setze notify in redis hash '..hash..' auf true') @@ -87,11 +87,11 @@ function notify:action(msg, config, matches) redis:hset(hash, 'id', msg.from.id) print('Adde '..username..' zu redis set notify:ls') redis:sadd('notify:ls', username) - local res = utilities.send_message(self, msg.from.id, 'Du erhälst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true, nil, true) + local res = utilities.send_message(msg.from.id, 'Du erhälst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true, nil, true) if not res then - utilities.send_reply(self, msg, 'Bitte schreibe mir [privat](http://telegram.me/' .. self.info.username .. '?start=notify), um den Vorgang abzuschließen.', true) + utilities.send_reply(msg, 'Bitte schreibe mir [privat](http://telegram.me/' .. self.info.username .. '?start=notify), um den Vorgang abzuschließen.', true) elseif msg.chat.type ~= 'private' then - utilities.send_reply(self, msg, 'Du erhälst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true) + utilities.send_reply(msg, 'Du erhälst jetzt Benachrichtigungen, wenn du angesprochen wirst, nutze `/notify del` zum Deaktivieren.', true) end end end diff --git a/miku/plugins/openingsmoe.lua b/miku/plugins/openingsmoe.lua index b6c97ad..97b31b9 100644 --- a/miku/plugins/openingsmoe.lua +++ b/miku/plugins/openingsmoe.lua @@ -26,10 +26,10 @@ function openingsmoe:action(msg, config, matches) local opening = matches[1] local text = openingsmoe:get_opening(opening) if not text then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return openingsmoe \ No newline at end of file diff --git a/miku/plugins/pagespeed_insights.lua b/miku/plugins/pagespeed_insights.lua index de1b199..4a3ef6d 100644 --- a/miku/plugins/pagespeed_insights.lua +++ b/miku/plugins/pagespeed_insights.lua @@ -26,10 +26,10 @@ function pagespeed_insights:get_pagespeed(test_url) end function pagespeed_insights:action(msg, config, matches) - utilities.send_typing(self, msg.chat.id, 'typing') + utilities.send_typing(msg.chat.id, 'typing') local text = pagespeed_insights:get_pagespeed(matches[1]) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_reply(self, msg, text, true) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text, true) end return pagespeed_insights diff --git a/miku/plugins/pasteee.lua b/miku/plugins/pasteee.lua index 15deb8c..724460a 100644 --- a/miku/plugins/pasteee.lua +++ b/miku/plugins/pasteee.lua @@ -33,10 +33,10 @@ function pasteee:action(msg, config, matches) local text = matches[1] local link, iserror = upload(text) if iserror then - utilities.send_reply(self, msg, link) + utilities.send_reply(msg, link) return end - utilities.send_reply(self, msg, '[Text auf Paste.ee ansehen]('..link..')', true) + utilities.send_reply(msg, '[Text auf Paste.ee ansehen]('..link..')', true) end return pasteee \ No newline at end of file diff --git a/miku/plugins/patterns.lua b/miku/plugins/patterns.lua index 7269c7f..646df21 100644 --- a/miku/plugins/patterns.lua +++ b/miku/plugins/patterns.lua @@ -23,11 +23,11 @@ function patterns:action(msg) end ) if res == false then - utilities.send_reply(self, msg, 'Falsches Pattern!') + utilities.send_reply(msg, 'Falsches Pattern!') else output = output:sub(1, 4000) output = '*Du meintest wohl*:\n"'..utilities.md_escape(utilities.trim(output))..'"' - utilities.send_reply(self, msg.reply_to_message, output, true) + utilities.send_reply(msg.reply_to_message, output, true) end end diff --git a/miku/plugins/pixabay.lua b/miku/plugins/pixabay.lua index 380722e..484678f 100644 --- a/miku/plugins/pixabay.lua +++ b/miku/plugins/pixabay.lua @@ -101,13 +101,13 @@ function pixabay:action(msg, config, matches) end if url == 'NOPIX' then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return else - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) local text = '"'..tags..'" von '..user - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..page_url..'"},{"text":"Volles Bild (Login notwendig)","url":"'..full_url..'"}]]}') + utilities.send_photo(msg.chat.id, file, text, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..page_url..'"},{"text":"Volles Bild (Login notwendig)","url":"'..full_url..'"}]]}') return end end diff --git a/miku/plugins/play_store.lua b/miku/plugins/play_store.lua index 3218f2b..511129d 100644 --- a/miku/plugins/play_store.lua +++ b/miku/plugins/play_store.lua @@ -50,7 +50,7 @@ function play_store:action(msg, config, matches) if data == nil then return else - utilities.send_reply(self, msg, play_store:send_playstore_data(data), true) + utilities.send_reply(msg, play_store:send_playstore_data(data), true) return end end diff --git a/miku/plugins/plex.lua b/miku/plugins/plex.lua index 69f2893..d4c916f 100644 --- a/miku/plugins/plex.lua +++ b/miku/plugins/plex.lua @@ -157,26 +157,26 @@ end function plex:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg. plex.doc, true) + utilities.send_reply(msg. plex.doc, true) return end local query = string.gsub(URL.escape(input), '&', '+') local text, pic = plex:get_plex(query) if not text then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return elseif text == 'NOTOK' then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end if pic then - utilities.send_typing(self, receiver, 'upload_photo') + utilities.send_typing(receiver, 'upload_photo') local file = download_to_file(pic, 'plex.png') - utilities.send_photo(self, msg.chat.id, file) + utilities.send_photo(msg.chat.id, file) end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return plex diff --git a/miku/plugins/plugins.lua b/miku/plugins/plugins.lua index f6ce2b2..8fad5c5 100644 --- a/miku/plugins/plugins.lua +++ b/miku/plugins/plugins.lua @@ -162,13 +162,13 @@ end function plugin_manager:action(msg, config, matches) if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end -- Show the available plugins if matches[1] == '/plugins' then - utilities.send_reply(self, msg, plugin_manager:list_plugins()) + utilities.send_reply(msg, plugin_manager:list_plugins()) return end @@ -178,11 +178,11 @@ function plugin_manager:action(msg, config, matches) if matches[4] then local id = matches[4] print("enable "..plugin..' on chat#id'..id) - utilities.send_reply(self, msg, plugin_manager:reenable_plugin_on_chat(id, plugin)) + utilities.send_reply(msg, plugin_manager:reenable_plugin_on_chat(id, plugin)) return else print("enable "..plugin..' on this chat') - utilities.send_reply(self, msg, plugin_manager:reenable_plugin_on_chat(msg, plugin)) + utilities.send_reply(msg, plugin_manager:reenable_plugin_on_chat(msg, plugin)) return end end @@ -191,7 +191,7 @@ function plugin_manager:action(msg, config, matches) if matches[1] == 'enable' then local plugin_name = matches[2] print("enable: "..matches[2]) - utilities.send_reply(self, msg, plugin_manager:enable_plugin(self, config, plugin_name)) + utilities.send_reply(msg, plugin_manager:enable_plugin(self, config, plugin_name)) return end @@ -201,11 +201,11 @@ function plugin_manager:action(msg, config, matches) if matches[4] then local id = matches[4] print("disable "..plugin..' on chat#id'..id) - utilities.send_reply(self, msg, plugin_manager:disable_plugin_on_chat(id, plugin)) + utilities.send_reply(msg, plugin_manager:disable_plugin_on_chat(id, plugin)) return else print("disable "..plugin..' on this chat') - utilities.send_reply(self, msg, plugin_manager:disable_plugin_on_chat(msg, plugin)) + utilities.send_reply(msg, plugin_manager:disable_plugin_on_chat(msg, plugin)) return end end @@ -213,13 +213,13 @@ function plugin_manager:action(msg, config, matches) -- Disable a plugin if matches[1] == 'disable' then print("disable: "..matches[2]) - utilities.send_reply(self, msg, plugin_manager:disable_plugin(self, config, matches[2])) + utilities.send_reply(msg, plugin_manager:disable_plugin(self, config, matches[2])) return end -- Reload all the plugins! if matches[1] == 'reload' then - utilities.send_reply(self, msg, plugin_manager:reload_plugins(self, config)) + utilities.send_reply(msg, plugin_manager:reload_plugins(self, config)) return end end diff --git a/miku/plugins/pocket.lua b/miku/plugins/pocket.lua index bb88dd4..ee1ffe8 100644 --- a/miku/plugins/pocket.lua +++ b/miku/plugins/pocket.lua @@ -102,40 +102,40 @@ function pocket:action(msg, config, matches) if matches[1] == 'set' then local access_token = matches[2] - utilities.send_reply(self, msg, pocket:set_pocket_access_token(hash, access_token), true) + utilities.send_reply(msg, pocket:set_pocket_access_token(hash, access_token), true) local message_id = redis:hget(hash, 'pocket_login_msg') - utilities.edit_message(self, msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) + utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) redis:hdel(hash, 'pocket_login_msg') return end if not access_token then - local result = utilities.send_reply(self, msg, '*Bitte authentifiziere dich zuerst, indem du dich anmeldest.*', true, '{"inline_keyboard":[[{"text":"Bei Pocket anmelden","url":"https://brawlbot.tk/apis/callback/pocket/connect.php"}]]}') + local result = utilities.send_reply(msg, '*Bitte authentifiziere dich zuerst, indem du dich anmeldest.*', true, '{"inline_keyboard":[[{"text":"Bei Pocket anmelden","url":"https://brawlbot.tk/apis/callback/pocket/connect.php"}]]}') redis:hset(hash, 'pocket_login_msg', result.result.message_id) return end if matches[1] == 'unauth' then redis:hdel(hash, 'pocket') - utilities.send_reply(self, msg, 'Erfolgreich ausgeloggt! Du kannst den Zugriff [in deinen Einstellungen](https://getpocket.com/connected_applications) endgültig entziehen.', true) + utilities.send_reply(msg, 'Erfolgreich ausgeloggt! Du kannst den Zugriff [in deinen Einstellungen](https://getpocket.com/connected_applications) endgültig entziehen.', true) return end if matches[1] == 'add' then - utilities.send_reply(self, msg, pocket:add_pocket_item(access_token, matches[2])) + utilities.send_reply(msg, pocket:add_pocket_item(access_token, matches[2])) return end if matches[1] == 'archive' or matches[1] == 'delete' or matches[1] == 'readd' or matches[1] == 'favorite' or matches[1] == 'unfavorite' then - utilities.send_reply(self, msg, pocket:modify_pocket_item(access_token, matches[1], matches[2])) + utilities.send_reply(msg, pocket:modify_pocket_item(access_token, matches[1], matches[2])) return end if msg.chat.type == 'chat' or msg.chat.type == 'supergroup' then - utilities.send_reply(self, msg, 'Ausgeben deiner privaten Pocket-Liste in einem öffentlichen Chat wird feige verweigert. Bitte schreibe mich privat an!', true) + utilities.send_reply(msg, 'Ausgeben deiner privaten Pocket-Liste in einem öffentlichen Chat wird feige verweigert. Bitte schreibe mich privat an!', true) return else - utilities.send_reply(self, msg, pocket:list_pocket_items(access_token)) + utilities.send_reply(msg, pocket:list_pocket_items(access_token)) return end end diff --git a/miku/plugins/pokedex.lua b/miku/plugins/pokedex.lua index 1aab7b9..c5e9ccf 100644 --- a/miku/plugins/pokedex.lua +++ b/miku/plugins/pokedex.lua @@ -13,14 +13,14 @@ end function pokedex:action(msg, config) - bindings.sendChatAction(self, { chat_id = msg.chat.id, action = 'typing' } ) + bindings.sendChatAction({ chat_id = msg.chat.id, action = 'typing' } ) local input = utilities.input(msg.text_lower) if not input then if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, pokedex.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, pokedex.doc, true, msg.message_id, true) return end end @@ -30,7 +30,7 @@ function pokedex:action(msg, config) local dex_url = url .. '/api/v1/pokemon/' .. input local dex_jstr, res = http.request(dex_url) if res ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end @@ -39,7 +39,7 @@ function pokedex:action(msg, config) local desc_url = url .. dex_jdat.descriptions[math.random(#dex_jdat.descriptions)].resource_uri local desc_jstr, _ = http.request(desc_url) if res ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end @@ -59,7 +59,7 @@ function pokedex:action(msg, config) local output = '*' .. dex_jdat.name .. '*\n#' .. dex_jdat.national_id .. ' | ' .. poke_type .. '\n_' .. desc_jdat.description:gsub('POKMON', 'Pokémon'):gsub('Pokmon', 'Pokémon') .. '_' - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_message(msg.chat.id, output, true, nil, true) end diff --git a/miku/plugins/porndoge.lua b/miku/plugins/porndoge.lua index 789ae0a..8b1526f 100644 --- a/miku/plugins/porndoge.lua +++ b/miku/plugins/porndoge.lua @@ -9,14 +9,14 @@ end porndoge.command = 'pdoge' function porndoge:action(msg, config) - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local url = 'https://porndoge.herokuapp.com/' local file = download_to_file(url, 'porndoge.png') if not file then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end return porndoge \ No newline at end of file diff --git a/miku/plugins/pornhub_gif.lua b/miku/plugins/pornhub_gif.lua index 5301baa..aadf9c0 100644 --- a/miku/plugins/pornhub_gif.lua +++ b/miku/plugins/pornhub_gif.lua @@ -14,10 +14,10 @@ pornhub.command = 'ge ' function pornhub:action(msg, config, matches) local url = 'http://img.pornhub.com/gif/'..matches[1]..'.gif' - utilities.send_typing(self, msg.chat.id, 'upload_document') + utilities.send_typing(msg.chat.id, 'upload_document') local file = download_to_file(url) if not file then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end @@ -26,7 +26,7 @@ function pornhub:action(msg, config, matches) else source = nil end - utilities.send_document(self, msg.chat.id, file, source, msg.message_id) + utilities.send_document(msg.chat.id, file, source, msg.message_id) end return pornhub \ No newline at end of file diff --git a/miku/plugins/post_photo.lua b/miku/plugins/post_photo.lua index 38eb757..90c9623 100644 --- a/miku/plugins/post_photo.lua +++ b/miku/plugins/post_photo.lua @@ -7,7 +7,7 @@ post_photo.triggers = { '/nil' } -function post_photo:pre_process(msg, self, config) +function post_photo:pre_process(msg, config) if not msg.document then return msg end -- Ignore local mime_type = msg.document.mime_type local valid_mimetypes = {['image/jpeg'] = true, ['image/png'] = true, ['image/bmp'] = true} @@ -20,15 +20,15 @@ function post_photo:pre_process(msg, self, config) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') -- Saving file to the Telegram Cloud - local request = bindings.request(self, 'getFile', { + local request = bindings.request('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) + utilities.send_photo(msg.chat.id, file, msg.caption, msg.message_id) return msg end diff --git a/miku/plugins/pr0gramm.lua b/miku/plugins/pr0gramm.lua index 861ca8d..86db717 100644 --- a/miku/plugins/pr0gramm.lua +++ b/miku/plugins/pr0gramm.lua @@ -27,16 +27,16 @@ function pr0gramm:action(msg, config, matches) local id = matches[1] local url = pr0gramm:get_post(id) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end end diff --git a/miku/plugins/preview.lua b/miku/plugins/preview.lua index 345d09a..532fca5 100644 --- a/miku/plugins/preview.lua +++ b/miku/plugins/preview.lua @@ -15,9 +15,9 @@ end function preview:inline_callback(inline_query, config, matches) local preview_url = matches[1] local res, code = https.request('https://brawlbot.tk/apis/simple_meta_api/?url='..URL.escape(preview_url)) - if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end + if code ~= 200 then abort_inline_query(inline_query) return end local data = json.decode(res) - if data.remote_code >= 400 then utilities.answer_inline_query(self, inline_query) return end + if data.remote_code >= 400 then abort_inline_query(inline_query) return end if data.title then title = data.title @@ -42,13 +42,13 @@ function preview:inline_callback(inline_query, config, matches) local message_text = ''..title..''..description_in_text..'\n— '..only_name local results = '[{"type":"article","id":"77","title":"'..title..'","description":"'..description..'","url":"'..preview_url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":150,"thumb_height":150,"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Webseite aufrufen","url":"'..preview_url..'"}]]},"input_message_content":{"message_text":"'..message_text..'","parse_mode":"HTML","disable_web_page_preview":true}}]' - utilities.answer_inline_query(self, inline_query, results, 3600, true) + utilities.answer_inline_query(inline_query, results, 3600, true) end function preview:action(msg) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, preview.doc, true) + utilities.send_reply(msg, preview.doc, true) return end @@ -59,18 +59,18 @@ function preview:action(msg) local res = http.request(input) if not res then - utilities.send_reply(self, msg, 'Bitte gebe einen validen Link an.') + utilities.send_reply(msg, 'Bitte gebe einen validen Link an.') return end if res:len() == 0 then - utilities.send_reply(self, msg, 'Sorry, dieser Link lässt uns keine Vorschau erstellen.') + utilities.send_reply(msg, 'Sorry, dieser Link lässt uns keine Vorschau erstellen.') return end -- Invisible zero-width, non-joiner. local output = '' .. utilities.char.zwnj .. '' - utilities.send_message(self, msg.chat.id, output, false, nil, 'HTML') + utilities.send_message(msg.chat.id, output, false, nil, 'HTML') end return preview \ No newline at end of file diff --git a/miku/plugins/qr.lua b/miku/plugins/qr.lua index 7959ba6..836fbe3 100644 --- a/miku/plugins/qr.lua +++ b/miku/plugins/qr.lua @@ -71,9 +71,9 @@ end function qr:inline_callback(inline_query, config, matches) local text = matches[1] - if string.len(text) > 200 then utilities.answer_inline_query(self, inline_query) return end + if string.len(text) > 200 then abort_inline_query(inline_query) return end local image_url = qr:qr(text, nil, nil, 'jpg') - if not image_url then utilities.answer_inline_query(self, inline_query) return end + if not image_url then abort_inline_query(inline_query) return end local id = 600 @@ -93,7 +93,7 @@ function qr:inline_callback(inline_query, config, matches) end local results = results..']' - utilities.answer_inline_query(self, inline_query, results, 10000) + utilities.answer_inline_query(inline_query, results, 10000) end function qr:action(msg, config, matches) @@ -108,9 +108,9 @@ function qr:action(msg, config, matches) end local image_url = qr:qr(text, color, back) - if not image_url then utilities.send_reply(self, msg, config.errors.connection) return end + if not image_url then utilities.send_reply(msg, config.errors.connection) return end local file = download_to_file(image_url, 'qr.png') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end return qr \ No newline at end of file diff --git a/miku/plugins/quotes.lua b/miku/plugins/quotes.lua index 07756b8..bb79faa 100644 --- a/miku/plugins/quotes.lua +++ b/miku/plugins/quotes.lua @@ -81,28 +81,28 @@ end function quotes:action(msg, config, matches) if matches[1] == "quote" then - utilities.send_message(self, msg.chat.id, quotes:get_quote(msg), true) + utilities.send_message(msg.chat.id, quotes:get_quote(msg), true) return elseif matches[1] == "addquote" and matches[2] then - utilities.send_reply(self, msg, quotes:save_quote(msg), true) + utilities.send_reply(msg, quotes:save_quote(msg), true) return elseif matches[1] == "delquote" and matches[2] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end - utilities.send_reply(self, msg, quotes:delete_quote(msg), true) + utilities.send_reply(msg, quotes:delete_quote(msg), true) return elseif matches[1] == "listquotes" then local link, iserror = quotes:list_quotes(msg) if iserror then - utilities.send_reply(self, msg, link, true) + utilities.send_reply(msg, link, true) return end - utilities.send_reply(self, msg, 'Ich habe eine Liste aller Zitate hochgeladen.', false, '{"inline_keyboard":[[{"text":"Alle Zitate abrufen","url":"'..link..'"}]]}') + utilities.send_reply(msg, 'Ich habe eine Liste aller Zitate hochgeladen.', false, '{"inline_keyboard":[[{"text":"Alle Zitate abrufen","url":"'..link..'"}]]}') return end - utilities.send_reply(self, msg, quotes.doc, true) + utilities.send_reply(msg, quotes.doc, true) end return quotes diff --git a/miku/plugins/random.lua b/miku/plugins/random.lua index 428c62e..bf11484 100644 --- a/miku/plugins/random.lua +++ b/miku/plugins/random.lua @@ -52,14 +52,14 @@ function fun:action(msg, config, matches) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, fun.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, fun.doc, true, msg.message_id, true) return end end local user_name = get_name(msg) local result = fun:choose_random(user_name, input) - utilities.send_message(self, msg.chat.id, result) + utilities.send_message(msg.chat.id, result) end return fun diff --git a/miku/plugins/random_pic.lua b/miku/plugins/random_pic.lua index 87f37f7..626ef11 100644 --- a/miku/plugins/random_pic.lua +++ b/miku/plugins/random_pic.lua @@ -26,7 +26,7 @@ end function rpic:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, rpic.doc, true) + utilities.send_reply(msg, rpic.doc, true) return end @@ -45,17 +45,17 @@ function rpic:action(msg, config) local img = pics[input]..rpic:get_random_image(pics[input]) print("Sende... "..img) if string.ends(img, ".gif") or string.ends(img, ".mp4") then - utilities.send_document(self, msg.chat.id, img) + utilities.send_document(msg.chat.id, img) return elseif string.ends(img, ".jpg") or string.ends(img, ".jpeg") or string.ends(img, ".png") then - utilities.send_photo(self, msg.chat.id, img) + utilities.send_photo(msg.chat.id, img) return else - utilities.send_reply(self, msg, 'Fehler: '..img) + utilities.send_reply(msg, 'Fehler: '..img) return end else - utilities.send_reply(self, msg, '*Dieses Thema gibt es nicht!*'..rpic.doc, true) + utilities.send_reply(msg, '*Dieses Thema gibt es nicht!*'..rpic.doc, true) return end end diff --git a/miku/plugins/random_pic_nsfw.lua b/miku/plugins/random_pic_nsfw.lua index 737bca1..79b0f17 100644 --- a/miku/plugins/random_pic_nsfw.lua +++ b/miku/plugins/random_pic_nsfw.lua @@ -36,17 +36,17 @@ function rpic_nsfw:action(msg, config) local img = pics[input]..rpic_nsfw:get_random_image(pics[input]) print("Sende... "..img) if string.ends(img, ".gif") or string.ends(img, ".mp4") then - utilities.send_document(self, msg.chat.id, img) + utilities.send_document(msg.chat.id, img) return elseif string.ends(img, ".jpg") or string.ends(img, ".jpeg") or string.ends(img, ".png") then - utilities.send_photo(self, msg.chat.id, img) + utilities.send_photo(msg.chat.id, img) return else - utilities.send_reply(self, msg, 'Fehler: '..img) + utilities.send_reply(msg, 'Fehler: '..img) return end else - utilities.send_reply(self, msg, '*Dieses Thema gibt es nicht!*'..rpic_nsfw.doc, true) + utilities.send_reply(msg, '*Dieses Thema gibt es nicht!*'..rpic_nsfw.doc, true) return end end diff --git a/miku/plugins/reddit.lua b/miku/plugins/reddit.lua index cc46488..04706e8 100644 --- a/miku/plugins/reddit.lua +++ b/miku/plugins/reddit.lua @@ -61,15 +61,15 @@ function reddit:action(msg, config) end local jstr, res = https.request(url) if res ~= 200 then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) else local jdat = json.decode(jstr) if #jdat.data.children == 0 then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) else local output = format_results(jdat.data.children) output = source .. output - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_message(msg.chat.id, output, true, nil, true) end end end diff --git a/miku/plugins/reddit_post.lua b/miku/plugins/reddit_post.lua index cc2d16d..fdc0ba1 100644 --- a/miku/plugins/reddit_post.lua +++ b/miku/plugins/reddit_post.lua @@ -39,12 +39,12 @@ function reddit_post:action(msg, config, matches) local subreddit = matches[1] local reddit_code = matches[2] local data = reddit_post:get_reddit_data(subreddit, reddit_code) - if not data then utilities.send_reply(self, msg, config.errors.connection) return end + if not data then utilities.send_reply(msg, config.errors.connection) return end local text = reddit_post:send_reddit_data(data) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end + if not text then utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) end return reddit_post diff --git a/miku/plugins/remind.lua b/miku/plugins/remind.lua index adf967c..c72c0cb 100644 --- a/miku/plugins/remind.lua +++ b/miku/plugins/remind.lua @@ -16,13 +16,13 @@ end function remind:action(msg, config) local input = utilities.input(msg.text) if not input then - utilities.send_reply(self, msg, remind.doc, true) + utilities.send_reply(msg, remind.doc, true) return end local duration = tonumber(utilities.get_word(input, 1)) if not duration then - utilities.send_reply(self, msg, remind.doc, true) + utilities.send_reply(msg, remind.doc, true) return end @@ -33,12 +33,12 @@ function remind:action(msg, config) end local message = utilities.input(input) if not message then - utilities.send_reply(self, msg, remind.doc, true) + utilities.send_reply(msg, remind.doc, true) return end if #message > config.remind.max_length then - utilities.send_reply(self, msg, 'Die maximale Länge einer Erinnerung ist ' .. config.remind.max_length .. '.') + utilities.send_reply(msg, 'Die maximale Länge einer Erinnerung ist ' .. config.remind.max_length .. '.') return end @@ -60,7 +60,7 @@ function remind:action(msg, config) local human_readable_time = convert_timestamp(timestamp, '%H:%M:%S') output = 'Ich werde dich um *'..human_readable_time..' Uhr* erinnern.' end - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end function remind:cron(config) @@ -73,7 +73,7 @@ function remind:cron(config) -- Otherwise, add it to the replacement table. if time > reminder.time then local output = '*ERINNERUNG:*\n"' .. utilities.md_escape(reminder.message) .. '"' - local res = utilities.send_message(self, chat_id, output, true, nil, true) + local res = utilities.send_message(chat_id, output, true, nil, true) -- If the message fails to send, save it for later (if enabled in config). if res or not config.remind.persist then group[k] = nil diff --git a/miku/plugins/respond.lua b/miku/plugins/respond.lua index 8b5117d..887432c 100644 --- a/miku/plugins/respond.lua +++ b/miku/plugins/respond.lua @@ -41,7 +41,7 @@ function respond:inline_callback(inline_query, config, matches) face = '¯\\\\\\_(ツ)_/¯' end results = '[{"type":"article","id":"8","title":"'..face..'","input_message_content":{"message_text":"'..face..'"}}]' - utilities.answer_inline_query(self, inline_query, results, 9999) + utilities.answer_inline_query(inline_query, results, 9999) end function respond:action(msg, config, matches) @@ -51,35 +51,35 @@ function respond:action(msg, config, matches) if user_name == "DefenderX" then user_name = "Deffu" end if string.match(msg.text, "[Ff][Gg][Tt].? [Ss][Ww][Ii][Ff][Tt]") then - utilities.send_message(self, receiver, 'Dünnes Eis, '..user_name..'!') + utilities.send_message(receiver, 'Dünnes Eis, '..user_name..'!') return elseif string.match(msg.text, "([Ee][Ii][Nn][Zz][Ii][Gg][Ss][Tt][Ee][Ss])") then - utilities.send_message(self, receiver, '*einziges') + utilities.send_message(receiver, '*einziges') return elseif string.match(msg.text, "([Ee][Ii][Nn][Zz][Ii][Gg][Ss][Tt][Ee][Rr])") then - utilities.send_message(self, receiver, '*einziger') + utilities.send_message(receiver, '*einziger') return elseif string.match(msg.text, "([Ee][Ii][Nn][Zz][Ii][Gg][Ss][Tt][Ee])") then - utilities.send_message(self, receiver, '*einzige') + utilities.send_message(receiver, '*einzige') return elseif string.match(msg.text, "[Bb][Oo][Tt]%??") then - utilities.send_reply(self, msg, '*Ich bin da, '..user_name..'!*', true) + utilities.send_reply(msg, '*Ich bin da, '..user_name..'!*', true) return elseif string.match(msg.text, "[Ll][Oo][Dd]") then - utilities.send_message(self, receiver, 'ಠ_ಠ') + utilities.send_message(receiver, 'ಠ_ಠ') return elseif string.match(msg.text, "[Ll][Ff]") then - utilities.send_message(self, receiver, '( ͡° ͜ʖ ͡°)') + utilities.send_message(receiver, '( ͡° ͜ʖ ͡°)') return elseif string.match(msg.text, "[Nn][Bb][Cc]") or string.match(msg.text, "[Ii][Dd][Cc]") or string.match(msg.text, "[Kk][Aa]") or string.match(msg.text, "[Ii][Dd][Kk]") then - utilities.send_message(self, receiver, [[¯\_(ツ)_/¯]]) + utilities.send_message(receiver, [[¯\_(ツ)_/¯]]) return elseif string.match(msg.text, "[Ff][Rr][Oo][Ss][Cc][Hh]") then - utilities.send_message(self, receiver, '🐸🐸🐸') + utilities.send_message(receiver, '🐸🐸🐸') return elseif string.match(msg.text, "[Ii][Nn][Ll][Oo][Vv][Ee]") then local file = download_to_file(BASE_URL..'/inlove.gif') - utilities.send_document(self, receiver, file) + utilities.send_document(receiver, file) return elseif string.match(msg.text, "[Ww][Aa][Tt]") then local WAT_URL = BASE_URL..'/wat' @@ -95,7 +95,7 @@ function respond:action(msg, config, matches) } local random_wat = math.random(5) local file = download_to_file(WAT_URL..wats[random_wat]) - utilities.send_photo(self, receiver, file) + utilities.send_photo(receiver, file, nil, msg.message_id) return end diff --git a/miku/plugins/roll.lua b/miku/plugins/roll.lua index d65bec6..bf82667 100644 --- a/miku/plugins/roll.lua +++ b/miku/plugins/roll.lua @@ -23,7 +23,7 @@ function roll:roll_dice() end function roll:action(msg) - utilities.send_reply(self, msg, 'Du hast eine *'..roll:roll_dice()..'* gewürfelt.', true) + utilities.send_reply(msg, 'Du hast eine *'..roll:roll_dice()..'* gewürfelt.', true) end return roll diff --git a/miku/plugins/rss.lua b/miku/plugins/rss.lua index b03a52b..a7af5df 100644 --- a/miku/plugins/rss.lua +++ b/miku/plugins/rss.lua @@ -223,42 +223,42 @@ function rss:action(msg, config, matches) -- For channels if matches[1] == 'sub' and matches[2] and matches[3] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local id = '@'..matches[3] - local result = utilities.get_chat_info(self, id) + local result = utilities.get_chat_info(id) if not result then - utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + utilities.send_reply(msg, 'Diesen Kanal gibt es nicht!') return end local output = rss:subscribe(id, matches[2]) - utilities.send_reply(self, msg, output, 'HTML') + utilities.send_reply(msg, output, 'HTML') return elseif matches[1] == 'del' and matches[2] and matches[3] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local id = '@'..matches[3] - local result = utilities.get_chat_info(self, id) + local result = utilities.get_chat_info(id) if not result then - utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + utilities.send_reply(msg, 'Diesen Kanal gibt es nicht!') return end local output = rss:unsubscribe(id, matches[2]) - utilities.send_reply(self, msg, output, 'HTML') + utilities.send_reply(msg, output, 'HTML') return elseif matches[1] == 'rss' and matches[2] then local id = '@'..matches[2] - local result = utilities.get_chat_info(self, id) + local result = utilities.get_chat_info(id) if not result then - utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + utilities.send_reply(msg, 'Diesen Kanal gibt es nicht!') return end local chat_name = result.result.title local output = rss:print_subs(id, chat_name) - utilities.send_reply(self, msg, output, 'HTML') + utilities.send_reply(msg, output, 'HTML') return end @@ -270,42 +270,39 @@ function rss:action(msg, config, matches) if matches[1] == 'sub' and matches[2] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local output = rss:subscribe(id, matches[2]) - utilities.send_reply(self, msg, output, 'HTML') + utilities.send_reply(msg, output, 'HTML') return elseif matches[1] == 'del' and matches[2] then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end local output = rss:unsubscribe(id, matches[2]) - utilities.send_reply(self, msg, output, 'HTML', '{"hide_keyboard":true}') + utilities.send_reply(msg, output, 'HTML', '{"hide_keyboard":true}') return elseif matches[1] == 'del' and not matches[2] then local list_subs, keyboard = rss:print_subs(id, chat_name) - utilities.send_reply(self, msg, list_subs, 'HTML', keyboard) + utilities.send_reply(msg, list_subs, 'HTML', keyboard) return elseif matches[1] == 'sync' then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end - rss:cron(self) + rss:cron() return end local output = rss:print_subs(id, chat_name) - utilities.send_reply(self, msg, output, 'HTML') + utilities.send_reply(msg, output, 'HTML') return end -function rss:cron(self_plz) - if not self.BASE_URL then - self = self_plz - end +function rss:cron() local keys = redis:keys(get_base_redis("*", "subs")) for k,v in pairs(keys) do local base = string.match(v, "rss:(.+):subs") -- Get the URL base @@ -355,7 +352,7 @@ function rss:cron(self_plz) for k2, receiver in pairs(redis:smembers(v)) do local receiver = string.gsub(receiver, 'chat%#id', '') local receiver = string.gsub(receiver, 'user%#id', '') - utilities.send_message(self, receiver, text, true, nil, 'HTML') + utilities.send_message(receiver, text, true, nil, 'HTML') end end end diff --git a/miku/plugins/rule34.lua b/miku/plugins/rule34.lua index e6a5d78..cf2acbc 100644 --- a/miku/plugins/rule34.lua +++ b/miku/plugins/rule34.lua @@ -46,15 +46,15 @@ function rule34:action(msg, config, matches) local id = matches[2] local img_url = rule34:get_r34_post(id) if not img_url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(img_url) if string.ends(img_url, ".gif") then - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end else @@ -64,15 +64,15 @@ function rule34:action(msg, config, matches) local tag = string.gsub(tag, "+", '%%2B') local url, id = rule34:get_r34_info(tag) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) if string.ends(url, ".gif") then - utilities.send_document(self, msg.chat.id, file, id, msg.message_id) + utilities.send_document(msg.chat.id, file, id, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, id, msg.message_id) + utilities.send_photo(msg.chat.id, file, id, msg.message_id) end end diff --git a/miku/plugins/sankakucomplex.lua b/miku/plugins/sankakucomplex.lua index 22609a5..62d9a4e 100644 --- a/miku/plugins/sankakucomplex.lua +++ b/miku/plugins/sankakucomplex.lua @@ -26,7 +26,7 @@ end function sankakucomplex:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, sankakucomplex.doc, true) + utilities.send_reply(msg, sankakucomplex.doc, true) return end @@ -35,18 +35,18 @@ function sankakucomplex:action(msg, config) local url = sankakucomplex:get_post(tag) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, url) + utilities.send_reply(msg, url) end return sankakucomplex \ No newline at end of file diff --git a/miku/plugins/service_entergroup.lua b/miku/plugins/service_entergroup.lua index 079930d..30b1598 100644 --- a/miku/plugins/service_entergroup.lua +++ b/miku/plugins/service_entergroup.lua @@ -22,10 +22,10 @@ function entergroup:chat_new_user(msg, self) return end local text = 'Hallo '..user_name..', willkommen bei '..chat_title..'!'..added_by - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end -function entergroup:chat_del_user(msg, self) +function entergroup:chat_del_user(msg) if msg.left_chat_member.id == msg.from.id then -- silent ignore, if user wasn't kicked return end @@ -36,7 +36,7 @@ function entergroup:chat_del_user(msg, self) at_name = '' end local text = ''..user_name..' wurde von '..msg.from.first_name..''..at_name..' aus der Gruppe gekickt.' - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end function entergroup:action(msg, config, matches) @@ -45,7 +45,7 @@ function entergroup:action(msg, config, matches) if matches[1] == 'new_chat_member' then entergroup:chat_new_user(msg, self) elseif matches[1] == 'left_chat_member'then - entergroup:chat_del_user(msg, self) + entergroup:chat_del_user(msg) end end diff --git a/miku/plugins/service_leave_group.lua b/miku/plugins/service_leave_group.lua index f8ae1a7..bf85724 100644 --- a/miku/plugins/service_leave_group.lua +++ b/miku/plugins/service_leave_group.lua @@ -7,13 +7,13 @@ leave_group.triggers = { local report_to_admin = true -- set to false to not be notified, when Bot leaves groups without you -function leave_group:check_for_admin(msg, self, config) - local result = bindings.request(self, 'getChatMember', { +function leave_group:check_for_admin(msg, config) + local result = bindings.request('getChatMember', { chat_id = msg.chat.id, user_id = config.admin } ) if not result.ok then - print('Konnte nicht prfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber...') + print('Konnte nicht prüfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber...') return false end if result.result.status ~= "member" and result.result.status ~= "administrator" and result.result.status ~= "creator" then @@ -25,11 +25,11 @@ end function leave_group:action(msg, config) if not is_service_msg(msg) then return end -- Bad attempt at trolling! - local admin_in_group = leave_group:check_for_admin(msg, self, config) + local admin_in_group = leave_group:check_for_admin(msg, config) if not admin_in_group then print('Admin ist nicht in der Gruppe, verlasse sie deshalb...') - utilities.send_reply(self, msg, 'Dieser Bot wurde in eine fremde Gruppe hinzugefgt. Dies wird gemeldet!\nThis bot was added to foreign group. This incident will be reported!') - local result = bindings.request(self, 'leaveChat', { + utilities.send_reply(msg, 'Dieser Bot wurde in eine fremde Gruppe hinzugefügt. Dies wird gemeldet!\nThis bot was added to foreign group. This incident will be reported!') + local result = bindings.request('leaveChat', { chat_id = msg.chat.id } ) local chat_name = msg.chat.title @@ -37,7 +37,7 @@ function leave_group:action(msg, config) local from = msg.from.name local from_id = msg.from.id if report_to_admin then - utilities.send_message(self, config.admin, '#WARNUNG: Bot wurde in fremde Gruppe hinzugefgt:\nGruppenname: '..chat_name..' ('..chat_id..')\nHinzugefgt von: '..from..' ('..from_id..')') + utilities.send_message(config.admin, '#WARNUNG: Bot wurde in fremde Gruppe hinzugefügt:\nGruppenname: '..chat_name..' ('..chat_id..')\nHinzugefügt von: '..from..' ('..from_id..')') end end end diff --git a/miku/plugins/service_migrate_to_supergroup.lua b/miku/plugins/service_migrate_to_supergroup.lua index 510f49d..725be1c 100644 --- a/miku/plugins/service_migrate_to_supergroup.lua +++ b/miku/plugins/service_migrate_to_supergroup.lua @@ -60,7 +60,7 @@ function migrate:action(msg, config, matches) end print('--- SUPERGROUP MIGRATION ENDED ---') - utilities.send_message(self, new_id, 'Die User-ID dieser Gruppe ist nun '..new_id..'.\nAlle Daten wurden bertragen.') + utilities.send_message(new_id, 'Die User-ID dieser Gruppe ist nun '..new_id..'.\nAlle Daten wurden übertragen.') end return migrate \ No newline at end of file diff --git a/miku/plugins/set.lua b/miku/plugins/set.lua index e133e92..ca1a441 100644 --- a/miku/plugins/set.lua +++ b/miku/plugins/set.lua @@ -33,7 +33,7 @@ end function set:action(msg) local input = utilities.input(msg.text) if not input or not input:match('([^%s]+) (.+)') then - utilities.send_message(self, msg.chat.id, set.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, set.doc, true, msg.message_id, true) return end @@ -46,7 +46,7 @@ function set:action(msg) output = set:save_value(msg, name, value) end - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_message(msg.chat.id, output, true, nil, true) end return set diff --git a/miku/plugins/settings.lua b/miku/plugins/settings.lua index b8a6f17..b206e99 100644 --- a/miku/plugins/settings.lua +++ b/miku/plugins/settings.lua @@ -35,18 +35,18 @@ function settings:action(msg, config, matches) local hash = 'user:'..msg.from.id if matches[1] == '⚙ Einstellungen' or matches[1] == '/settings' then - utilities.send_reply(self, msg, 'Was möchtest du einstellen?', false, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') + utilities.send_reply(msg, 'Was möchtest du einstellen?', false, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') return elseif matches[1] == '💤 AFK-Keyboard einschalten' then redis:hset(hash, 'afk_keyboard', 'true') - utilities.send_reply(self, msg, 'Das AFK-Keyboard wurde erfolgreich *eingeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') + utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *eingeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') return elseif matches[1] == '💤 AFK-Keyboard ausschalten' then redis:hset(hash, 'afk_keyboard', 'false') - utilities.send_reply(self, msg, 'Das AFK-Keyboard wurde erfolgreich *ausgeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') + utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *ausgeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') return elseif matches[1] == '❌ Einstellungen verstecken' then - utilities.send_reply(self, msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}') + utilities.send_reply(msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}') return end end diff --git a/miku/plugins/shell.lua b/miku/plugins/shell.lua index 08e7308..1df7ff1 100644 --- a/miku/plugins/shell.lua +++ b/miku/plugins/shell.lua @@ -39,7 +39,7 @@ end function shell:action(msg, config, matches) if not is_sudo(msg, config) then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end @@ -49,7 +49,7 @@ function shell:action(msg, config, matches) local cmd = run_command('uptime -s && uptime -p') local text1 = 'Der PC ist seit dem '..makeOurDate(string.match(cmd, '(%d+-%d+-%d+)'))..' an.' local text2 = shell:transeng('Das sind '..string.match(cmd, 'up (.*)')..'') - utilities.send_reply(self, msg, text1..'\n'..text2, 'HTML') + utilities.send_reply(msg, text1..'\n'..text2, 'HTML') return end @@ -58,28 +58,28 @@ function shell:action(msg, config, matches) local taken_time = os.date("%A, %d. %B %Y um %H:%M:%S Uhr") run_command("scrot 'scrot.png' -e 'mv $f /tmp/'") local text = '#Screenshot vom '..shell:transeng(taken_time) - utilities.send_photo(self, msg.chat.id, '/tmp/scrot.png', text, msg.message_id) + utilities.send_photo(msg.chat.id, '/tmp/scrot.png', text, msg.message_id) return end -- Requires fswebcam (sudo apt-get install fswebcam) if msg.text:match('^/[Ww][Ee][Bb][Cc][Aa][Mm]$') then run_command("fswebcam -r 640x480 --png 9 -D 1 /tmp/webcam.png") - utilities.send_photo(self, msg.chat.id, '/tmp/webcam.png', nil, msg.message_id) + utilities.send_photo(msg.chat.id, '/tmp/webcam.png', nil, msg.message_id) return end if msg.text:match('^/[Cc][Hh][Ee][Cc][Kk]$') then local cmd = run_command("apt --just-print upgrade") local text = 'Es gibt '..string.match(cmd, '(%d+) aktualisiert')..' Updates' - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') return end -- Requires vnstat & vnstati (sudo apt-get install vnstat vnstati) if msg.text:match('^/[Tt][Rr][Aa][Ff][Ff][Ii][Cc]$') then run_command("vnstati -m -vs -i enp2s0 -o /tmp/vnstat.png") - utilities.send_photo(self, msg.chat.id, '/tmp/vnstat.png', nil, msg.message_id) + utilities.send_photo(msg.chat.id, '/tmp/vnstat.png', nil, msg.message_id) return end @@ -93,7 +93,7 @@ function shell:action(msg, config, matches) end output = output:gsub('
%\n', '
')
   output = output:gsub('%\n%\n
', '
') - utilities.send_message(self, msg.chat.id, output, true, msg.message_id, 'HTML') + utilities.send_message(msg.chat.id, output, true, msg.message_id, 'HTML') end return shell \ No newline at end of file diff --git a/miku/plugins/site_header.lua b/miku/plugins/site_header.lua index 6d07844..eeca8e1 100644 --- a/miku/plugins/site_header.lua +++ b/miku/plugins/site_header.lua @@ -9,7 +9,7 @@ end function site_header:action(msg, config, matches) if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) end local url = matches[2] @@ -20,7 +20,7 @@ function site_header:action(msg, config, matches) end local output = io.popen(input):read('*all') output = '```\n' .. output .. '\n```' - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end return site_header diff --git a/miku/plugins/soundboard.lua b/miku/plugins/soundboard.lua index bbfdfb3..5105514 100644 --- a/miku/plugins/soundboard.lua +++ b/miku/plugins/soundboard.lua @@ -29,9 +29,9 @@ function soundboard:inline_callback(inline_query, config, matches) url = GRONKH_URL..'/'..string.lower(input)..'.mp3' end local _, code = get_http_header(url) - if code ~= 200 then utilities.answer_inline_query(self, inline_query, nil, 5, true) return end + if code ~= 200 then utilities.answer_inline_query(inline_query, nil, 5, true) return end local results = '[{"type":"audio","id":"7900","title":"'..input..'","audio_url":"'..url..'"}]' - utilities.answer_inline_query(self, inline_query, results, 2) + utilities.answer_inline_query(inline_query, results, 2) end function soundboard:action(msg, config, matches) @@ -40,10 +40,10 @@ function soundboard:action(msg, config, matches) if input:match('^[Ll][Ii][Ss][Tt][Ee]$') then if board == 'sound' then - utilities.send_reply(self, msg, 'Hier findest du eine Liste aller Sounds!', 'HTML') + utilities.send_reply(msg, 'Hier findest du eine Liste aller Sounds!', 'HTML') return elseif board == 'gronkh' then - utilities.send_reply(self, msg, 'Hier findest du eine Liste aller Gronkh-Sounds!', 'HTML') + utilities.send_reply(msg, 'Hier findest du eine Liste aller Gronkh-Sounds!', 'HTML') return end end @@ -56,10 +56,10 @@ function soundboard:action(msg, config, matches) local sound = download_to_file(url) if not sound then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_audio(self, msg.chat.id, sound, msg.message_id) + utilities.send_audio(msg.chat.id, sound, msg.message_id) end return soundboard diff --git a/miku/plugins/soundcloud.lua b/miku/plugins/soundcloud.lua index 475681e..8f0f6bf 100644 --- a/miku/plugins/soundcloud.lua +++ b/miku/plugins/soundcloud.lua @@ -30,8 +30,8 @@ end function soundcloud:action(msg, config, matches) local text = soundcloud:send_soundcloud_info(matches[1]) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_reply(self, msg, text, true) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text, true) end return soundcloud diff --git a/miku/plugins/speedtest.lua b/miku/plugins/speedtest.lua index dfa0682..f384d73 100644 --- a/miku/plugins/speedtest.lua +++ b/miku/plugins/speedtest.lua @@ -7,9 +7,9 @@ speedtest.triggers = { function speedtest:action(msg, config, matches) local url = 'http://www.speedtest.net/result/'..matches[1]..'.png' - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end return speedtest \ No newline at end of file diff --git a/miku/plugins/speedtest_cli.lua b/miku/plugins/speedtest_cli.lua index ee52958..1aa2000 100644 --- a/miku/plugins/speedtest_cli.lua +++ b/miku/plugins/speedtest_cli.lua @@ -10,16 +10,16 @@ function speedtest_cli:init(config) end function speedtest_cli:action(msg, config) - utilities.send_typing(self, msg.chat.id, 'typing') + utilities.send_typing(msg.chat.id, 'typing') local result = run_command('speedtest-cli --share') local url = result:match("Share results: (.*)") - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local photo = download_to_file(url, 'speedtest_cli.png') if not photo then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_photo(self, msg.chat.id, photo, nil, msg.message_id) + utilities.send_photo(msg.chat.id, photo, nil, msg.message_id) end return speedtest_cli \ No newline at end of file diff --git a/miku/plugins/spotify.lua b/miku/plugins/spotify.lua index 744c527..81f7ac4 100644 --- a/miku/plugins/spotify.lua +++ b/miku/plugins/spotify.lua @@ -15,7 +15,7 @@ function spotify:get_track_data(track) return data end -function spotify:send_track_data(data, self, msg) +function spotify:send_track_data(data, msg) local name = data.name local album = data.album.name local artist = data.artists[1].name @@ -28,20 +28,20 @@ function spotify:send_track_data(data, self, msg) local text = '*'..name..'* von *'..artist..'* aus dem Album *'..album..'* _('..duration..')_' if preview then - utilities.send_typing(self, msg.chat.id, 'upload_audio') + utilities.send_typing(msg.chat.id, 'upload_audio') local file = download_to_file(preview, name..'.mp3') - utilities.send_audio(self, msg.chat.id, file, msg.message_id, totalseconds, artist, name) + utilities.send_audio(msg.chat.id, file, msg.message_id, totalseconds, artist, name) return else - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) return end end function spotify:action(msg, config, matches) local data = spotify:get_track_data(matches[1]) - if not data then utilities.send_reply(self, msg, config.errors.connection) return end - spotify:send_track_data(data, self, msg) + if not data then utilities.send_reply(msg, config.errors.connection) return end + spotify:send_track_data(data, msg) return end diff --git a/miku/plugins/stats.lua b/miku/plugins/stats.lua index 7780c62..b08dc28 100644 --- a/miku/plugins/stats.lua +++ b/miku/plugins/stats.lua @@ -79,7 +79,7 @@ function stats:chat_stats(chat_id) return text end -function stats:pre_process(msg, self) +function stats:pre_process(msg) if msg.left_chat_member then -- delete user from redis set, but keep message count local hash = 'chat:'..msg.chat.id..':users' @@ -126,21 +126,21 @@ function stats:action(msg, config, matches) if not matches[2] then if msg.chat.type == 'private' then - utilities.send_reply(self, msg, 'Stats funktionieren nur in Chats!') + utilities.send_reply(msg, 'Stats funktionieren nur in Chats!') return else local chat_id = msg.chat.id - utilities.send_reply(self, msg, stats:chat_stats(chat_id), 'HTML') + utilities.send_reply(msg, stats:chat_stats(chat_id), 'HTML') return end end if matches[2] == "chat" then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return else - utilities.send_reply(self, msg, stats:chat_stats(matches[3]), 'HTML') + utilities.send_reply(msg, stats:chat_stats(matches[3]), 'HTML') return end end diff --git a/miku/plugins/steam.lua b/miku/plugins/steam.lua index 145b1ea..2d9383a 100644 --- a/miku/plugins/steam.lua +++ b/miku/plugins/steam.lua @@ -35,7 +35,7 @@ function steam:price_info(data) return price end -function steam:send_steam_data(data, self, msg) +function steam:send_steam_data(data, msg) local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...' local title = data.name local price = steam:price_info(data.price_overview) @@ -47,12 +47,12 @@ end function steam:action(msg) local data = steam:get_steam_data(matches[1]) - if not data then utilities.send_reply(self, msg, config.errors.connection) return end + if not data then utilities.send_reply(msg, config.errors.connection) return end - local text, image_url = steam:send_steam_data(data, self, msg) - utilities.send_typing(self, msg.chat.id, 'upload_photo') - utilities.send_photo(self, msg.chat.id, download_to_file(image_url, matches[1]..'.jpg'), nil, msg.message_id) - utilities.send_reply(self, msg, text, true) + local text, image_url = steam:send_steam_data(data, msg) + utilities.send_typing(msg.chat.id, 'upload_photo') + utilities.send_photo(msg.chat.id, download_to_file(image_url, matches[1]..'.jpg'), nil, msg.message_id) + utilities.send_reply(msg, text, true) end return steam \ No newline at end of file diff --git a/miku/plugins/streamable.lua b/miku/plugins/streamable.lua index 518a2f2..96ea2e5 100644 --- a/miku/plugins/streamable.lua +++ b/miku/plugins/streamable.lua @@ -4,13 +4,13 @@ streamable.triggers = { "streamable.com/([A-Za-z0-9-_-]+)", } -function streamable:send_streamable_video(shortcode, self, msg) +function streamable:send_streamable_video(shortcode, msg) local BASE_URL = "https://api.streamable.com" local url = BASE_URL..'/videos/'..shortcode local res,code = https.request(url) if code ~= 200 then return 'HTTP-Fehler' end local data = json.decode(res) - if data.status ~= 2 then utilities.send_reply(self, msg, "Video ist (noch) nicht verfügbar.") return end + if data.status ~= 2 then utilities.send_reply(msg, "Video ist (noch) nicht verfügbar.") return end if data.files.webm then if data.title == "" then title = shortcode..'.webm' else title = data.title..'.webm' end @@ -19,7 +19,7 @@ function streamable:send_streamable_video(shortcode, self, msg) height = data.files.webm.height if data.files.webm.size > 50000000 then local size = math.floor(data.files.webm.size / 1000000) - utilities.send_reply(self, msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true) + utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true) return end elseif data.files.mp4 then @@ -29,20 +29,20 @@ function streamable:send_streamable_video(shortcode, self, msg) height = data.files.mp4.height if data.files.mp4.size > 50000000 then local size = math.floor(data.files.mp4.size / 1000000) - utilities.send_reply(self, msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true) + utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true) return end end - utilities.send_typing(self, msg.chat.id, 'upload_video') + utilities.send_typing(msg.chat.id, 'upload_video') local file = download_to_file(url, title) - utilities.send_video(self, msg.chat.id, file, nil, msg.message_id, nil, width, height) + utilities.send_video(msg.chat.id, file, nil, msg.message_id, nil, width, height) return end function streamable:action(msg, config, matches) local shortcode = matches[1] - streamable:send_streamable_video(shortcode, self, msg) + streamable:send_streamable_video(shortcode, msg) return end diff --git a/miku/plugins/surrogate.lua b/miku/plugins/surrogate.lua index e627c09..8001c0a 100644 --- a/miku/plugins/surrogate.lua +++ b/miku/plugins/surrogate.lua @@ -8,10 +8,10 @@ surrogate.triggers = { function surrogate:action(msg, config, matches) if not is_sudo(msg, config) then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end - utilities.send_message(self, matches[1], matches[2], true, nil, true) + utilities.send_message(matches[1], matches[2], true, nil, true) return end diff --git a/miku/plugins/tagesschau.lua b/miku/plugins/tagesschau.lua index 915dac6..1c74e42 100644 --- a/miku/plugins/tagesschau.lua +++ b/miku/plugins/tagesschau.lua @@ -42,7 +42,7 @@ function tagesschau:inline_callback(inline_query, config, matches) local article = matches[1] local full_url = 'http://www.tagesschau.de/'..article..'.html' local text, img_url, headline, shorttext = tagesschau:get_tagesschau_article(article) - if text == 'HTTP-Fehler' or text == 'Artikel nicht gefunden!' then utilities.answer_inline_query(self, inline_query) return end + if text == 'HTTP-Fehler' or text == 'Artikel nicht gefunden!' then abort_inline_query(inline_query) return end if text:match('"') then text = text:gsub('"', '\\"') @@ -56,18 +56,18 @@ function tagesschau:inline_callback(inline_query, config, matches) local text = text:gsub('\n', '\\n') local results = '[{"type":"article","id":"11","title":"'..headline..'","description":"'..shorttext..'","url":"'..full_url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/tagesschau/tagesschau.jpg","thumb_width":150,"thumb_height":150,"hide_url":true,"reply_markup":{"inline_keyboard":[[{"text":"Artikel aufrufen","url":"'..full_url..'"}]]},"input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}}]' - utilities.answer_inline_query(self, inline_query, results, 7200) + utilities.answer_inline_query(inline_query, results, 7200) end function tagesschau:action(msg, config, matches) local article = matches[1] local text, image_url = tagesschau:get_tagesschau_article(article) if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return tagesschau \ No newline at end of file diff --git a/miku/plugins/thetvdb.lua b/miku/plugins/thetvdb.lua index a640cee..c5e72d5 100644 --- a/miku/plugins/thetvdb.lua +++ b/miku/plugins/thetvdb.lua @@ -30,7 +30,7 @@ function tv:get_tv_info(series) return result end -function tv:send_tv_data(result, self, msg) +function tv:send_tv_data(result, msg) local title = xml.find(result, 'SeriesName')[1] local id = xml.find(result, 'seriesid')[1] @@ -68,11 +68,11 @@ function tv:send_tv_data(result, self, msg) local text = '*'..title..'*'..alias..aired..publisher..imdb..desc..'\n[TVDB-Seite besuchen](http://thetvdb.com/?id='..id..'&tab=series)' if xml.find(result, 'banner') then local image_url = 'http://www.thetvdb.com/banners/'..xml.find(result, 'banner')[1] - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) end @@ -80,13 +80,13 @@ function tv:action(msg, config, matches) local series = URL.escape(matches[1]) local tv_info = tv:get_tv_info(series) if tv_info == "NOTFOUND" then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return elseif tv_info == "HTTP-ERROR" then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return else - tv:send_tv_data(tv_info, self,msg) + tv:send_tv_data(tv_info, msg) end end diff --git a/miku/plugins/time.lua b/miku/plugins/time.lua index c2b7f26..a0a5da0 100644 --- a/miku/plugins/time.lua +++ b/miku/plugins/time.lua @@ -82,31 +82,31 @@ function time:inline_callback(inline_query, config, matches) results = '[{"type":"article","id":"12","title":"Europa/Berlin","description":"'..desc_time..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/time/clock.jpg","input_message_content":{"message_text":"'..cur_time..'","parse_mode":"Markdown"}}]' else local coords = utilities.get_coords(matches[1], config) - if type(coords) == 'string' then utilities.answer_inline_query(self, inline_query) return end + if type(coords) == 'string' then abort_inline_query(inline_query) return end local output, place, desc_time = time:get_time(coords) - if not output then utilities.answer_inline_query(self, inline_query) return end + if not output then abort_inline_query(inline_query) return end results = '[{"type":"article","id":"13","title":"'..place..'","description":"'..desc_time..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/time/clock.jpg","input_message_content":{"message_text":"'..output..'","parse_mode":"Markdown"}}]' end - utilities.answer_inline_query(self, inline_query, results, 1) + utilities.answer_inline_query(inline_query, results, 1) end function time:action(msg, config) local input = utilities.input_from_msg(msg) if not input then local output = os.date("%A, %d. %B %Y, *%H:%M:%S Uhr*") - utilities.send_reply(self, msg, time:localize(output), true) + utilities.send_reply(msg, time:localize(output), true) return end local coords = utilities.get_coords(input, config) if type(coords) == 'string' then - utilities.send_reply(self, msg, coords) + utilities.send_reply(msg, coords) return end local output = time:get_time(coords) - if not output then utilities.send_reply(self, msg, config.errors.connection) return end + if not output then utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end return time \ No newline at end of file diff --git a/miku/plugins/translate.lua b/miku/plugins/translate.lua index d20e0ea..ad0f3d4 100644 --- a/miku/plugins/translate.lua +++ b/miku/plugins/translate.lua @@ -93,17 +93,17 @@ function translate:get_all_languages() end function translate:action(msg, config, matches) - utilities.send_typing(self, msg.chat.id, 'typing') + utilities.send_typing(msg.chat.id, 'typing') if matches[1] == '/getlanguages' then - utilities.send_reply(self, msg, translate:get_all_languages(), true) + utilities.send_reply(msg, translate:get_all_languages(), true) return end if matches[1] == 'whatlang' and matches[2] then local text = matches[2] local lang = translate:detect_language(text) - utilities.send_reply(self, msg, 'Erkannte Sprache: '..lang, true) + utilities.send_reply(msg, 'Erkannte Sprache: '..lang, true) return end @@ -112,7 +112,7 @@ function translate:action(msg, config, matches) print("First") local text = matches[1] local language = translate:detect_language(text) - utilities.send_reply(self, msg, translate:translate(language, nil, text)) + utilities.send_reply(msg, translate:translate(language, nil, text)) return end @@ -122,7 +122,7 @@ function translate:action(msg, config, matches) local target = matches[2] local text = matches[3] local language = translate:detect_language(text) - utilities.send_reply(self, msg, translate:translate(language, target, text)) + utilities.send_reply(msg, translate:translate(language, target, text)) return end @@ -132,7 +132,7 @@ function translate:action(msg, config, matches) local source = matches[1] local target = matches[2] local text = matches[3] - utilities.send_reply(self, msg, translate:translate(source, target, text)) + utilities.send_reply(msg, translate:translate(source, target, text)) return end diff --git a/miku/plugins/twitch.lua b/miku/plugins/twitch.lua index edd0aa8..a3b0570 100644 --- a/miku/plugins/twitch.lua +++ b/miku/plugins/twitch.lua @@ -29,8 +29,8 @@ end function twitch:action(msg, config, matches) local text = twitch:send_twitch_info(matches[1]) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_reply(self, msg, text, true) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text, true) end return twitch diff --git a/miku/plugins/twitter.lua b/miku/plugins/twitter.lua index 2fc62d4..8e0fcbc 100644 --- a/miku/plugins/twitter.lua +++ b/miku/plugins/twitter.lua @@ -130,15 +130,15 @@ function twitter:action(msg, config, matches) end -- send the parts - utilities.send_reply(self, msg, header .. "\n" .. text.."\n"..footer, 'HTML') + utilities.send_reply(msg, header .. "\n" .. text.."\n"..footer, 'HTML') if videos[1] then images = {} end for k, v in pairs(images) do local file = download_to_file(v) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end for k, v in pairs(videos) do local file = download_to_file(v) - utilities.send_video(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_video(msg.chat.id, file, nil, msg.message_id) end end diff --git a/miku/plugins/twitter_send.lua b/miku/plugins/twitter_send.lua index f4f52de..3d0dfe2 100644 --- a/miku/plugins/twitter_send.lua +++ b/miku/plugins/twitter_send.lua @@ -249,7 +249,7 @@ end function twitter_send:action(msg, config, matches) if matches[1] == "twwhitelist add" then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return else local user_id = matches[2] @@ -259,14 +259,14 @@ function twitter_send:action(msg, config, matches) end user_id = msg.reply_to_message.from.id end - utilities.send_reply(self, msg, twitter_send:add_to_twitter_whitelist(user_id), true) + utilities.send_reply(msg, twitter_send:add_to_twitter_whitelist(user_id), true) return end end if matches[1] == "twwhitelist del" then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return else local user_id = matches[2] @@ -276,7 +276,7 @@ function twitter_send:action(msg, config, matches) end user_id = msg.reply_to_message.from.id end - utilities.send_reply(self, msg, twitter_send:del_from_twitter_whitelist(user_id), true) + utilities.send_reply(msg, twitter_send:del_from_twitter_whitelist(user_id), true) return end end @@ -289,22 +289,22 @@ function twitter_send:action(msg, config, matches) if not oauth_token and not oauth_token_secret then if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return else local text, auth_url = twitter_send:do_twitter_authorization_flow(hash, true) - local res = utilities.send_message(self, msg.from.id, text, true, nil, true, '{"inline_keyboard":[[{"text":"Bei Twitter anmelden","url":"'..auth_url..'"}]]}') + local res = utilities.send_message(msg.from.id, text, true, nil, true, '{"inline_keyboard":[[{"text":"Bei Twitter anmelden","url":"'..auth_url..'"}]]}') if not res then - utilities.send_reply(self, msg, 'Bitte starte mich zuerst [privat](http://telegram.me/' .. self.info.username .. '?start).', true) + utilities.send_reply(msg, 'Bitte starte mich zuerst [privat](http://telegram.me/' .. self.info.username .. '?start).', true) elseif msg.chat.type ~= 'private' then - local result = utilities.send_message(self, msg.chat.id, '_Bitte warten, der Administrator meldet sich an..._', true, nil, true) + local result = utilities.send_message(msg.chat.id, '_Bitte warten, der Administrator meldet sich an..._', true, nil, true) redis:hset(hash, 'login_msg', result.result.message_id) end return end else local text, auth_url = twitter_send:do_twitter_authorization_flow(hash) - local result = utilities.send_reply(self, msg, text, true, '{"inline_keyboard":[[{"text":"Bei Twitter anmelden","url":"'..auth_url..'"}]]}') + local result = utilities.send_reply(msg, text, true, '{"inline_keyboard":[[{"text":"Bei Twitter anmelden","url":"'..auth_url..'"}]]}') redis:hset(hash, 'login_msg', result.result.message_id) return end @@ -313,14 +313,14 @@ function twitter_send:action(msg, config, matches) if matches[1] == 'auth' and matches[2] then if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end end - if string.len(matches[2]) > 7 then utilities.send_reply(self, msg, 'Invalide PIN!') return end - utilities.send_reply(self, msg, twitter_send:get_twitter_access_token(hash, matches[2], oauth_token, oauth_token_secret), 'HTML') + if string.len(matches[2]) > 7 then utilities.send_reply(msg, 'Invalide PIN!') return end + utilities.send_reply(msg, twitter_send:get_twitter_access_token(hash, matches[2], oauth_token, oauth_token_secret), 'HTML') local message_id = redis:hget(hash, 'login_msg') - utilities.edit_message(self, msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) + utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) redis:hdel(hash, 'login_msg') return end @@ -328,33 +328,33 @@ function twitter_send:action(msg, config, matches) if matches[1] == 'unauth' then if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) + utilities.send_reply(msg, config.errors.sudo) return end end - utilities.send_reply(self, msg, twitter_send:reset_twitter_auth(hash), 'HTML') + utilities.send_reply(msg, twitter_send:reset_twitter_auth(hash), 'HTML') return end if matches[1] == 'verify' then local text, pp_url = twitter_send:twitter_verify_credentials(oauth_token, oauth_token_secret) local file = download_to_file(pp_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) - utilities.send_reply(self, msg, text) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + utilities.send_reply(msg, text) return end if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then if not can_send_tweet(msg) then - utilities.send_reply(self, msg, '*Du darfst keine Tweets senden.* Entweder wurdest du noch gar nicht freigeschaltet oder ausgeschlossen.', true) + utilities.send_reply(msg, '*Du darfst keine Tweets senden.* Entweder wurdest du noch gar nicht freigeschaltet oder ausgeschlossen.', true) return else - utilities.send_reply(self, msg, twitter_send:send_tweet(matches[1], oauth_token, oauth_token_secret, hash), 'HTML') + utilities.send_reply(msg, twitter_send:send_tweet(matches[1], oauth_token, oauth_token_secret, hash), 'HTML') return end else - utilities.send_reply(self, msg, twitter_send:send_tweet(matches[1], oauth_token, oauth_token_secret, hash), 'HTML') + utilities.send_reply(msg, twitter_send:send_tweet(matches[1], oauth_token, oauth_token_secret, hash), 'HTML') return end end diff --git a/miku/plugins/twitter_user.lua b/miku/plugins/twitter_user.lua index 8e0fd43..e1c35f6 100644 --- a/miku/plugins/twitter_user.lua +++ b/miku/plugins/twitter_user.lua @@ -97,16 +97,16 @@ function twitter_user:action(msg, config, matches) local footer = statuses..' Tweets, '..follower..' Follower, '..following..' folge ich, '..favorites..' Tweets favorisiert' local pic_url = string.gsub(response.profile_image_url_https, "normal", "400x400") - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(pic_url) local text = header..body..footer if string.len(text) > 199 then -- can only send captions with < 200 characters - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) - utilities.send_reply(self, msg, text) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + utilities.send_reply(msg, text) return else - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + utilities.send_photo(msg.chat.id, file, text, msg.message_id) return end end diff --git a/miku/plugins/urbandictionary.lua b/miku/plugins/urbandictionary.lua index 821fc24..8db68df 100644 --- a/miku/plugins/urbandictionary.lua +++ b/miku/plugins/urbandictionary.lua @@ -19,7 +19,7 @@ function urbandictionary:action(msg, config) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, urbandictionary.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, urbandictionary.doc, true, msg.message_id, true) return end end @@ -28,13 +28,13 @@ function urbandictionary:action(msg, config) local jstr, res = http.request(url) if res ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end local jdat = json.decode(jstr) if jdat.result_type == "no_results" then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end @@ -45,7 +45,7 @@ function urbandictionary:action(msg, config) output = output:gsub('%[', ''):gsub('%]', '') - utilities.send_reply(self, msg, output, 'HTML') + utilities.send_reply(msg, output, 'HTML') end diff --git a/miku/plugins/venue.lua b/miku/plugins/venue.lua index 83339bc..0df2697 100644 --- a/miku/plugins/venue.lua +++ b/miku/plugins/venue.lua @@ -6,7 +6,7 @@ venue.triggers = { local apikey = cred_data.google_apikey -function venue:pre_process(msg, self) +function venue:pre_process(msg) if not msg.venue then return msg end -- Ignore local lat = msg.venue.location.latitude @@ -16,7 +16,7 @@ function venue:pre_process(msg, self) if code ~= 200 then return msg end local data = json.decode(res).results[1] local city = data.formatted_address - utilities.send_reply(self, msg, city) + utilities.send_reply(msg, city) return msg end diff --git a/miku/plugins/vimeo.lua b/miku/plugins/vimeo.lua index c5668ad..da6efdd 100644 --- a/miku/plugins/vimeo.lua +++ b/miku/plugins/vimeo.lua @@ -27,8 +27,8 @@ end function vimeo:action(msg, config, matches) local text = vimeo:send_vimeo_data(matches[1]) - if not text then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_reply(self, msg, text, true) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text, true) end return vimeo diff --git a/miku/plugins/vine.lua b/miku/plugins/vine.lua index baa8bba..963173c 100644 --- a/miku/plugins/vine.lua +++ b/miku/plugins/vine.lua @@ -31,11 +31,11 @@ end function vine:action(msg, config, matches) local data = vine:get_vine_data(matches[1]) - if not data then utilities.send_reply(self, msg, config.errors.connection) return end + if not data then utilities.send_reply(msg, config.errors.connection) return end - utilities.send_typing(self, msg.chat.id, 'upload_video') + utilities.send_typing(msg.chat.id, 'upload_video') local text, file = vine:send_vine_data(data) - utilities.send_video(self, msg.chat.id, file, text, msg.message_id) + utilities.send_video(msg.chat.id, file, text, msg.message_id) end return vine diff --git a/miku/plugins/weather.lua b/miku/plugins/weather.lua index 7211c05..95cbaae 100644 --- a/miku/plugins/weather.lua +++ b/miku/plugins/weather.lua @@ -167,10 +167,10 @@ function weather:inline_callback(inline_query, config, matches) end end local lat, lng = get_city_coordinates(city, config) - if not lat and not lng then utilities.answer_inline_query(self, inline_query) return end + if not lat and not lng then abort_inline_query(inline_query) return end local title, description, icon, text, ttl = weather:get_weather(lat, lng, true) - if not title and not description and not icon and not text and not ttl then utilities.answer_inline_query(self, inline_query) return end + if not title and not description and not icon and not text and not ttl then abort_inline_query(inline_query) return end local text = text:gsub('\n', '\\n') local thumb_url = 'https://anditest.perseus.uberspace.de/inlineQuerys/weather/' @@ -188,7 +188,7 @@ function weather:inline_callback(inline_query, config, matches) thumb_url = thumb_url..'cloudy.jpg' end local results = '[{"type":"article","id":"19122006","title":"'..title..'","description":"'..description..'","thumb_url":"'..thumb_url..'","thumb_width":80,"thumb_height":80,"input_message_content":{"message_text":"'..text..'", "parse_mode":"Markdown"}}]' - utilities.answer_inline_query(self, inline_query, results, ttl, is_personal) + utilities.answer_inline_query(inline_query, results, ttl, is_personal) end function weather:action(msg, config, matches) @@ -207,7 +207,7 @@ function weather:action(msg, config, matches) local lat, lng = get_city_coordinates(city, config) if not lat and not lng then - utilities.send_reply(self, msg, '*Diesen Ort gibt es nicht!*', true) + utilities.send_reply(msg, '*Diesen Ort gibt es nicht!*', true) return end @@ -215,7 +215,7 @@ function weather:action(msg, config, matches) if not text then text = 'Konnte das Wetter von dieser Stadt nicht bekommen.' end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(msg, text, true) end return weather \ No newline at end of file diff --git a/miku/plugins/webshot.lua b/miku/plugins/webshot.lua index 8e2e07b..7d8b7db 100644 --- a/miku/plugins/webshot.lua +++ b/miku/plugins/webshot.lua @@ -57,19 +57,19 @@ function webshot:action(msg, config, matches) webshot_url = matches[2] size = string.upper(matches[1]) end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local find = webshot:get_webshot_url(webshot_url, size) if find then local imgurl = base .. find local file = download_to_file(imgurl) if size == "F" then - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) return else - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end else - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) end end diff --git a/miku/plugins/wiimmfi.lua b/miku/plugins/wiimmfi.lua index 0e5c054..0b4bec7 100644 --- a/miku/plugins/wiimmfi.lua +++ b/miku/plugins/wiimmfi.lua @@ -43,10 +43,10 @@ end function wiimmfi:action(msg, config, matches) if matches[1] == "mkw" then - utilities.send_reply(self, msg, wiimmfi:getplayer('mkw')) + utilities.send_reply(msg, wiimmfi:getplayer('mkw')) return else - utilities.send_reply(self, msg, wiimmfi:getplayer()) + utilities.send_reply(msg, wiimmfi:getplayer()) return end end diff --git a/miku/plugins/wikia.lua b/miku/plugins/wikia.lua index 71cf3d4..0b204b7 100644 --- a/miku/plugins/wikia.lua +++ b/miku/plugins/wikia.lua @@ -34,7 +34,7 @@ end function wikia:action(msg, config, matches) local wikia = matches[1] local article = matches[2] - utilities.send_reply(self, msg, send_wikia_article(wikia, article), true) + utilities.send_reply(msg, send_wikia_article(wikia, article), true) end return wikia \ No newline at end of file diff --git a/miku/plugins/wikipedia.lua b/miku/plugins/wikipedia.lua index 4f13a34..2d17ec6 100644 --- a/miku/plugins/wikipedia.lua +++ b/miku/plugins/wikipedia.lua @@ -183,7 +183,7 @@ function wikipedia:inline_callback(inline_query, config, matches) local search_url = 'https://'..lang..'.wikipedia.org/w/api.php?action=query&list=search&srsearch='..URL.escape(query)..'&format=json&prop=extracts&srprop=snippet&&srlimit=5' local res, code = https.request(search_url) - if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end + if code ~= 200 then abort_inline_query(inline_query) return end local data = json.decode(res).query @@ -191,7 +191,7 @@ function wikipedia:inline_callback(inline_query, config, matches) local id = 700 for num in pairs(data.search) do local title, result, keyboard = wikipedia:wikintro(data.search[num].title, lang, true) - if not title or not result or not keyboard then utilities.answer_inline_query(self, inline_query) return end + if not title or not result or not keyboard then abort_inline_query(inline_query) return end results = results..'{"type":"article","id":"'..id..'","title":"'..title..'","description":"'..wikipedia:snip_snippet(data.search[num].snippet)..'","url":"https://'..lang..'.wikipedia.org/wiki/'..URL.escape(title)..'","hide_url":true,"thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/wiki/logo.jpg","thumb_width":95,"thumb_height":86,"reply_markup":'..keyboard..',"input_message_content":{"message_text":"'..result..'","parse_mode":"HTML"}}' id = id+1 if num < #data.search then @@ -199,7 +199,7 @@ function wikipedia:inline_callback(inline_query, config, matches) end end local results = results..']' - utilities.answer_inline_query(self, inline_query, results, 3600) + utilities.answer_inline_query(inline_query, results, 3600) end function wikipedia:action(msg, config, matches) @@ -221,7 +221,7 @@ function wikipedia:action(msg, config, matches) lang = nil end if term == "" then - utilities.send_reply(self, msg, wikipedia.doc, true) + utilities.send_reply(msg, wikipedia.doc, true) return end @@ -231,7 +231,7 @@ function wikipedia:action(msg, config, matches) else result, keyboard = wikipedia:wikintro(term, lang) end - utilities.send_reply(self, msg, result, true, keyboard) + utilities.send_reply(msg, result, true, keyboard) end return wikipedia \ No newline at end of file diff --git a/miku/plugins/wordpress_posts.lua b/miku/plugins/wordpress_posts.lua index a498987..e4c18c7 100644 --- a/miku/plugins/wordpress_posts.lua +++ b/miku/plugins/wordpress_posts.lua @@ -63,19 +63,19 @@ function wordpress_recent_post:action(msg, config, matches) end local text, image_url = wordpress_recent_post:get_full_url(blog, matches[2]) if not text then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return elseif text == 'NOTFOUND' then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end if image_url then - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end return wordpress_recent_post \ No newline at end of file diff --git a/miku/plugins/xkcd.lua b/miku/plugins/xkcd.lua index e512ae3..7f86824 100644 --- a/miku/plugins/xkcd.lua +++ b/miku/plugins/xkcd.lua @@ -24,10 +24,10 @@ end function xkcd:action(msg, config, matches) local url, title, alt = xkcd:get_xkcd(matches[1]) - if not url then utilities.send_reply(self, msg, config.errors.connection) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + if not url then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, title..'\n'..alt, msg.message_id) + utilities.send_photo(msg.chat.id, file, title..'\n'..alt, msg.message_id) end return xkcd diff --git a/miku/plugins/yandere.lua b/miku/plugins/yandere.lua index a070f11..740bcc0 100644 --- a/miku/plugins/yandere.lua +++ b/miku/plugins/yandere.lua @@ -24,20 +24,20 @@ end function yandere:action(msg, config) local input = utilities.input_from_msg(msg) if not input then - utilities.send_reply(self, msg, yandere.doc, true) + utilities.send_reply(msg, yandere.doc, true) return end local tag = string.gsub(input, " ", '_' ) local url = yandere:get_post(tag) if not url then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end - utilities.send_typing(self, msg.chat.id, 'upload_photo') + utilities.send_typing(msg.chat.id, 'upload_photo') local file = download_to_file(url) - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) - utilities.send_reply(self, msg, url) + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + utilities.send_reply(msg, url) end return yandere \ No newline at end of file diff --git a/miku/plugins/yourls.lua b/miku/plugins/yourls.lua index 2a805b6..48c93ec 100644 --- a/miku/plugins/yourls.lua +++ b/miku/plugins/yourls.lua @@ -46,7 +46,7 @@ end function yourls:action(msg, config, matches) local long_url = matches[1] local baseurl, protocol = yourls:prot_url(SITE_URL) - utilities.send_reply(self, msg, yourls:create_yourls_link(long_url, protocol)) + utilities.send_reply(msg, yourls:create_yourls_link(long_url, protocol)) return end diff --git a/miku/plugins/youtube.lua b/miku/plugins/youtube.lua index 1f1c8dd..d3f26a8 100644 --- a/miku/plugins/youtube.lua +++ b/miku/plugins/youtube.lua @@ -137,9 +137,9 @@ function send_youtube_data(data, msg, self, link, sendpic) text = text..'\nACHTUNG, In Deutschland gesperrt!' end local file = download_to_file(image_url) - utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) + utilities.send_photo(msg.chat.id, file, text, msg.message_id) else - utilities.send_reply(self, msg, text, 'HTML') + utilities.send_reply(msg, text, 'HTML') end end @@ -147,10 +147,10 @@ function youtube:inline_callback(inline_query, config, matches) local query = matches[1] local url = BASE_URL..'/search?part=snippet&key='..apikey..'&maxResults=10&type=video&q='..URL.escape(query)..'&fields=items(id(videoId),snippet(publishedAt,title,thumbnails,channelTitle))' local res,code = https.request(url) - if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end + if code ~= 200 then abort_inline_query(inline_query) return end local data = json.decode(res) - if not data.items[1] then utilities.answer_inline_query(self, inline_query) return end + if not data.items[1] then abort_inline_query(inline_query) return end local video_ids = "" -- We get all videoIds from search... @@ -203,14 +203,14 @@ function youtube:inline_callback(inline_query, config, matches) end end local results = results..']' - utilities.answer_inline_query(self, inline_query, results, 0) + utilities.answer_inline_query(inline_query, results, 0) end function youtube:action(msg, config, matches) local yt_code = matches[1] local data = get_yt_data(yt_code) if not data then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(msg, config.errors.results) return end send_youtube_data(data, msg, self) diff --git a/miku/plugins/youtube_channel.lua b/miku/plugins/youtube_channel.lua index b4b250a..fa412ba 100644 --- a/miku/plugins/youtube_channel.lua +++ b/miku/plugins/youtube_channel.lua @@ -57,7 +57,7 @@ function youtube_channel:action(msg) local data = youtube_channel:get_yt_channel_data(channel_name) local output = youtube_channel:send_yt_channel_data(data) - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end return youtube_channel \ No newline at end of file diff --git a/miku/plugins/youtube_dl.lua b/miku/plugins/youtube_dl.lua index 091990c..8664c25 100644 --- a/miku/plugins/youtube_dl.lua +++ b/miku/plugins/youtube_dl.lua @@ -92,7 +92,7 @@ function youtube_dl:convert_audio(id) end function youtube_dl:callback(callback, msg, self, config, input) - utilities.answer_callback_query(self, callback, 'Informationen werden verarbeitet...') + utilities.answer_callback_query(callback, 'Informationen werden verarbeitet...') local video_id = input:match('(.+)@') local vid_format = input:match('@(%d+)') local hash = 'telegram:cache:youtube_dl:mp4:'..video_id @@ -116,19 +116,19 @@ function youtube_dl:callback(callback, msg, self, config, input) local file = format_info.file_id if size > 52420000 then - utilities.edit_message(self, msg.chat.id, msg.message_id, 'Direktlink zum Video ('..format..', '..pretty_size..')', nil, 'HTML', keyboard) + utilities.edit_message(msg.chat.id, msg.message_id, 'Direktlink zum Video ('..format..', '..pretty_size..')', nil, 'HTML', keyboard) return end - utilities.edit_message(self, msg.chat.id, msg.message_id, 'Video wird hochgeladen', nil, 'HTML') - utilities.send_typing(self, msg.chat.id, 'upload_video') + utilities.edit_message(msg.chat.id, msg.message_id, 'Video wird hochgeladen', nil, 'HTML') + utilities.send_typing(msg.chat.id, 'upload_video') if not file then file = download_to_file(full_url, video_id..'.'..ext) end if not file then return end - local result = utilities.send_video(self, msg.chat.id, file, '('..format..')', msg.message_id, duration, width, height) - utilities.edit_message(self, msg.chat.id, msg.message_id, 'Direktlink zum Video ('..format..', '..pretty_size..')', nil, 'HTML', keyboard) + local result = utilities.send_video(msg.chat.id, file, '('..format..')', msg.message_id, duration, width, height) + utilities.edit_message(msg.chat.id, msg.message_id, 'Direktlink zum Video ('..format..', '..pretty_size..')', nil, 'HTML', keyboard) if not result then return end local file_id = result.result.video.file_id redis:hset(format_hash, 'file_id', file_id) @@ -136,20 +136,20 @@ end function youtube_dl:action(msg, config, matches) if msg.chat.type ~= 'private' then - utilities.send_reply(self, msg, 'Dieses Plugin kann nur im Privatchat benutzt werden') + utilities.send_reply(msg, 'Dieses Plugin kann nur im Privatchat benutzt werden') return end local id = matches[2] if matches[1] == 'mp4' then local hash = 'telegram:cache:youtube_dl:mp4:'..id - local first_msg = utilities.send_reply(self, msg, 'Verfügbare Videoformate werden ausgelesen...', 'HTML') + local first_msg = utilities.send_reply(msg, 'Verfügbare Videoformate werden ausgelesen...', 'HTML') local callback_keyboard = redis:hget(hash, 'keyboard') if not callback_keyboard then - utilities.send_typing(self, msg.chat.id, 'typing') + utilities.send_typing(msg.chat.id, 'typing') local available_formats = youtube_dl:get_availabe_formats(id, hash) if not available_formats then - utilities.edit_message(self, msg.chat.id, first_msg.result.message_id, config.errors.results) + utilities.edit_message(msg.chat.id, first_msg.result.message_id, config.errors.results) return end @@ -180,19 +180,19 @@ function youtube_dl:action(msg, config, matches) redis:hset(hash, 'keyboard', callback_keyboard) redis:expire(hash, 7889400) end - utilities.edit_message(self, msg.chat.id, first_msg.result.message_id, 'Wähle die gewünschte Auflösung.', nil, nil, callback_keyboard) + utilities.edit_message(msg.chat.id, first_msg.result.message_id, 'Wähle die gewünschte Auflösung.', nil, nil, callback_keyboard) return end if matches[1] == 'mp3' then - local first_msg = utilities.send_reply(self, msg, 'Audio wird heruntergeladen...', 'HTML') - utilities.send_typing(self, msg.chat.id, 'upload_audio') + local first_msg = utilities.send_reply(msg, 'Audio wird heruntergeladen...', 'HTML') + utilities.send_typing(msg.chat.id, 'upload_audio') local file = youtube_dl:convert_audio(id) if file == 'TOOBIG' then - utilities.edit_message(self, msg.chat.id, first_msg.result.message_id, 'Die MP3 überschreitet die Grenze von 50 MB!', nil, 'HTML') + utilities.edit_message(msg.chat.id, first_msg.result.message_id, 'Die MP3 überschreitet die Grenze von 50 MB!', nil, 'HTML') return end - utilities.send_audio(self, msg.chat.id, file, msg.message_id) + utilities.send_audio(msg.chat.id, file, msg.message_id) return end end diff --git a/miku/plugins/youtube_playlist.lua b/miku/plugins/youtube_playlist.lua index 97ffdc6..673cdae 100644 --- a/miku/plugins/youtube_playlist.lua +++ b/miku/plugins/youtube_playlist.lua @@ -55,7 +55,7 @@ function youtube_playlist:action(msg) local data = youtube_playlist:get_pl_data(pl_code) local output = youtube_playlist:send_youtubepl_data(data) - utilities.send_reply(self, msg, output, true) + utilities.send_reply(msg, output, true) end return youtube_playlist \ No newline at end of file diff --git a/miku/plugins/youtube_search.lua b/miku/plugins/youtube_search.lua index c33c997..5f3947a 100644 --- a/miku/plugins/youtube_search.lua +++ b/miku/plugins/youtube_search.lua @@ -44,13 +44,13 @@ function yt_search:action(msg) if msg.reply_to_message and msg.reply_to_message.text then input = msg.reply_to_message.text else - utilities.send_message(self, msg.chat.id, yt_search.doc, true, msg.message_id, true) + utilities.send_message(msg.chat.id, yt_search.doc, true, msg.message_id, true) return end end local link, videoId = searchYoutubeVideo(input) - if link == "YouTube-Video nicht gefunden!" or nil then utilities.send_reply(self, msg, 'YouTube-Video nicht gefunden!') return end + if link == "YouTube-Video nicht gefunden!" or nil then utilities.send_reply(msg, 'YouTube-Video nicht gefunden!') return end local data = get_yt_data(videoId) diff --git a/miku/plugins/z0r.lua b/miku/plugins/z0r.lua index 88ebd8a..217eb8a 100644 --- a/miku/plugins/z0r.lua +++ b/miku/plugins/z0r.lua @@ -13,14 +13,14 @@ z0r.command = 'z0r ' function z0r:action(msg, config, matches) local id = matches[1] - utilities.send_typing(self, msg.chat.id, 'upload_video') + utilities.send_typing(msg.chat.id, 'upload_video') local url = 'http://z0r.de/L/z0r-de_'..matches[1]..'.swf' local file = download_to_file(url) if not file then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(msg, config.errors.connection) return end - utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + utilities.send_document(msg.chat.id, file, nil, msg.message_id) end return z0r \ No newline at end of file diff --git a/miku/utilities.lua b/miku/utilities.lua index 3fe6a59..ccea833 100644 --- a/miku/utilities.lua +++ b/miku/utilities.lua @@ -1,5 +1,22 @@ --- utilities.lua --- Functions shared among plugins. +--[[ + utilities.lua + Functions shared among otouto plugins. + + Copyright 2016 topkecleon + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License version 3 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +]]-- local utilities = {} @@ -22,55 +39,83 @@ https.timeout = 5 -- For the sake of ease to new contributors and familiarity to old contributors, -- we'll provide a couple of aliases to real bindings here. -function utilities:send_message(chat_id, text, disable_web_page_preview, reply_to_message_id, use_markdown, reply_markup) - local parse_mode - if type(use_markdown) == 'string' then - parse_mode = use_markdown - elseif use_markdown == true then - parse_mode = 'Markdown' - end - return bindings.request(self, 'sendMessage', { - chat_id = chat_id, - text = text, - disable_web_page_preview = disable_web_page_preview, - reply_to_message_id = reply_to_message_id, - parse_mode = parse_mode, - reply_markup = reply_markup - } ) +function utilities.send_message(chat_id, text, disable_web_page_preview, reply_to_message_id, use_markdown, reply_markup) + local parse_mode + if type(use_markdown) == 'string' then + parse_mode = use_markdown + elseif use_markdown == true then + parse_mode = 'markdown' + end + return bindings.request( + 'sendMessage', + { + chat_id = chat_id, + text = text, + disable_web_page_preview = disable_web_page_preview, + reply_to_message_id = reply_to_message_id, + parse_mode = parse_mode, + reply_markup = reply_markup + } + ) end -- https://core.telegram.org/bots/api#editmessagetext -function utilities:edit_message(chat_id, message_id, text, disable_web_page_preview, use_markdown, reply_markup) +function utilities.edit_message(chat_id, message_id, text, disable_web_page_preview, use_markdown, reply_markup) local parse_mode if type(use_markdown) == 'string' then parse_mode = use_markdown elseif use_markdown == true then parse_mode = 'Markdown' end - return bindings.request(self, 'editMessageText', { - chat_id = chat_id, - message_id = message_id, - text = text, - disable_web_page_preview = disable_web_page_preview, - parse_mode = parse_mode, - reply_markup = reply_markup - } ) + return bindings.request( + 'editMessageText', + { + chat_id = chat_id, + message_id = message_id, + text = text, + disable_web_page_preview = disable_web_page_preview, + parse_mode = parse_mode, + reply_markup = reply_markup + } + ) end -function utilities:send_reply(old_msg, text, use_markdown, reply_markup) - return utilities.send_message(self, old_msg.chat.id, text, true, old_msg.message_id, use_markdown, reply_markup) +function utilities.send_reply(msg, text, use_markdown, reply_markup) + local parse_mode + if type(use_markdown) == 'string' then + parse_mode = use_markdown + elseif use_markdown == true then + parse_mode = 'markdown' + end + return bindings.request( + 'sendMessage', + { + chat_id = msg.chat.id, + text = text, + disable_web_page_preview = true, + reply_to_message_id = msg.message_id, + parse_mode = parse_mode, + reply_markup = reply_markup + } + ) 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, reply_markup) +function utilities.send_photo(chat_id, file, text, reply_to_message_id, reply_markup) if not file then return false end - local output = bindings.request(self, 'sendPhoto', { - chat_id = chat_id, - caption = text or nil, - reply_to_message_id = reply_to_message_id, - reply_markup = reply_markup - }, {photo = file} ) + local output = bindings.request( + 'sendPhoto', + { + chat_id = chat_id, + caption = text or nil, + reply_to_message_id = reply_to_message_id, + reply_markup = reply_markup + }, + { + photo = file + } + ) if string.match(file, '/tmp/') then os.remove(file) print("Deleted: "..file) @@ -79,15 +124,21 @@ function utilities:send_photo(chat_id, file, text, reply_to_message_id, reply_ma end -- https://core.telegram.org/bots/api#sendaudio -function utilities:send_audio(chat_id, file, reply_to_message_id, duration, performer, title) +function utilities.send_audio(chat_id, file, reply_to_message_id, duration, performer, title) if not file then return false end - local output = bindings.request(self, 'sendAudio', { - chat_id = chat_id, - duration = duration or nil, - performer = performer or nil, - title = title or nil, - reply_to_message_id = reply_to_message_id - }, {audio = file} ) + local output = bindings.request( + 'sendAudio', + { + chat_id = chat_id, + duration = duration or nil, + performer = performer or nil, + title = title or nil, + reply_to_message_id = reply_to_message_id + }, + { + audio = file + } + ) if string.match(file, '/tmp/') then os.remove(file) print("Deleted: "..file) @@ -96,14 +147,20 @@ function utilities:send_audio(chat_id, file, reply_to_message_id, duration, perf end -- https://core.telegram.org/bots/api#senddocument -function utilities:send_document(chat_id, file, text, reply_to_message_id, reply_markup) +function utilities.send_document(chat_id, file, text, reply_to_message_id, reply_markup) if not file then return false end - local output = bindings.request(self, 'sendDocument', { - chat_id = chat_id, - caption = text or nil, - reply_to_message_id = reply_to_message_id, - reply_markup = reply_markup - }, {document = file} ) + local output = bindings.request( + 'sendDocument', + { + chat_id = chat_id, + caption = text or nil, + reply_to_message_id = reply_to_message_id, + reply_markup = reply_markup + }, + { + document = file + } + ) if string.match(file, '/tmp/') then os.remove(file) print("Deleted: "..file) @@ -112,16 +169,22 @@ function utilities:send_document(chat_id, file, text, reply_to_message_id, reply end -- https://core.telegram.org/bots/api#sendvideo -function utilities:send_video(chat_id, file, text, reply_to_message_id, duration, width, height) +function utilities.send_video(chat_id, file, text, reply_to_message_id, duration, width, height) if not file then return false end - 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} ) + local output = bindings.request( + '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 + } + ) if string.match(file, '/tmp/') then os.remove(file) print("Deleted: "..file) @@ -131,13 +194,19 @@ 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) +function utilities.send_voice(chat_id, file, text, reply_to_message_id, duration) if not file then return false end - local output = bindings.request(self, 'sendVoice', { - chat_id = chat_id, - duration = duration or nil, - reply_to_message_id = reply_to_message_id - }, {voice = file} ) + local output = bindings.request( + 'sendVoice', + { + chat_id = chat_id, + duration = duration or nil, + reply_to_message_id = reply_to_message_id + }, + { + voice = file + } + ) if string.match(file, '/tmp/') then os.remove(file) print("Deleted: "..file) @@ -146,71 +215,103 @@ function utilities:send_voice(chat_id, file, text, reply_to_message_id, duration 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 - } ) +function utilities.send_location(chat_id, latitude, longitude, reply_to_message_id) + return bindings.request( + '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 - } ) +function utilities.send_venue(chat_id, latitude, longitude, reply_to_message_id, title, address) + return bindings.request( + '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 - } ) +function utilities.send_typing(chat_id, action) + return bindings.request( + 'sendChatAction', + { + chat_id = chat_id, + action = action + } + ) end -- https://core.telegram.org/bots/api#answercallbackquery -function utilities:answer_callback_query(callback, text, show_alert) - return bindings.request(self, 'answerCallbackQuery', { - callback_query_id = callback.id, - text = text, - show_alert = show_alert - } ) +function utilities.answer_callback_query(callback, text, show_alert) + return bindings.request( + 'answerCallbackQuery', + { + callback_query_id = callback.id, + text = text, + show_alert = show_alert + } + ) end -- https://core.telegram.org/bots/api#getchat -function utilities:get_chat_info(chat_id) - return bindings.request(self, 'getChat', { - chat_id = chat_id - } ) +function utilities.get_chat_info(chat_id) + return bindings.request( + 'getChat', + { + chat_id = chat_id + } + ) end -- https://core.telegram.org/bots/api#getchatadministrators -function utilities:get_chat_administrators(chat_id) - return bindings.request(self, 'getChatAdministrators', { - chat_id = chat_id - } ) +function utilities.get_chat_administrators(chat_id) + return bindings.request( + 'getChatAdministrators', + { + chat_id = chat_id + } + ) end -- https://core.telegram.org/bots/api#answerinlinequery -function utilities:answer_inline_query(inline_query, results, cache_time, is_personal, next_offset, switch_pm_text, switch_pm_parameter) - return bindings.request(self, 'answerInlineQuery', { - inline_query_id = inline_query.id, - results = results, - cache_time = cache_time, - is_personal = is_personal, - next_offset = next_offset, - switch_pm_text = switch_pm_text, - switch_pm_parameter = switch_pm_parameter - } ) +function utilities.answer_inline_query(inline_query, results, cache_time, is_personal, next_offset, switch_pm_text, switch_pm_parameter) + return bindings.request( + 'answerInlineQuery', + { + inline_query_id = inline_query.id, + results = results, + cache_time = cache_time, + is_personal = is_personal, + next_offset = next_offset, + switch_pm_text = switch_pm_text, + switch_pm_parameter = switch_pm_parameter + } + ) +end + +function abort_inline_query(inline_query) + return bindings.request( + 'answerInlineQuery', + { + inline_query_id = inline_query.id, + cache_time = 5, + is_personal = true + } + ) end -- get the indexed word in a string @@ -398,15 +499,21 @@ function utilities:resolve_username(input) end end -function utilities:handle_exception(err, message, config) - if not err then err = '' end - local output = '\n[' .. os.date('%F %T', os.time()) .. ']\n' .. self.info.username .. ': ' .. err .. '\n' .. message .. '\n' - if config.log_chat then - output = '```' .. output .. '```' - utilities.send_message(self, config.log_chat, output, true, nil, true) - else - print(output) - end +function utilities:handle_exception(err, message, log_chat) + local output = string.format( + '[%s]\n%s: %s\n%s\n', + os.date('%F %T'), + self.info.username, + err or '', + message + ) + if log_chat then + output = '' .. utilities.html_escape(output) .. '' + return utilities.send_message(log_chat, output, true, nil, 'html') + else + print(output) + end + end -- MOVED TO DOWNLOAD_TO_FILE @@ -809,7 +916,7 @@ function was_modified_since(url, last_modified) end -- only url is needed! -function get_cached_file(url, file_name, receiver, chat_action, self) +function get_cached_file(url, file_name, receiver, chat_action) local hash = 'telegram:cache:sent_file' local cached_file_id = redis:hget(hash..':'..url, 'file_id') local cached_last_modified = redis:hget(hash..':'..url, 'last_modified') @@ -825,8 +932,8 @@ function get_cached_file(url, file_name, receiver, chat_action, self) return end print('File was modified, redownloading...') - if receiver and chat_action and self then - utilities.send_typing(self, receiver, chat_action) + if receiver and chat_action then + utilities.send_typing(receiver, chat_action) end file = download_to_file(url, file_name) return file, new_last_modified, false @@ -861,8 +968,8 @@ function get_cached_file(url, file_name, receiver, chat_action, self) nocache = false end - if receiver and chat_action and self then - utilities.send_typing(self, receiver, chat_action) + if receiver and chat_action then + utilities.send_typing(receiver, chat_action) end if not nocache then