]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Initial factorization of botconfig into kernel functionality and a coremodule
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 2 Aug 2006 20:37:02 +0000 (20:37 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 2 Aug 2006 20:37:02 +0000 (20:37 +0000)
lib/rbot/config.rb
lib/rbot/core/config.rb [new file with mode: 0644]
lib/rbot/core/core.rb
lib/rbot/ircbot.rb
lib/rbot/keywords.rb
lib/rbot/plugins.rb

index f91cfa70914fc3f74ee1a967fde990b224272da5..e8cea284ab136d80cb06b763fa884a3ad00b56e4 100644 (file)
@@ -1,7 +1,8 @@
+require 'singleton'
+
 module Irc
 
   require 'yaml'
-  require 'rbot/messagemapper'
 
   unless YAML.respond_to?(:load_file)
       def YAML.load_file( filepath )
@@ -21,8 +22,11 @@ module Irc
     attr_reader :key
     attr_reader :wizard
     attr_reader :requires_restart
+    attr_reader :requires_rescan
     attr_reader :order
+    attr_reader :manager
     def initialize(key, params)
+      @manager = BotConfig::configmanager
       # Keys must be in the form 'module.name'.
       # They will be internally passed around as symbols,
       # but we accept them both in string and symbol form.
@@ -31,7 +35,7 @@ module Irc
       end
       @order = @@order
       @@order += 1
-      @key = key.intern
+      @key = key.to_sym
       if params.has_key? :default
         @default = params[:default]
       else
@@ -43,6 +47,7 @@ module Irc
       @validate = params[:validate]
       @wizard = params[:wizard]
       @requires_restart = params[:requires_restart]
+      @requires_rescan = params[:requires_rescan]
     end
     def default
       if @default.instance_of?(Proc)
@@ -52,16 +57,16 @@ module Irc
       end
     end
     def get
-      return BotConfig.config[@key] if BotConfig.config.has_key?(@key)
+      return @manager.config[@key] if @manager.config.has_key?(@key)
       return @default
     end
     alias :value :get
     def set(value, on_change = true)
-      BotConfig.config[@key] = value
-      @on_change.call(BotConfig.bot, value) if on_change && @on_change
+      @manager.config[@key] = value
+      @on_change.call(@manager.bot, value) if on_change && @on_change
     end
     def unset
-      BotConfig.config.delete(@key)
+      @manager.config.delete(@key)
     end
 
     # set string will raise ArgumentErrors on failed parse/validate
@@ -73,7 +78,7 @@ module Irc
         raise ArgumentError, "invalid value: #{string}"
       end
     end
-    
+
     # override this. the default will work for strings only
     def parse(string)
       string
@@ -99,6 +104,7 @@ module Irc
 
   class BotConfigStringValue < BotConfigValue
   end
+
   class BotConfigBooleanValue < BotConfigValue
     def parse(string)
       return true if string == "true"
@@ -106,18 +112,21 @@ module Irc
       raise ArgumentError, "#{string} does not match either 'true' or 'false'"
     end
   end
+
   class BotConfigIntegerValue < BotConfigValue
     def parse(string)
       raise ArgumentError, "not an integer: #{string}" unless string =~ /^-?\d+$/
       string.to_i
     end
   end
+
   class BotConfigFloatValue < BotConfigValue
     def parse(string)
       raise ArgumentError, "not a float #{string}" unless string =~ /^-?[\d.]+$/
       string.to_f
     end
   end
+
   class BotConfigArrayValue < BotConfigValue
     def parse(string)
       string.split(/,\s+/)
@@ -135,6 +144,7 @@ module Irc
       set(curval - [val])
     end
   end
+
   class BotConfigEnumValue < BotConfigValue
     def initialize(key, params)
       super
@@ -142,7 +152,7 @@ module Irc
     end
     def values
       if @values.instance_of?(Proc)
-        return @values.call(BotConfig.bot)
+        return @values.call(@manager.bot)
       else
         return @values
       end
@@ -159,26 +169,51 @@ module Irc
   end
 
   # container for bot configuration
-  class BotConfig
-    # Array of registered BotConfigValues for defaults, types and help
-    @@items = Hash.new
-    def BotConfig.items
-      @@items
+  class BotConfigManagerClass
+
+    include Singleton
+
+    attr_reader :bot
+    attr_reader :items
+    attr_reader :config
+
+    def initialize
+      bot_associate(nil,true)
     end
-    # Hash containing key => value pairs for lookup and serialisation
-    @@config = Hash.new(false)
-    def BotConfig.config
-      @@config
+
+    def reset_config
+      @items = Hash.new
+      @config = Hash.new(false)
     end
-    def BotConfig.bot
-      @@bot
+
+    # Associate with bot _bot_
+    def bot_associate(bot, reset=false)
+      reset_config if reset
+      @bot = bot
+      return unless @bot
+
+      if(File.exist?("#{@bot.botclass}/conf.yaml"))
+        begin
+          newconfig = YAML::load_file("#{@bot.botclass}/conf.yaml")
+          newconfig.each { |key, val|
+            @config[key.to_sym] = val
+          }
+          return
+        rescue
+          error "failed to read conf.yaml: #{$!}"
+        end
+      end
+      # if we got here, we need to run the first-run wizard
+      BotConfigWizard.new(@bot).run
+      # save newly created config
+      save
     end
-    
-    def BotConfig.register(item)
+
+    def register(item)
       unless item.kind_of?(BotConfigValue)
         raise ArgumentError,"item must be a BotConfigValue"
       end
-      @@items[item.key] = item
+      @items[item.key] = item
     end
 
     # currently we store values in a hash but this could be changed in the
@@ -186,17 +221,17 @@ module Irc
     # components that register their config keys and setup defaults are
     # supported via []
     def [](key)
-      return @@items[key].value if @@items.has_key?(key)
-      return @@items[key.intern].value if @@items.has_key?(key.intern)
+      # return @items[key].value if @items.has_key?(key)
+      return @items[key.to_sym].value if @items.has_key?(key.to_sym)
       # try to still support unregistered lookups
       # but warn about them
-      if @@config.has_key?(key)
-        warning "Unregistered lookup #{key.inspect}"
-        return @@config[key]
-      end
-      if @@config.has_key?(key.intern)
-        warning "Unregistered lookup #{key.intern.inspect}"
-        return @@config[key.intern]
+      #      if @config.has_key?(key)
+      #        warning "Unregistered lookup #{key.inspect}"
+      #        return @config[key]
+      #      end
+      if @config.has_key?(key.to_sym)
+        warning "Unregistered lookup #{key.to_sym.inspect}"
+        return @config[key.to_sym]
       end
       return false
     end
@@ -204,237 +239,54 @@ module Irc
     # TODO should I implement this via BotConfigValue or leave it direct?
     #    def []=(key, value)
     #    end
-    
+
     # pass everything else through to the hash
     def method_missing(method, *args, &block)
-      return @@config.send(method, *args, &block)
-    end
-
-    def handle_list(m, params)
-      modules = []
-      if params[:module]
-        @@items.each_key do |key|
-          mod, name = key.to_s.split('.')
-          next unless mod == params[:module]
-          modules.push key unless modules.include?(name)
-        end
-        if modules.empty?
-          m.reply "no such module #{params[:module]}"
-        else
-          m.reply modules.join(", ")
-        end
-      else
-        @@items.each_key do |key|
-          name = key.to_s.split('.').first
-          modules.push name unless modules.include?(name)
-        end
-        m.reply "modules: " + modules.join(", ")
-      end
-    end
-
-    def handle_get(m, params)
-      key = params[:key].to_s.intern
-      unless @@items.has_key?(key)
-        m.reply "no such config key #{key}"
-        return
-      end
-      value = @@items[key].to_s
-      m.reply "#{key}: #{value}"
-    end
-
-    def handle_desc(m, params)
-      key = params[:key].to_s.intern
-      unless @@items.has_key?(key)
-        m.reply "no such config key #{key}"
-      end
-      puts @@items[key].inspect
-      m.reply "#{key}: #{@@items[key].desc}"
-    end
-
-    def handle_unset(m, params)
-      key = params[:key].to_s.intern
-      unless @@items.has_key?(key)
-        m.reply "no such config key #{key}"
-      end
-      @@items[key].unset
-      handle_get(m, params)
-      m.reply "this config change will take effect on the next restart" if @@items[key].requires_restart
-    end
-
-    def handle_set(m, params)
-      key = params[:key].to_s.intern
-      value = params[:value].join(" ")
-      unless @@items.has_key?(key)
-        m.reply "no such config key #{key}"
-        return
-      end
-      begin
-        @@items[key].set_string(value)
-      rescue ArgumentError => e
-        m.reply "failed to set #{key}: #{e.message}"
-        return
-      end
-      if @@items[key].requires_restart
-        m.reply "this config change will take effect on the next restart"
-      else
-        m.okay
-      end
-    end
-
-    def handle_add(m, params)
-      key = params[:key].to_s.intern
-      value = params[:value]
-      unless @@items.has_key?(key)
-        m.reply "no such config key #{key}"
-        return
-      end
-      unless @@items[key].class <= BotConfigArrayValue
-        m.reply "config key #{key} is not an array"
-        return
-      end
-      begin
-        @@items[key].add(value)
-      rescue ArgumentError => e
-        m.reply "failed to add #{value} to #{key}: #{e.message}"
-        return
-      end
-      handle_get(m,{:key => key})
-      m.reply "this config change will take effect on the next restart" if @@items[key].requires_restart
-    end
-
-    def handle_rm(m, params)
-      key = params[:key].to_s.intern
-      value = params[:value]
-      unless @@items.has_key?(key)
-        m.reply "no such config key #{key}"
-        return
-      end
-      unless @@items[key].class <= BotConfigArrayValue
-        m.reply "config key #{key} is not an array"
-        return
-      end
-      begin
-        @@items[key].rm(value)
-      rescue ArgumentError => e
-        m.reply "failed to remove #{value} from #{key}: #{e.message}"
-        return
-      end
-      handle_get(m,{:key => key})
-      m.reply "this config change will take effect on the next restart" if @@items[key].requires_restart
-    end
-
-    def handle_help(m, params)
-      topic = params[:topic]
-      case topic
-      when false
-        m.reply "config module - bot configuration. usage: list, desc, get, set, unset, add, rm"
-      when "list"
-        m.reply "config list => list configuration modules, config list <module> => list configuration keys for module <module>"
-      when "get"
-        m.reply "config get <key> => get configuration value for key <key>"
-      when "unset"
-        m.reply "reset key <key> to the default"
-      when "set"
-        m.reply "config set <key> <value> => set configuration value for key <key> to <value>"
-      when "desc"
-        m.reply "config desc <key> => describe what key <key> configures"
-      when "add"
-        m.reply "config add <value> to <key> => add value <value> to key <key> if <key> is an array"
-      when "rm"
-        m.reply "config rm <value> from <key> => remove value <value> from key <key> if <key> is an array"
-      else
-        m.reply "no help for config #{topic}"
-      end
-    end
-    def usage(m,params)
-      m.reply "incorrect usage, try '#{@@bot.nick}: help config'"
-    end
-
-    # bot:: parent bot class
-    # create a new config hash from #{botclass}/conf.rbot
-    # TODO make this into a core module to guide a BotCOnfigManagerClass
-    # singleton instance from IRC
-    #
-    def initialize(bot)
-      @@bot = bot
-
-      # respond to config messages, to provide runtime configuration
-      # management
-      # messages will be:
-      #  get
-      #  set
-      #  unset
-      #  desc
-      #  and for arrays:
-      #    add
-      #    remove
-      @handler = MessageMapper.new(self)
-      @handler.map 'config', 'config list :module', :action => 'handle_list',
-                   :defaults => {:module => false}
-      @handler.map 'config', 'config get :key', :action => 'handle_get'
-      @handler.map 'config', 'config desc :key', :action => 'handle_desc'
-      @handler.map 'config', 'config describe :key', :action => 'handle_desc'
-      @handler.map 'config', 'config set :key *value', :action => 'handle_set'
-      @handler.map 'config', 'config add :value to :key', :action => 'handle_add'
-      @handler.map 'config', 'config rm :value from :key', :action => 'handle_rm'
-      @handler.map 'config', 'config del :value from :key', :action => 'handle_rm'
-      @handler.map 'config', 'config delete :value from :key', :action => 'handle_rm'
-      @handler.map 'config', 'config unset :key', :action => 'handle_unset'
-      @handler.map 'config', 'config reset :key', :action => 'handle_unset'
-      @handler.map 'config', 'config help :topic', :action => 'handle_help',
-                   :defaults => {:topic => false}
-      @handler.map 'config', 'help config :topic', :action => 'handle_help',
-                   :defaults => {:topic => false}
-      
-      if(File.exist?("#{@@bot.botclass}/conf.yaml"))
-        begin
-          newconfig = YAML::load_file("#{@@bot.botclass}/conf.yaml")
-          newconfig.each { |key, val|
-            @@config[key.intern] = val
-          }
-          return
-        rescue
-          error "failed to read conf.yaml: #{$!}"
-        end
-      end
-      # if we got here, we need to run the first-run wizard
-      BotConfigWizard.new(@@bot).run
-      # save newly created config
-      save
+      return @config.send(method, *args, &block)
     end
 
     # write current configuration to #{botclass}/conf.yaml
     def save
       begin
         debug "Writing new conf.yaml ..."
-        File.open("#{@@bot.botclass}/conf.yaml.new", "w") do |file|
+        File.open("#{@bot.botclass}/conf.yaml.new", "w") do |file|
           savehash = {}
-          @@config.each { |key, val|
+          @config.each { |key, val|
             savehash[key.to_s] = val
           }
           file.puts savehash.to_yaml
         end
         debug "Officializing conf.yaml ..."
-        File.rename("#{@@bot.botclass}/conf.yaml.new",
-                    "#{@@bot.botclass}/conf.yaml")
+        File.rename("#{@bot.botclass}/conf.yaml.new",
+                    "#{@bot.botclass}/conf.yaml")
       rescue => e
         error "failed to write configuration file conf.yaml! #{$!}"
         error "#{e.class}: #{e}"
         error e.backtrace.join("\n")
       end
     end
+  end
 
-    def privmsg(m)
-      @handler.handle(m)
+  module BotConfig
+    # Returns the only BotConfigManagerClass
+    #
+    def BotConfig.configmanager
+      return BotConfigManagerClass.instance
+    end
+
+    # Register a config value
+    def BotConfig.register(item)
+      BotConfig.configmanager.register(item)
     end
   end
 
   class BotConfigWizard
     def initialize(bot)
       @bot = bot
-      @questions = BotConfig.items.values.find_all {|i| i.wizard }
+      @manager = BotConfig::configmanager
+      @questions = @manager.items.values.find_all {|i| i.wizard }
     end
-    
+
     def run()
       puts "First time rbot configuration wizard"
       puts "===================================="
@@ -464,4 +316,5 @@ module Irc
       end
     end
   end
+
 end
diff --git a/lib/rbot/core/config.rb b/lib/rbot/core/config.rb
new file mode 100644 (file)
index 0000000..47bed10
--- /dev/null
@@ -0,0 +1,252 @@
+#-- vim:sw=2:et\r
+#++\r
+\r
+\r
+class ConfigModule < CoreBotModule\r
+\r
+  def handle_list(m, params)\r
+    modules = []\r
+    if params[:module]\r
+      @bot.config.items.each_key do |key|\r
+        mod, name = key.to_s.split('.')\r
+        next unless mod == params[:module]\r
+        modules.push key unless modules.include?(name)\r
+      end\r
+      if modules.empty?\r
+        m.reply "no such module #{params[:module]}"\r
+      else\r
+        m.reply modules.join(", ")\r
+      end\r
+    else\r
+      @bot.configitems.each_key do |key|\r
+        name = key.to_s.split('.').first\r
+        modules.push name unless modules.include?(name)\r
+      end\r
+      m.reply "modules: " + modules.join(", ")\r
+    end\r
+  end\r
+\r
+  def handle_get(m, params)\r
+    key = params[:key].to_s.intern\r
+    unless @bot.config.items.has_key?(key)\r
+      m.reply "no such config key #{key}"\r
+      return\r
+    end\r
+    value = @bot.config.items[key].to_s\r
+    m.reply "#{key}: #{value}"\r
+  end\r
+\r
+  def handle_desc(m, params)\r
+    key = params[:key].to_s.intern\r
+    unless @bot.config.items.has_key?(key)\r
+      m.reply "no such config key #{key}"\r
+    end\r
+    puts @bot.config.items[key].inspect\r
+    m.reply "#{key}: #{@bot.config.items[key].desc}"\r
+  end\r
+\r
+  def handle_unset(m, params)\r
+    key = params[:key].to_s.intern\r
+    unless @bot.config.items.has_key?(key)\r
+      m.reply "no such config key #{key}"\r
+    end\r
+    @bot.config.items[key].unset\r
+    handle_get(m, params)\r
+    m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart\r
+    m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan\r
+  end\r
+\r
+  def handle_set(m, params)\r
+    key = params[:key].to_s.intern\r
+    value = params[:value].join(" ")\r
+    unless @bot.config.items.has_key?(key)\r
+      m.reply "no such config key #{key}"\r
+      return\r
+    end\r
+    begin\r
+      @bot.config.items[key].set_string(value)\r
+    rescue ArgumentError => e\r
+      m.reply "failed to set #{key}: #{e.message}"\r
+      return\r
+    end\r
+    if @bot.config.items[key].requires_restart\r
+      m.reply "this config change will take effect on the next restart"\r
+    elsif @bot.config.items[key].requires_rescan\r
+      m.reply "this config change will take effect on the next rescan"\r
+    else\r
+      m.okay\r
+    end\r
+  end\r
+\r
+  def handle_add(m, params)\r
+    key = params[:key].to_s.intern\r
+    value = params[:value]\r
+    unless @bot.config.items.has_key?(key)\r
+      m.reply "no such config key #{key}"\r
+      return\r
+    end\r
+    unless @bot.config.items[key].class <= BotConfigArrayValue\r
+      m.reply "config key #{key} is not an array"\r
+      return\r
+    end\r
+    begin\r
+      @bot.config.items[key].add(value)\r
+    rescue ArgumentError => e\r
+      m.reply "failed to add #{value} to #{key}: #{e.message}"\r
+      return\r
+    end\r
+    handle_get(m,{:key => key})\r
+    m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart\r
+    m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan\r
+  end\r
+\r
+  def handle_rm(m, params)\r
+    key = params[:key].to_s.intern\r
+    value = params[:value]\r
+    unless @bot.config.items.has_key?(key)\r
+      m.reply "no such config key #{key}"\r
+      return\r
+    end\r
+    unless @bot.config.items[key].class <= BotConfigArrayValue\r
+      m.reply "config key #{key} is not an array"\r
+      return\r
+    end\r
+    begin\r
+      @bot.config.items[key].rm(value)\r
+    rescue ArgumentError => e\r
+      m.reply "failed to remove #{value} from #{key}: #{e.message}"\r
+      return\r
+    end\r
+    handle_get(m,{:key => key})\r
+    m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart\r
+    m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan\r
+  end\r
+\r
+  def bot_save(m, param)\r
+    @bot.save\r
+    m.okay\r
+  end\r
+\r
+  def bot_rescan(m, param)\r
+    m.reply "saving ..."\r
+    @bot.save\r
+    m.reply "rescanning ..."\r
+    @bot.rescan\r
+    m.reply "done. #{@plugins.status(true)}"\r
+  end\r
+\r
+  def bot_nick(m, param)\r
+    @bot.nickchg(param[:nick])\r
+  end\r
+\r
+  def bot_status(m, param)\r
+    m.reply @bot.status\r
+  end\r
+\r
+  # TODO is this one of the methods that disappeared when the bot was moved\r
+  # from the single-file to the multi-file registry?\r
+  #\r
+  #  def bot_reg_stat(m, param)\r
+  #    m.reply @registry.stat.inspect\r
+  #  end\r
+\r
+  def bot_version(m, param)\r
+    m.reply  "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"\r
+  end\r
+\r
+  def handle_help(m, params)\r
+    m.reply help(params[:topic])\r
+  end\r
+\r
+  def help(topic="")\r
+    case topic\r
+    when false\r
+      "config module - bot configuration. usage: list, desc, get, set, unset, add, rm"\r
+    when "list"\r
+      "config list => list configuration modules, config list <module> => list configuration keys for module <module>"\r
+    when "get"\r
+      "config get <key> => get configuration value for key <key>"\r
+    when "unset"\r
+      "reset key <key> to the default"\r
+    when "set"\r
+      "config set <key> <value> => set configuration value for key <key> to <value>"\r
+    when "desc"\r
+      "config desc <key> => describe what key <key> configures"\r
+    when "add"\r
+      "config add <value> to <key> => add value <value> to key <key> if <key> is an array"\r
+    when "rm"\r
+      "config rm <value> from <key> => remove value <value> from key <key> if <key> is an array"\r
+    else\r
+      "no help for config #{topic}"\r
+    end\r
+  end\r
+\r
+end\r
+\r
+conf = ConfigModule.new\r
+\r
+conf.map 'config list :module',\r
+  :action => 'handle_list',\r
+  :defaults => {:module => false},\r
+  :auth_path => 'show'\r
+# TODO this one is presently a security risk, since the bot\r
+# stores the master password in the config. Do we need auth levels\r
+# on the BotConfig keys too?\r
+conf.map 'config get :key',\r
+  :action => 'handle_get',\r
+  :auth_path => 'show'\r
+conf.map 'config desc :key',\r
+  :action => 'handle_desc',\r
+  :auth_path => 'show'\r
+conf.map 'config describe :key',\r
+  :action => 'handle_desc',\r
+  :auth_path => 'show'\r
+\r
+conf.map "save",\r
+  :action => 'bot_save'\r
+conf.map "rescan",\r
+  :action => 'bot_rescan'\r
+conf.map "nick :nick",\r
+  :action => 'bot_nick'\r
+conf.map "status",\r
+  :action => 'bot_status',\r
+  :auth_path => 'show::status'\r
+# TODO see above\r
+#\r
+# conf.map "registry stats",\r
+#   :action => 'bot_reg_stat',\r
+#   :auth_path => '!config::status'\r
+conf.map "version",\r
+  :action => 'bot_version',\r
+  :auth_path => 'show::status'\r
+\r
+conf.map 'config set :key *value',\r
+  :action => 'handle_set',\r
+  :auth_path => 'edit'\r
+conf.map 'config add :value to :key',\r
+  :action => 'handle_add',\r
+  :auth_path => 'edit'\r
+conf.map 'config rm :value from :key',\r
+  :action => 'handle_rm',\r
+  :auth_path => 'edit'\r
+conf.map 'config del :value from :key',\r
+  :action => 'handle_rm',\r
+  :auth_path => 'edit'\r
+conf.map 'config delete :value from :key',\r
+  :action => 'handle_rm',\r
+  :auth_path => 'edit'\r
+conf.map 'config unset :key',\r
+  :action => 'handle_unset',\r
+  :auth_path => 'edit'\r
+conf.map 'config reset :key',\r
+  :action => 'handle_unset',\r
+  :auth_path => 'edit'\r
+\r
+conf.map 'config help :topic',\r
+  :action => 'handle_help',\r
+  :defaults => {:topic => false},\r
+  :auth_path => '!help!'\r
+\r
+conf.default_auth('*', false)\r
+conf.default_auth('show::status', true)\r
+\r
index 55da1a7d4ea604ca7f2eb43cddfa8e841975af29..cb5df226c3ca17809af923503029fb0b236e79a9 100644 (file)
@@ -2,7 +2,7 @@
 #++\r
 \r
 \r
-class Core < CoreBotModule\r
+class CoreModule < CoreBotModule\r
 \r
   def listen(m)\r
     return unless m.class <= PrivMessage\r
@@ -41,15 +41,6 @@ class Core < CoreBotModule
     @bot.join 0\r
   end\r
 \r
-  def bot_save(m, param)\r
-    @bot.save\r
-    m.okay\r
-  end\r
-\r
-  def bot_nick(m, param)\r
-    @bot.nickchg(param[:nick])\r
-  end\r
-\r
   def bot_say(m, param)\r
     @bot.say param[:where], param[:what].join(" ")\r
   end\r
@@ -66,14 +57,6 @@ class Core < CoreBotModule
     m.reply "pong"\r
   end\r
 \r
-  def bot_rescan(m, param)\r
-    m.reply "saving ..."\r
-    @bot.save\r
-    m.reply "rescanning ..."\r
-    @bot.rescan\r
-    m.reply "done. #{@plugins.status(true)}"\r
-  end\r
-\r
   def bot_quiet(m, param)\r
     if param.has_key?(:where)\r
       @bot.set_quiet param[:where].sub(/^here$/, m.target)\r
@@ -90,21 +73,6 @@ class Core < CoreBotModule
     end\r
   end\r
 \r
-  def bot_status(m, param)\r
-    m.reply @bot.status\r
-  end\r
-\r
-  # TODO is this one of the methods that disappeared when the bot was moved\r
-  # from the single-file to the multi-file registry?\r
-  #\r
-  #  def bot_reg_stat(m, param)\r
-  #    m.reply @registry.stat.inspect\r
-  #  end\r
-\r
-  def bot_version(m, param)\r
-    m.reply  "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"\r
-  end\r
-\r
   def bot_help(m, param)\r
     m.reply @bot.help(param[:topic].join(" "))\r
   end\r
@@ -160,7 +128,7 @@ class Core < CoreBotModule
   end\r
 end\r
 \r
-core = Core.new\r
+core = CoreModule.new\r
 \r
 core.map "quit *msg",\r
   :action => 'bot_quit',\r
@@ -171,27 +139,6 @@ core.map "restart *msg",
   :defaults => { :msg => nil },\r
   :auth_path => 'quit'\r
 \r
-core.map "save",\r
-  :action => 'bot_save',\r
-  :auth_path => 'config'\r
-core.map "rescan",\r
-  :action => 'bot_rescan',\r
-  :auth_path => 'config'\r
-core.map "nick :nick",\r
-  :action => 'bot_nick',\r
-  :auth_path => 'config'\r
-core.map "status",\r
-  :action => 'bot_status',\r
-  :auth_path => 'config::show'\r
-  # TODO see above\r
-  #\r
-  # core.map "registry stats",\r
-  #   :action => 'bot_reg_stat',\r
-  #   :auth_path => 'config::show'\r
-core.map "version",\r
-  :action => 'bot_version',\r
-  :auth_path => 'config::show'\r
-\r
 core.map "quiet",\r
   :action => 'bot_quiet',\r
   :auth_path => 'talk::set'\r
@@ -235,8 +182,5 @@ core.map "help *topic",
   :default => { :topic => [""] },\r
   :auth_path => '!help!'\r
 \r
-# TODO the first line should probably go to the auth module?\r
-#\r
 core.default_auth('*', false)\r
-core.default_auth('config::show', true)\r
 \r
index d96e036896555699ec237878c41f0e8071688a23..9664f653c5185269039438d292da6fdb5acfeaf3 100644 (file)
@@ -268,7 +268,16 @@ class IrcBot
     @pong_timer = nil
     @last_ping = nil
     @startup_time = Time.new
-    @config = BotConfig.new(self)
+
+    begin
+      @config = BotConfig.configmanager
+      @config.bot_associate(self)
+    rescue => e
+      fatal e.inspect
+      fatal e.backtrace.join("\n")
+      log_session_end
+      exit 2
+    end
 
     if @config['core.run_as_daemon']
       $daemonize = true
index d65478fe961250d0425d79e6d4531fba0944a69f..1604faf753d8a503bb5cded859688c8811ac7f84 100644 (file)
@@ -11,10 +11,10 @@ module Irc
 
     # type of keyword (e.g. "is" or "are")
     attr_reader :type
-    
+
     # type::   type of keyword (e.g "is" or "are")
     # values:: array of values
-    # 
+    #
     # create a keyword of type +type+ with values +values+
     def initialize(type, values)
       @type = type.downcase
@@ -73,7 +73,7 @@ module Irc
     end
   end
 
-  # keywords class. 
+  # keywords class.
   #
   # Handles all that stuff like "bot: foo is bar", "bot: foo?"
   #
@@ -87,7 +87,7 @@ module Irc
     BotConfig.register BotConfigBooleanValue.new('keyword.address',
       :default => true,
       :desc => "Should the bot require that keyword lookups are addressed to it? If not, the bot will attempt to lookup foo if someone says 'foo?' in channel")
-    
+
     # create a new Keywords instance, associated to bot +bot+
     def initialize(bot)
       @bot = bot
@@ -96,7 +96,7 @@ module Irc
       @keywords = DBTree.new bot, "keyword"
 
       scan
-      
+
       # import old format keywords into DBHash
       if(File.exist?("#{@bot.botclass}/keywords.rbot"))
         log "auto importing old keywords.rbot"
index 7e98b1b34f138933e8db0066e88f2a7483ef4ab0..ec99fe30f25830d768957a2298d4069bd81c4825 100644 (file)
@@ -176,7 +176,7 @@ module Plugins
     # return an identifier for this plugin, defaults to a list of the message
     # prefixes handled (used for error messages etc)
     def name
-      self.class.to_s.downcase.sub(/^#<module:.*?>::/,"").sub(/(plugin)?$/,"")
+      self.class.to_s.downcase.sub(/^#<module:.*?>::/,"").sub(/(plugin|module)?$/,"")
     end
 
     # just calls name