From 5856804891053e1c236a461a82c8205b86f4a418 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Mon, 1 Aug 2016 21:07:27 +0200 Subject: [PATCH] =?UTF-8?q?Seeeeehr=20gro=C3=9Fes=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Meiste Änderungen von Brawl345/Brawlbot-v2 Einige Pattern angepasst Einiges übersetzt Und noch einiges mehr Stabilitätsverbesserungen --- config.lua.example | 4 - miku/bot.lua | 22 +- miku/plugins/9gag.lua | 14 +- miku/plugins/about.lua | 3 +- miku/plugins/adfly.lua | 6 +- miku/plugins/afk.lua | 15 +- miku/plugins/app_store.lua | 5 - miku/plugins/bImages.lua | 16 +- miku/plugins/banhammer.lua | 4 - miku/plugins/bitly.lua | 9 +- miku/plugins/bitly_create.lua | 21 +- miku/plugins/botan.lua | 34 --- miku/plugins/br.lua | 6 - miku/plugins/btc.lua | 6 - miku/plugins/calc.lua | 4 - miku/plugins/cats.lua | 41 +++- miku/plugins/channel.lua | 97 +++++---- miku/plugins/channels.lua | 4 - miku/plugins/cleverbot.lua | 5 - miku/plugins/clypit.lua | 5 - miku/plugins/control.lua | 1 - miku/plugins/creds.lua | 3 - miku/plugins/currency.lua | 5 +- miku/plugins/dailymotion.lua | 4 - miku/plugins/deviantart.lua | 4 - miku/plugins/dhl.lua | 12 +- miku/plugins/dropbox.lua | 12 +- miku/plugins/echo.lua | 10 +- miku/plugins/entergroup.lua | 3 - miku/plugins/expand.lua | 9 +- miku/plugins/facebook.lua | 38 ++-- miku/plugins/flickr.lua | 13 +- miku/plugins/flickr_search.lua | 13 +- miku/plugins/forecast.lua | 27 +-- miku/plugins/gImages.lua | 36 ++- miku/plugins/gImages_nsfw.lua | 36 ++- miku/plugins/gMaps.lua | 5 +- miku/plugins/gSearch.lua | 11 +- miku/plugins/games.lua | 6 +- miku/plugins/gdrive.lua | 10 +- miku/plugins/get.lua | 7 +- miku/plugins/getfile.lua | 16 +- miku/plugins/gfycat.lua | 4 - miku/plugins/giphy.lua | 7 +- miku/plugins/github.lua | 8 - miku/plugins/github_feed.lua | 302 ++++++++++++++++++++++++++ miku/plugins/googl.lua | 29 ++- miku/plugins/gps.lua | 3 - miku/plugins/help.lua | 2 - miku/plugins/id.lua | 12 +- miku/plugins/images.lua | 1 - miku/plugins/imdb.lua | 14 +- miku/plugins/imgblacklist.lua | 13 +- miku/plugins/imgur.lua | 11 +- miku/plugins/ip_info.lua | 9 +- miku/plugins/isup.lua | 8 +- miku/plugins/leave_group.lua | 5 +- miku/plugins/location_manager.lua | 7 +- miku/plugins/lyrics.lua | 10 +- miku/plugins/magische_miesmuschel.lua | 2 - miku/plugins/media.lua | 23 +- miku/plugins/minecraft_server.lua | 6 - miku/plugins/minecraft_skin.lua | 6 +- miku/plugins/myanimelist.lua | 14 +- miku/plugins/notify.lua | 19 +- miku/plugins/pagespeed_insights.lua | 10 +- miku/plugins/pasteee.lua | 7 +- miku/plugins/patterns.lua | 6 +- miku/plugins/pixabay.lua | 9 +- miku/plugins/play_store.lua | 8 +- miku/plugins/plugins.lua | 3 - miku/plugins/pocket.lua | 10 +- miku/plugins/pokedex.lua | 13 +- miku/plugins/preview.lua | 5 +- miku/plugins/qr.lua | 4 - miku/plugins/quotes.lua | 3 - miku/plugins/random.lua | 2 - miku/plugins/reddit.lua | 7 +- miku/plugins/reddit_post.lua | 5 - miku/plugins/remind.lua | 2 - miku/plugins/respond.lua | 4 - miku/plugins/roll.lua | 2 - miku/plugins/rss.lua | 42 +--- miku/plugins/set.lua | 3 - miku/plugins/shell.lua | 2 - miku/plugins/site_header.lua | 2 - miku/plugins/soundcloud.lua | 4 - miku/plugins/speedtest.lua | 2 - miku/plugins/spotify.lua | 4 - miku/plugins/stats.lua | 17 +- miku/plugins/steam.lua | 5 - miku/plugins/streamable.lua | 4 - miku/plugins/surrogate.lua | 2 - miku/plugins/tagesschau.lua | 33 ++- miku/plugins/tagesschau_eil.lua | 112 ---------- miku/plugins/tex.lua | 34 --- miku/plugins/thetvdb.lua | 5 +- miku/plugins/time.lua | 8 +- miku/plugins/translate.lua | 12 +- miku/plugins/tweet.lua | 25 +-- miku/plugins/twitch.lua | 4 - miku/plugins/twitter.lua | 26 +-- miku/plugins/twitter_send.lua | 17 +- miku/plugins/twitter_user.lua | 23 +- miku/plugins/urbandictionary.lua | 9 +- miku/plugins/venue.lua | 4 - miku/plugins/vimeo.lua | 4 - miku/plugins/vine.lua | 4 - miku/plugins/weather.lua | 23 +- miku/plugins/webshot.lua | 7 - miku/plugins/wiimmfi.lua | 4 - miku/plugins/wikia.lua | 5 - miku/plugins/wikipedia.lua | 14 +- miku/plugins/xkcd.lua | 4 - miku/plugins/yourls.lua | 12 +- miku/plugins/youtube.lua | 16 +- miku/plugins/youtube_channel.lua | 12 +- miku/plugins/youtube_dl.lua | 4 +- miku/plugins/youtube_playlist.lua | 10 +- miku/plugins/youtube_search.lua | 13 +- miku/utilities.lua | 57 ++--- 121 files changed, 742 insertions(+), 1063 deletions(-) delete mode 100644 miku/plugins/botan.lua create mode 100644 miku/plugins/github_feed.lua delete mode 100644 miku/plugins/tagesschau_eil.lua delete mode 100644 miku/plugins/tex.lua diff --git a/config.lua.example b/config.lua.example index 85a52f0..dff3c5b 100644 --- a/config.lua.example +++ b/config.lua.example @@ -24,10 +24,6 @@ Sende /hilfe, um zu starten -- false = only whitelisted users can use inline querys -- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted! enable_inline_for_everyone = true, - - -- Botan.io statistics - enable_statistics = false, - botan_token = '', errors = { -- Generic error messages used in various plugins. generic = 'An unexpected error occurred.', diff --git a/miku/bot.lua b/miku/bot.lua index 0ff6804..90e6c1d 100644 --- a/miku/bot.lua +++ b/miku/bot.lua @@ -1,17 +1,11 @@ local bot = {} --- Requires are moved to init to allow for reloads. -local bindings -- Load Telegram bindings. -local utilities -- Load miscellaneous and cross-plugin functions. -local redis = (loadfile "./miku/redis.lua")() +bindings = require('miku.bindings') +utilities = require('miku.utilities') -bot.version = '160726' +bot.version = '160801' function bot:init(config) -- The function run when the bot is started or reloaded. - - bindings = require('miku.bindings') - utilities = require('miku.utilities') - redis = (loadfile "./miku/redis.lua")() cred_data = load_cred() assert( @@ -239,7 +233,6 @@ function match_plugins(self, msg, config, plugin) end end print(plugin.name..' ausgelöst') - plugin_name = plugin.name return plugin.action(self, msg, config, matches) end) if not success then @@ -254,15 +247,6 @@ function match_plugins(self, msg, config, plugin) utilities.handle_exception(self, result, msg.from.id .. ': ' .. msg.text, config) return end - - -- Analytics - if config.enable_analytics and config.botan_token ~= '' then - for _,plugin in ipairs(self.plugins) do - if plugin.name == 'botan' then - plugin.action(self, msg, config, nil, plugin_name) - end - end - end -- If the action returns a table, make that table the new msg. if type(result) == 'table' then diff --git a/miku/plugins/9gag.lua b/miku/plugins/9gag.lua index a312377..a126c28 100644 --- a/miku/plugins/9gag.lua +++ b/miku/plugins/9gag.lua @@ -1,11 +1,5 @@ local ninegag = {} -local HTTP = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - ninegag.command = '9gag' function ninegag:init(config) @@ -23,9 +17,9 @@ end local url = "http://api-9gag.herokuapp.com/" function ninegag:get_9GAG() - local b,c = HTTP.request(url) + local b,c = http.request(url) if c ~= 200 then return nil end - local gag = JSON.decode(b) + local gag = json.decode(b) -- random max json table size local i = math.random(#gag) @@ -36,9 +30,9 @@ function ninegag:get_9GAG() end function ninegag:inline_callback(inline_query, config) - local res, code = HTTP.request(url) + local res, code = http.request(url) if code ~= 200 then return end - local gag = JSON.decode(res) + local gag = json.decode(res) local results = '[' for n in pairs(gag) do diff --git a/miku/plugins/about.lua b/miku/plugins/about.lua index 4be0cd4..07836aa 100644 --- a/miku/plugins/about.lua +++ b/miku/plugins/about.lua @@ -1,7 +1,6 @@ local about = {} local bot = require('miku.bot') -local utilities = require('miku.utilities') about.command = 'about' about.doc = '`Sendet Informationen über den Bot.`' @@ -18,7 +17,7 @@ function about:action(msg, config) -- disabled to restore old behaviour -- if msg.forward_from then return end - local output = config.about_text .. '\n[Mikudayobot](https://github.com/Akamaru/Mikubot-V2) v'..bot.version..' von @Akamaru, basierend auf [Otouto](https://github.com/topkecleon/otouto) von topkecleon.' + local output = config.about_text .. '\n[Mikudayobot](https://github.com/Akamaru/Mikubot-V2) v'..bot.version..' von @Akamaru, basierend auf [miku](https://github.com/topkecleon/miku) von topkecleon.' if (msg.new_chat_member and msg.new_chat_member.id == self.info.id) diff --git a/miku/plugins/adfly.lua b/miku/plugins/adfly.lua index 27de474..cbe23e3 100644 --- a/miku/plugins/adfly.lua +++ b/miku/plugins/adfly.lua @@ -1,9 +1,5 @@ local adfly = {} -local utilities = require('miku.utilities') -local HTTPS = require('ssl.https') -local redis = (loadfile "./miku/redis.lua")() - function adfly:init(config) adfly.triggers = { 'adf.ly/([A-Za-z0-9-_-]+)' @@ -15,7 +11,7 @@ end function adfly:expand_adfly_link(adfly_code) local BASE_URL = 'https://andibi.tk/dl/adfly.php' local url = BASE_URL..'/?url=http://adf.ly/'..adfly_code - local res,code = HTTPS.request(url) + local res,code = https.request(url) if code ~= 200 then return nil end if res == 'Fehler: Keine Adf.ly-URL gefunden!' then return 'NOTFOUND' end cache_data('adfly', adfly_code, res, 31536000, 'key') diff --git a/miku/plugins/afk.lua b/miku/plugins/afk.lua index 496976c..8811d85 100644 --- a/miku/plugins/afk.lua +++ b/miku/plugins/afk.lua @@ -3,9 +3,6 @@ local afk = {} -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - function afk:init(config) afk.triggers = { "^/([Aa][Ff][Kk])$", @@ -80,17 +77,7 @@ function afk:pre_process(msg, self) local timestamp = redis:hget(hash, 'time') local current_timestamp = msg.date local afk_time = current_timestamp - timestamp - local seconds = afk_time % 60 - local minutes = math.floor(afk_time / 60) - local minutes = minutes % 60 - local hours = math.floor(afk_time / 3600) - if minutes == 00 and hours == 00 then - duration = seconds..' Sekunden' - elseif hours == 00 and minutes ~= 00 then - duration = string.format("%02d:%02d", minutes, seconds)..' Minuten' - elseif hours ~= 00 then - duration = string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunden' - end + local duration = makeHumanTime(afk_time) redis:hset(hash, 'afk', false) if afk_text then diff --git a/miku/plugins/app_store.lua b/miku/plugins/app_store.lua index 111709f..d2b36a0 100644 --- a/miku/plugins/app_store.lua +++ b/miku/plugins/app_store.lua @@ -1,10 +1,5 @@ local app_store = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - app_store.triggers = { "itunes.apple.com/(.*)/app/(.*)/id(%d+)", "^/[Ii][Tt][Uu][Nn][Ee][Ss] (%d+)$", diff --git a/miku/plugins/bImages.lua b/miku/plugins/bImages.lua index 1532978..330325a 100644 --- a/miku/plugins/bImages.lua +++ b/miku/plugins/bImages.lua @@ -1,17 +1,9 @@ local bImages = {} -local HTTPS = require('ssl.https') -HTTPS.timeout = 10 -local URL = require('socket.url') -local JSON = require('dkjson') -local redis = (loadfile "./miku/redis.lua")() -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function bImages:init(config) if not cred_data.bing_search_key then - print('Missing config value: bing_search_key.') - print('bImages.lua will not be enabled.') + print('Fehlender Key: bing_search_key.') + print('bImages.lua wird nicht aktiviert.') return end @@ -36,9 +28,9 @@ function bImages:getImages(query) ["Ocp-Apim-Subscription-Key"] = apikey } } - local ok, response_code, response_headers = HTTPS.request(request_constructor) + local ok, response_code, response_headers = https.request(request_constructor) if not ok then return end - local images = JSON.decode(table.concat(response_body)).value + local images = json.decode(table.concat(response_body)).value if not images[1] then return end diff --git a/miku/plugins/banhammer.lua b/miku/plugins/banhammer.lua index 9c33bcb..f0669de 100644 --- a/miku/plugins/banhammer.lua +++ b/miku/plugins/banhammer.lua @@ -1,9 +1,5 @@ local banhammer = {} -local bindings = require('miku.bindings') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - banhammer.command = 'banhammer ' function banhammer:init(config) diff --git a/miku/plugins/bitly.lua b/miku/plugins/bitly.lua index fe29d5b..59648c5 100644 --- a/miku/plugins/bitly.lua +++ b/miku/plugins/bitly.lua @@ -1,14 +1,9 @@ local bitly = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - function bitly:init(config) if not cred_data.bitly_access_token then - print('Missing config value: bitly_access_token.') - print('bitly.lua will not be enabled.') + print('Fehlender Key: bitly_access_token.') + print('bitly.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/bitly_create.lua b/miku/plugins/bitly_create.lua index 55f55c8..e17c4a1 100644 --- a/miku/plugins/bitly_create.lua +++ b/miku/plugins/bitly_create.lua @@ -1,26 +1,17 @@ local bitly_create = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') -local OAuth = require "OAuth" -local redis = (loadfile "./miku/redis.lua")() - function bitly_create:init(config) if not cred_data.bitly_client_id then - print('Missing config value: bitly_client_id.') - print('bitly_create.lua will not be enabled.') + print('Fehlender Key: bitly_client_id.') + print('bitly_create.lua wird nicht aktiviert.') return elseif not cred_data.bitly_client_secret then - print('Missing config value: bitly_client_secret.') - print('bitly_create.lua will not be enabled.') + print('Fehlender Key: bitly_client_secret.') + print('bitly_create.lua wird nicht aktiviert.') return elseif not cred_data.bitly_redirect_uri then - print('Missing config value: bitly_redirect_uri.') - print('bitly_create.lua will not be enabled.') + print('Fehlender Key: bitly_redirect_uri.') + print('bitly_create.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/botan.lua b/miku/plugins/botan.lua deleted file mode 100644 index 765fe0c..0000000 --- a/miku/plugins/botan.lua +++ /dev/null @@ -1,34 +0,0 @@ -local botan = {} - -local https = require('ssl.https') -local URL = require('socket.url') -local redis = (loadfile "./miku/redis.lua")() -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - -function botan:init(config) - if not config.botan_token then - print('Fehlender Key: botan_token.') - print('botan.lua wird nicht aktiviert.') - return - end - botan.triggers = { - "^/nil$" - } -end - -local BASE_URL = 'https://api.botan.io/track' - -function botan:appmetrica(text, token, plugin_name) - https.request(BASE_URL..'/?token='..token..'&uid=1&name='..plugin_name) -end - -function botan:action(msg, config, matches, plugin_name) - if not plugin_name then - return - end - - botan:appmetrica(msg.text, config.botan_token, plugin_name) -end - -return botan \ No newline at end of file diff --git a/miku/plugins/br.lua b/miku/plugins/br.lua index 6acfb48..d7e50f3 100644 --- a/miku/plugins/br.lua +++ b/miku/plugins/br.lua @@ -1,11 +1,5 @@ local br = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - br.triggers = { "br.de/nachrichten/(.*).html$" } diff --git a/miku/plugins/btc.lua b/miku/plugins/btc.lua index 5db771d..483294c 100644 --- a/miku/plugins/btc.lua +++ b/miku/plugins/btc.lua @@ -1,11 +1,5 @@ local btc = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function btc:init(config) btc.triggers = { "^/[Bb][Tt][Cc]$" diff --git a/miku/plugins/calc.lua b/miku/plugins/calc.lua index 7e8519a..cd645db 100644 --- a/miku/plugins/calc.lua +++ b/miku/plugins/calc.lua @@ -1,9 +1,5 @@ local calc = {} -local URL = require('socket.url') -local http = require('socket.http') -local utilities = require('miku.utilities') - calc.command = 'calc ' function calc:init(config) diff --git a/miku/plugins/cats.lua b/miku/plugins/cats.lua index 919ac9f..7298325 100644 --- a/miku/plugins/cats.lua +++ b/miku/plugins/cats.lua @@ -1,13 +1,10 @@ local cats = {} -local HTTP = require('socket.http') -local utilities = require('miku.utilities') - cats.command = 'kitty [gif]' function cats:init(config) if not cred_data.cat_apikey then - print('Missing config value: cat_apikey.') + print('Fehlender Key: cat_apikey.') print('cats.lua will be enabled, but there are more features with a key.') end @@ -16,6 +13,11 @@ function cats:init(config) "^/[Kk][Ii][Tt][Tt][Yy] (gif)$" } + cats.inline_triggers = { + "^[Kk][Ii][Tt][Tt][Yy] (gif)$", + "^[Kk][Ii][Tt][Tt][Yy]$" + } + cats.doc = [[* ]]..config.cmd_pat..[[kitty*: Postet eine zufällige Katze *]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]] @@ -24,6 +26,35 @@ end local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html +function cats:inline_callback(inline_query, config, matches) + if matches[1] == 'gif' then + img_type = 'gif' + else + img_type = 'jpg' + end + local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%27http%3A%2F%2Fthecatapi.com%2Fapi%2Fimages%2Fget%3Fformat%3Dxml%26results_per_page%3D50%26type%3D'..img_type..'%26apikey%3D'..apikey..'%27&format=json' -- no way I'm using XML, plz die + local res, code = https.request(url) + if code ~= 200 then return end + local data = json.decode(res).query.results.response.data.images.image + if not data then return end + if not data[1] then return end + + local results = '[' + + for n in pairs(data) do + if img_type == 'gif' then + results = results..'{"type":"gif","id":"'..math.random(100000000000000000)..'","gif_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' + else + results = results..'{"type":"photo","id":"'..math.random(100000000000000000)..'","photo_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' + end + if n < #data then + results = results..',' + end + end + local results = results..']' + utilities.answer_inline_query(self, inline_query, results, 120) +end + function cats:action(msg, config) if matches[1] == 'gif' then local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey @@ -36,4 +67,4 @@ function cats:action(msg, config) end end -return cats +return cats \ No newline at end of file diff --git a/miku/plugins/channel.lua b/miku/plugins/channel.lua index 0659d91..d9b7779 100644 --- a/miku/plugins/channel.lua +++ b/miku/plugins/channel.lua @@ -1,63 +1,66 @@ local channel = {} -local bindings = require('miku.bindings') -local utilities = require('miku.utilities') - channel.command = 'ch \\n ' channel.doc = [[* -/ch*_ _ +/ch*_ _|_[Inline-Keyboard]_ __ - Sendet eine Nachricht in den Kanal. Der Kanal kann per Username oder ID bestimmt werden, Markdown wird unterstützt. Du musst Administrator oder Besitzer des Kanals sein. - -Markdown-Syntax: - *Fetter Text* - _Kursiver Text_ - [Text](URL) - `Inline-Codeblock` - `‌`‌`Größere Code-Block über mehrere Zeilen`‌`‌` + +Inline-Keyboards sind OPTIONAL, in dem Falle einfach den Strich weglassen. Es werden NUR URL-Buttons unterstützt! Eine Beispielsyntax für einen Button findest du [auf GitHub](https://gist.githubusercontent.com/Brawl345/e671b60e24243da81934/raw/Inline-Keyboard.json). *Der Kanalname muss mit einem @ beginnen!*]] function channel:init(config) - channel.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('ch', true).table + channel.triggers = { + "^/ch @([A-Za-z0-9-_-]+)|(.+)\n(.*)", + "^/ch @([A-Za-z0-9-_-]+)\n(.*)" + } end function channel:action(msg, config) - local input = utilities.input(msg.text) - local output - if input then - local chat_id = utilities.get_word(input, 1) - local admin_list, t = bindings.getChatAdministrators(self, { chat_id = chat_id } ) - if admin_list then - local is_admin = false - for _, admin in ipairs(admin_list.result) do - if admin.user.id == msg.from.id then - is_admin = true - end - end - if is_admin then - local text = input:match('\n(.+)') - if text then - local success, result = utilities.send_message(self, chat_id, text, true, nil, true) - if success then - output = 'Deine Nachricht wurde versendet!' - else - output = 'Sorry, ich konnte deine Nachricht nicht senden.\n`' .. result.description .. '`' - end - else - output = 'Bitte gebe deine Nachricht ein. Markdown wird unterstützt.' - end - else - output = 'Es sieht nicht so aus, als wärst du der Administrator dieses Kanals.' - end - else - output = 'Sorry, ich konnte die Administratorenliste nicht abrufen. Falls du den Kanalnamen benutzt: Beginnt er mit einem @?\n`' .. t.description .. '`' - end - else - output = channel.doc + 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) + + if admin_list then + local is_admin = false + for _, admin in ipairs(admin_list.result) do + if admin.user.id == msg.from.id then + is_admin = true + end end - utilities.send_reply(self, msg, output, true) + if is_admin then + if matches[3] then + text = matches[3] + reply_markup = matches[2] + -- Yeah, channels don't allow this buttons currently, but when they're ready + -- 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.') + return + elseif reply_markup:match('"switch_inline_query":"') then + utilities.send_reply(self, 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) + if success then + output = 'Deine Nachricht wurde versendet!' + else + output = 'Sorry, ich konnte deine Nachricht nicht senden.\n`' .. result.description .. '`' + end + else + output = 'Es sieht nicht so aus, als wärst du der Administrator dieses Kanals.' + end + else + output = 'Sorry, ich konnte die Administratorenliste nicht abrufen!\n`'..gca_results.description..'`' + end + utilities.send_reply(self, msg, output, true) end -return channel +return channel \ No newline at end of file diff --git a/miku/plugins/channels.lua b/miku/plugins/channels.lua index dccf6fe..e831ebc 100644 --- a/miku/plugins/channels.lua +++ b/miku/plugins/channels.lua @@ -1,9 +1,5 @@ local channels = {} -local bindings = require('miku.bindings') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - channels.command = 'channel ' function channels:init(config) diff --git a/miku/plugins/cleverbot.lua b/miku/plugins/cleverbot.lua index 790a19c..07f8be4 100644 --- a/miku/plugins/cleverbot.lua +++ b/miku/plugins/cleverbot.lua @@ -1,10 +1,5 @@ local cleverbot = {} -local https = require('ssl.https') -local URL = require('socket.url') -local utilities = require('miku.utilities') -local json = require('dkjson') - function cleverbot:init(config) cleverbot.triggers = { "^/[Cc][Bb][Oo][Tt] (.*)$" diff --git a/miku/plugins/clypit.lua b/miku/plugins/clypit.lua index 913837c..8a41aec 100644 --- a/miku/plugins/clypit.lua +++ b/miku/plugins/clypit.lua @@ -1,10 +1,5 @@ local clypit = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - clypit.triggers = { "clyp.it/([A-Za-z0-9-_-]+)" } diff --git a/miku/plugins/control.lua b/miku/plugins/control.lua index 9389992..ddfa4b3 100644 --- a/miku/plugins/control.lua +++ b/miku/plugins/control.lua @@ -1,7 +1,6 @@ local control = {} local bot = require('miku.bot') -local utilities = require('miku.utilities') local cmd_pat -- Prevents the command from being uncallable. diff --git a/miku/plugins/creds.lua b/miku/plugins/creds.lua index 913529e..1c95ddf 100644 --- a/miku/plugins/creds.lua +++ b/miku/plugins/creds.lua @@ -1,8 +1,5 @@ local creds_manager = {} -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - function creds_manager:init(config) creds_manager.triggers = { "^(/creds)$", diff --git a/miku/plugins/currency.lua b/miku/plugins/currency.lua index 67f3c28..92b8a47 100644 --- a/miku/plugins/currency.lua +++ b/miku/plugins/currency.lua @@ -1,8 +1,5 @@ local currency = {} -local HTTPS = require('ssl.https') -local utilities = require('miku.utilities') - currency.command = 'cash [Menge] ' function currency:init(config) @@ -42,7 +39,7 @@ function currency:action(msg, config) end local url = BASE_URL..'?from='..from..'&to='..to..'&a='..amount - local str, res = HTTPS.request(url) + local str, res = https.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return diff --git a/miku/plugins/dailymotion.lua b/miku/plugins/dailymotion.lua index c865e2c..33f5fc3 100644 --- a/miku/plugins/dailymotion.lua +++ b/miku/plugins/dailymotion.lua @@ -1,9 +1,5 @@ local dailymotion = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - dailymotion.triggers = { "dailymotion.com/video/([A-Za-z0-9-_-]+)" } diff --git a/miku/plugins/deviantart.lua b/miku/plugins/deviantart.lua index 34861e8..9497877 100644 --- a/miku/plugins/deviantart.lua +++ b/miku/plugins/deviantart.lua @@ -1,9 +1,5 @@ local deviantart = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - deviantart.triggers = { "http://(.*).deviantart.com/art/(.*)" } diff --git a/miku/plugins/dhl.lua b/miku/plugins/dhl.lua index 4aca7be..8ac51db 100644 --- a/miku/plugins/dhl.lua +++ b/miku/plugins/dhl.lua @@ -1,12 +1,8 @@ local dhl = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - function dhl:init(config) dhl.triggers = { - "/[Dd][Hh][Ll] (%d+)$" + '/[Dd][Hh][Ll] (%d+)$' } dhl.doc = [[* ]]..config.cmd_pat..[[dhl* __: Aktueller Status der Sendung]] @@ -18,10 +14,10 @@ local BASE_URL = 'https://mobil.dhl.de' function dhl:sendungsstatus(id) local url = BASE_URL..'/shipmentdetails.html?shipmentId='..id local res,code = https.request(url) - if code ~= 200 then return "Fehler beim Abrufen von mobil.dhl.de" end - local status = string.match(res, "
(.-)
") + if code ~= 200 then return 'Fehler beim Abrufen von mobil.dhl.de' end + local status = string.match(res, '
(.-)
') local status = all_trim(status) - local zeit = string.match(res, "
(.-)
") + local zeit = string.match(res, '
(.-)
') local zeit = all_trim(zeit) if not zeit or zeit == '
' then return status diff --git a/miku/plugins/dropbox.lua b/miku/plugins/dropbox.lua index 47770f3..d2f3eb3 100644 --- a/miku/plugins/dropbox.lua +++ b/miku/plugins/dropbox.lua @@ -2,27 +2,23 @@ local dropbox = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - dropbox.triggers = { - "dropbox.com/s/([a-z0-9]+)/(.*)" + 'dropbox.com/s/([a-z0-9]+)/(.*)' } function dropbox:action(msg, config, matches) local folder = matches[1] - local file = string.gsub(matches[2], "?dl=0", "") + local file = string.gsub(matches[2], '?dl=0', '') local link = 'https://dl.dropboxusercontent.com/s/'..folder..'/'..file local v,code = https.request(link) if code == 200 then - if string.ends(link, ".png") or string.ends(link, ".jpe?g")then + if string.ends(link, '.png') or string.ends(link, '.jpe?g')then utilities.send_typing(self, msg.chat.id, 'upload_photo') local file = download_to_file(link) utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) return - elseif string.ends(link, ".webp") or string.ends(link, ".gif") then + elseif string.ends(link, '.webp') or string.ends(link, '.gif') then utilities.send_typing(self, msg.chat.id, 'upload_photo') local file = download_to_file(link) utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) diff --git a/miku/plugins/echo.lua b/miku/plugins/echo.lua index f67e992..0c9abef 100644 --- a/miku/plugins/echo.lua +++ b/miku/plugins/echo.lua @@ -1,14 +1,12 @@ local echo = {} -local utilities = require('miku.utilities') - echo.command = 'echo ' function echo:init(config) - echo.triggers = {"/[Ee][Cc][Hh][Oo] (.*)$"} + echo.triggers = {'/[Ee][Cc][Hh][Oo] (.*)$'} echo.inline_triggers = { - "^echo (.*)", - "^bold (.*)" + '^echo (.*)', + '^bold (.*)' } echo.doc = [[* ]]..config.cmd_pat..[[echo* __: Gibt den Text aus]] @@ -35,6 +33,8 @@ function echo:action(msg) 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) + return end utilities.send_message(self, msg.chat.id, input, true, nil, true) end diff --git a/miku/plugins/entergroup.lua b/miku/plugins/entergroup.lua index e2958d6..7423d82 100644 --- a/miku/plugins/entergroup.lua +++ b/miku/plugins/entergroup.lua @@ -1,8 +1,5 @@ local entergroup = {} -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - entergroup.triggers = { '/nil' } diff --git a/miku/plugins/expand.lua b/miku/plugins/expand.lua index 2f2c735..d416f93 100644 --- a/miku/plugins/expand.lua +++ b/miku/plugins/expand.lua @@ -1,14 +1,11 @@ local expand = {} -local http = require('socket.http') -local utilities = require('miku.utilities') - function expand:init(config) expand.triggers = { - "^/[Ee][Xx][Pp][Aa][Nn][Dd] (https?://[%w-_%.%?%.:/%+=&]+)$" + '^/[Ee][Xx][Pp][Aa][Nn][Dd] (https?://[%w-_%.%?%.:/%+=&]+)$' } expand.inline_triggers = { - "^ex (https?://[%w-_%.%?%.:/%+=&]+)$" + '^ex (https?://[%w-_%.%?%.:/%+=&]+)$' } expand.doc = [[* @@ -53,7 +50,7 @@ function expand:action(msg, config, matches) utilities.send_reply(self, msg, response_headers.location) return else - utilities.send_reply(self, msg, "Fehler beim Erweitern der URL.") + utilities.send_reply(self, msg, 'Fehler beim Erweitern der URL.') return end end diff --git a/miku/plugins/facebook.lua b/miku/plugins/facebook.lua index 983c87d..ec51012 100644 --- a/miku/plugins/facebook.lua +++ b/miku/plugins/facebook.lua @@ -1,28 +1,20 @@ local facebook = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') -local redis = (loadfile "./miku/redis.lua")() - function facebook:init(config) if not cred_data.fb_access_token then - print('Missing config value: fb_access_token.') - print('facebook.lua will not be enabled.') + print('Fehlender Key: fb_access_token.') + print('facebook.lua wird nicht aktiviert.') return end facebook.triggers = { - "facebook.com/([A-Za-z0-9-._-]+)/(posts)/(%d+)", - "facebook.com/(permalink).php%?(story_fbid)=(%d+)&id=(%d+)", - "facebook.com/(photo).php%?fbid=(%d+)", - "facebook.com/([A-Za-z0-9-._-]+)/(photos)/a.(%d+[%d%.]*)/(%d+)", - "facebook.com/(video).php%?v=(%d+)", - "facebook.com/([A-Za-z0-9-._-]+)/(videos)/(%d+[%d%.]*)", - "facebook.com/([A-Za-z0-9-._-]+)" + 'facebook.com/([A-Za-z0-9-._-]+)/(posts)/(%d+)', + 'facebook.com/(permalink).php%?(story_fbid)=(%d+)&id=(%d+)', + 'facebook.com/(photo).php%?fbid=(%d+)', + 'facebook.com/([A-Za-z0-9-._-]+)/(photos)/a.(%d+[%d%.]*)/(%d+)', + 'facebook.com/(video).php%?v=(%d+)', + 'facebook.com/([A-Za-z0-9-._-]+)/(videos)/(%d+[%d%.]*)', + 'facebook.com/([A-Za-z0-9-._-]+)' } end @@ -30,7 +22,7 @@ local BASE_URL = 'https://graph.facebook.com/v2.5' local fb_access_token = cred_data.fb_access_token local makeOurDate = function(dateString) - local pattern = "(%d+)%/(%d+)%/(%d+)" + local pattern = '(%d+)%/(%d+)%/(%d+)' local month, day, year = dateString:match(pattern) return day..'.'..month..'.'..year end @@ -55,13 +47,13 @@ function facebook:fb_post (id, story_id) if data.link then link = '\n'..data.name..':\n'..utilities.md_escape(data.link) else - link = "" + link = '' end if data.story then story = ' ('..data.story..')' else - story = "" + story = '' end local text = '*'..from..'*'..story..':\n'..message..'\n'..link @@ -112,13 +104,13 @@ function facebook:facebook_info(name) if data.about then about = '\n'..data.about else - about = "" + about = '' end if data.general_info then general_info = '\n'..data.general_info else - general_info = "" + general_info = '' end if data.birthday and data.founded then @@ -128,7 +120,7 @@ function facebook:facebook_info(name) elseif data.founded and not data.birthday then birth = '\nGegründet: '..data.founded else - birth = "" + birth = '' end local text = '*'..name..'* ('..category..')_'..about..'_'..general_info..birth diff --git a/miku/plugins/flickr.lua b/miku/plugins/flickr.lua index 9670cf0..4ee16c9 100644 --- a/miku/plugins/flickr.lua +++ b/miku/plugins/flickr.lua @@ -1,26 +1,21 @@ local flickr = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function flickr:init(config) if not cred_data.flickr_apikey then - print('Missing config value: flickr_apikey.') - print('flickr.lua will not be enabled.') + print('Fehlender Key: flickr_apikey.') + print('flickr.lua wird nicht aktiviert.') return end flickr.triggers = { - "flickr.com/photos/([A-Za-z0-9-_-]+)/([0-9]+)" + 'flickr.com/photos/([A-Za-z0-9-_-]+)/([0-9]+)' } end local BASE_URL = 'https://api.flickr.com/services/rest' local makeOurDate = function(dateString) - local pattern = "(%d+)%-(%d+)%-(%d+) (%d+)%:(%d+)%:(%d+)" + local pattern = '(%d+)%-(%d+)%-(%d+) (%d+)%:(%d+)%:(%d+)' local year, month, day, hours, minutes, seconds = dateString:match(pattern) return day..'.'..month..'.'..year..' um '..hours..':'..minutes..':'..seconds..' Uhr' end diff --git a/miku/plugins/flickr_search.lua b/miku/plugins/flickr_search.lua index a8ab715..e1b87e9 100644 --- a/miku/plugins/flickr_search.lua +++ b/miku/plugins/flickr_search.lua @@ -1,19 +1,14 @@ local flickr_search = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function flickr_search:init(config) if not cred_data.flickr_apikey then - print('Missing config value: flickr_apikey.') - print('flickr_search.lua will not be enabled.') + print('Fehlender Key: flickr_apikey.') + print('flickr_search.lua wird nicht aktiviert.') return end flickr_search.triggers = { - "^/flickr (.*)$" + '^/[Ff][Ll][Ii][Cc][Kk][Rr] (.*)' } end @@ -41,7 +36,7 @@ function flickr_search:action(msg, config, matches) local file = download_to_file(url) - if string.ends(url, ".gif") then + if string.ends(url, '.gif') then utilities.send_document(self, msg.chat.id, file, url) return else diff --git a/miku/plugins/forecast.lua b/miku/plugins/forecast.lua index 47cef27..86046de 100644 --- a/miku/plugins/forecast.lua +++ b/miku/plugins/forecast.lua @@ -1,20 +1,13 @@ local forecast = {} -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') -local redis = (loadfile "./miku/redis.lua")() - function forecast:init(config) if not cred_data.forecastio_apikey then - print('Missing config value: forecastio_apikey.') - print('weather.lua will not be enabled.') + print('Fehlender Key: forecastio_apikey.') + print('weather.lua wird nicht aktiviert.') return elseif not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('weather.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('weather.lua wird nicht aktiviert.') return end @@ -46,9 +39,9 @@ function get_city_name(lat, lng) local city = redis:hget('telegram:cache:weather:pretty_names', lat..','..lng) if city then return city end local url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='..lat..','..lng..'&result_type=political&language=de&key='..google_apikey - local res, code = HTTPS.request(url) + local res, code = https.request(url) if code ~= 200 then return 'Unbekannte Stadt' end - local data = JSON.decode(res).results[1] + local data = json.decode(res).results[1] local city = data.formatted_address print('Setting '..lat..','..lng..' in redis hash telegram:cache:weather:pretty_names to "'..city..'"') redis:hset('telegram:cache:weather:pretty_names', lat..','..lng, city) @@ -107,9 +100,9 @@ function forecast:get_forecast(lat, lng) method = "GET", sink = ltn12.sink.table(response_body) } - local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + local ok, response_code, response_headers, response_status_line = https.request(request_constructor) if not ok then return nil end - local data = JSON.decode(table.concat(response_body)) + local data = json.decode(table.concat(response_body)) local ttl = string.sub(response_headers["cache-control"], 9) @@ -153,9 +146,9 @@ function forecast:get_forecast_hourly(lat, lng) method = "GET", sink = ltn12.sink.table(response_body) } - local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + local ok, response_code, response_headers, response_status_line = https.request(request_constructor) if not ok then return nil end - local data = JSON.decode(table.concat(response_body)) + local data = json.decode(table.concat(response_body)) local ttl = string.sub(response_headers["cache-control"], 9) diff --git a/miku/plugins/gImages.lua b/miku/plugins/gImages.lua index e2f5f7f..3929f53 100644 --- a/miku/plugins/gImages.lua +++ b/miku/plugins/gImages.lua @@ -3,22 +3,14 @@ local gImages = {} -local HTTPS = require('ssl.https') -HTTPS.timeout = 10 -local URL = require('socket.url') -local JSON = require('dkjson') -local redis = (loadfile "./miku/redis.lua")() -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function gImages:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('gImages.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('gImages.lua wird nicht aktiviert.') return elseif not cred_data.google_cse_id then - print('Missing config value: google_cse_id.') - print('gImages.lua will not be enabled.') + print('Fehlender Key: google_cse_id.') + print('gImages.lua wird nicht aktiviert.') return end @@ -97,7 +89,7 @@ function gImages:callback(callback, msg, self, config, input) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}') + utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) return end @@ -114,12 +106,12 @@ function gImages:callback(callback, msg, self, config, input) end function gImages:get_image(input) - local apikey = cred_data.google_apikey -- 100 requests is RIDICULOUS, Google! + local apikey = cred_data.google_apikey local cseid = cred_data.google_cse_id local BASE_URL = 'https://www.googleapis.com/customsearch/v1' local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&safe=high'..'&q=' .. input .. '&fields=items(link,mime,image(contextLink))' - local jstr, res = HTTPS.request(url) - local jdat = JSON.decode(jstr).items + local jstr, res = https.request(url) + local jdat = json.decode(jstr).items if not jdat then return 'NORESULTS' @@ -160,9 +152,9 @@ function gImages:action(msg, config, matches) end end - print ('Checking if search contains blacklisted word: '..input) + 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(self, msg, 'Vergiss es!') return end @@ -204,11 +196,11 @@ function gImages:action(msg, config, matches) -- It's important to save the image with the right ending! if mimetype == 'image/gif' then - file = download_to_file(img_url, 'img.gif') + file = download_to_file(img_url) elseif mimetype == 'image/png' then - file = download_to_file(img_url, 'img.png') + file = download_to_file(img_url) elseif mimetype == 'image/jpeg' then - file = download_to_file(img_url, 'img.jpg') + file = download_to_file(img_url) else file = nil end @@ -226,7 +218,7 @@ function gImages:action(msg, config, matches) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}') + utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) return end diff --git a/miku/plugins/gImages_nsfw.lua b/miku/plugins/gImages_nsfw.lua index 94f977e..c32e411 100644 --- a/miku/plugins/gImages_nsfw.lua +++ b/miku/plugins/gImages_nsfw.lua @@ -3,22 +3,14 @@ local gImages_nsfw = {} -local HTTPS = require('ssl.https') -HTTPS.timeout = 10 -local URL = require('socket.url') -local JSON = require('dkjson') -local redis = (loadfile "./miku/redis.lua")() -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function gImages_nsfw:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('gImages_nsfw.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('gImages_nsfw.lua wird nicht aktiviert.') return elseif not cred_data.google_cse_id then - print('Missing config value: google_cse_id.') - print('gImages_nsfw.lua will not be enabled.') + print('Fehlender Key: google_cse_id.') + print('gImages_nsfw.lua wird nicht aktiviert.') return end @@ -97,7 +89,7 @@ function gImages_nsfw:callback(callback, msg, self, config, input) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') + utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) return end @@ -114,12 +106,12 @@ function gImages_nsfw:callback(callback, msg, self, config, input) end function gImages_nsfw:get_image(input) - local apikey = cred_data.google_apikey -- 100 requests is RIDICULOUS, Google! + local apikey = cred_data.google_apikey local cseid = cred_data.google_cse_id local BASE_URL = 'https://www.googleapis.com/customsearch/v1' local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&q=' .. input .. '&fields=items(link,mime,image(contextLink))' - local jstr, res = HTTPS.request(url) - local jdat = JSON.decode(jstr).items + local jstr, res = https.request(url) + local jdat = json.decode(jstr).items if not jdat then return 'NORESULTS' @@ -160,9 +152,9 @@ function gImages_nsfw:action(msg, config, matches) end end - print ('Checking if search contains blacklisted word: '..input) + 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(self, msg, 'Vergiss es!') return end @@ -204,11 +196,11 @@ function gImages_nsfw:action(msg, config, matches) -- It's important to save the image with the right ending! if mimetype == 'image/gif' then - file = download_to_file(img_url, 'img.gif') + file = download_to_file(img_url) elseif mimetype == 'image/png' then - file = download_to_file(img_url, 'img.png') + file = download_to_file(img_url) elseif mimetype == 'image/jpeg' then - file = download_to_file(img_url, 'img.jpg') + file = download_to_file(img_url) else file = nil end @@ -226,7 +218,7 @@ function gImages_nsfw:action(msg, config, matches) end if failed then - utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') + utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true) return end diff --git a/miku/plugins/gMaps.lua b/miku/plugins/gMaps.lua index 801a0af..659be17 100644 --- a/miku/plugins/gMaps.lua +++ b/miku/plugins/gMaps.lua @@ -1,12 +1,9 @@ local gMaps = {} -local URL = require('socket.url') -local utilities = require('miku.utilities') - gMaps.command = 'loc ' function gMaps:init(config) - gMaps.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('loc', true).table + gMaps.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Oo][Cc]', true).table gMaps.doc = [[* ]]..config.cmd_pat..[[loc* __: Sendet Ort via Google Maps]] end diff --git a/miku/plugins/gSearch.lua b/miku/plugins/gSearch.lua index 99380ba..b5fd5d0 100644 --- a/miku/plugins/gSearch.lua +++ b/miku/plugins/gSearch.lua @@ -1,14 +1,9 @@ local gSearch = {} -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') - gSearch.command = 'google ' function gSearch:init(config) - gSearch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('g', true):t('google', true).table + gSearch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg]', true):t('[Gg][Oo][Oo][Gg][Ll][Ee]', true).table gSearch.doc = [[* ]]..config.cmd_pat..[[google* __: Sendet Suchergebnisse von Google Alias: _]]..config.cmd_pat..[[g_]] @@ -23,7 +18,7 @@ function gSearch:googlethat(query, config) local api = BASE_URL.."/?key="..apikey.."&cx="..cseid.."&gl=de&num="..number.."&safe=medium&fields=searchInformation%28formattedSearchTime,formattedTotalResults%29,items%28title,link,displayLink%29&" local parameters = "q=".. (URL.escape(query) or "") -- Do the request - local res, code = HTTPS.request(api..parameters) + local res, code = https.request(api..parameters) if code == 403 then return '403' end @@ -31,7 +26,7 @@ function gSearch:googlethat(query, config) utilities.send_reply(self, msg, config.errors.connection) return end - local data = JSON.decode(res) + local data = json.decode(res) if data.searchInformation.formattedTotalResults == "0" then return nil end local results={} diff --git a/miku/plugins/games.lua b/miku/plugins/games.lua index 364de1d..cf7952f 100644 --- a/miku/plugins/games.lua +++ b/miku/plugins/games.lua @@ -1,10 +1,6 @@ local games = {} -local http = require('socket.http') -local URL = require('socket.url') -local xml = require("xml") -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') +local xml = require("xml") games.command = 'game ' diff --git a/miku/plugins/gdrive.lua b/miku/plugins/gdrive.lua index 00bc78b..3622c89 100644 --- a/miku/plugins/gdrive.lua +++ b/miku/plugins/gdrive.lua @@ -1,15 +1,9 @@ local gdrive = {} -local utilities = require('miku.utilities') -local https = require('ssl.https') -local ltn12 = require('ltn12') -local json = require('dkjson') -local bindings = require('miku.bindings') - function gdrive:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('gdrive.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('gdrive.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/get.lua b/miku/plugins/get.lua index 73744bc..7c40486 100644 --- a/miku/plugins/get.lua +++ b/miku/plugins/get.lua @@ -1,12 +1,9 @@ local get = {} -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - get.command = 'get ' function get:init(config) - get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('get', true).table + get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg][Ee][Tt]', true).table get.doc = [[* ]]..config.cmd_pat..[[get*: Gibt alle Variablen aus *]]..config.cmd_pat..[[get* __: Gibt _Variable_ aus @@ -30,7 +27,7 @@ function get:list_variables(msg) print(hash) if hash then - print('Getting variable from redis hash '..hash) + print('Hole Variable von Redis Hash '..hash) local names = redis:hkeys(hash) local text = '' for i=1, #names do diff --git a/miku/plugins/getfile.lua b/miku/plugins/getfile.lua index 41d183b..77d0446 100644 --- a/miku/plugins/getfile.lua +++ b/miku/plugins/getfile.lua @@ -4,12 +4,6 @@ local media_download = {} -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') -local ltn12 = require('ltn12') -local HTTPS = require('ssl.https') -local redis = (loadfile "./miku/redis.lua")() - media_download.triggers = { '/nil' } @@ -22,7 +16,7 @@ function media_download:download_to_file_permanently(url, file_name) redirect = false } local response = nil - response = {HTTPS.request(options)} + response = {https.request(options)} local code = response[2] local headers = response[3] @@ -65,14 +59,14 @@ function media_download:pre_process(msg, self) end if file_size > 19922944 then - print('File is over 20 MB - can\'t download :(') + print('Datei ist größer als 20 MB - Nicht downloadbar!') return end -- Check if file has already been downloaded local already_downloaded = redis:sismember('telegram:file_id', file_id) if already_downloaded == true then - print('File has already been downloaded in the past, skipping...') + print('Datei wurde bereits gedownloadet') return end @@ -83,7 +77,7 @@ function media_download:pre_process(msg, self) -- Getting file from the Telegram Cloud if not request then - print('Download failed!') + print('Download fehlgeschlagen!') return end @@ -98,7 +92,7 @@ function media_download:pre_process(msg, self) local download_url = 'https://api.telegram.org/file/bot'..cred_data.bot_api_key..'/'..request.result.file_path local ok = media_download:download_to_file_permanently(download_url, file_path) if not ok then - print('Download failed!') + print('Download fehlgeschlagen!') return end diff --git a/miku/plugins/gfycat.lua b/miku/plugins/gfycat.lua index a3857c8..18781bf 100644 --- a/miku/plugins/gfycat.lua +++ b/miku/plugins/gfycat.lua @@ -2,10 +2,6 @@ local gfycat = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - gfycat.triggers = { "gfycat.com/([A-Za-z0-9-_-]+)" } diff --git a/miku/plugins/giphy.lua b/miku/plugins/giphy.lua index a19377d..3177cf3 100644 --- a/miku/plugins/giphy.lua +++ b/miku/plugins/giphy.lua @@ -1,10 +1,5 @@ local giphy = {} -local http = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') - function giphy:init(config) giphy.triggers = { "/nil" @@ -26,7 +21,7 @@ function giphy:get_gifs(query) end local res, code = http.request(url) if code ~= 200 then return nil end - return JSON.decode(res).data + return json.decode(res).data end function giphy:inline_callback(inline_query, config, matches) diff --git a/miku/plugins/github.lua b/miku/plugins/github.lua index 370c1fd..62adc4d 100644 --- a/miku/plugins/github.lua +++ b/miku/plugins/github.lua @@ -1,13 +1,5 @@ local github = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') -local redis = (loadfile "./miku/redis.lua")() - function github:init(config) github.triggers = { "github.com/([A-Za-z0-9-_-.-._.]+)/([A-Za-z0-9-_-.-._.]+)/commit/([a-z0-9-]+)", diff --git a/miku/plugins/github_feed.lua b/miku/plugins/github_feed.lua new file mode 100644 index 0000000..e8dcbf3 --- /dev/null +++ b/miku/plugins/github_feed.lua @@ -0,0 +1,302 @@ +local gh_feed = {} + +gh_feed.command = 'gh ' + +function gh_feed:init(config) + if not cred_data.github_token then + print('Fehlender Key: github_token.') + print('github_feed.lua wird nicht aktiviert.') + return + elseif not cred_data.github_username then + print('Fehlender Key: github_username.') + print('github_feed.lua wird nicht aktiviert.') + return + end + + gh_feed.triggers = { + "^/(gh) @(.*)$", + "^/gh$", + "^/gh (sub) ([A-Za-z0-9-_-.-._.]+/[A-Za-z0-9-_-.-._.]+) @(.*)$", + "^/gh (sub) ([A-Za-z0-9-_-.-._.]+/[A-Za-z0-9-_-.-._.]+)$", + "^/gh (del) (%d+) @(.*)$", + "^/gh (del) (%d+)$", + "^/gh (del)", + "^/gh (sync)$" + } + gh_feed.doc = [[* +]]..config.cmd_pat..[[gh* _@[Kanalname]_: GitHub-Abonnements anzeigen +*]]..config.cmd_pat..[[gh* _sub_ __ _@[Kanalname]_: Diese Repo abonnieren +*]]..config.cmd_pat..[[gh* _del_ _<#>_ _@[Kanalname]_: Diese Repo deabonnieren +*]]..config.cmd_pat..[[gh* _sync_: Repos syncen (nur Superuser) +Der Kanalname ist optional]] +end + +local token = cred_data.github_token -- get a token here: https://github.com/settings/tokens/new (you don't need any scopes) +local BASE_URL = 'https://api.github.com/repos' + +function gh_feed_get_base_redis(id, option, extra) + local ex = '' + if option ~= nil then + ex = ex .. ':' .. option + if extra ~= nil then + ex = ex .. ':' .. extra + end + end + return 'github:' .. id .. ex +end + +function gh_feed_check_modified(repo, cur_etag, last_date) + local url = BASE_URL..'/'..repo + local response_body = {} + local request_constructor = { + url = url, + method = "HEAD", + redirect = false, + headers = { + Authorization = 'token '..token, + ["If-None-Match"] = cur_etag + } + } + local ok, response_code = https.request(request_constructor) + if not ok then return nil end + if response_code == 304 then return true end + + local url = BASE_URL..'/'..repo..'/commits?since='..last_date + local response_body = {} + local request_constructor = { + url = url, + method = "GET", + sink = ltn12.sink.table(response_body), + headers = { + Authorization = 'token '..token + } + } + local ok, response_code, response_headers = https.request(request_constructor) + if not response_headers then return nil end + local data = json.decode(table.concat(response_body)) + return false, data, response_headers.etag +end + +function gh_feed:check_repo(repo) + local url = BASE_URL..'/'..repo + local response_body = {} + local request_constructor = { + url = url, + method = "GET", + sink = ltn12.sink.table(response_body), + headers = { + Authorization = 'token '..token + } + } + local ok, response_code, response_headers = https.request(request_constructor) + if not ok then return nil end + return json.decode(table.concat(response_body)), response_headers.etag +end + +function gh_feed:subscribe(id, repo) + local lasthash = gh_feed_get_base_redis(repo, "last_commit") + local lastetag = gh_feed_get_base_redis(repo, "etag") + local lastdate = gh_feed_get_base_redis(repo, "date") + local lhash = gh_feed_get_base_redis(repo, "subs") + local uhash = gh_feed_get_base_redis(id) + + if redis:sismember(uhash, repo) then + return "Du hast `"..repo.."` bereits abonniert." + end + + local data, etag = gh_feed:check_repo(repo) + if not data or not data.full_name then return 'Diese Repo gibt es nicht!' end + if not etag then return 'Ein Fehler ist aufgetreten.' end + + local last_commit = "" + local pushed_at = data.pushed_at + local name = data.full_name + + redis:set(lasthash, last_commit) + redis:set(lastdate, pushed_at) + redis:set(lastetag, etag) + redis:sadd(lhash, id) + redis:sadd(uhash, repo) + + return "_"..utilities.md_escape(name) .."_ abonniert!" +end + +function gh_feed:unsubscribe(id, n) + if #n > 3 then + return "Du kannst nicht mehr als drei Repos abonnieren!" + end + n = tonumber(n) + + local uhash = gh_feed_get_base_redis(id) + local subs = redis:smembers(uhash) + if n < 1 or n > #subs then + return "Abonnement-ID zu hoch!" + end + local sub = subs[n] + local lhash = gh_feed_get_base_redis(sub, "subs") + + redis:srem(uhash, sub) + redis:srem(lhash, id) + + local left = redis:smembers(lhash) + if #left < 1 then -- no one subscribed, remove it + local lastetag = gh_feed_get_base_redis(sub, "etag") + local lastdate = gh_feed_get_base_redis(sub, "date") + local lasthash = gh_feed_get_base_redis(sub, "last_commit") + redis:del(lastetag) + redis:del(lasthash) + redis:del(lastdate) + end + + return "Du hast `"..utilities.md_escape(sub).."` deabonniert." +end + +function gh_feed:print_subs(id, chat_name) + local uhash = gh_feed_get_base_redis(id) + local subs = redis:smembers(uhash) + if not subs[1] then + return 'Keine GitHub-Repos abonniert!' + end + local keyboard = '{"keyboard":[[' + local keyboard_buttons = '' + local text = '*'..chat_name..'* hat abonniert:\n---------\n' + for k,v in pairs(subs) do + text = text .. k .. ") ["..v.."](https://github.com/"..v..')\n' + if k == #subs then + keyboard_buttons = keyboard_buttons..'{"text":"/gh del '..k..'"}' + break; + end + keyboard_buttons = keyboard_buttons..'{"text":"/gh del '..k..'"},' + end + local keyboard = keyboard..keyboard_buttons..']], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}' + return text, keyboard +end + +function gh_feed:action(msg, config, matches) + local id = msg.from.id + if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then + id = msg.chat.id + end + + -- 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) + return + end + local id = '@'..matches[3] + local result = utilities.get_chat_info(self, id) + if not result then + utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + return + end + local output = gh_feed:subscribe(id, matches[2]) + utilities.send_reply(self, 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) + return + end + local id = '@'..matches[3] + local result = utilities.get_chat_info(self, id) + if not result then + utilities.send_reply(self, msg, 'Diesen Kanal gibt es nicht!') + return + end + local output = gh_feed:unsubscribe(id, matches[2]) + utilities.send_reply(self, msg, output, true) + return + elseif matches[1] == 'gh' and matches[2] then + local id = '@'..matches[2] + local result = utilities.get_chat_info(self, id) + if not result then + utilities.send_reply(self, 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) + return + end + + if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then + chat_name = msg.chat.title + else + chat_name = msg.chat.first_name + end + + if matches[1] == 'sub' and matches[2] then + if msg.from.id ~= config.admin then + utilities.send_reply(self, msg, config.errors.sudo) + return + end + local output = gh_feed:subscribe(id, matches[2]) + utilities.send_reply(self, 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) + return + end + local output = gh_feed:unsubscribe(id, matches[2]) + utilities.send_reply(self, 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) + return + elseif matches[1] == 'sync' then + if msg.from.id ~= config.admin then + utilities.send_reply(self, msg, config.errors.sudo) + return + end + gh_feed:cron(self) + return + end + + local output = gh_feed:print_subs(id, chat_name) + utilities.send_reply(self, msg, output, true) + return +end + +function gh_feed:cron(self_plz) + if not self.BASE_URL then + self = self_plz + end + local keys = redis:keys(gh_feed_get_base_redis("*", "subs")) + for k,v in pairs(keys) do + local repo = string.match(v, "github:(.+):subs") + print('GitHub: '..repo) + local cur_etag = redis:get(gh_feed_get_base_redis(repo, "etag")) + local last_date = redis:get(gh_feed_get_base_redis(repo, "date")) + local was_not_modified, data, last_etag = gh_feed_check_modified(repo, cur_etag, last_date) + if not was_not_modified then + if not data or not last_etag then return end + -- When there are new commits + local last_commit = redis:get(gh_feed_get_base_redis(repo, "last_commit")) + text = '' + for n in ipairs(data) do + if data[n].sha ~= last_commit then + local sha = data[n].sha + local author = data[n].commit.author.name + local message = utilities.md_escape(data[n].commit.message) + local link = data[n].html_url + text = text..'\n#GitHub: `'..repo..'@'..sha..'` von *'..author..'*:\n'..message..'\n[GitHub aufrufen]('..link..')\n' + end + end + if text ~= '' then + local last_commit = data[1].sha + local last_date = data[1].commit.author.date + redis:set(gh_feed_get_base_redis(repo, "last_commit"), last_commit) + 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) + end + end + end + end +end + +return gh_feed \ No newline at end of file diff --git a/miku/plugins/googl.lua b/miku/plugins/googl.lua index 5ff63bf..f56a499 100644 --- a/miku/plugins/googl.lua +++ b/miku/plugins/googl.lua @@ -1,19 +1,17 @@ local googl = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - function googl:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('googl.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('googl.lua wird nicht aktiviert.') return end googl.triggers = { "goo.gl/([A-Za-z0-9-_-/-/]+)" } + + googl.inline_triggers = googl.triggers end local BASE_URL = 'https://www.googleapis.com/urlshortener/v1' @@ -24,11 +22,20 @@ local makeOurDate = function(dateString) return day..'.'..month..'.'..year 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 return end + + local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","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) +end + function googl:send_googl_info (shorturl) local apikey = cred_data.google_apikey local url = BASE_URL..'/url?key='..apikey..'&shortUrl=http://goo.gl/'..shorturl..'&projection=FULL&fields=longUrl,created,analytics(allTime(shortUrlClicks))' local res,code = https.request(url) - if code ~= 200 then return "HTTP-FEHLER" end + if code ~= 200 then return nil end local data = json.decode(res) local longUrl = data.longUrl @@ -36,12 +43,14 @@ function googl:send_googl_info (shorturl) local created = makeOurDate(data.created) local text = longUrl..'\n'..shortUrlClicks..' mal geklickt (erstellt am '..created..')' - return text + return text, longUrl end function googl:action(msg, config, matches) local shorturl = matches[1] - utilities.send_reply(self, msg, googl:send_googl_info(shorturl)) + 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) end -return googl +return googl \ No newline at end of file diff --git a/miku/plugins/gps.lua b/miku/plugins/gps.lua index fcc2eb0..c6aa79a 100644 --- a/miku/plugins/gps.lua +++ b/miku/plugins/gps.lua @@ -1,8 +1,5 @@ local gps = {} -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - gps.command = 'gps ,' function gps:init(config) diff --git a/miku/plugins/help.lua b/miku/plugins/help.lua index ea40b86..7f140c5 100644 --- a/miku/plugins/help.lua +++ b/miku/plugins/help.lua @@ -2,8 +2,6 @@ local help = {} -local utilities = require('miku.utilities') - local help_text function help:init(config) diff --git a/miku/plugins/id.lua b/miku/plugins/id.lua index 0cbc974..b57c0a9 100644 --- a/miku/plugins/id.lua +++ b/miku/plugins/id.lua @@ -1,9 +1,5 @@ local id = {} -local redis = (loadfile "./miku/redis.lua")() -local bindings = require('miku.bindings') -local utilities = require('miku.utilities') - id.command = 'id' function id:init(config) @@ -104,7 +100,7 @@ function id:action(msg) end end local result = id:get_member_count(self, msg, chat_id) - local member_count = result.result - 1 -- minus the bot + local member_count = result.result if member_count == 1 then member_count = 'ist *1 Mitglied' else @@ -115,13 +111,13 @@ function id:action(msg) if table.contains(admins, tostring(user.id)) then text = text..'*'..user.name..'* `['..user.id..']` _Administrator_\n' elseif tostring(creator_id) == user.id then - text = text..'*'..user.name..'* `['..user.id..']` _Gruppenersteller_\n' + text = text..'*'..user.name..'* `['..user.id..']` _Gründer_\n' else text = text..'*'..user.name..'* `['..user.id..']`\n' end end - utilities.send_reply(self, msg, text, true) + utilities.send_reply(self, msg, text..'_(Bots sind nicht gelistet)_', true) end end -return id +return id \ No newline at end of file diff --git a/miku/plugins/images.lua b/miku/plugins/images.lua index 629ba33..70a83b8 100644 --- a/miku/plugins/images.lua +++ b/miku/plugins/images.lua @@ -1,6 +1,5 @@ local images = {} -local utilities = require('miku.utilities') images.triggers = { "(https?://[%w-_%%%.%?%.:,/%+=~&%[%]]+%.[Pp][Nn][Gg])$", "(https?://[%w-_%%%.%?%.:,/%+=~&%[%]]+%.[Jj][Pp][Ee]?[Gg])$" diff --git a/miku/plugins/imdb.lua b/miku/plugins/imdb.lua index 5dc1496..1e7e3fc 100644 --- a/miku/plugins/imdb.lua +++ b/miku/plugins/imdb.lua @@ -1,18 +1,12 @@ local imdb = {} -local HTTP = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - imdb.command = 'imdb ' function imdb:init(config) - imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table + imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ii][Mm][Dd][Bb]', true).table imdb.doc = [[* ]]..config.cmd_pat..[[imdb* __ -Sucht _Film_ bei IMDB]] +Sucht einen _Film_ bei IMDB]] end function imdb:action(msg, config) @@ -29,13 +23,13 @@ function imdb:action(msg, config) local url = 'http://www.omdbapi.com/?t=' .. URL.escape(input) - local jstr, res = HTTP.request(url) + local jstr, res = http.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if jdat.Response ~= 'True' then utilities.send_reply(self, msg, config.errors.results) diff --git a/miku/plugins/imgblacklist.lua b/miku/plugins/imgblacklist.lua index d8bc3b7..6f8cfd5 100644 --- a/miku/plugins/imgblacklist.lua +++ b/miku/plugins/imgblacklist.lua @@ -1,15 +1,12 @@ local imgblacklist = {} -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - imgblacklist.command = 'imgblacklist' function imgblacklist:init(config) imgblacklist.triggers = { - "^/imgblacklist show$", - "^/imgblacklist (add) (.*)$", - "^/imgblacklist (remove) (.*)$" + "^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] show$", + "^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] (add) (.*)$", + "^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] (remove) (.*)$" } imgblacklist.doc = [[* ]]..config.cmd_pat..[[imgblacklist* _show_: Zeige Blacklist @@ -32,7 +29,7 @@ function imgblacklist:show_blacklist() end function imgblacklist:add_blacklist(word) - print('Blacklisting '..word..' - saving to redis set telegram:img_blacklist') + print('Blackliste '..word..' - Speicher in Redis Hash telegram:img_blacklist') if redis:sismember("telegram:img_blacklist", word) == true then return '"'..word..'" steht schon auf der Blacklist.' else @@ -42,7 +39,7 @@ function imgblacklist:add_blacklist(word) end function imgblacklist:remove_blacklist(word) - print('De-blacklisting '..word..' - removing from redis set telegram:img_blacklist') + print('Deblackliste '..word..' - Lösche aus Redis Hash telegram:img_blacklist') if redis:sismember("telegram:img_blacklist", word) == true then redis:srem("telegram:img_blacklist", word) return '"'..word..'" erfolgreich von der Blacklist gelöscht!' diff --git a/miku/plugins/imgur.lua b/miku/plugins/imgur.lua index bd24e01..61554a6 100644 --- a/miku/plugins/imgur.lua +++ b/miku/plugins/imgur.lua @@ -1,19 +1,14 @@ local imgur = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - function imgur:init(config) if not cred_data.imgur_client_id then - print('Missing config value: imgur_client_id.') - print('imgur.lua will not be enabled.') + print('Fehlender Key: imgur_client_id.') + print('imgur.lua wird nicht aktiviert.') return end imgur.triggers = { - "imgur.com/([A-Za-z0-9]+).gifv", - "https?://imgur.com/([A-Za-z0-9]+)" + "imgur.com/([A-Za-z0-9]+)" } end diff --git a/miku/plugins/ip_info.lua b/miku/plugins/ip_info.lua index 6ebbff2..bee92f8 100644 --- a/miku/plugins/ip_info.lua +++ b/miku/plugins/ip_info.lua @@ -1,14 +1,9 @@ local ip_info = {} -local http = require('socket.http') -local json = require('dkjson') -local URL = require('socket.url') -local utilities = require('miku.utilities') - function ip_info:init(config) ip_info.triggers = { - "^/ip (.*)$", - "^/dns (.*)$" + "^/[Ii][Pp] (.*)$", + "^/[Dd][Nn][Ss] (.*)$" } ip_info.doc = [[* diff --git a/miku/plugins/isup.lua b/miku/plugins/isup.lua index cbdafa6..dacbb20 100644 --- a/miku/plugins/isup.lua +++ b/miku/plugins/isup.lua @@ -1,11 +1,5 @@ local isup = {} -local http = require('socket.http') -local https = require('ssl.https') -local socket = require('socket') -local URL = require('socket.url') -local utilities = require('miku.utilities') - function isup:init(config) isup.triggers = { "^/[Ii][Ss][Uu][Pp] (.*)$", @@ -17,7 +11,7 @@ function isup:init(config) end function isup:is_up_socket(ip, port) - print('Connect to', ip, port) + print('Verbinde zu ', ip, port) local c = socket.try(socket.tcp()) c:settimeout(3) local conn = c:connect(ip, port) diff --git a/miku/plugins/leave_group.lua b/miku/plugins/leave_group.lua index 21f425f..532d6db 100644 --- a/miku/plugins/leave_group.lua +++ b/miku/plugins/leave_group.lua @@ -1,8 +1,5 @@ local leave_group = {} -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - leave_group.triggers = { '/nil' } @@ -15,7 +12,7 @@ function leave_group:check_for_admin(msg, self, config) user_id = config.admin } ) if not result.ok then - print('Konnte nicht prüfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber...') + print('Konnte nicht prüfen, ob Admin in Gruppe ist. Verlasse Gruppe.') return false end if result.result.status ~= "member" and result.result.status ~= "administrator" and result.result.status ~= "creator" then diff --git a/miku/plugins/location_manager.lua b/miku/plugins/location_manager.lua index 46c3870..f26615a 100644 --- a/miku/plugins/location_manager.lua +++ b/miku/plugins/location_manager.lua @@ -1,8 +1,5 @@ local loc_manager = {} -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - function loc_manager:init(config) loc_manager.triggers = { "^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn] (set) (.*)$", @@ -24,7 +21,7 @@ function loc_manager:set_location(user_id, location) if set_location == location then return 'Dieser Ort wurde bereits gesetzt.' else - print('Setting location in redis hash '..hash..' to location') + print('Setze location in redis hash '..hash..' zu '..location) redis:hset(hash, 'location', location) return 'Dein Wohnort wurde auf *'..location..'* festgelegt.' end @@ -36,7 +33,7 @@ function loc_manager:del_location(user_id) if not set_location then return 'Du hast keinen Ort gesetzt' else - print('Setting location in redis hash '..hash..' to false') + print('Setze location in redis hash '..hash..' auf false') -- We set the location to false, because deleting the value blocks redis for a few milliseconds redis:hset(hash, 'location', false) return 'Dein Wohnort *'..set_location..'* wurde gelöscht!' diff --git a/miku/plugins/lyrics.lua b/miku/plugins/lyrics.lua index a7f66dd..b3c3d68 100644 --- a/miku/plugins/lyrics.lua +++ b/miku/plugins/lyrics.lua @@ -1,17 +1,13 @@ local lyrics = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('miku.utilities') - function lyrics:init(config) if not cred_data.lyricsnmusic_apikey then - print('Missing config value: lyricsnmusic_apikey.') - print('lyrics.lua will not be enabled.') + print('Fehlender Key: lyricsnmusic_apikey.') + print('lyrics.lua wird nicht aktiviert.') return end - lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lyrics', true).table + lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Yy][Rr][Ii][Cc][Ss]', true).table lyrics.doc = [[* ]]..config.cmd_pat..[[lyrics* __: Postet Liedertext]] end diff --git a/miku/plugins/magische_miesmuschel.lua b/miku/plugins/magische_miesmuschel.lua index d8adbd3..ff0e6c4 100644 --- a/miku/plugins/magische_miesmuschel.lua +++ b/miku/plugins/magische_miesmuschel.lua @@ -1,7 +1,5 @@ local muschel = {} -local utilities = require('miku.utilities') - muschel.triggers = { "^[Mm][Aa][Gg][Ii][Ss][Cc][Hh][Ee] [Mm][Ii][Ee][Ss][Mm][Uu][Ss][Cc][Hh][Ee][Ll] (.*)$" } diff --git a/miku/plugins/media.lua b/miku/plugins/media.lua index 3eb5744..67e26fe 100644 --- a/miku/plugins/media.lua +++ b/miku/plugins/media.lua @@ -1,14 +1,10 @@ local media = {} -local HTTP = require('socket.http') -local HTTPS = require('ssl.https') -local redis = (loadfile "./miku/redis.lua")() -local utilities = require('miku.utilities') -local mimetype = (loadfile "./miku/mimetype.lua")() +mimetype = (loadfile "./miku/mimetype.lua")() media.triggers = { "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(gif))$", - "^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp4))$", + "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp4))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(pdf))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogg))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(zip))$", @@ -18,12 +14,12 @@ media.triggers = { "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(rar))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wmv))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(doc))$", - "^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(avi))$", + "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(avi))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wav))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(apk))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ipa))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webm))$", - "^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogv))$", + "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogv))$", "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webp))$" } @@ -45,16 +41,19 @@ function media:action(msg) if not file then return end if ext == 'gif' then - print('send gif') + print('Sende GIF') result = utilities.send_document(self, receiver, file, nil, msg.message_id) + elseif ext == 'ogg' then + print('Sende OGG') + result = utilities.send_voice(self, receiver, file, nil, msg.message_id) elseif mime_type == 'audio' then - print('send_audio') + print('Sende Audio') result = utilities.send_audio(self, receiver, file, nil, msg.message_id) elseif mime_type == 'video' then - print('send_video') + print('Sende Video') result = utilities.send_video(self, receiver, file, nil, msg.message_id) else - print('send_file') + print('Sende Datei') result = utilities.send_document(self, receiver, file, nil, msg.message_id) end diff --git a/miku/plugins/minecraft_server.lua b/miku/plugins/minecraft_server.lua index 0cf85ef..d235bea 100644 --- a/miku/plugins/minecraft_server.lua +++ b/miku/plugins/minecraft_server.lua @@ -1,11 +1,5 @@ local mc_server = {} -local http = require('socket.http') -local ltn12 = require('ltn12') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') - function mc_server:init(config) mc_server.triggers = { "^/mine (.*)$" diff --git a/miku/plugins/minecraft_skin.lua b/miku/plugins/minecraft_skin.lua index a2c738f..8c0d756 100644 --- a/miku/plugins/minecraft_skin.lua +++ b/miku/plugins/minecraft_skin.lua @@ -1,9 +1,7 @@ local mc_skin = {} -local utilities = require('miku.utilities') - function mc_skin:init(config) - mc_skin.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('skin', true).table + mc_skin.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ss][Kk][Ii][Nn]', true).table mc_skin.doc = [[* ]]..config.cmd_pat..[[skin* __: Sendet Minecraft-Skin dieses Nutzers]] end @@ -24,7 +22,7 @@ function mc_skin:action(msg, config, matches) 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) + local file = download_to_file(url, input..'.png') utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) end diff --git a/miku/plugins/myanimelist.lua b/miku/plugins/myanimelist.lua index b666b83..a0fd012 100644 --- a/miku/plugins/myanimelist.lua +++ b/miku/plugins/myanimelist.lua @@ -1,21 +1,17 @@ local mal = {} -local http = require('socket.http') -local URL = require('socket.url') -local xml = require("xml") -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') +local xml = require("xml") mal.command = 'anime , /manga ' function mal:init(config) if not cred_data.mal_username then - print('Missing config value: mal_username.') - print('myanimelist.lua will not be enabled.') + print('Fehlender Key: mal_username.') + print('myanimelist.lua wird nicht aktiviert.') return elseif not cred_data.mal_pw then - print('Missing config value: mal_pw.') - print('myanimelist.lua will not be enabled.') + print('Fehlender Key: mal_pw.') + print('myanimelist.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/notify.lua b/miku/plugins/notify.lua index 2a76aae..e6e0419 100644 --- a/miku/plugins/notify.lua +++ b/miku/plugins/notify.lua @@ -3,13 +3,10 @@ local notify = {} -local redis = (loadfile "./miku/redis.lua")() -local utilities = require('miku.utilities') - function notify:init(config) notify.triggers = { - "^/notify (del)$", - "^/notify$" + "^/[Nn][Oo][Tt][Ii][Ff][Yy] (del)$", + "^/[Nn][Oo][Tt][Ii][Ff][Yy]$" } notify.doc = [[* @@ -49,7 +46,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) + utilities.send_message(self, id, text, true) end end end @@ -74,9 +71,9 @@ function notify:action(msg, config, matches) utilities.send_reply(self, msg, 'Du wirst noch gar nicht benachrichtigt!') return end - print('Setting notify in redis hash '..hash..' to false') + print('Setze notify redis hash '..hash..' auf false') redis:hset(hash, 'notify', false) - print('Removing '..username..' from redis set notify:ls') + 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.') return @@ -85,11 +82,11 @@ function notify:action(msg, config, matches) utilities.send_reply(self, msg, 'Du wirst schon benachrichtigt!') return end - print('Setting notify in redis hash '..hash..' to true') + print('Setze notify in redis hash '..hash..' auf true') redis:hset(hash, 'notify', true) - print('Setting id in redis hash '..hash..' to '..msg.from.id) + print('Setze id in redis hash '..hash..' auf '..msg.from.id) redis:hset(hash, 'id', msg.from.id) - print('Adding '..username..' to redis set notify:ls') + 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) if not res then diff --git a/miku/plugins/pagespeed_insights.lua b/miku/plugins/pagespeed_insights.lua index 6f8f159..de1b199 100644 --- a/miku/plugins/pagespeed_insights.lua +++ b/miku/plugins/pagespeed_insights.lua @@ -1,18 +1,14 @@ local pagespeed_insights = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - function pagespeed_insights:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('pagespeed_insights.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('pagespeed_insights.lua wird nicht aktiviert.') return end pagespeed_insights.triggers = { - "^/speed (https?://[%w-_%.%?%.:/%+=&]+)" + "^/[Ss][Pp][Ee][Ee][Dd] (https?://[%w-_%.%?%.:/%+=&]+)" } pagespeed_insights.doc = [[* ]]..config.cmd_pat..[[speed* __: Testet Geschwindigkeit der Seite mit PageSpeed Insights]] diff --git a/miku/plugins/pasteee.lua b/miku/plugins/pasteee.lua index 62706a7..15deb8c 100644 --- a/miku/plugins/pasteee.lua +++ b/miku/plugins/pasteee.lua @@ -1,12 +1,9 @@ local pasteee = {} -local bot = require('miku.bot') -local utilities = require('miku.utilities') - function pasteee:init(config) if not cred_data.pasteee_key then - print('Missing config value: pasteee_key.') - print('pasteee.lua will not be enabled, listquotes won\'t be available.') + print('Fehlender Key: pasteee_key.') + print('pasteee.lua wird nicht aktiviert, listquotes won\'t be available.') return end diff --git a/miku/plugins/patterns.lua b/miku/plugins/patterns.lua index 8b19514..68a5208 100644 --- a/miku/plugins/patterns.lua +++ b/miku/plugins/patterns.lua @@ -1,7 +1,5 @@ local patterns = {} -local utilities = require('miku.utilities') - patterns.triggers = { '^/?s/.-/.-$' } @@ -25,8 +23,8 @@ function patterns:action(msg) utilities.send_reply(self, msg, 'Falsches Pattern!') else output = output:sub(1, 4000) - output = 'Du meintest wohl:\n"' .. output .. '"' - utilities.send_reply(self, msg.reply_to_message, output) + output = '*Du meintest wohl*:\n"'..utilities.md_escape(utilities.trim(output))..'"' + utilities.send_reply(self, msg.reply_to_message, output, true) end end diff --git a/miku/plugins/pixabay.lua b/miku/plugins/pixabay.lua index e9a5982..380722e 100644 --- a/miku/plugins/pixabay.lua +++ b/miku/plugins/pixabay.lua @@ -1,14 +1,9 @@ local pixabay = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - function pixabay:init(config) if not cred_data.pixabay_apikey then - print('Missing config value: pixabay_apikey.') - print('pixabay.lua will not be enabled.') + print('Fehlender Key: pixabay_apikey.') + print('pixabay.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/play_store.lua b/miku/plugins/play_store.lua index ca3ca45..3218f2b 100644 --- a/miku/plugins/play_store.lua +++ b/miku/plugins/play_store.lua @@ -1,13 +1,9 @@ local play_store = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - function play_store:init(config) if not cred_data.x_mashape_key then - print('Missing config value: x_mashape_key.') - print('play_store.lua will not be enabled.') + print('Fehlender Key: x_mashape_key.') + print('play_store.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/plugins.lua b/miku/plugins/plugins.lua index 02302d5..240426c 100644 --- a/miku/plugins/plugins.lua +++ b/miku/plugins/plugins.lua @@ -1,9 +1,6 @@ local plugin_manager = {} local bot = require('miku.bot') -local bindings = require('miku.bindings') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() function plugin_manager:init(config) plugin_manager.triggers = { diff --git a/miku/plugins/pocket.lua b/miku/plugins/pocket.lua index d9d23b6..bb88dd4 100644 --- a/miku/plugins/pocket.lua +++ b/miku/plugins/pocket.lua @@ -1,15 +1,9 @@ local pocket = {} -local https = require('ssl.https') -local URL = require('socket.url') -local redis = (loadfile "./miku/redis.lua")() -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function pocket:init(config) if not cred_data.pocket_consumer_key then - print('Missing config value: pocket_consumer_key.') - print('pocket.lua will not be enabled.') + print('Fehlender Key: pocket_consumer_key.') + print('pocket.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/pokedex.lua b/miku/plugins/pokedex.lua index 4a0782c..1aab7b9 100644 --- a/miku/plugins/pokedex.lua +++ b/miku/plugins/pokedex.lua @@ -1,10 +1,5 @@ local pokedex = {} -local HTTP = require('socket.http') -local JSON = require('dkjson') -local bindings = require('miku.bindings') -local utilities = require('miku.utilities') - pokedex.command = 'pokedex ' function pokedex:init(config) @@ -33,22 +28,22 @@ function pokedex:action(msg, config) local url = 'http://pokeapi.co' local dex_url = url .. '/api/v1/pokemon/' .. input - local dex_jstr, res = HTTP.request(dex_url) + local dex_jstr, res = http.request(dex_url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local dex_jdat = JSON.decode(dex_jstr) + local dex_jdat = json.decode(dex_jstr) local desc_url = url .. dex_jdat.descriptions[math.random(#dex_jdat.descriptions)].resource_uri - local desc_jstr, _ = HTTP.request(desc_url) + local desc_jstr, _ = http.request(desc_url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local desc_jdat = JSON.decode(desc_jstr) + local desc_jdat = json.decode(desc_jstr) local poke_type for _,v in ipairs(dex_jdat.types) do diff --git a/miku/plugins/preview.lua b/miku/plugins/preview.lua index 8ceb6d1..a09bbc9 100644 --- a/miku/plugins/preview.lua +++ b/miku/plugins/preview.lua @@ -1,8 +1,5 @@ local preview = {} -local HTTP = require('socket.http') -local utilities = require('miku.utilities') - preview.command = 'preview ' function preview:init(config) @@ -27,7 +24,7 @@ function preview:action(msg) input = 'http://' .. input end - local res = HTTP.request(input) + local res = http.request(input) if not res then utilities.send_reply(self, msg, 'Please provide a valid link.') return diff --git a/miku/plugins/qr.lua b/miku/plugins/qr.lua index a4589f6..2c607d4 100644 --- a/miku/plugins/qr.lua +++ b/miku/plugins/qr.lua @@ -1,9 +1,5 @@ local qr = {} -local http = require('socket.http') -local URL = require('socket.url') -local utilities = require('miku.utilities') - function qr:init(config) qr.triggers = { '^/qr "(%w+)" "(%w+)" (.+)$', diff --git a/miku/plugins/quotes.lua b/miku/plugins/quotes.lua index 9564c3f..07756b8 100644 --- a/miku/plugins/quotes.lua +++ b/miku/plugins/quotes.lua @@ -1,8 +1,5 @@ local quotes = {} -local bot = require('miku.bot') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() require("./miku/plugins/pasteee") function quotes:init(config) diff --git a/miku/plugins/random.lua b/miku/plugins/random.lua index 9bad539..428c62e 100644 --- a/miku/plugins/random.lua +++ b/miku/plugins/random.lua @@ -1,7 +1,5 @@ local fun = {} -local utilities = require('miku.utilities') - function fun:init(config) fun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('random', true).table fun.doc = [[* diff --git a/miku/plugins/reddit.lua b/miku/plugins/reddit.lua index 6653747..cc46488 100644 --- a/miku/plugins/reddit.lua +++ b/miku/plugins/reddit.lua @@ -1,10 +1,5 @@ local reddit = {} -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') - reddit.command = 'reddit [r/subreddit | Suchbegriff]' function reddit:init(config) @@ -68,7 +63,7 @@ function reddit:action(msg, config) if res ~= 200 then utilities.send_reply(self, msg, config.errors.results) else - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if #jdat.data.children == 0 then utilities.send_reply(self, msg, config.errors.results) else diff --git a/miku/plugins/reddit_post.lua b/miku/plugins/reddit_post.lua index 62ecaab..cc2d16d 100644 --- a/miku/plugins/reddit_post.lua +++ b/miku/plugins/reddit_post.lua @@ -1,10 +1,5 @@ local reddit_post = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') - reddit_post.triggers = { "reddit.com/r/([A-Za-z0-9-/-_-.]+)/comments/([A-Za-z0-9-/-_-.]+)" } diff --git a/miku/plugins/remind.lua b/miku/plugins/remind.lua index 1f7ecaa..e691d83 100644 --- a/miku/plugins/remind.lua +++ b/miku/plugins/remind.lua @@ -1,7 +1,5 @@ local remind = {} -local utilities = require('miku.utilities') - remind.command = 'remind ' function remind:init(config) diff --git a/miku/plugins/respond.lua b/miku/plugins/respond.lua index 8cd49ba..8368d7d 100644 --- a/miku/plugins/respond.lua +++ b/miku/plugins/respond.lua @@ -1,9 +1,5 @@ local respond = {} -local https = require('ssl.https') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function respond:init(config) respond.triggers = { "([Ff][Gg][Tt].? [Ss][Ww][Ii][Ff][Tt])", diff --git a/miku/plugins/roll.lua b/miku/plugins/roll.lua index bac0dcd..d65bec6 100644 --- a/miku/plugins/roll.lua +++ b/miku/plugins/roll.lua @@ -1,7 +1,5 @@ local roll = {} -local utilities = require('miku.utilities') - roll.command = 'roll' function roll:init(config) diff --git a/miku/plugins/rss.lua b/miku/plugins/rss.lua index ea7f5f0..95bc8d2 100644 --- a/miku/plugins/rss.lua +++ b/miku/plugins/rss.lua @@ -1,11 +1,5 @@ local rss = {} -local http = require('socket.http') -local https = require('ssl.https') -local url = require('socket.url') -local bindings = require('miku.bindings') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() local feedparser = require("feedparser") rss.command = 'rss ' @@ -60,24 +54,6 @@ function to_utf8(a) end end -function unescape_for_rss(str) - str = string.gsub( str, '<', '<' ) - str = string.gsub( str, '>', '>' ) - str = string.gsub( str, '"', '"' ) - str = string.gsub( str, ''', "'" ) - str = string.gsub( str, "Ä", "Ä") - str = string.gsub( str, "ä", "ä") - str = string.gsub( str, "Ö", "Ö") - str = string.gsub( str, "ö", "ö") - str = string.gsub( str, "Uuml;", "Ü") - str = string.gsub( str, "ü", "ü") - str = string.gsub( str, "ß", "ß") - str = string.gsub(str, '&#(%d+);', to_utf8) - str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end ) - str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others - return str -end - function cleanRSS(str) str = string.gsub(str, '%[mehr%]', '') str = string.gsub(str, '%[video%]', '') @@ -344,23 +320,23 @@ function rss:cron(self_plz) local subscribers = {} local text = '' -- Send one message per feed with the latest entries for k2, v2 in pairs(newentr) do - local title = v2.title or 'Kein Titel' + local title = unescape(v2.title) or 'Kein Titel' local link = v2.link or v2.id or 'Kein Link' if v2.content then content = v2.content:gsub("%b<>", "") - if string.len(v2.content) > 250 then - content = unescape_for_rss(content) - content = string.sub(content, 1, 250)..'...' + if string.len(v2.content) > 300 then + content = unescape(content) + content = string.sub(content, 1, 300)..'...' else - content = unescape_for_rss(content) + content = unescape(content) end elseif v2.summary then content = v2.summary:gsub("%b<>", "") - if string.len(v2.summary) > 250 then - content = unescape_for_rss(content) - content = string.sub(content, 1, 250)..'...' + if string.len(v2.summary) > 300 then + content = unescape(content) + content = string.sub(content, 1, 300)..'...' else - content = unescape_for_rss(content) + content = unescape(content) end else content = '' diff --git a/miku/plugins/set.lua b/miku/plugins/set.lua index 63870ba..e133e92 100644 --- a/miku/plugins/set.lua +++ b/miku/plugins/set.lua @@ -1,8 +1,5 @@ local set = {} -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - set.command = 'set ' function set:init(config) diff --git a/miku/plugins/shell.lua b/miku/plugins/shell.lua index df48f12..4399c26 100644 --- a/miku/plugins/shell.lua +++ b/miku/plugins/shell.lua @@ -1,7 +1,5 @@ local shell = {} -local utilities = require('miku.utilities') - function shell:init(config) shell.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('sh', true).table end diff --git a/miku/plugins/site_header.lua b/miku/plugins/site_header.lua index 9bab562..6d07844 100644 --- a/miku/plugins/site_header.lua +++ b/miku/plugins/site_header.lua @@ -1,7 +1,5 @@ local site_header = {} -local utilities = require('miku.utilities') - function site_header:init(config) site_header.triggers = { "^/(head) ([%w-_%.%?%.:,/%+=&#!]+)$", diff --git a/miku/plugins/soundcloud.lua b/miku/plugins/soundcloud.lua index 79c72fe..475681e 100644 --- a/miku/plugins/soundcloud.lua +++ b/miku/plugins/soundcloud.lua @@ -1,9 +1,5 @@ local soundcloud = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('miku.utilities') - soundcloud.triggers = { "soundcloud.com/([A-Za-z0-9-/-_-.]+)" } diff --git a/miku/plugins/speedtest.lua b/miku/plugins/speedtest.lua index da76f6a..dfa0682 100644 --- a/miku/plugins/speedtest.lua +++ b/miku/plugins/speedtest.lua @@ -1,7 +1,5 @@ local speedtest = {} -local utilities = require('miku.utilities') - speedtest.triggers = { "speedtest.net/my%-result/(%d+)", "speedtest.net/my%-result/i/(%d+)" diff --git a/miku/plugins/spotify.lua b/miku/plugins/spotify.lua index 78f58b1..744c527 100644 --- a/miku/plugins/spotify.lua +++ b/miku/plugins/spotify.lua @@ -1,9 +1,5 @@ local spotify = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - spotify.triggers = { "open.spotify.com/track/([A-Za-z0-9-]+)", "play.spotify.com/track/([A-Za-z0-9-]+)" diff --git a/miku/plugins/stats.lua b/miku/plugins/stats.lua index 00b7b5b..3ba40bd 100644 --- a/miku/plugins/stats.lua +++ b/miku/plugins/stats.lua @@ -1,8 +1,5 @@ local stats = {} -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - function stats:init(config) stats.triggers = { "^/([Ss]tats)$", @@ -56,6 +53,13 @@ function stats:chat_stats(chat_id) local user_info = stats:get_msgs_user_chat(user_id, chat_id) table.insert(users_info, user_info) end + + -- Get total message count + local all_msgs = 0 + for n, user in pairs(users_info) do + local msg_num = users_info[n].msgs + all_msgs = all_msgs + msg_num + end -- Sort users by msgs number table.sort(users_info, function(a, b) @@ -66,10 +70,11 @@ function stats:chat_stats(chat_id) local text = '' for k,user in pairs(users_info) do - text = text..user.name..': '..user.msgs..'\n' + text = text..user.name..': '..comma_value(user.msgs)..'\n' text = string.gsub(text, "%_", " ") -- Bot API doesn't use underscores anymore! Yippie! end if text:isempty() then return 'Keine Stats für diesen Chat verfügbar!'end + local text = utilities.md_escape(text)..'\n*TOTAL*: '..comma_value(all_msgs) return text end @@ -124,7 +129,7 @@ function stats:action(msg, config, matches) return else local chat_id = msg.chat.id - utilities.send_reply(self, msg, stats:chat_stats(chat_id)) + utilities.send_reply(self, msg, stats:chat_stats(chat_id), true) return end end @@ -134,7 +139,7 @@ function stats:action(msg, config, matches) utilities.send_reply(self, msg, config.errors.sudo) return else - utilities.send_reply(self, msg, stats:chat_stats(matches[3])) + utilities.send_reply(self, msg, stats:chat_stats(matches[3]), true) return end end diff --git a/miku/plugins/steam.lua b/miku/plugins/steam.lua index c6df8ea..145b1ea 100644 --- a/miku/plugins/steam.lua +++ b/miku/plugins/steam.lua @@ -1,10 +1,5 @@ local steam = {} -local utilities = require('miku.utilities') -local http = require('socket.http') -local json = require('dkjson') -local bindings = require('miku.bindings') - steam.triggers = { "store.steampowered.com/app/([0-9]+)", "steamcommunity.com/app/([0-9]+)" diff --git a/miku/plugins/streamable.lua b/miku/plugins/streamable.lua index d779f9d..518a2f2 100644 --- a/miku/plugins/streamable.lua +++ b/miku/plugins/streamable.lua @@ -1,9 +1,5 @@ local streamable = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - streamable.triggers = { "streamable.com/([A-Za-z0-9-_-]+)", } diff --git a/miku/plugins/surrogate.lua b/miku/plugins/surrogate.lua index a752781..2b52d94 100644 --- a/miku/plugins/surrogate.lua +++ b/miku/plugins/surrogate.lua @@ -1,7 +1,5 @@ local surrogate = {} -local utilities = require('miku.utilities') - surrogate.triggers = { "^/s (%-%d+) +(.+)$", "^/s (%d+) +(.+)$" diff --git a/miku/plugins/tagesschau.lua b/miku/plugins/tagesschau.lua index 28cf7af..24a5494 100644 --- a/miku/plugins/tagesschau.lua +++ b/miku/plugins/tagesschau.lua @@ -1,14 +1,10 @@ local tagesschau = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - tagesschau.triggers = { "tagesschau.de/([A-Za-z0-9-_-_-/]+).html" } + +tagesschau.inline_triggers = tagesschau.triggers local BASE_URL = 'https://www.tagesschau.de/api' @@ -36,12 +32,33 @@ function tagesschau:get_tagesschau_article(article) local text = '*'..title..'*\n_'..posted_at..'_\n'..news if data.banner[1] then - return text, data.banner[1].variants[1].modPremium + return text, data.banner[1].variants[1].modPremium, data.shortheadline, data.shorttext else - return text + return text, nil, data.shortheadline, data.shorttext end end +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 return end + + if text:match('"') then + text = text:gsub('"', '\\"') + end + if shorttext:match('"') then + shorttext = shorttext:gsub('"', '\\"') + end + if headline:match('"') then + headline = headline:gsub('"', '\\"') + end + + local text = text:gsub('\n', '\\n') + local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","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":"Markdown"}}]' + utilities.answer_inline_query(self, inline_query, results, 7200) +end + function tagesschau:action(msg, config, matches) local article = matches[1] local text, image_url = tagesschau:get_tagesschau_article(article) diff --git a/miku/plugins/tagesschau_eil.lua b/miku/plugins/tagesschau_eil.lua deleted file mode 100644 index 34a832c..0000000 --- a/miku/plugins/tagesschau_eil.lua +++ /dev/null @@ -1,112 +0,0 @@ -local tagesschau_eil = {} - -local http = require('socket.http') -local https = require('ssl.https') -local url = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local redis = (loadfile "./miku/redis.lua")() - -tagesschau_eil.command = 'eil ' - -function tagesschau_eil:init(config) - tagesschau_eil.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('eil', true).table - tagesschau_eil.doc = [[* -]]..config.cmd_pat..[[eil* _sub_: Eilmeldungen abonnieren -*]]..config.cmd_pat..[[eil* _del_: Eilmeldungen deabonnieren -*]]..config.cmd_pat..[[eil* _sync_: Nach neuen Eilmeldungen prüfen (nur Superuser)]] -end - -local makeOurDate = function(dateString) - local pattern = "(%d+)%-(%d+)%-(%d+)T(%d+)%:(%d+)%:(%d+)" - local year, month, day, hours, minutes, seconds = dateString:match(pattern) - return day..'.'..month..'.'..year..' um '..hours..':'..minutes..':'..seconds -end - -local url = 'http://www.tagesschau.de/api' -local hash = 'telegram:tagesschau' - -function tagesschau_eil:abonnieren(id) - if redis:sismember(hash..':subs', id) == false then - redis:sadd(hash..':subs', id) - return '*Eilmeldungen abonniert.*' - else - return 'Die Eilmeldungen wurden hier bereits abonniert.' - end -end - -function tagesschau_eil:deabonnieren(id) - if redis:sismember(hash..':subs', id) == true then - redis:srem(hash..':subs', id) - return '*Eilmeldungen deabonniert.*' - else - return 'Die Eilmeldungen wurden hier noch nicht abonniert.' - end -end - -function tagesschau_eil:action(msg, config) - local input = utilities.input(msg.text) - - 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, tagesschau_eil.doc, true, msg.message_id, true) - return - end - end - - local id = "user#id" .. msg.from.id - if msg.chat.type == 'channel' then - print('Kanäle werden momentan nicht unterstützt') - end - if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then - id = 'chat#id'..msg.chat.id - end - - if input:match('(sub)$') then - local output = tagesschau_eil:abonnieren(id) - utilities.send_reply(self, msg, output, true) - elseif input:match('(del)$') then - local output = tagesschau_eil:deabonnieren(id) - utilities.send_reply(self, msg, output, true) - elseif input:match('(sync)$') then - if msg.from.id ~= config.admin then - utilities.send_reply(self, msg, config.errors.sudo) - return - end - tagesschau_eil:cron(self) - end - - return -end - -function tagesschau_eil:cron(self_plz) - if not self.BASE_URL then - self = self_plz - end - -- print('EIL: Prüfe...') - local last_eil = redis:get(hash..':last_entry') - local res,code = http.request(url) - if code ~= 200 then return end - local data = json.decode(res) - if not data then return end - if data.breakingnews[1] then - if data.breakingnews[1].date ~= last_eil then - local title = '#EIL: *'..data.breakingnews[1].headline..'*' - local news = data.breakingnews[1].shorttext - local posted_at = makeOurDate(data.breakingnews[1].date)..' Uhr' - local post_url = string.gsub(data.breakingnews[1].details, '/api/', '/') - local post_url = string.gsub(post_url, '.json', '.html') - local eil = title..'\n_'..posted_at..'_\n'..news - redis:set(hash..':last_entry', data.breakingnews[1].date) - for _,user in pairs(redis:smembers(hash..':subs')) do - local user = string.gsub(user, 'chat%#id', '') - local user = string.gsub(user, 'user%#id', '') - utilities.send_message(self, user, eil, true, nil, true, '{"inline_keyboard":[[{"text":"Eilmeldung aufrufen","url":"'..post_url..'"}]]}') - end - end - end -end - -return tagesschau_eil diff --git a/miku/plugins/tex.lua b/miku/plugins/tex.lua deleted file mode 100644 index d4c7402..0000000 --- a/miku/plugins/tex.lua +++ /dev/null @@ -1,34 +0,0 @@ -local tex = {} - -local URL = require('socket.url') -local utilities = require('miku.utilities') - -tex.command = 'tex ' - -function tex:init(config) - tex.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('tex', true).table - tex.doc = [[* -]]..config.cmd_pat..[[tex* __: Konvertiert LaTeX in ein Bild]] -end - -function tex:action(msg, config) - local input = utilities.input(msg.text) - 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, tex.doc, true, msg.message_id, true) - return - end - end - - utilities.send_typing(self, msg.chat.id, 'upload_photo') - local eq = URL.escape(input) - - local url = "http://latex.codecogs.com/png.download?" - .."\\dpi{300}%20\\LARGE%20"..eq - local file = download_to_file(url, 'latex.png') - utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) -end - -return tex diff --git a/miku/plugins/thetvdb.lua b/miku/plugins/thetvdb.lua index 0aa7381..a640cee 100644 --- a/miku/plugins/thetvdb.lua +++ b/miku/plugins/thetvdb.lua @@ -1,9 +1,6 @@ local tv = {} -local http = require('socket.http') -local URL = require('socket.url') -local xml = require("xml") -local utilities = require('miku.utilities') +local xml = require("xml") tv.command = 'tv ' diff --git a/miku/plugins/time.lua b/miku/plugins/time.lua index 6338241..779e2cf 100644 --- a/miku/plugins/time.lua +++ b/miku/plugins/time.lua @@ -1,9 +1,5 @@ local time = {} -local HTTPS = require('ssl.https') -local JSON = require('dkjson') -local utilities = require('miku.utilities') - time.command = 'time ' function time:init(config) @@ -67,13 +63,13 @@ function time:action(msg, config) local utc = os.time(os.date("!*t", now)) local url = 'https://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '×tamp='..utc..'&language=de' - local jstr, res = HTTPS.request(url) + local jstr, res = https.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) local timezoneid = '*'..string.gsub(jdat.timeZoneId, '_', ' ' )..'*' local timestamp = now + jdat.rawOffset + jdat.dstOffset local utcoff = (jdat.rawOffset + jdat.dstOffset) / 3600 diff --git a/miku/plugins/translate.lua b/miku/plugins/translate.lua index a6e9943..d20e0ea 100644 --- a/miku/plugins/translate.lua +++ b/miku/plugins/translate.lua @@ -1,15 +1,15 @@ local translate = {} - -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') local mime = require("mime") require("./miku/plugins/pasteee") translate.command = 'translate [Text]' function translate:init(config) + if not cred_data.bing_key then + print('Fehlender Key: bing_key.') + print('translate.lua wird nicht aktiviert.') + return + end translate.triggers = { "^/translate ([%w]+),([%a]+) (.+)", "^/translate (to%:)([%w]+) (.+)", @@ -138,4 +138,4 @@ function translate:action(msg, config, matches) end -return translate +return translate \ No newline at end of file diff --git a/miku/plugins/tweet.lua b/miku/plugins/tweet.lua index 926c94d..1e1723f 100644 --- a/miku/plugins/tweet.lua +++ b/miku/plugins/tweet.lua @@ -1,28 +1,21 @@ local tweet = {} -local utilities = require('miku.utilities') -local HTTPS = require('ssl.https') -local JSON = require('dkjson') -local redis = (loadfile "./miku/redis.lua")() -local OAuth = (require "OAuth") -local bindings = require('miku.bindings') - function tweet:init(config) if not cred_data.tw_consumer_key then - print('Missing config value: tw_consumer_key.') - print('tweet.lua will not be enabled.') + print('Fehlender Key: tw_consumer_key.') + print('tweet.lua wird nicht aktiviert.') return elseif not cred_data.tw_consumer_secret then - print('Missing config value: tw_consumer_secret.') - print('tweet.lua will not be enabled.') + print('Fehlender Key: tw_consumer_secret.') + print('tweet.lua wird nicht aktiviert.') return elseif not cred_data.tw_access_token then - print('Missing config value: tw_access_token.') - print('tweet.lua will not be enabled.') + print('Fehlender Key: tw_access_token.') + print('tweet.lua wird nicht aktiviert.') return elseif not cred_data.tw_access_token_secret then - print('Missing config value: tw_access_token_secret.') - print('tweet.lua will not be enabled.') + print('Fehlender Key: tw_access_token_secret.') + print('tweet.lua wird nicht aktiviert.') return end @@ -145,7 +138,7 @@ function tweet:getTweet(self, msg, base, all) return "Konnte nicht verbinden, evtl. existiert der User nicht?" end - local response = JSON.decode(response_body) + local response = json.decode(response_body) if #response == 0 then return "Konnte keinen Tweet bekommen, sorry" end diff --git a/miku/plugins/twitch.lua b/miku/plugins/twitch.lua index c9e0a8a..edd0aa8 100644 --- a/miku/plugins/twitch.lua +++ b/miku/plugins/twitch.lua @@ -1,9 +1,5 @@ local twitch = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - twitch.triggers = { "twitch.tv/([A-Za-z0-9-_-]+)" } diff --git a/miku/plugins/twitter.lua b/miku/plugins/twitter.lua index 067fe0f..1902c6a 100644 --- a/miku/plugins/twitter.lua +++ b/miku/plugins/twitter.lua @@ -1,28 +1,21 @@ local twitter = {} -local utilities = require('miku.utilities') -local HTTPS = require('ssl.https') -local JSON = require('dkjson') -local redis = (loadfile "./miku/redis.lua")() -local OAuth = (require "OAuth") -local bindings = require('miku.bindings') - function twitter:init(config) if not cred_data.tw_consumer_key then - print('Missing config value: tw_consumer_key.') - print('twitter.lua will not be enabled.') + print('Fehlender Key: tw_consumer_key.') + print('twitter.lua wird nicht aktiviert.') return elseif not cred_data.tw_consumer_secret then - print('Missing config value: tw_consumer_secret.') - print('twitter.lua will not be enabled.') + print('Fehlender Key: tw_consumer_secret.') + print('twitter.lua wird nicht aktiviert.') return elseif not cred_data.tw_access_token then - print('Missing config value: tw_access_token.') - print('twitter.lua will not be enabled.') + print('Fehlender Key: tw_access_token.') + print('twitter.lua wird nicht aktiviert.') return elseif not cred_data.tw_access_token_secret then - print('Missing config value: tw_access_token_secret.') - print('twitter.lua will not be enabled.') + print('Fehlender Key: tw_access_token_secret.') + print('twitter.lua wird nicht aktiviert.') return end @@ -57,7 +50,7 @@ function twitter:action(msg, config, matches) local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. id.. ".json" local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url) - local response = JSON.decode(response_body) + local response = json.decode(response_body) local full_name = response.user.name local user_name = response.user.screen_name @@ -97,6 +90,7 @@ function twitter:action(msg, config, matches) for k, v in pairs(response.entities.urls) do local short = v.url local long = v.expanded_url + local long = long:gsub('%%', '%%%%') text = text:gsub(short, long) end end diff --git a/miku/plugins/twitter_send.lua b/miku/plugins/twitter_send.lua index 0e519cd..71b4b72 100644 --- a/miku/plugins/twitter_send.lua +++ b/miku/plugins/twitter_send.lua @@ -1,22 +1,13 @@ local twitter_send = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') -local OAuth = require "OAuth" -local redis = (loadfile "./miku/redis.lua")() - function twitter_send:init(config) if not cred_data.tw_consumer_key then - print('Missing config value: tw_consumer_key.') - print('twitter_send.lua will not be enabled.') + print('Fehlender Key: tw_consumer_key.') + print('twitter_send.lua wird nicht aktiviert.') return elseif not cred_data.tw_consumer_secret then - print('Missing config value: tw_consumer_secret.') - print('twitter_send.lua will not be enabled.') + print('Fehlender Key: tw_consumer_secret.') + print('twitter_send.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/twitter_user.lua b/miku/plugins/twitter_user.lua index 7b01263..4f0f4f2 100644 --- a/miku/plugins/twitter_user.lua +++ b/miku/plugins/twitter_user.lua @@ -1,28 +1,21 @@ local twitter_user = {} -local utilities = require('miku.utilities') -local http = require('socket.http') -local https = require('ssl.https') -local json = require('dkjson') -local OAuth = (require "OAuth") -local bindings = require('miku.bindings') - function twitter_user:init(config) if not cred_data.tw_consumer_key then - print('Missing config value: tw_consumer_key.') - print('twitter_user.lua will not be enabled.') + print('Fehlender Key: tw_consumer_key.') + print('twitter_user.lua wird nicht aktiviert.') return elseif not cred_data.tw_consumer_secret then - print('Missing config value: tw_consumer_secret.') - print('twitter_user.lua will not be enabled.') + print('Fehlender Key: tw_consumer_secret.') + print('twitter_user.lua wird nicht aktiviert.') return elseif not cred_data.tw_access_token then - print('Missing config value: tw_access_token.') - print('twitter_user.lua will not be enabled.') + print('Fehlender Key: tw_access_token.') + print('twitter_user.lua wird nicht aktiviert.') return elseif not cred_data.tw_access_token_secret then - print('Missing config value: tw_access_token_secret.') - print('twitter_user.lua will not be enabled.') + print('Fehlender Key: tw_access_token_secret.') + print('twitter_user.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/urbandictionary.lua b/miku/plugins/urbandictionary.lua index 27753f8..4c2bdee 100644 --- a/miku/plugins/urbandictionary.lua +++ b/miku/plugins/urbandictionary.lua @@ -1,10 +1,5 @@ local urbandictionary = {} -local HTTP = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') - urbandictionary.command = 'urbandictionary ' function urbandictionary:init(config) @@ -31,13 +26,13 @@ function urbandictionary:action(msg, config) local url = 'http://api.urbandictionary.com/v0/define?term=' .. URL.escape(input) - local jstr, res = HTTP.request(url) + local jstr, res = http.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if jdat.result_type == "no_results" then utilities.send_reply(self, msg, config.errors.results) return diff --git a/miku/plugins/venue.lua b/miku/plugins/venue.lua index 45c5264..ce75c59 100644 --- a/miku/plugins/venue.lua +++ b/miku/plugins/venue.lua @@ -1,9 +1,5 @@ local venue = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - venue.triggers = { '/nil' } diff --git a/miku/plugins/vimeo.lua b/miku/plugins/vimeo.lua index 83789ac..c5668ad 100644 --- a/miku/plugins/vimeo.lua +++ b/miku/plugins/vimeo.lua @@ -1,9 +1,5 @@ local vimeo = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - vimeo.triggers = { "vimeo.com/(%d+)" } diff --git a/miku/plugins/vine.lua b/miku/plugins/vine.lua index 3cd83f0..baa8bba 100644 --- a/miku/plugins/vine.lua +++ b/miku/plugins/vine.lua @@ -1,9 +1,5 @@ local vine = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('miku.utilities') - vine.triggers = { "vine.co/v/([A-Za-z0-9-_-]+)" } diff --git a/miku/plugins/weather.lua b/miku/plugins/weather.lua index ee5defc..d2dd48b 100644 --- a/miku/plugins/weather.lua +++ b/miku/plugins/weather.lua @@ -1,20 +1,13 @@ local weather = {} -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') -local redis = (loadfile "./miku/redis.lua")() - function weather:init(config) if not cred_data.forecastio_apikey then - print('Missing config value: forecastio_apikey.') - print('weather.lua will not be enabled.') + print('Fehlender Key: forecastio_apikey.') + print('weather.lua wird nicht aktiviert.') return elseif not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('weather.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('weather.lua wird nicht aktiviert.') return end @@ -40,9 +33,9 @@ function get_city_name(lat, lng) local city = redis:hget('telegram:cache:weather:pretty_names', lat..','..lng) if city then return city end local url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='..lat..','..lng..'&result_type=political&language=de&key='..google_apikey - local res, code = HTTPS.request(url) + local res, code = https.request(url) if code ~= 200 then return 'Unbekannte Stadt' end - local data = JSON.decode(res).results[1] + local data = json.decode(res).results[1] local city = data.formatted_address print('Setting '..lat..','..lng..' in redis hash telegram:cache:weather:pretty_names to "'..city..'"') redis:hset('telegram:cache:weather:pretty_names', lat..','..lng, city) @@ -62,9 +55,9 @@ function weather:get_weather(lat, lng) method = "GET", sink = ltn12.sink.table(response_body) } - local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + local ok, response_code, response_headers, response_status_line = https.request(request_constructor) if not ok then return nil end - local data = JSON.decode(table.concat(response_body)) + local data = json.decode(table.concat(response_body)) local ttl = string.sub(response_headers["cache-control"], 9) diff --git a/miku/plugins/webshot.lua b/miku/plugins/webshot.lua index 337d480..8e2e07b 100644 --- a/miku/plugins/webshot.lua +++ b/miku/plugins/webshot.lua @@ -1,12 +1,5 @@ local webshot = {} -local helpers = require('OAuth.helpers') -local utilities = require('miku.utilities') -local https = require('ssl.https') -local ltn12 = require('ltn12') -local json = require('dkjson') -local bindings = require('miku.bindings') - local base = 'https://screenshotmachine.com/' local url = base .. 'processor.php' diff --git a/miku/plugins/wiimmfi.lua b/miku/plugins/wiimmfi.lua index 617a647..0e5c054 100644 --- a/miku/plugins/wiimmfi.lua +++ b/miku/plugins/wiimmfi.lua @@ -1,9 +1,5 @@ local wiimmfi = {} -local http = require('socket.http') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - function wiimmfi:init(config) wiimmfi.triggers = { "^/(mkw)$", diff --git a/miku/plugins/wikia.lua b/miku/plugins/wikia.lua index 2ce36af..71cf3d4 100644 --- a/miku/plugins/wikia.lua +++ b/miku/plugins/wikia.lua @@ -1,10 +1,5 @@ local wikia = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('miku.utilities') -local bindings = require('miku.bindings') - wikia.triggers = { "https?://(.+).wikia.com/wiki/(.+)" } diff --git a/miku/plugins/wikipedia.lua b/miku/plugins/wikipedia.lua index 6eae6c5..0174999 100644 --- a/miku/plugins/wikipedia.lua +++ b/miku/plugins/wikipedia.lua @@ -1,11 +1,5 @@ local wikipedia = {} -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local socket = require('socket') -local utilities = require('miku.utilities') - wikipedia.command = 'wiki ' function wikipedia:init(config) @@ -63,7 +57,7 @@ function wikipedia:getWikiServer(lang) end --[[ --- return decoded JSON table from Wikipedia +-- return decoded json table from Wikipedia --]] function wikipedia:loadPage(text, lang, intro, plain, is_search) local request, sink = {}, {} @@ -101,7 +95,7 @@ function wikipedia:loadPage(text, lang, intro, plain, is_search) local content = table.concat(sink) if content ~= "" then - local ok, result = pcall(JSON.decode, content) + local ok, result = pcall(json.decode, content) if ok and result then return result else @@ -174,7 +168,7 @@ function wikipedia:inline_callback(inline_query, config, matches) local url = 'https://'..lang..'.wikipedia.org/w/api.php?action=query&list=search&srsearch='..URL.escape(query)..'&format=json&prop=extracts&srprop=snippet' local res, code = https.request(url) if code ~= 200 then return end - local data = JSON.decode(res).query + local data = json.decode(res).query if data.searchinfo.totalhits == 0 then return end @@ -209,7 +203,7 @@ function wikipedia:action(msg, config, matches) lang = nil end if term == "" then - utilities.send_reply(msg, self, wikipedia.doc) + utilities.send_reply(self, msg, wikipedia.doc, true) return end diff --git a/miku/plugins/xkcd.lua b/miku/plugins/xkcd.lua index c310b7e..e3dc69c 100644 --- a/miku/plugins/xkcd.lua +++ b/miku/plugins/xkcd.lua @@ -1,9 +1,5 @@ local xkcd = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('miku.utilities') - xkcd.command = 'xkcd [i]' function xkcd:init(config) diff --git a/miku/plugins/yourls.lua b/miku/plugins/yourls.lua index 67f1358..2a805b6 100644 --- a/miku/plugins/yourls.lua +++ b/miku/plugins/yourls.lua @@ -1,17 +1,13 @@ local yourls = {} -local http = require('socket.http') -local https = require('ssl.https') -local utilities = require('miku.utilities') - function yourls:init(config) if not cred_data.yourls_site_url then - print('Missing config value: yourls_site_url.') - print('yourls.lua will not be enabled.') + print('Fehlender Key: yourls_site_url.') + print('yourls.lua wird nicht aktiviert.') return elseif not cred_data.yourls_signature_token then - print('Missing config value: yourls_signature_token.') - print('yourls.lua will not be enabled.') + print('Fehlender Key: yourls_signature_token.') + print('yourls.lua wird nicht aktiviert.') return end diff --git a/miku/plugins/youtube.lua b/miku/plugins/youtube.lua index 466e205..3122e8e 100644 --- a/miku/plugins/youtube.lua +++ b/miku/plugins/youtube.lua @@ -1,15 +1,9 @@ local youtube = {} -local utilities = require('miku.utilities') -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local bindings = require('miku.bindings') - function youtube:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('youtube.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('youtube.lua wird nicht aktiviert.') return end @@ -46,7 +40,7 @@ function get_yt_data (yt_code) local url = BASE_URL..'/videos?part=snippet,statistics,contentDetails&key='..apikey..'&id='..yt_code..'&fields=items(snippet(publishedAt,channelTitle,localized(title,description),thumbnails),statistics(viewCount,likeCount,dislikeCount,commentCount),contentDetails(duration,regionRestriction(blocked)))' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - local data = JSON.decode(res).items[1] + local data = json.decode(res).items[1] return data end @@ -162,7 +156,7 @@ function youtube:inline_callback(inline_query, config, matches) local res,code = https.request(url) if code ~= 200 then return end - local data = JSON.decode(res) + local data = json.decode(res) if not data.items[1] then return end local video_ids = "" @@ -179,7 +173,7 @@ function youtube:inline_callback(inline_query, config, matches) local res,code = https.request(url) if code ~= 200 then return end - local video_results = JSON.decode(res) + local video_results = json.decode(res) if not video_results.items[1] then return end local results = '[' diff --git a/miku/plugins/youtube_channel.lua b/miku/plugins/youtube_channel.lua index 0d6fcdc..b4b250a 100644 --- a/miku/plugins/youtube_channel.lua +++ b/miku/plugins/youtube_channel.lua @@ -1,13 +1,9 @@ local youtube_channel = {} -local utilities = require('miku.utilities') -local https = require('ssl.https') -local JSON = require('dkjson') - function youtube_channel:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('youtube_channel.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('youtube_channel.lua wird nicht aktiviert.') return end @@ -30,12 +26,12 @@ function youtube_channel:get_yt_channel_data(channel_name) local url = BASE_URL..'/channels?part=snippet,statistics&key='..apikey..'&forUsername='..channel_name..'&fields=items%28snippet%28publishedAt,localized%28title,description%29%29,statistics%28viewCount,subscriberCount,videoCount%29%29' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - local data = JSON.decode(res).items[1] + local data = json.decode(res).items[1] if data == nil then local url = BASE_URL..'/channels?part=snippet,statistics&key='..apikey..'&id='..channel_name..'&fields=items%28snippet%28publishedAt,localized%28title,description%29%29,statistics%28viewCount,subscriberCount,videoCount%29%29' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - return JSON.decode(res).items[1] + return json.decode(res).items[1] end return data end diff --git a/miku/plugins/youtube_dl.lua b/miku/plugins/youtube_dl.lua index 5b4e6a1..973d237 100644 --- a/miku/plugins/youtube_dl.lua +++ b/miku/plugins/youtube_dl.lua @@ -1,7 +1,7 @@ +-- Requires: sudo apt-get install youtube-dl +-- See https://github.com/rg3/youtube-dl/blob/master/README.md#options local youtube_dl = {} -local utilities = require('miku.utilities') - function youtube_dl:init(config) youtube_dl.triggers = { "^/(mp4) (https?://[%w-_%.%?%.:/%+=&]+)$", diff --git a/miku/plugins/youtube_playlist.lua b/miku/plugins/youtube_playlist.lua index 6a3e723..97ffdc6 100644 --- a/miku/plugins/youtube_playlist.lua +++ b/miku/plugins/youtube_playlist.lua @@ -1,13 +1,9 @@ local youtube_playlist = {} -local utilities = require('miku.utilities') -local https = require('ssl.https') -local JSON = require('dkjson') - function youtube_playlist:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('youtube_playlist.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('youtube_playlist.lua wird nicht aktiviert.') return end @@ -29,7 +25,7 @@ function youtube_playlist:get_pl_data (pl_code) local url = BASE_URL..'/playlists?part=snippet,contentDetails&key='..apikey..'&id='..pl_code..'&fields=items(snippet(publishedAt,channelTitle,localized(title,description)),contentDetails(itemCount))' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - local data = JSON.decode(res).items[1] + local data = json.decode(res).items[1] return data end diff --git a/miku/plugins/youtube_search.lua b/miku/plugins/youtube_search.lua index 4963163..c33c997 100644 --- a/miku/plugins/youtube_search.lua +++ b/miku/plugins/youtube_search.lua @@ -1,18 +1,13 @@ -require("./miku/plugins/youtube") - local yt_search = {} -local utilities = require('miku.utilities') -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') +require("./miku/plugins/youtube") yt_search.command = 'yt ' function yt_search:init(config) if not cred_data.google_apikey then - print('Missing config value: google_apikey.') - print('youtube_search.lua will not be enabled.') + print('Fehlender Key: google_apikey.') + print('youtube_search.lua wird nicht aktiviert.') return end @@ -40,7 +35,7 @@ end function httpsRequest(url) local res,code = https.request(url) if code ~= 200 then return nil end - return JSON.decode(res) + return json.decode(res) end function yt_search:action(msg) diff --git a/miku/utilities.lua b/miku/utilities.lua index fa7e8fb..7f58285 100644 --- a/miku/utilities.lua +++ b/miku/utilities.lua @@ -3,20 +3,21 @@ local utilities = {} -local HTTP = require('socket.http') -local ltn12 = require('ltn12') -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local http = require('socket.http') -local serpent = require("serpent") -local bindings = require('miku.bindings') -local redis = (loadfile "./miku/redis.lua")() -local mimetype = (loadfile "./miku/mimetype.lua")() -local OAuth = require "OAuth" -local helpers = require "OAuth.helpers" +ltn12 = require('ltn12') +http = require('socket.http') +https = require('ssl.https') +socket = require('socket') +URL = require('socket.url') +json = require('dkjson') +serpent = require("serpent") +bindings = require('miku.bindings') +redis = (loadfile "./miku/redis.lua")() +mimetype = (loadfile "./miku/mimetype.lua")() +OAuth = require "OAuth" +helpers = require "OAuth.helpers" -HTTP.timeout = 10 +http.timeout = 5 +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. @@ -301,10 +302,10 @@ function download_to_file(url, file_name) file_name = '/tmp/' .. file_name end local body = {} - local doer = HTTP + local doer = http local do_redir = true if url:match('^https') then - doer = HTTPS + doer = https do_redir = false end local _, res = doer.request{ @@ -324,7 +325,7 @@ function vardump(value) print(serpent.block(value, {comment=false})) end - -- Loads a JSON file as a table. + -- Loads a json file as a table. function utilities.load_data(filename) local f = io.open(filename) if not f then @@ -332,13 +333,13 @@ function utilities.load_data(filename) end local s = f:read('*all') f:close() - local data = JSON.decode(s) + local data = json.decode(s) return data end - -- Saves a table to a JSON file. + -- Saves a table to a json file. function utilities.save_data(filename, data) - local s = JSON.encode(data) + local s = json.encode(data) local f = io.open(filename, 'w') f:write(s) f:close() @@ -349,12 +350,12 @@ function utilities.get_coords(input, config) local url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' .. URL.escape(input) - local jstr, res = HTTPS.request(url) + local jstr, res = https.request(url) if res ~= 200 then return config.errors.connection end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if jdat.status == 'ZERO_RESULTS' then return config.errors.results end @@ -522,10 +523,10 @@ function utilities.triggers(username, cmd_pat, trigger_table) end function utilities.with_http_timeout(timeout, fun) - local original = HTTP.TIMEOUT - HTTP.TIMEOUT = timeout + local original = http.TIMEOUT + http.TIMEOUT = timeout fun() - HTTP.TIMEOUT = original + http.TIMEOUT = original end function utilities.enrich_user(user) @@ -661,14 +662,14 @@ function post_petition(url, arguments, headers) if post_prot == "http" then ok, response_code, response_headers, response_status_line = http.request(request_constructor) else - ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + ok, response_code, response_headers, response_status_line = https.request(request_constructor) end if not ok then return nil end - response_body = JSON.decode(table.concat(response_body)) + response_body = json.decode(table.concat(response_body)) return response_body, response_headers end @@ -778,10 +779,10 @@ function cache_file(result, url, last_modified) end function get_http_header(url) - local doer = HTTP + local doer = http local do_redir = true if url:match('^https') then - doer = HTTPS + doer = https do_redir = false end local _, code, header = doer.request {