]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/plugins.rb
Fix small typo in basics core botmodule
[user/henk/code/ruby/rbot.git] / lib / rbot / plugins.rb
index 43793e99760fe95f0d5790cc42b163fd966857e4..b0626b9687181c8416e5d3e68e19ce0efaa439b4 100644 (file)
@@ -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
@@ -417,9 +417,7 @@ module Plugins
 
     # call the cleanup method for each active plugin
     def cleanup
-      @bot.save_mutex.synchronize do
-        delegate 'cleanup'
-      end
+      delegate 'cleanup'
       reset_botmodule_lists
     end
 
@@ -506,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
@@ -542,9 +543,9 @@ module Plugins
               # debug "#{p.botmodule_class} #{p.name} responds"
               p.send method, *args
             rescue Exception => err
-              raise if err.class <= SystemExit
+              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
         }
@@ -579,9 +580,9 @@ module Plugins
                 # debug "#{p.botmodule_class} #{p.name} responds"
                 p.privmsg(m)
               rescue Exception => err
-                raise if err.class <= SystemExit
+                raise if err.kind_of?(SystemExit)
                 error report_error("#{p.botmodule_class} #{p.name} privmsg() failed:", err)
-                raise if err.class <= BDB::Fatal
+                raise if err.kind_of?(BDB::Fatal)
               end
               # debug "Successfully delegated #{m.message}"
               return true