summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-08-04 00:19:51 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-08-04 00:19:51 +0000
commit5aa914133c6482c500cf439d65584282212beb6b (patch)
tree0f41aad864af62ceeebb76578ba65020de896b7f
parent6c470685174bdee375beb2d968059172d5689575 (diff)
Fix stupid bug introduced with the new debugging messages. switch to kind_of? instead of .class<=
-rw-r--r--lib/rbot/botuser.rb8
-rw-r--r--lib/rbot/core/auth.rb2
-rw-r--r--lib/rbot/core/config.rb4
-rw-r--r--lib/rbot/core/core.rb2
-rw-r--r--lib/rbot/httputil.rb6
-rw-r--r--lib/rbot/irc.rb22
-rw-r--r--lib/rbot/plugins.rb12
-rw-r--r--lib/rbot/rfc2812.rb2
8 files changed, 33 insertions, 25 deletions
diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb
index ea47fcbd..b324a2a7 100644
--- a/lib/rbot/botuser.rb
+++ b/lib/rbot/botuser.rb
@@ -14,13 +14,13 @@ module Irc
# This method raises a TypeError if _user_ is not of class User
#
def Irc.error_if_not_user(user)
- raise TypeError, "#{user.inspect} must be of type Irc::User and not #{user.class}" unless user.class <= User
+ raise TypeError, "#{user.inspect} must be of type Irc::User and not #{user.class}" unless user.kind_of?(User)
end
# This method raises a TypeError if _chan_ is not of class Chan
#
def Irc.error_if_not_channel(chan)
- raise TypeError, "#{chan.inspect} must be of type Irc::User and not #{chan.class}" unless chan.class <= Channel
+ raise TypeError, "#{chan.inspect} must be of type Irc::User and not #{chan.class}" unless chan.kind_of?(Channel)
end
@@ -89,7 +89,7 @@ module Irc
# This method raises a TypeError if _user_ is not of class User
#
def Irc.error_if_not_command(cmd)
- raise TypeError, "#{cmd.inspect} must be of type Irc::Auth::Command and not #{cmd.class}" unless cmd.class <= Command
+ raise TypeError, "#{cmd.inspect} must be of type Irc::Auth::Command and not #{cmd.class}" unless cmd.kind_of?(Command)
end
@@ -452,7 +452,7 @@ module Irc
raise "Won't load with unsaved changes" if @has_changes and not forced
reset_hashes
ary.each { |x|
- raise TypeError, "#{x} should be a Hash" unless x.class <= Hash
+ raise TypeError, "#{x} should be a Hash" unless x.kind_of?(Hash)
u = x[:username]
unless include?(u)
create_botuser(u)
diff --git a/lib/rbot/core/auth.rb b/lib/rbot/core/auth.rb
index 9a30dc0a..228f76a8 100644
--- a/lib/rbot/core/auth.rb
+++ b/lib/rbot/core/auth.rb
@@ -85,7 +85,7 @@ class AuthModule < CoreBotModule
def auth_set(m, params)
cmds, locs, warns = parse_args(params[:args])
- errs = warns.select { |w| w.class <= Exception }
+ errs = warns.select { |w| w.kind_of?(Exception) }
unless errs.empty?
m.reply "couldn't satisfy your request: #{errs.join(',')}"
return
diff --git a/lib/rbot/core/config.rb b/lib/rbot/core/config.rb
index 3099a00a..29a0b564 100644
--- a/lib/rbot/core/config.rb
+++ b/lib/rbot/core/config.rb
@@ -89,7 +89,7 @@ class ConfigModule < CoreBotModule
m.reply "no such config key #{key}"
return
end
- unless @bot.config.items[key].class <= BotConfigArrayValue
+ unless @bot.config.items[key].kind_of?(BotConfigArrayValue)
m.reply "config key #{key} is not an array"
return
end
@@ -111,7 +111,7 @@ class ConfigModule < CoreBotModule
m.reply "no such config key #{key}"
return
end
- unless @bot.config.items[key].class <= BotConfigArrayValue
+ unless @bot.config.items[key].kind_of?(BotConfigArrayValue)
m.reply "config key #{key} is not an array"
return
end
diff --git a/lib/rbot/core/core.rb b/lib/rbot/core/core.rb
index 178675b1..feff7491 100644
--- a/lib/rbot/core/core.rb
+++ b/lib/rbot/core/core.rb
@@ -5,7 +5,7 @@
class CoreModule < CoreBotModule
def listen(m)
- return unless m.class <= PrivMessage
+ return unless m.kind_of?(PrivMessage)
if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)
@bot.notice m.sourcenick, "\001PING #$1\001"
@bot.irclog "@ #{m.sourcenick} pinged me"
diff --git a/lib/rbot/httputil.rb b/lib/rbot/httputil.rb
index 92918f77..6383d4e2 100644
--- a/lib/rbot/httputil.rb
+++ b/lib/rbot/httputil.rb
@@ -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)
diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb
index 93ac6b85..1cfb4592 100644
--- a/lib/rbot/irc.rb
+++ b/lib/rbot/irc.rb
@@ -156,7 +156,7 @@ class ArrayOf < Array
# optionally filling it with the elements from the Array argument.
#
def initialize(kl, ar=[])
- raise TypeError, "#{kl.inspect} must be a class name" unless kl.class <= Class
+ raise TypeError, "#{kl.inspect} must be a class name" unless kl.kind_of?(Class)
super()
@element_class = kl
case ar
@@ -174,7 +174,7 @@ class ArrayOf < Array
#
def internal_will_accept?(raising, *els)
els.each { |el|
- unless el.class <= @element_class
+ unless el.kind_of?(@element_class)
raise TypeError, "#{el.inspect} is not of class #{@element_class}" if raising
return false
end
@@ -303,6 +303,13 @@ module Irc
@host = "*" if @host.to_s.empty?
end
+ def inspect
+ str = "<#{self.class}:#{'0x%08x' % self.object_id}:"
+ str << " @nick=#{@nick.inspect} @user=#{@user.inspect}"
+ str << " @host=<#{@host}>"
+ str
+ end
+
# Equality: two Netmasks are equal if they have the same @nick, @user, @host and @casemap
#
def ==(other)
@@ -376,7 +383,7 @@ module Irc
def matches?(arg)
cmp = Netmask.new(arg)
raise TypeError, "#{arg} and #{self} have different casemaps" if @casemap != cmp.casemap
- raise TypeError, "#{arg} is not a valid Netmask" unless cmp.class <= Netmask
+ raise TypeError, "#{arg} is not a valid Netmask" unless cmp.kind_of?(Netmask)
[:nick, :user, :host].each { |component|
us = self.send(component)
them = cmp.send(component)
@@ -518,7 +525,7 @@ module Irc
# Replace a ChannelTopic with another one
def replace(topic)
- raise TypeError, "#{topic.inspect} is not an Irc::ChannelTopic" unless topic.class <= ChannelTopic
+ raise TypeError, "#{topic.inspect} is not an Irc::ChannelTopic" unless topic.kind_of?(ChannelTopic)
@text = topic.text.dup
@set_by = topic.set_by.dup
@set_on = topic.set_on.dup
@@ -659,7 +666,7 @@ module Irc
# FIXME doesn't check if users have the same casemap as the channel yet
#
def initialize(server, name, topic=nil, users=[])
- raise TypeError, "First parameter must be an Irc::Server" unless server.class <= Server
+ raise TypeError, "First parameter must be an Irc::Server" unless server.kind_of?(Server)
raise ArgumentError, "Channel name cannot be empty" if name.to_s.empty?
raise ArgumentError, "Unknown channel prefix #{name[0].chr}" if name !~ /^[&#+!]/
raise ArgumentError, "Invalid character in #{name.inspect}" if name =~ /[ \x07,]/
@@ -692,7 +699,7 @@ module Irc
#
def delete_user(user)
@mode.each { |sym, mode|
- mode.reset(user) if mode.class <= ChannelUserMode
+ mode.reset(user) if mode.kind_of?(ChannelUserMode)
}
@users.delete(user)
end
@@ -1161,6 +1168,7 @@ module Irc
def user(str)
u = new_user(str, false)
debug "Server user #{u.inspect} from #{str.inspect}"
+ u
end
# Remove User _someuser_ from the list of <code>User</code>s.
@@ -1180,7 +1188,7 @@ module Irc
# Create a new Netmask object with the appropriate casemap
#
def new_netmask(str)
- if str.class <= Netmask
+ if str.kind_of?(Netmask )
raise "Wrong casemap for Netmask #{str.inspect}" if str.casemap != self.casemap
return str
end
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 43793e99..42ff2aaa 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -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
diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb
index 7832f998..8a83ec88 100644
--- a/lib/rbot/rfc2812.rb
+++ b/lib/rbot/rfc2812.rb
@@ -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)