]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/config.rb
timer: tick when rescheduling
[user/henk/code/ruby/rbot.git] / lib / rbot / config.rb
index 7cedc11ec544b3083f5b65fc56c9e2a9ed280f64..eb342f7cbcc27fe55010a1c069c592e0d4545064 100644 (file)
@@ -114,15 +114,36 @@ module Irc
     def parse(string)
       return true if string == "true"
       return false if string == "false"
-      raise ArgumentError, "#{string} does not match either 'true' or 'false'"
+      if string =~ /^-?\d+$/
+        return string.to_i != 0
+      end
+      raise ArgumentError, "#{string} does not match either 'true' or 'false', and it's not an integer either"
+    end
+    def get
+      r = super
+      if r.kind_of?(Integer)
+        return r != 0
+      else
+        return r
+      end
     end
   end
 
   class BotConfigIntegerValue < BotConfigValue
     def parse(string)
+      return 1 if string == "true"
+      return 0 if string == "false"
       raise ArgumentError, "not an integer: #{string}" unless string =~ /^-?\d+$/
       string.to_i
     end
+    def get
+      r = super
+      if r.kind_of?(Integer)
+        return r
+      else
+        return r ? 1 : 0
+      end
+    end
   end
 
   class BotConfigFloatValue < BotConfigValue
@@ -169,7 +190,7 @@ module Irc
       string
     end
     def desc
-      _("#{@desc} [valid values are: #{values.join(', ')}]")
+      _("%{desc} [valid values are: %{values}]") % {:desc => @desc, :values => values.join(', ')}
     end
   end
 
@@ -207,7 +228,7 @@ module Irc
           }
           return
         rescue
-          error _("failed to read conf.yaml: #{$!}")
+          error "failed to read conf.yaml: #{$!}"
         end
       end
       # if we got here, we need to run the first-run wizard
@@ -273,7 +294,7 @@ module Irc
                     "#{@bot.botclass}/conf.yaml")
         @changed = false
       rescue => e
-        error _("failed to write configuration file conf.yaml! #{$!}")
+        error "failed to write configuration file conf.yaml! #{$!}"
         error "#{e.class}: #{e}"
         error e.backtrace.join("\n")
       end