Parent

Included Modules

Cinch::User

Attributes

authname[R]

@return [String]

bot[R]

@return [Bot]

channels[R]

@return [Array<Channel>] All channels the user is in.

data[R]

By default, you can use methods like User#user, User#host and alike – If you however fear that another thread might change data while you're using it and if this means a critical issue to your code, you can store a clone of the result of this method and work with that instead.

@example

on :channel do |m|
  data = m.user.data.dup
  do_something_with(data.user)
  do_something_with(data.host)
end

@return [Hash]

host[R]

@return [String]

idle[R]

@return [Number] How long this user has been idle, in seconds.

This is a snapshot of the last WHOIS.
in_whois[RW]

@return [Boolean]

last_nick[R]

@return [String]

nick[R]

@return [String]

realname[R]

@return [String]

secure[R]

@return [Boolean] True if the user is using a secure connection, i.e. SSL.

secure?[R]

@return [Boolean] True if the user is using a secure connection, i.e. SSL.

signed_on_at[R]

@return [Time]

synced[R]

@return [Boolean]

unknown[R]

@return [Boolean] True if the instance references an user who

cannot be found on the server.
unknown?[R]

@return [Boolean] True if the instance references an user who

cannot be found on the server.
user[R]

@return [String]

Public Class Methods

all() click to toggle source

@return [Array<User>] Returns all users @deprecated See {Bot#user_manager} and {CacheManager#each} instead @note This method does not work properly if running more than one bot @note This method will be removed in Cinch 2.0.0

# File lib/cinch/user.rb, line 67
def all
  $stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.all should not be used anymore."
  puts caller

  @users.values
end
find(nick) click to toggle source

Finds a user.

@param [String] nick nick of a user @return [User, nil] @deprecated See {Bot#user_manager} and {UserManager#find} instead @note This method does not work properly if running more than one bot @note This method will be removed in Cinch 2.0.0

# File lib/cinch/user.rb, line 56
def find(nick)
  $stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.find should not be used anymore."
  puts caller

  @users[downcased_nick]
end
find_ensured(*args) click to toggle source

@overload find_ensured(nick, bot)

Finds or creates a user based on his nick.

@param [String] nick The user's nickname
@param [Bot]    bot  An instance of Bot

@overload find_ensured(user, nick, host, bot)

Finds or creates a user based on his nick but already
setting user and host.

@param [String] user The username
@param [String] nick The nickname
@param [String] host The user's hostname
@param [Bot]    bot  An instance of bot

@return [User] @deprecated See {Bot#user_manager} and {UserManager#find_ensured} instead @note This method does not work properly if running more than one bot @note This method will be removed in Cinch 2.0.0

# File lib/cinch/user.rb, line 26
def find_ensured(*args)
  $stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.find_ensured should not be used anymore."
  puts caller

  case args.size
  when 2
    nick = args.first
    bot  = args.last
    bargs = [nick]
  when 4
    nick = args[1]
    bot  = args.pop
    bargs = args
  else
    raise ArgumentError
  end
  downcased_nick = nick.irc_downcase(bot.irc.isupport["CASEMAPPING"])
  @users[downcased_nick] = args.last.user_manager.find_ensured(*args[0..-2])
  # note: the complete case statement and the assignment to
  #   @users is only for keeping compatibility with older
  #   versions, which still use User.find and User.all.
end
new(*args) click to toggle source
# File lib/cinch/user.rb, line 151
def initialize(*args)
  @data = {
    :user         => nil,
    :host         => nil,
    :realname     => nil,
    :authname     => nil,
    :idle         => 0,
    :signed_on_at => nil,
    :unknown?     => false,
    :channels     => [],
    :secure?      => false,
  }
  case args.size
  when 2
    @nick, @bot = args
  when 4
    @data[:user], @nick, @data[:host], @bot = args
  else
    raise ArgumentError
  end

  @synced_attributes  = Set.new

  @when_requesting_synced_attribute = lambda {|attr|
    unless @synced
      @data[:unknown?] = false
      unsync :unknown?

      unsync attr
      whois
    end
  }
end

Public Instance Methods

==(other) click to toggle source

@return [Boolean]

# File lib/cinch/user.rb, line 423
def ==(other)
  return case other
         when self.class
           @nick == other.nick
         when String
           self.to_s == other
         when Bot
           self.nick == other.config.nick
         else
           false
         end
end
action(message) click to toggle source

Send an action (/me) to the user.

@param [String] message the message @return [void] @see safe_action

# File lib/cinch/user.rb, line 332
def action(message)
  @bot.action(@name, message)
end
attr(attribute, data = true, unsync = false) click to toggle source

@see Syncable#attr

# File lib/cinch/user.rb, line 194
def attr(attribute, data = true, unsync = false)
  super
end
authed?() click to toggle source

Checks if the user is identified. Currently officially supports Quakenet and Freenode.

@return [Boolean] true if the user is identified

# File lib/cinch/user.rb, line 189
def authed?
  !attr(:authname).nil?
end
ctcp(message) click to toggle source

Send a CTCP to the user.

@param [String] message the ctcp message @return [void]

# File lib/cinch/user.rb, line 323
def ctcp(message)
  send "\0001#{message}\0001"
end
end_of_whois(values, not_found = false) click to toggle source

@param [Hash, nil] values A hash of values gathered from WHOIS,

or `nil` if no data was returned

@param [Boolean] not_found Has to be true if WHOIS resulted in

an unknown user

@return [void] @api private @since 1.0.1

# File lib/cinch/user.rb, line 222
def end_of_whois(values, not_found = false)
  @in_whois = false
  if not_found
    sync(:unknown?, true, true)
    sync(:idle, 0, true)
    sync(:channels, [], true)

    fields = @data.keys
    fields.delete(:unknown?)
    fields.delete(:idle)
    fields.delete(:channels)
    fields.each do |field|
      sync(field, nil, true)
    end

    return
  end

  if values.nil?
    # for some reason, we did not receive user information. one
    # reason is freenode throttling WHOIS
    Thread.new do
      sleep 2
      whois
    end
    return
  end

  {
    :authname => nil,
    :idle => 0,
    :secure? => false,
  }.merge(values).each do |attr, value|
    sync(attr, value, true)
  end

  sync(:unknown?, false, true)
  @synced = true
end
hash() click to toggle source

@return [Fixnum]

# File lib/cinch/user.rb, line 438
def hash
  @nick.hash
end
inspect() click to toggle source

@return [String]

# File lib/cinch/user.rb, line 360
def inspect
  "#<User nick=#{@nick.inspect}>"
end
mask(s = "%n!%u@%h") click to toggle source

Generates a mask for the user.

@param [String] s a pattern for generating the mask.

- %n = nickname
- %u = username
- %h = host
- %r = realname
- %a = authname

@return [Mask]

# File lib/cinch/user.rb, line 375
def mask(s = "%n!%u@%h")
  s = s.gsub(/%(.)/) {
    case $1
    when "n"
      @nick
    when "u"
      self.user
    when "h"
      self.host
    when "r"
      self.realname
    when "a"
      self.authname
    end
  }

  Mask.new(s)
end
method_missing(m, *args) click to toggle source

Provides synced access to user attributes.

# File lib/cinch/user.rb, line 401
def method_missing(m, *args)
  if m.to_s =~ /^(.+)_unsynced$/
    m = $1.to_sym
    unsync = true
  end

  if @data.has_key?(m)
    attr(m, true, unsync = false)
  else
    super
  end
end
msg(message) click to toggle source
Alias for: send
notice(message) click to toggle source

Send a notice to the user.

@param [String] message the message @return [void]

# File lib/cinch/user.rb, line 287
def notice(message)
  @bot.notice(@nick, message)
end
privmsg(message) click to toggle source
Alias for: send
refresh() click to toggle source
Alias for: whois
respond_to?(m) click to toggle source
# File lib/cinch/user.rb, line 414
def respond_to?(m)
  if m.to_s =~ /^(.+)_unsynced$/
    m = $1.to_sym
  end

  return @data.has_key?(m) || super
end
safe_action(message) click to toggle source

Send an action (/me) to the user but remove any non-printable characters. The purpose of this method is to send text from untrusted sources, like other users or feeds.

Note: this will *break* any mIRC color codes embedded in the string.

@param (see action) @return (see action) @see action @see Bot#safe_action @todo Handle mIRC color codes more gracefully.

# File lib/cinch/user.rb, line 348
def safe_action(message)
  @bot.safe_action(@name, message)
end
safe_msg(message) click to toggle source
Alias for: safe_send
safe_notice(message) click to toggle source

Like {safe_send} but for notices.

@param (see safe_send) @return (see safe_send) @see safe_send @todo (see safe_send)

# File lib/cinch/user.rb, line 297
def safe_notice(message)
  @bot.safe_notice(@nick, message)
end
safe_privmsg(message) click to toggle source
Alias for: safe_send
safe_send(message) click to toggle source

Send a message to the user, but remove any non-printable characters. The purpose of this method is to send text from untrusted sources, like other users or feeds.

Note: this will *break* any mIRC color codes embedded in the string.

@param (see send) @return (see send) @see send @see Bot#safe_msg @todo Handle mIRC color codes more gracefully.

# File lib/cinch/user.rb, line 313
def safe_send(message)
  @bot.safe_msg(@nick, message)
end
Also aliased as: safe_privmsg, safe_msg
send(message) click to toggle source

Send a message to the user.

@param [String] message the message @return [void]

# File lib/cinch/user.rb, line 277
def send(message)
  @bot.msg(@nick, message)
end
Also aliased as: privmsg, msg
to_s() click to toggle source

@return [String]

# File lib/cinch/user.rb, line 355
def to_s
  @nick
end
unsync_all() click to toggle source

@return [void] @since 1.0.1 @api private @see Syncable#unsync_all

# File lib/cinch/user.rb, line 266
def unsync_all
  @synced = false
  super
end
update_nick(new_nick) click to toggle source

@api private

# File lib/cinch/user.rb, line 395
def update_nick(new_nick)
  @last_nick, @nick = @nick, new_nick
  @bot.user_manager.update_nick(self)
end
whois() click to toggle source

Queries the IRC server for information on the user. This will set the User's state to not synced. After all information are received, the object will be set back to synced.

@return [void]

# File lib/cinch/user.rb, line 203
def whois
  return if @in_whois
  @synced = false
  @data.keys.each do |attr|
    unsync attr
  end

  @in_whois = true
  @bot.raw "WHOIS #@nick #@nick"
end
Also aliased as: refresh

[Validate]

Generated with the Darkfish Rdoc Generator 2.