Some little changes

This commit is contained in:
Akamaru 2015-04-17 16:29:30 +02:00
parent d71cac24cd
commit 85437c8dc0
5 changed files with 37 additions and 25 deletions

View File

@ -1,5 +1,5 @@
function run(msg, matches)
local function run(msg, matches)
return matches[1]
end

View File

@ -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 {

View File

@ -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 {

View File

@ -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
}

View File

@ -52,7 +52,7 @@ 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
@ -63,19 +63,19 @@ local function enable_plugin( plugin_name )
-- 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,7 +163,7 @@ end
return {
description = "",
usage = {""},
usage = { "" },
patterns = {
"^/plugins$",
"^/plugins? (enable) ([%w_%.%-]+)$",
@ -172,6 +173,5 @@ return {
"^/plugins? (reload)$" },
run = run,
privileged = true
}
end
}
end