]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Fix stupid bug introduced with the new debugging messages. switch to kind_of? instead...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 4 Aug 2006 00:19:51 +0000 (00:19 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 4 Aug 2006 00:19:51 +0000 (00:19 +0000)
lib/rbot/botuser.rb
lib/rbot/core/auth.rb
lib/rbot/core/config.rb
lib/rbot/core/core.rb
lib/rbot/httputil.rb
lib/rbot/irc.rb
lib/rbot/plugins.rb
lib/rbot/rfc2812.rb

index ea47fcbd7641b33ab51ae3966bb783fd63c8947e..b324a2a78208e4d6fa1fef1b1201ac65b3ff6e18 100644 (file)
@@ -14,13 +14,13 @@ module Irc
   # This method raises a TypeError if _user_ is not of class User\r
   #\r
   def Irc.error_if_not_user(user)\r
-    raise TypeError, "#{user.inspect} must be of type Irc::User and not #{user.class}" unless user.class <= User\r
+    raise TypeError, "#{user.inspect} must be of type Irc::User and not #{user.class}" unless user.kind_of?(User)\r
   end\r
 \r
   # This method raises a TypeError if _chan_ is not of class Chan\r
   #\r
   def Irc.error_if_not_channel(chan)\r
-    raise TypeError, "#{chan.inspect} must be of type Irc::User and not #{chan.class}" unless chan.class <= Channel\r
+    raise TypeError, "#{chan.inspect} must be of type Irc::User and not #{chan.class}" unless chan.kind_of?(Channel)\r
   end\r
 \r
 \r
@@ -89,7 +89,7 @@ module Irc
     # This method raises a TypeError if _user_ is not of class User\r
     #\r
     def Irc.error_if_not_command(cmd)\r
-      raise TypeError, "#{cmd.inspect} must be of type Irc::Auth::Command and not #{cmd.class}" unless cmd.class <= Command\r
+      raise TypeError, "#{cmd.inspect} must be of type Irc::Auth::Command and not #{cmd.class}" unless cmd.kind_of?(Command)\r
     end\r
 \r
 \r
@@ -452,7 +452,7 @@ module Irc
         raise "Won't load with unsaved changes" if @has_changes and not forced\r
         reset_hashes\r
         ary.each { |x|\r
-          raise TypeError, "#{x} should be a Hash" unless x.class <= Hash\r
+          raise TypeError, "#{x} should be a Hash" unless x.kind_of?(Hash)\r
           u = x[:username]\r
           unless include?(u)\r
             create_botuser(u)\r
index 9a30dc0a90c9e42a06d4b5afc67300eea4f9476a..228f76a8d78413b75e2979749e1db060c427122d 100644 (file)
@@ -85,7 +85,7 @@ class AuthModule < CoreBotModule
 \r
   def auth_set(m, params)\r
     cmds, locs, warns = parse_args(params[:args])\r
-    errs = warns.select { |w| w.class <= Exception }\r
+    errs = warns.select { |w| w.kind_of?(Exception) }\r
     unless errs.empty?\r
       m.reply "couldn't satisfy your request: #{errs.join(',')}"\r
       return\r
index 3099a00a79aa2d5d50375032f2cf96ce56fa17f0..29a0b56467f2bc91fc797f1201207c91c786d244 100644 (file)
@@ -89,7 +89,7 @@ class ConfigModule < CoreBotModule
       m.reply "no such config key #{key}"\r
       return\r
     end\r
-    unless @bot.config.items[key].class <= BotConfigArrayValue\r
+    unless @bot.config.items[key].kind_of?(BotConfigArrayValue)\r
       m.reply "config key #{key} is not an array"\r
       return\r
     end\r
@@ -111,7 +111,7 @@ class ConfigModule < CoreBotModule
       m.reply "no such config key #{key}"\r
       return\r
     end\r
-    unless @bot.config.items[key].class <= BotConfigArrayValue\r
+    unless @bot.config.items[key].kind_of?(BotConfigArrayValue)\r
       m.reply "config key #{key} is not an array"\r
       return\r
     end\r
index 178675b1fabc758a516542ab863b0ca06ec58763..feff7491b058f6445e13ffba4cb6f1b83ff9b667 100644 (file)
@@ -5,7 +5,7 @@
 class CoreModule < CoreBotModule\r
 \r
   def listen(m)\r
-    return unless m.class <= PrivMessage\r
+    return unless m.kind_of?(PrivMessage)\r
     if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)\r
       @bot.notice m.sourcenick, "\001PING #$1\001"\r
       @bot.irclog "@ #{m.sourcenick} pinged me"\r
index 92918f7745ccd2f7747e79d60a5fc09241ccd834..6383d4e2ab9a7b8706083f370f36f0777c374f05 100644 (file)
@@ -135,7 +135,7 @@ class HttpUtil
   # if a block is given, it yields the urls it gets redirected to
   # TODO we really need something to implement proper caching
   def get(uri_or_str, readtimeout=10, opentimeout=5, max_redir=@bot.config["http.max_redir"], cache=false)
-    if uri_or_str.class <= URI
+    if uri_or_str.kind_of?(URI)
       uri = uri_or_str
     else
       uri = URI.parse(uri_or_str.to_s)
@@ -189,7 +189,7 @@ class HttpUtil
 
   # just like the above, but only gets the head
   def head(uri_or_str, readtimeout=10, opentimeout=5, max_redir=@bot.config["http.max_redir"])
-    if uri_or_str.class <= URI
+    if uri_or_str.kind_of?(URI)
       uri = uri_or_str
     else
       uri = URI.parse(uri_or_str.to_s)
@@ -231,7 +231,7 @@ class HttpUtil
   def get_cached(uri_or_str, readtimeout=10, opentimeout=5,
                  max_redir=@bot.config['http.max_redir'],
                  noexpire=@bot.config['http.no_expire_cache'])
-    if uri_or_str.class <= URI
+    if uri_or_str.kind_of?(URI)
       uri = uri_or_str
     else
       uri = URI.parse(uri_or_str.to_s)
index 93ac6b85d6141094eb9cba1c082671873be43823..1cfb45926c98acaefd29126eeb83734f18e70074 100644 (file)
@@ -156,7 +156,7 @@ class ArrayOf < Array
   # optionally filling it with the elements from the Array argument.\r
   #\r
   def initialize(kl, ar=[])\r
-    raise TypeError, "#{kl.inspect} must be a class name" unless kl.class <= Class\r
+    raise TypeError, "#{kl.inspect} must be a class name" unless kl.kind_of?(Class)\r
     super()\r
     @element_class = kl\r
     case ar\r
@@ -174,7 +174,7 @@ class ArrayOf < Array
   #\r
   def internal_will_accept?(raising, *els)\r
     els.each { |el|\r
-      unless el.class <= @element_class\r
+      unless el.kind_of?(@element_class)\r
         raise TypeError, "#{el.inspect} is not of class #{@element_class}" if raising\r
         return false\r
       end\r
@@ -303,6 +303,13 @@ module Irc
       @host = "*" if @host.to_s.empty?\r
     end\r
 \r
+    def inspect\r
+      str = "<#{self.class}:#{'0x%08x' % self.object_id}:"\r
+      str << " @nick=#{@nick.inspect} @user=#{@user.inspect}"\r
+      str << " @host=<#{@host}>"\r
+      str\r
+    end\r
+\r
     # Equality: two Netmasks are equal if they have the same @nick, @user, @host and @casemap\r
     #\r
     def ==(other)\r
@@ -376,7 +383,7 @@ module Irc
     def matches?(arg)\r
       cmp = Netmask.new(arg)\r
       raise TypeError, "#{arg} and #{self} have different casemaps" if @casemap != cmp.casemap\r
-      raise TypeError, "#{arg} is not a valid Netmask" unless cmp.class <= Netmask\r
+      raise TypeError, "#{arg} is not a valid Netmask" unless cmp.kind_of?(Netmask)\r
       [:nick, :user, :host].each { |component|\r
         us = self.send(component)\r
         them = cmp.send(component)\r
@@ -518,7 +525,7 @@ module Irc
 \r
     # Replace a ChannelTopic with another one\r
     def replace(topic)\r
-      raise TypeError, "#{topic.inspect} is not an Irc::ChannelTopic" unless topic.class <= ChannelTopic\r
+      raise TypeError, "#{topic.inspect} is not an Irc::ChannelTopic" unless topic.kind_of?(ChannelTopic)\r
       @text = topic.text.dup\r
       @set_by = topic.set_by.dup\r
       @set_on = topic.set_on.dup\r
@@ -659,7 +666,7 @@ module Irc
     # FIXME doesn't check if users have the same casemap as the channel yet\r
     #\r
     def initialize(server, name, topic=nil, users=[])\r
-      raise TypeError, "First parameter must be an Irc::Server" unless server.class <= Server\r
+      raise TypeError, "First parameter must be an Irc::Server" unless server.kind_of?(Server)\r
       raise ArgumentError, "Channel name cannot be empty" if name.to_s.empty?\r
       raise ArgumentError, "Unknown channel prefix #{name[0].chr}" if name !~ /^[&#+!]/\r
       raise ArgumentError, "Invalid character in #{name.inspect}" if name =~ /[ \x07,]/\r
@@ -692,7 +699,7 @@ module Irc
     #\r
     def delete_user(user)\r
       @mode.each { |sym, mode|\r
-        mode.reset(user) if mode.class <= ChannelUserMode\r
+        mode.reset(user) if mode.kind_of?(ChannelUserMode)\r
       }\r
       @users.delete(user)\r
     end\r
@@ -1161,6 +1168,7 @@ module Irc
     def user(str)\r
       u = new_user(str, false)\r
       debug "Server user #{u.inspect} from #{str.inspect}"\r
+      u\r
     end\r
 \r
     # Remove User _someuser_ from the list of <code>User</code>s.\r
@@ -1180,7 +1188,7 @@ module Irc
     # Create a new Netmask object with the appropriate casemap\r
     #\r
     def new_netmask(str)\r
-      if str.class <= Netmask \r
+      if str.kind_of?(Netmask )\r
         raise "Wrong casemap for Netmask #{str.inspect}" if str.casemap != self.casemap\r
         return str\r
       end\r
index 43793e99760fe95f0d5790cc42b163fd966857e4..42ff2aaa959382c6992b25b9bba7f8f3670d38a8 100644 (file)
@@ -266,7 +266,7 @@ module Plugins
 
     # Registers botmodule _botmodule_ with command _cmd_ and command path _auth_path_
     def register(botmodule, cmd, auth_path)
-      raise TypeError, "First argument #{botmodule.inspect} is not of class BotModule" unless botmodule.class <= BotModule
+      raise TypeError, "First argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule)
       kl = botmodule.botmodule_class
       @commandmappers[kl.to_sym][cmd.to_sym] = {:botmodule => botmodule, :auth => auth_path}
       h = @commandmappers[kl.to_sym][cmd.to_sym]
@@ -274,7 +274,7 @@ module Plugins
     end
 
     def add_botmodule(botmodule)
-      raise TypeError, "Argument #{botmodule.inspect} is not of class BotModule" unless botmodule.class <= BotModule
+      raise TypeError, "Argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule)
       kl = botmodule.botmodule_class
       raise "#{kl.to_s} #{botmodule.name} already registered!" if @botmodules[kl.to_sym].include?(botmodule)
       @botmodules[kl.to_sym] << botmodule
@@ -542,9 +542,9 @@ module Plugins
               # debug "#{p.botmodule_class} #{p.name} responds"
               p.send method, *args
             rescue Exception => err
-              raise if err.class <= SystemExit
+              raise if err.kind_of?(SystemExit)
               error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err)
-              raise if err.class <= BDB::Fatal
+              raise if err.kind_of?(BDB::Fatal)
             end
           end
         }
@@ -579,9 +579,9 @@ module Plugins
                 # debug "#{p.botmodule_class} #{p.name} responds"
                 p.privmsg(m)
               rescue Exception => err
-                raise if err.class <= SystemExit
+                raise if err.kind_of?(SystemExit)
                 error report_error("#{p.botmodule_class} #{p.name} privmsg() failed:", err)
-                raise if err.class <= BDB::Fatal
+                raise if err.kind_of?(BDB::Fatal)
               end
               # debug "Successfully delegated #{m.message}"
               return true
index 7832f9980a403d540c7c7d591738f99d32e1a3a1..8a83ec889155bc5a5a8c334ddf7781fda2c3b6de 100644 (file)
@@ -1099,7 +1099,7 @@ module Irc
         handle(:privmsg, data)
 
         # Now we split it
-        if(data[:target].class <= Channel)
+        if data[:target].kind_of?(Channel)
           handle(:public, data)
         else
           handle(:msg, data)