]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/plugins.rb
Utils: when looking for the first par in a web page, look after any header, not just...
[user/henk/code/ruby/rbot.git] / lib / rbot / plugins.rb
index 66a7d84294778572ef7f3f2a53462cef379a279a..7b476da93a5819bdbfb359a5e9c73a8d99aa8a77 100644 (file)
@@ -61,11 +61,14 @@ module Plugins
                          etc.
 
   privmsg(PrivMessage)::
                          etc.
 
   privmsg(PrivMessage)::
-                         called for a PRIVMSG if the first word matches one
+                         Called for a PRIVMSG if the first word matches one
                          the plugin register()d for. Use m.plugin to get
                          that word and m.params for the rest of the message,
                          if applicable.
 
                          the plugin register()d for. Use m.plugin to get
                          that word and m.params for the rest of the message,
                          if applicable.
 
+  unreplied(PrivMessage)::
+                         Called for a PRIVMSG which has not been replied to.
+
   kick(KickMessage)::
                          Called when a user (or the bot) is kicked from a
                          channel the bot is in.
   kick(KickMessage)::
                          Called when a user (or the bot) is kicked from a
                          channel the bot is in.
@@ -106,7 +109,7 @@ module Plugins
     # initialise your bot module. Always call super if you override this method,
     # as important variables are set up for you
     def initialize
     # initialise your bot module. Always call super if you override this method,
     # as important variables are set up for you
     def initialize
-      @manager = Plugins::pluginmanager
+      @manager = Plugins::manager
       @bot = @manager.bot
 
       @botmodule_triggers = Array.new
       @bot = @manager.bot
 
       @botmodule_triggers = Array.new
@@ -252,19 +255,29 @@ module Plugins
     attr_reader :botmodules
 
     def initialize
     attr_reader :botmodules
 
     def initialize
-      bot_associate(nil)
-
-      @dirs = []
-    end
-
-    # Reset lists of botmodules
-    def reset_botmodule_lists
       @botmodules = {
         :CoreBotModule => [],
         :Plugin => []
       }
       @botmodules = {
         :CoreBotModule => [],
         :Plugin => []
       }
+
       @names_hash = Hash.new
       @commandmappers = Hash.new
       @names_hash = Hash.new
       @commandmappers = Hash.new
+
+      @dirs = []
+
+      @failed = Array.new
+      @ignored = Array.new
+
+      bot_associate(nil)
+    end
+
+    # Reset lists of botmodules
+    def reset_botmodule_lists
+      @botmodules[:CoreBotModule].clear
+      @botmodules[:Plugin].clear
+      @names_hash.clear
+      @commandmappers.clear
+      @failures_shown = false
     end
 
     # Associate with bot _bot_
     end
 
     # Associate with bot _bot_
@@ -378,10 +391,15 @@ module Plugins
       debug "Botmodule loading path: #{@dirs.join(', ')}"
     end
 
       debug "Botmodule loading path: #{@dirs.join(', ')}"
     end
 
+    def clear_botmodule_dirs
+      @dirs.clear
+      debug "Botmodule loading path cleared"
+    end
+
     # load plugins from pre-assigned list of directories
     def scan
     # load plugins from pre-assigned list of directories
     def scan
-      @failed = Array.new
-      @ignored = Array.new
+      @failed.clear
+      @ignored.clear
       processed = Hash.new
 
       @bot.config['plugins.blacklist'].each { |p|
       processed = Hash.new
 
       @bot.config['plugins.blacklist'].each { |p|
@@ -472,12 +490,12 @@ module Plugins
         list << "no plugins active"
       end
       # Ignored plugins next
         list << "no plugins active"
       end
       # Ignored plugins next
-      unless @ignored.empty?
+      unless @ignored.empty? or @failures_shown
         list << "; #{Underline}#{@ignored.length} plugin#{'s' if @ignored.length > 1} ignored#{Underline}"
         list << ": use #{Bold}help ignored plugins#{Bold} to see why" unless short
       end
       # Failed plugins next
         list << "; #{Underline}#{@ignored.length} plugin#{'s' if @ignored.length > 1} ignored#{Underline}"
         list << ": use #{Bold}help ignored plugins#{Bold} to see why" unless short
       end
       # Failed plugins next
-      unless @failed.empty?
+      unless @failed.empty? or @failures_shown
         list << "; #{Reverse}#{@failed.length} plugin#{'s' if @failed.length > 1} failed to load#{Reverse}"
         list << ": use #{Bold}help failed plugins#{Bold} to see why" unless short
       end
         list << "; #{Reverse}#{@failed.length} plugin#{'s' if @failed.length > 1} failed to load#{Reverse}"
         list << ": use #{Bold}help failed plugins#{Bold} to see why" unless short
       end
@@ -486,7 +504,9 @@ module Plugins
 
     # return list of help topics (plugin names)
     def helptopics
 
     # return list of help topics (plugin names)
     def helptopics
-      return status
+      rv = status
+      @failures_shown = true
+      rv
     end
 
     def length
     end
 
     def length
@@ -511,15 +531,19 @@ module Plugins
         }.join("\n")
       when /ignored?\s*plugins?/
         return "no plugins were ignored" if @ignored.empty?
         }.join("\n")
       when /ignored?\s*plugins?/
         return "no plugins were ignored" if @ignored.empty?
-        return @ignored.inject(Array.new) { |list, p|
-          case p[:reason]
-          when :loaded
-            list << "#{p[:name]} in #{p[:dir]} (overruled by previous)"
-          else
-            list << "#{p[:name]} in #{p[:dir]} (#{p[:reason].to_s})"
-          end
-          list
-        }.join(", ")
+
+        tmp = Hash.new
+        @ignored.each do |p|
+          reason = p[:loaded] ? 'overruled by previous' : p[:reason].to_s
+          ((tmp[p[:dir]] ||= Hash.new)[reason] ||= Array.new).push(p[:name])
+        end
+
+        return tmp.map do |dir, reasons|
+          s = reasons.map { |r, list|
+            list.map { |_| _.sub(/\.rb$/, '') }.join(', ') + " (#{r})"
+          }.join('; ')
+          "in #{dir}: #{s}"
+        end.join('; ')
       when /^(\S+)\s*(.*)$/
         key = $1
         params = $2
       when /^(\S+)\s*(.*)$/
         key = $1
         params = $2
@@ -610,7 +634,7 @@ module Plugins
   end
 
   # Returns the only PluginManagerClass instance
   end
 
   # Returns the only PluginManagerClass instance
-  def Plugins.pluginmanager
+  def Plugins.manager
     return PluginManagerClass.instance
   end
 
     return PluginManagerClass.instance
   end