Module: Fargo::Supports::NickList

Extended by:
ActiveSupport::Concern
Included in:
Client
Defined in:
lib/fargo/supports/nick_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nicksObject

Returns the value of attribute nicks.



10
11
12
# File 'lib/fargo/supports/nick_list.rb', line 10

def nicks
  @nicks
end

Instance Method Details

#get_info(nick) ⇒ Object



12
13
14
# File 'lib/fargo/supports/nick_list.rb', line 12

def get_info nick
  hub.send_message 'GetINFO', "#{nick} #{config.nick}"
end

#get_ip(*nicks) ⇒ Object



16
17
18
# File 'lib/fargo/supports/nick_list.rb', line 16

def get_ip *nicks
  hub.send_message 'UserIP', nicks.flatten.join('$$')
end

#info(nick) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fargo/supports/nick_list.rb', line 20

def info nick
  if @nick_info.has_key?(nick) || !connected? || !@nicks.include?(nick)
    return @nick_info[nick]
  end

  # If we're connected and we don't already have this user's info, ask the
  # server. We'll wait for 5 second to respond, otherwise we'll just
  # return nil and be done with it
  info_gotten = lambda{ |type, map|
    type == :myinfo && map[:nick].to_s == nick.to_s
  }
  timeout_response(5, info_gotten){ get_info nick }

  @nick_info[nick]
end

#nick_has_slot?(nick) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fargo/supports/nick_list.rb', line 36

def nick_has_slot? nick
  # This query must be up to date so remove any cached information we have
  # about the nick so we can get a fresh copy
  @nick_info.try :delete, nick
  info = info nick

  return false if info.nil?
  return true  if info[:interest].nil?

  match = info[:interest].match /.*?<.*S:(\d+).*>/
  return true if match.nil?

  Fargo.logger.debug "#{self} User: #{nick} has #{match[1]} open slots"
  match[1].to_i > 0
end