X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fconfig.rb;h=eb342f7cbcc27fe55010a1c069c592e0d4545064;hb=c986bc82f4b856818e97e24fbf5fc11eef5f25c2;hp=de7b29b78719a90d038ed1f9db44dc4c06d1e566;hpb=077e87909b0bf490c6ca08a3ab1df34ce77b1397;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb index de7b29b7..eb342f7c 100644 --- a/lib/rbot/config.rb +++ b/lib/rbot/config.rb @@ -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