# 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
# 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
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
\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
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
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
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
# 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)
# 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)
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)
# 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
#\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
@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
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
\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
# 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
#\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
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
# 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
# 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]
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
# 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
}
# 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
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)