class Irc::User

An IRC User is identified by his/her Netmask (which must not have globs). In fact, User is just a subclass of Netmask.

Ideally, the user and host information of an IRC User should never change, and it shouldn’t contain glob patterns. However, IRC is somewhat idiosincratic and it may be possible to know the nick of a User much before its user and host are known. Moreover, some networks (namely Freenode) may change the hostname of a User when (s)he identifies with Nickserv.

As a consequence, we must allow changes to a User host and user attributes. We impose a restriction, though: they may not contain glob patterns, except for the special case of an unknown user/host which is represented by a *.

It is possible to create a totally unknown User (e.g. for initializations) by setting the nick to * too.

TODO list:

Attributes

idle_since[RW]
real_name[RW]
signon[RW]

Public Class Methods

new(str="", opts={}) click to toggle source

Create a new IRC User from a given Netmask (or anything that can be converted into a Netmask) provided that the given Netmask does not have globs.

Calls superclass method Irc::Netmask::new
# File lib/rbot/irc.rb, line 960
def initialize(str="", opts={})
  super
  raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if nick.has_irc_glob? && nick != "*"
  raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if user.has_irc_glob? && user != "*"
  raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if host.has_irc_glob? && host != "*"
  @away = false
  @real_name = String.new
  @idle_since = nil
  @signon = nil
end

Public Instance Methods

away=(msg="") click to toggle source

Set the away status of the user. Use away=(nil) or away=(false) to unset away

# File lib/rbot/irc.rb, line 1011
def away=(msg="")
  if msg
    @away = msg
  else
    @away = false
  end
end
away?() click to toggle source

Is the user away?

# File lib/rbot/irc.rb, line 1004
def away?
  return @away
end
botuser() click to toggle source

A convenience method to automatically found the botuser associated with the receiver

# File lib/rbot/botuser.rb, line 936
def botuser
  Irc::Bot::Auth.manager.irc_to_botuser(self)
end
channels() click to toggle source
# File lib/rbot/irc.rb, line 1075
def channels
  if @server
    @server.channels.select { |ch| ch.has_user?(self) }
  else
    Array.new
  end
end
host=(newhost) click to toggle source

We have to allow changing the host of an Irc User due to some networks (e.g. Freenode) changing hostmasks on the fly. We still check if the new host data has glob patterns though.

Calls superclass method Irc::Netmask#host=
# File lib/rbot/irc.rb, line 991
def host=(newhost)
  raise "Can't change the hostname to #{newhost}" if defined?(@host) and newhost.has_irc_glob?
  super
end
is_op?(channel) click to toggle source
# File lib/rbot/irc.rb, line 1055
def is_op?(channel)
  case channel
  when Channel
    channel.has_op?(self)
  else
    return @server.channel(channel).has_op?(self) if @server
    raise "Can't resolve channel #{channel}"
  end
end
is_voice?(channel) click to toggle source
# File lib/rbot/irc.rb, line 1065
def is_voice?(channel)
  case channel
  when Channel
    channel.has_voice?(self)
  else
    return @server.channel(channel).has_voice?(self) if @server
    raise "Can't resolve channel #{channel}"
  end
end
known?() click to toggle source

Checks if a User is well-known or not by looking at the hostname and user

# File lib/rbot/irc.rb, line 998
def known?
  return nick != "*" && user != "*" && host != "*"
end
modes_on(channel) click to toggle source
# File lib/rbot/irc.rb, line 1045
def modes_on(channel)
  case channel
  when Channel
    channel.modes_of(self)
  else
    return @server.channel(channel).modes_of(self) if @server
    raise "Can't resolve channel #{channel}"
  end
end
nick=(newnick) click to toggle source

The nick of a User may be changed freely, but it must not contain glob patterns.

Calls superclass method Irc::Netmask#nick=
# File lib/rbot/irc.rb, line 973
def nick=(newnick)
  raise "Can't change the nick to #{newnick}" if defined?(@nick) and newnick.has_irc_glob?
  super
end
replace(other) click to toggle source

We can replace everything at once with data from another User

# File lib/rbot/irc.rb, line 1031
def replace(other)
  case other
  when User
    self.nick = other.nick
    self.user = other.user
    self.host = other.host
    @server = other.server
    @casemap = other.casemap unless @server
    @away = other.away?
  else
    self.replace(other.to_irc_user(server_and_casemap))
  end
end
to_irc_user(opts={}) click to toggle source

Since to_irc_user runs the same checks on server and channel as to_irc_netmask, we just try that and return self if it works.

Subclasses of User will return self if possible.

# File lib/rbot/irc.rb, line 1024
def to_irc_user(opts={})
  return self if fits_with_server_and_casemap?(opts)
  return self.full_downcase.to_irc_user(opts)
end
user=(newuser) click to toggle source

We have to allow changing the user of an Irc User due to some networks (e.g. Freenode) changing hostmasks on the fly. We still check if the new user data has glob patterns though.

Calls superclass method Irc::Netmask#user=
# File lib/rbot/irc.rb, line 982
def user=(newuser)
  raise "Can't change the username to #{newuser}" if defined?(@user) and newuser.has_irc_glob?
  super
end