Some little changes
This commit is contained in:
		| @@ -1,5 +1,5 @@ | |||||||
|  |  | ||||||
| function run(msg, matches) | local function run(msg, matches) | ||||||
|   return matches[1] |   return matches[1] | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ do | |||||||
| local BASE_URL = 'http://api.giphy.com/v1' | local BASE_URL = 'http://api.giphy.com/v1' | ||||||
| local API_KEY = 'dc6zaTOxFJmzC' -- public beta key | local API_KEY = 'dc6zaTOxFJmzC' -- public beta key | ||||||
|  |  | ||||||
| function get_image(response) | local function get_image(response) | ||||||
|   local images = json:decode(response).data |   local images = json:decode(response).data | ||||||
|   if #images == 0 then return nil end -- No images |   if #images == 0 then return nil end -- No images | ||||||
|   local i = math.random(#images) |   local i = math.random(#images) | ||||||
| @@ -23,14 +23,14 @@ function get_image(response) | |||||||
|   return nil |   return nil | ||||||
| end | end | ||||||
|  |  | ||||||
| function get_random_top() | local function get_random_top() | ||||||
|   local url = BASE_URL.."/gifs/trending?api_key="..API_KEY |   local url = BASE_URL.."/gifs/trending?api_key="..API_KEY | ||||||
|   local response, code = http.request(url) |   local response, code = http.request(url) | ||||||
|   if code ~= 200 then return nil end |   if code ~= 200 then return nil end | ||||||
|   return get_image(response) |   return get_image(response) | ||||||
| end | end | ||||||
|  |  | ||||||
| function search(text) | local function search(text) | ||||||
|   text = URL.escape(text) |   text = URL.escape(text) | ||||||
|   local url = BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY |   local url = BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY | ||||||
|   local response, code = http.request(url) |   local response, code = http.request(url) | ||||||
| @@ -38,11 +38,17 @@ function search(text) | |||||||
|   return get_image(response) |   return get_image(response) | ||||||
| end | 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 |   local gif_url = nil | ||||||
|    |    | ||||||
|   -- If no search data, a random trending GIF will be sended |   -- 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() |     gif_url = get_random_top() | ||||||
|   else |   else | ||||||
|     gif_url = search(matches[1]) |     gif_url = search(matches[1]) | ||||||
| @@ -53,8 +59,13 @@ function run(msg, matches) | |||||||
|   end |   end | ||||||
|  |  | ||||||
|   local receiver = get_receiver(msg) |   local receiver = get_receiver(msg) | ||||||
|   send_document_from_url(receiver, gif_url) |   print("GIF URL"..gif_url) | ||||||
|   return "Einen Moment, GIF wird hochgeladen." |   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 | end | ||||||
|  |  | ||||||
| return { | return { | ||||||
|   | |||||||
| @@ -33,12 +33,12 @@ function run(msg, matches) | |||||||
|   local url = getGoogleImage(text) |   local url = getGoogleImage(text) | ||||||
|    |    | ||||||
|   if not url then |   if not url then | ||||||
|     return "Kein Bild gefunden. Versuch es nochmal" |     return "Kein Bild gefunden." | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   print("Bilder-URL: ", url) |   print("Bilder-URL: ", url) | ||||||
|     send_photo_from_url(receiver, url) |     send_photo_from_url(receiver, url) | ||||||
|     return "Source:"..url |     return "Source: "..url | ||||||
| end | end | ||||||
|  |  | ||||||
| return { | return { | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ function run(msg, matches) | |||||||
|   local url = getGoogleImage(text) |   local url = getGoogleImage(text) | ||||||
|    |    | ||||||
|   if not url then |   if not url then | ||||||
|     return "Kein Bild gefunden. Versuch es nochmal" |     return "Kein Bild gefunden." | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   print("Bilder-URL: ", url) |   print("Bilder-URL: ", url) | ||||||
| @@ -43,7 +43,8 @@ end | |||||||
| return { | return { | ||||||
|     description = "Sucht Bild mit Google-API und versendet es (SafeSearch aktiv)",  |     description = "Sucht Bild mit Google-API und versendet es (SafeSearch aktiv)",  | ||||||
|     usage = "/img2 [Suchbegriff]", |     usage = "/img2 [Suchbegriff]", | ||||||
|     patterns = {"^/img2 (.*)$"},  |     patterns = {"^/img2 (.*)$", | ||||||
|  | 				"^/nsfwimg (.*)$"},  | ||||||
|     run = run  |     run = run  | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -52,30 +52,30 @@ local function enable_plugin( plugin_name ) | |||||||
|   print('checking if '..plugin_name..' exists') |   print('checking if '..plugin_name..' exists') | ||||||
|   -- Check if plugin is enabled |   -- Check if plugin is enabled | ||||||
|   if plugin_enabled(plugin_name) then |   if plugin_enabled(plugin_name) then | ||||||
|     return 'Plugin '..plugin_name..' ist aktiviert!' |     return 'Plugin "'..plugin_name..'" ist aktiviert!' | ||||||
|   end |   end | ||||||
|   -- Checks if plugin exists |   -- Checks if plugin exists | ||||||
|   if plugin_exists(plugin_name) then |   if plugin_exists(plugin_name) then | ||||||
|     -- Add to the config table |     -- Add to the config table | ||||||
|     table.insert(_config.enabled_plugins, plugin_name) |     table.insert(_config.enabled_plugins, plugin_name) | ||||||
| 	print(plugin_name..' added to _config table') |     print(plugin_name..' added to _config table') | ||||||
|     save_config() |     save_config() | ||||||
|     -- Reload the plugins |     -- Reload the plugins | ||||||
|     return reload_plugins( ) |     return reload_plugins( ) | ||||||
|   else |   else | ||||||
|     return 'Das Plugin '..plugin_name..' exestiert nicht!' |     return 'Das Plugin "'..plugin_name..'" exestiert nicht!' | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| local function disable_plugin( name, chat ) | local function disable_plugin( name, chat ) | ||||||
|   -- Check if plugins exists |   -- Check if plugins exists | ||||||
|   if not plugin_exists(name) then |   if not plugin_exists(name) then | ||||||
|     return 'Das Plugin '..name..' exestiert nicht!' |     return 'Das Plugin "'..plugin_name..'" exestiert nicht!' | ||||||
|   end |   end | ||||||
|   local k = plugin_enabled(name) |   local k = plugin_enabled(name) | ||||||
|   -- Check if plugin is enabled |   -- Check if plugin is enabled | ||||||
|   if not k then |   if not k then | ||||||
|     return 'Das Plugin '..name..' ist nicht aktiviert!' |     return 'Das Plugin "'..name..'" ist nicht aktiviert!' | ||||||
|   end |   end | ||||||
|   -- Disable and reload |   -- Disable and reload | ||||||
|   table.remove(_config.enabled_plugins, k) |   table.remove(_config.enabled_plugins, k) | ||||||
| @@ -85,7 +85,7 @@ end | |||||||
|  |  | ||||||
| local function disable_plugin_on_chat(receiver, plugin) | local function disable_plugin_on_chat(receiver, plugin) | ||||||
|   if not plugin_exists(plugin) then |   if not plugin_exists(plugin) then | ||||||
|     return "Das Plugin exestiert nicht!" |     return "Dieses Plugin exestiert nicht!" | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   if not _config.disabled_plugin_on_chat then |   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 |   _config.disabled_plugin_on_chat[receiver][plugin] = true | ||||||
|  |  | ||||||
|   save_config() |   save_config() | ||||||
|   return 'Das Plugin '..plugin..' ist hier nun deaktiviert!' |   return 'Das Plugin "'..plugin..'" ist hier nun deaktiviert!' | ||||||
| end | end | ||||||
|  |  | ||||||
| local function reenable_plugin_on_chat(receiver, plugin) | 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 |   _config.disabled_plugin_on_chat[receiver][plugin] = false | ||||||
|   save_config() |   save_config() | ||||||
|   return 'Das Plugin '..plugin..' ist wieder aktiviert!' |   return 'Das Plugin "'..plugin..'" ist wieder aktiviert!' | ||||||
| end | end | ||||||
|  |  | ||||||
| local function run(msg, matches) | local function run(msg, matches) | ||||||
| @@ -136,6 +136,7 @@ local function run(msg, matches) | |||||||
|  |  | ||||||
|   -- Enable a plugin |   -- Enable a plugin | ||||||
|   if matches[1] == 'enable' then |   if matches[1] == 'enable' then | ||||||
|  |     local plugin_name = matches[2] | ||||||
|     print("enable: "..matches[2]) |     print("enable: "..matches[2]) | ||||||
|     return enable_plugin(plugin_name) |     return enable_plugin(plugin_name) | ||||||
|   end |   end | ||||||
| @@ -162,16 +163,15 @@ end | |||||||
|  |  | ||||||
| return { | return { | ||||||
|   description = "",  |   description = "",  | ||||||
|   usage = {""}, |   usage = { "" }, | ||||||
|   patterns = { |   patterns = { | ||||||
|     "^/plugins$", |     "^/plugins$", | ||||||
|     "^/plugins? (enable) ([%w_%.%-]+)$", |     "^/plugins? (enable) ([%w_%.%-]+)$", | ||||||
|     "^/plugins? (disable) ([%w_%.%-]+)$", |     "^/plugins? (disable) ([%w_%.%-]+)$", | ||||||
|     "^/plugins? (enable) ([%w_%.%-]+) (chat)", |     "^/plugins? (enable) ([%w_%.%-]+) (chat)", | ||||||
|     "^/plugins? (disable) ([%w_%.%-]+) (chat)", |     "^/plugins? (disable) ([%w_%.%-]+) (chat)", | ||||||
|     "^/plugins? (reload)$" },  |     "^/plugins? (reload)$" }, | ||||||
|   run = run, |   run = run, | ||||||
|   privileged = true |   privileged = true | ||||||
| } |   } | ||||||
|  |   end | ||||||
| end |  | ||||||
		Reference in New Issue
	
	Block a user