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