merge upstream

LoWeR cAsE
Show red error if loading plugin fails
This commit is contained in:
Akamaru 2015-05-14 21:37:51 +02:00
parent 38268496e0
commit 281d01859b
2 changed files with 21 additions and 8 deletions

View File

@ -112,7 +112,7 @@ function match_plugin(plugin, plugin_name, msg)
-- Go over patterns. If one matches is enough.
for k, pattern in pairs(plugin.patterns) do
local matches = match_pattern(pattern, msg.text)
local matches = match_pattern(pattern, msg.text, true)
if matches then
print("Nachricht stimmt überein mit ", pattern)
@ -249,8 +249,16 @@ end
function load_plugins()
for k, v in pairs(_config.enabled_plugins) do
print("Lade Plugin", v)
local t = loadfile("plugins/"..v..'.lua')()
plugins[v] = t
local ok, err = pcall(function()
local t = loadfile("plugins/"..v..'.lua')()
plugins[v] = t
end)
if not ok then
print('\27[31mFehler beim laden des Plugins '..v..'\27[39m')
print('\27[31m'..err..'\27[39m')
end
end
end

View File

@ -430,12 +430,17 @@ function send_large_msg_callback(cb_extra, success, result)
end
-- Returns a table with matches or nil
function match_pattern(pattern, text)
function match_pattern(pattern, text, lower_case)
if text then
local matches = { string.match(text, pattern) }
if next(matches) then
return matches
end
local matches = {}
if lower_case then
matches = { string.match(text:lower(), pattern) }
else
matches = { string.match(text, pattern) }
end
if next(matches) then
return matches
end
end
-- nil
end