From 281d01859be6f73f2d330349a11fb49cd5f558a4 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Thu, 14 May 2015 21:37:51 +0200 Subject: [PATCH] merge upstream LoWeR cAsE Show red error if loading plugin fails --- bot/bot.lua | 14 +++++++++++--- bot/utils.lua | 15 ++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 04f6094..1fcca23 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -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 diff --git a/bot/utils.lua b/bot/utils.lua index b0a4cb2..16eec86 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -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