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.



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

def nicks
  @nicks
end

Instance Method Details

#get_info(nick) ⇒ Object



14
15
16
# File 'lib/fargo/supports/nick_list.rb', line 14

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

#get_ip(*nicks) ⇒ Object



18
19
20
# File 'lib/fargo/supports/nick_list.rb', line 18

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

#info(nick) ⇒ Object



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

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

This query must be up to date so remove any cached information we have about the nick so we can get a fresh copy

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fargo/supports/nick_list.rb', line 40

def nick_has_slot? nick
  if @search_result_slots[nick] &&
      @search_result_slots[nick][:updated_at] + 10.minutes > Time.now
    return @search_result_slots[nick][:slots] > 0
  end

  @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