\r
require 'singleton'\r
\r
+class Object\r
+\r
+ # We extend the Object class with a method that\r
+ # checks if the receiver is nil or empty\r
+ def nil_or_empty?\r
+ return true unless self\r
+ return true if self.respond_to? :empty and self.empty?\r
+ return false\r
+ end\r
+end\r
\r
# The Irc module is used to keep all IRC-related classes\r
# in the same namespace\r
# Checks if the receiver already has a channel with the given _name_\r
#\r
def has_channel?(name)\r
+ return false if name.nil_or_empty?\r
channel_names.index(name.irc_downcase(casemap))\r
end\r
alias :has_chan? :has_channel?\r
# Returns the channel with name _name_, if available\r
#\r
def get_channel(name)\r
+ return nil if name.nil_or_empty?\r
idx = has_channel?(name)\r
channels[idx] if idx\r
end\r
# Create a new Channel object bound to the receiver and add it to the\r
# list of <code>Channel</code>s on the receiver, unless the channel was\r
# present already. In this case, the default action is to raise an\r
- # exception, unless _fails_ is set to false\r
+ # exception, unless _fails_ is set to false. An exception can also be\r
+ # raised if _str_ is nil or empty, again only if _fails_ is set to true;\r
+ # otherwise, the method just returns nil\r
#\r
def new_channel(name, topic=nil, users=[], fails=true)\r
+ if name.nil_or_empty?\r
+ raise "Tried to look for empty or nil channel name #{name.inspect}" if fails\r
+ return nil\r
+ end\r
ex = get_chan(name)\r
if ex\r
raise "Channel #{name} already exists on server #{self}" if fails\r
# Checks if the receiver already has a user with the given _nick_\r
#\r
def has_user?(nick)\r
+ return false if nick.nil_or_empty?\r
user_nicks.index(nick.irc_downcase(casemap))\r
end\r
\r
# Create a new User object bound to the receiver and add it to the list\r
# of <code>User</code>s on the receiver, unless the User was present\r
# already. In this case, the default action is to raise an exception,\r
- # unless _fails_ is set to false\r
+ # unless _fails_ is set to false. An exception can also be raised\r
+ # if _str_ is nil or empty, again only if _fails_ is set to true;\r
+ # otherwise, the method just returns nil\r
#\r
def new_user(str, fails=true)\r
+ if str.nil_or_empty?\r
+ raise "Tried to look for empty or nil user name #{str.inspect}" if fails\r
+ return nil\r
+ end\r
tmp = str.to_irc_user(:server => self)\r
old = get_user(tmp.nick)\r
# debug "Tmp: #{tmp.inspect}"\r