From 85437c8dc0f6b5bf8b13790ce51f59a74b51fafd Mon Sep 17 00:00:00 2001 From: Akamaru Date: Fri, 17 Apr 2015 16:29:30 +0200 Subject: [PATCH] Some little changes --- plugins/echo.lua | 2 +- plugins/giphy.lua | 25 ++++++++++++++++++------- plugins/img_google.lua | 4 ++-- plugins/img_google_nsfw.lua | 5 +++-- plugins/plugins.lua | 26 +++++++++++++------------- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/plugins/echo.lua b/plugins/echo.lua index aa4c740..9fb678b 100644 --- a/plugins/echo.lua +++ b/plugins/echo.lua @@ -1,5 +1,5 @@ -function run(msg, matches) +local function run(msg, matches) return matches[1] end diff --git a/plugins/giphy.lua b/plugins/giphy.lua index 9cc9fc0..f5ddc3a 100644 --- a/plugins/giphy.lua +++ b/plugins/giphy.lua @@ -6,7 +6,7 @@ do local BASE_URL = 'http://api.giphy.com/v1' local API_KEY = 'dc6zaTOxFJmzC' -- public beta key -function get_image(response) +local function get_image(response) local images = json:decode(response).data if #images == 0 then return nil end -- No images local i = math.random(#images) @@ -23,14 +23,14 @@ function get_image(response) return nil end -function get_random_top() +local function get_random_top() local url = BASE_URL.."/gifs/trending?api_key="..API_KEY local response, code = http.request(url) if code ~= 200 then return nil end return get_image(response) end -function search(text) +local function search(text) text = URL.escape(text) local url = BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY local response, code = http.request(url) @@ -38,11 +38,17 @@ function search(text) return get_image(response) end -function run(msg, matches) +local function send_gif(cb_extra, success, result) + local receiver = cb_extra.receiver + local gif_url = cb_extra.gif_url + send_document_from_url(receiver, gif_url) +end + +local function run(msg, matches) local gif_url = nil -- If no search data, a random trending GIF will be sended - if matches[1] == "!gif" or matches[1] == "!giphy" then + if matches[1] == "/gif" or matches[1] == "/giphy" then gif_url = get_random_top() else gif_url = search(matches[1]) @@ -53,8 +59,13 @@ function run(msg, matches) end local receiver = get_receiver(msg) - send_document_from_url(receiver, gif_url) - return "Einen Moment, GIF wird hochgeladen." + print("GIF URL"..gif_url) + local text = 'Einen Moment, GIF wird hochgeladen.' + local cb_extra = { + gif_url = gif_url, + receiver = receiver + } + send_msg(receiver, text, send_gif, cb_extra) end return { diff --git a/plugins/img_google.lua b/plugins/img_google.lua index 033e995..794475e 100644 --- a/plugins/img_google.lua +++ b/plugins/img_google.lua @@ -33,12 +33,12 @@ function run(msg, matches) local url = getGoogleImage(text) if not url then - return "Kein Bild gefunden. Versuch es nochmal" + return "Kein Bild gefunden." end print("Bilder-URL: ", url) send_photo_from_url(receiver, url) - return "Source:"..url + return "Source: "..url end return { diff --git a/plugins/img_google_nsfw.lua b/plugins/img_google_nsfw.lua index fe24665..54ce17c 100644 --- a/plugins/img_google_nsfw.lua +++ b/plugins/img_google_nsfw.lua @@ -32,7 +32,7 @@ function run(msg, matches) local url = getGoogleImage(text) if not url then - return "Kein Bild gefunden. Versuch es nochmal" + return "Kein Bild gefunden." end print("Bilder-URL: ", url) @@ -43,7 +43,8 @@ end return { description = "Sucht Bild mit Google-API und versendet es (SafeSearch aktiv)", usage = "/img2 [Suchbegriff]", - patterns = {"^/img2 (.*)$"}, + patterns = {"^/img2 (.*)$", + "^/nsfwimg (.*)$"}, run = run } diff --git a/plugins/plugins.lua b/plugins/plugins.lua index 66d3b07..5f042c2 100644 --- a/plugins/plugins.lua +++ b/plugins/plugins.lua @@ -52,30 +52,30 @@ local function enable_plugin( plugin_name ) print('checking if '..plugin_name..' exists') -- Check if plugin is enabled if plugin_enabled(plugin_name) then - return 'Plugin '..plugin_name..' ist aktiviert!' + return 'Plugin "'..plugin_name..'" ist aktiviert!' end -- Checks if plugin exists if plugin_exists(plugin_name) then -- Add to the config table table.insert(_config.enabled_plugins, plugin_name) - print(plugin_name..' added to _config table') + print(plugin_name..' added to _config table') save_config() -- Reload the plugins return reload_plugins( ) else - return 'Das Plugin '..plugin_name..' exestiert nicht!' + return 'Das Plugin "'..plugin_name..'" exestiert nicht!' end end local function disable_plugin( name, chat ) -- Check if plugins exists if not plugin_exists(name) then - return 'Das Plugin '..name..' exestiert nicht!' + return 'Das Plugin "'..plugin_name..'" exestiert nicht!' end local k = plugin_enabled(name) -- Check if plugin is enabled if not k then - return 'Das Plugin '..name..' ist nicht aktiviert!' + return 'Das Plugin "'..name..'" ist nicht aktiviert!' end -- Disable and reload table.remove(_config.enabled_plugins, k) @@ -85,7 +85,7 @@ end local function disable_plugin_on_chat(receiver, plugin) if not plugin_exists(plugin) then - return "Das Plugin exestiert nicht!" + return "Dieses Plugin exestiert nicht!" end if not _config.disabled_plugin_on_chat then @@ -99,7 +99,7 @@ local function disable_plugin_on_chat(receiver, plugin) _config.disabled_plugin_on_chat[receiver][plugin] = true save_config() - return 'Das Plugin '..plugin..' ist hier nun deaktiviert!' + return 'Das Plugin "'..plugin..'" ist hier nun deaktiviert!' end local function reenable_plugin_on_chat(receiver, plugin) @@ -117,7 +117,7 @@ local function reenable_plugin_on_chat(receiver, plugin) _config.disabled_plugin_on_chat[receiver][plugin] = false save_config() - return 'Das Plugin '..plugin..' ist wieder aktiviert!' + return 'Das Plugin "'..plugin..'" ist wieder aktiviert!' end local function run(msg, matches) @@ -136,6 +136,7 @@ local function run(msg, matches) -- Enable a plugin if matches[1] == 'enable' then + local plugin_name = matches[2] print("enable: "..matches[2]) return enable_plugin(plugin_name) end @@ -162,16 +163,15 @@ end return { description = "", - usage = {""}, + usage = { "" }, patterns = { "^/plugins$", "^/plugins? (enable) ([%w_%.%-]+)$", "^/plugins? (disable) ([%w_%.%-]+)$", "^/plugins? (enable) ([%w_%.%-]+) (chat)", "^/plugins? (disable) ([%w_%.%-]+) (chat)", - "^/plugins? (reload)$" }, + "^/plugins? (reload)$" }, run = run, privileged = true -} - -end \ No newline at end of file + } + end \ No newline at end of file