X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fplugins.rb;h=b0626b9687181c8416e5d3e68e19ce0efaa439b4;hb=570d8535619cf3a9d20ca3d72e5176db2c4c8223;hp=f8eddd6ed65736c689f1a9ae92db35894757dd80;hpb=158056c6f68bbe75e4c9a33433e1502c445c26b8;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index f8eddd6e..b0626b96 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -2,7 +2,7 @@ require 'singleton' module Irc BotConfig.register BotConfigArrayValue.new('plugins.blacklist', - :default => [], :wizard => false, :requires_restart => true, + :default => [], :wizard => false, :requires_rescan => true, :desc => "Plugins that should not be loaded") module Plugins require 'rbot/messagemapper' @@ -266,7 +266,7 @@ module Plugins # Registers botmodule _botmodule_ with command _cmd_ and command path _auth_path_ def register(botmodule, cmd, auth_path) - raise TypeError, "First argument #{botmodule.inspect} is not of class BotModule" unless botmodule.class <= BotModule + raise TypeError, "First argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule) kl = botmodule.botmodule_class @commandmappers[kl.to_sym][cmd.to_sym] = {:botmodule => botmodule, :auth => auth_path} h = @commandmappers[kl.to_sym][cmd.to_sym] @@ -274,7 +274,7 @@ module Plugins end def add_botmodule(botmodule) - raise TypeError, "Argument #{botmodule.inspect} is not of class BotModule" unless botmodule.class <= BotModule + raise TypeError, "Argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule) kl = botmodule.botmodule_class raise "#{kl.to_s} #{botmodule.name} already registered!" if @botmodules[kl.to_sym].include?(botmodule) @botmodules[kl.to_sym] << botmodule @@ -504,25 +504,28 @@ module Plugins when /^(\S+)\s*(.*)$/ key = $1 params = $2 - (core_modules + plugins).each { |p| - # debug "checking #{p.name.inspect} against #{key.inspect}" + + # We test for the mapped commands first + k = key.to_sym + [core_commands, plugin_commands].each { |pl| + next unless pl.has_key?(k) + p = pl[k][:botmodule] begin - return p.help(params) + return p.help(key, params) rescue Exception => err #rescue TimeoutError, StandardError, NameError, SyntaxError => err error report_error("#{p.botmodule_class} #{p.name} help() failed:", err) - end if p.name == key + end } - [core_commands, plugin_commands].each { |pl| - # debug "looking for #{key.inspect} in #{pl.keys.sort.inspect}" - if pl.has_key?(key) - p = pl[key][:botmodule] - begin - return p.help(key, params) - rescue Exception => err - #rescue TimeoutError, StandardError, NameError, SyntaxError => err - error report_error("#{p.botmodule_class} #{p.name} help() failed:", err) - end + + # If no such commmand was found, we look for a botmodule with that name + (core_modules + plugins).each { |p| + next unless p.name == key + begin + return p.help(key, params) + rescue Exception => err + #rescue TimeoutError, StandardError, NameError, SyntaxError => err + error report_error("#{p.botmodule_class} #{p.name} help() failed:", err) end } end @@ -540,8 +543,9 @@ module Plugins # debug "#{p.botmodule_class} #{p.name} responds" p.send method, *args rescue Exception => err + raise if err.kind_of?(SystemExit) error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err) - raise if err.class <= BDB::Fatal + raise if err.kind_of?(BDB::Fatal) end end } @@ -554,49 +558,46 @@ module Plugins def privmsg(m) # debug "Delegating privmsg #{m.message.inspect} from #{m.source} to #{m.replyto} with pluginkey #{m.plugin.inspect}" return unless m.plugin - begin - [core_commands, plugin_commands].each { |pl| - # We do it this way to skip creating spurious keys - # FIXME use fetch? - k = m.plugin.to_sym - if pl.has_key?(k) - p = pl[k][:botmodule] - a = pl[k][:auth] - else - p = nil - a = nil - end - if p - # We check here for things that don't check themselves - # (e.g. mapped things) - # debug "Checking auth ..." - if a.nil? || @bot.auth.allow?(a, m.source, m.replyto) - # debug "Checking response ..." - if p.respond_to?("privmsg") - begin - # debug "#{p.botmodule_class} #{p.name} responds" - p.privmsg(m) - rescue Exception => err - error report_error("#{p.botmodule_class} #{p.name} privmsg() failed:", err) - raise if err.class <= BDB::Fatal - end - # debug "Successfully delegated #{m.message}" - return true - else - # debug "#{p.botmodule_class} #{p.name} is registered, but it doesn't respond to privmsg()" + [core_commands, plugin_commands].each { |pl| + # We do it this way to skip creating spurious keys + # FIXME use fetch? + k = m.plugin.to_sym + if pl.has_key?(k) + p = pl[k][:botmodule] + a = pl[k][:auth] + else + p = nil + a = nil + end + if p + # We check here for things that don't check themselves + # (e.g. mapped things) + # debug "Checking auth ..." + if a.nil? || @bot.auth.allow?(a, m.source, m.replyto) + # debug "Checking response ..." + if p.respond_to?("privmsg") + begin + # debug "#{p.botmodule_class} #{p.name} responds" + p.privmsg(m) + rescue Exception => err + raise if err.kind_of?(SystemExit) + error report_error("#{p.botmodule_class} #{p.name} privmsg() failed:", err) + raise if err.kind_of?(BDB::Fatal) end + # debug "Successfully delegated #{m.message}" + return true else - # debug "#{p.botmodule_class} #{p.name} is registered, but #{m.source} isn't allowed to call #{m.plugin.inspect} on #{m.replyto}" + # debug "#{p.botmodule_class} #{p.name} is registered, but it doesn't respond to privmsg()" end else - # debug "No #{pl.values.first[:botmodule].botmodule_class} registered #{m.plugin.inspect}" unless pl.empty? + # debug "#{p.botmodule_class} #{p.name} is registered, but #{m.source} isn't allowed to call #{m.plugin.inspect} on #{m.replyto}" end - # debug "Finished delegating privmsg with key #{m.plugin.inspect}" + ( pl.empty? ? "" : " to #{pl.values.first[:botmodule].botmodule_class}s" ) - } - return false - rescue Exception => e - error report_error("couldn't delegate #{m.message.inspect}", e) - end + else + # debug "No #{pl.values.first[:botmodule].botmodule_class} registered #{m.plugin.inspect}" unless pl.empty? + end + # debug "Finished delegating privmsg with key #{m.plugin.inspect}" + ( pl.empty? ? "" : " to #{pl.values.first[:botmodule].botmodule_class}s" ) + } + return false # debug "Finished delegating privmsg with key #{m.plugin.inspect}" end end