]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/plugins.rb
Merge pull request #4 from ahpook/rename_karma
[user/henk/code/ruby/rbot.git] / lib / rbot / plugins.rb
index 3ec52fd99b6463e564ff27e60507d57283aecdb1..8621fe45341456e485894a4768c8d8c298ae8257 100644 (file)
@@ -4,6 +4,7 @@
 # :title: rbot plugin management
 
 require 'singleton'
+require_relative './core/utils/where_is.rb'
 
 module Irc
 class Bot
@@ -37,36 +38,36 @@ module Plugins
 
      Examples:
 
-       plugin.map 'karmastats', :action => 'karma_stats'
+       plugin.map 'pointstats', :action => 'point_stats'
 
        # while in the plugin...
-       def karma_stats(m, params)
+       def point_stats(m, params)
          m.reply "..."
        end
 
        # the default action is the first component
-       plugin.map 'karma'
+       plugin.map 'points'
 
        # attributes can be pulled out of the match string
-       plugin.map 'karma for :key'
-       plugin.map 'karma :key'
+       plugin.map 'points for :key'
+       plugin.map 'points :key'
 
        # while in the plugin...
-       def karma(m, params)
+       def points(m, params)
          item = params[:key]
-         m.reply 'karma for #{item}'
+         m.reply 'points for #{item}'
        end
 
        # you can setup defaults, to make parameters optional
-       plugin.map 'karma :key', :defaults => {:key => 'defaultvalue'}
+       plugin.map 'points :key', :defaults => {:key => 'defaultvalue'}
 
        # the default auth check is also against the first component
        # but that can be changed
-       plugin.map 'karmastats', :auth => 'karma'
+       plugin.map 'pointstats', :auth => 'points'
 
        # maps can be restricted to public or private message:
-       plugin.map 'karmastats', :private => false
-       plugin.map 'karmastats', :public => false
+       plugin.map 'pointstats', :private => false
+       plugin.map 'pointstats', :public => false
 
      See MessageMapper#map for more information on the template format and the
      allowed options.
@@ -409,6 +410,9 @@ module Plugins
     attr_reader :botmodules
     attr_reader :maps
 
+    attr_reader :core_module_dirs
+    attr_reader :plugin_dirs
+
     # This is the list of patterns commonly delegated to plugins.
     # A fast delegation lookup is enabled for them.
     DEFAULT_DELEGATE_PATTERNS = %r{^(?:
@@ -603,17 +607,6 @@ module Plugins
         debug "loading #{desc}#{fname}"
         plugin_module.module_eval(plugin_string, fname)
 
-        # this sets a BOTMODULE_FNAME constant in all BotModule
-        # classes defined in the module. This allows us to know
-        # the filename the plugin was declared in from outside
-        # the plugin itself (from within, a __FILE__ would work.)
-        plugin_module.constants.each do |const|
-          cls = plugin_module.const_get(const)
-          if cls.is_a? Class and cls < BotModule
-            cls.const_set("BOTMODULE_FNAME", fname)
-          end
-        end
-
         return :loaded
       rescue Exception => err
         # rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err
@@ -767,7 +760,7 @@ module Plugins
     def save(botmodule=nil)
       if botmodule
         botmodule.flush_registry
-        botmodule.save          
+        botmodule.save if botmodule.respond_to? 'save'
       else
         delegate 'flush_registry'
         delegate 'save'
@@ -800,7 +793,7 @@ module Plugins
       if botmodule
         @failed.clear
         @ignored.clear
-        filename = botmodule.class::BOTMODULE_FNAME
+        filename = where_is(botmodule.class)
         err = load_botmodule_file(filename, "plugin")
         if err.is_a? Exception
           @failed << { :name => botmodule.to_s,